Пример #1
0
 def _OH_RejectOperation(self, operation):
     if self.state != 'incoming':
         return
     reason = jingle.Reason(jingle.ReasonType(operation.reason))
     stanza = self._protocol.sessionTerminate(self._local_jid, self._remote_jid, self._id, reason)
     self._send_stanza(stanza)
     self.state = 'terminated'
     self._channel.send_exception(proc.ProcExit)
Пример #2
0
 def _fail(self, originator='local', reason='general-error', description=None):
     reason = jingle.Reason(jingle.ReasonType(reason), text=description)
     stanza = self._protocol.sessionTerminate(self._local_jid, self._remote_jid, self._id, reason)
     self._send_stanza(stanza)
     self.state = 'terminated'
     failure_str = '%s%s' % (reason, ' %s' % description if description else '')
     NotificationCenter().post_notification('JingleSessionDidFail', sender=self, data=NotificationData(originator='local', reason=failure_str))
     self._channel.send_exception(proc.ProcExit)
Пример #3
0
    def _OH_EndOperation(self, operation):
        if self.state not in ('connecting', 'connected'):
            return

        if self._timer is not None and self._timer.active():
            self._timer.cancel()
        self._timer = None

        prev_state = self.state
        self.state = 'terminating'
        notification_center = NotificationCenter()
        notification_center.post_notification('JingleSessionWillEnd', self)

        streams = (self.streams or []) + (self.proposed_streams or [])
        for stream in streams[:]:
            try:
                notification_center.remove_observer(self, sender=stream)
            except KeyError:
                streams.remove(stream)
            else:
                stream.deactivate()

        if prev_state == 'connected':
            reason = jingle.Reason(jingle.ReasonType('success'))
        else:
            reason = jingle.Reason(jingle.ReasonType('cancel'))
        stanza = self._protocol.sessionTerminate(self._local_jid,
                                                 self._remote_jid, self._id,
                                                 reason)
        self._send_stanza(stanza)

        self.state = 'terminated'
        if prev_state == 'connected':
            self.end_time = datetime.now()
            notification_center.post_notification(
                'JingleSessionDidEnd', self,
                NotificationData(originator='local'))
        else:
            notification_center.post_notification(
                'JingleSessionDidFail', self,
                NotificationData(originator='local', reason='cancel'))

        for stream in streams:
            stream.end()
        self._channel.send_exception(proc.ProcExit)