示例#1
0
 def end(self):
     if self.ended:
         return
     notification_center = NotificationCenter()
     if self._xmpp_muc_session is not None:
         notification_center.remove_observer(self,
                                             sender=self._xmpp_muc_session)
         # Send indication that the user has been kicked from the room
         sender = Identity(
             FrozenURI(self.sip_identity.uri.user,
                       self.sip_identity.uri.host, self.nickname))
         stanza = MUCAvailabilityPresence(sender,
                                          self.xmpp_identity,
                                          available=False)
         stanza.jid = self.xmpp_identity
         stanza.muc_statuses.append('307')
         xmpp_manager = XMPPManager()
         xmpp_manager.send_muc_stanza(stanza)
         self._xmpp_muc_session.end()
         self._xmpp_muc_session = None
     if self._sip_session is not None:
         notification_center.remove_observer(self, sender=self._sip_session)
         self._sip_session.end()
         self._sip_session = None
     self.ended = True
     notification_center.post_notification('X2SMucHandlerDidEnd',
                                           sender=self)
示例#2
0
 def _NH_ChatStreamDidDeliverMessage(self, notification):
     # Echo back the message to the sender
     stanza = self._pending_messages_map.pop(notification.data.message_id)
     stanza.sender, stanza.recipient = stanza.recipient, stanza.sender
     stanza.sender.uri = FrozenURI(stanza.sender.uri.user,
                                   stanza.sender.uri.host, self.nickname)
     xmpp_manager = XMPPManager()
     xmpp_manager.send_muc_stanza(stanza)
示例#3
0
 def _NH_ChatStreamDidNotSetNickname(self, notification):
     # Notification is sent by the MSRP stream
     nickname, stanza = self._pending_nicknames_map.pop(
         notification.data.message_id)
     error_stanza = MUCErrorPresence.from_stanza(stanza, 'cancel',
                                                 [('conflict', STANZAS_NS)])
     xmpp_manager = XMPPManager()
     xmpp_manager.send_muc_stanza(error_stanza)
示例#4
0
class XMPPIncomingMucSession(object):
    local_identity = WriteOnceAttribute()
    remote_identity = WriteOnceAttribute()

    def __init__(self, local_identity, remote_identity):
        self.local_identity = local_identity
        self.remote_identity = remote_identity
        self.state = None
        self.channel = coros.queue()
        self._proc = None
        from sylk.applications.xmppgateway.xmpp import XMPPManager

        self.xmpp_manager = XMPPManager()

    def start(self):
        NotificationCenter().post_notification("XMPPIncomingMucSessionDidStart", sender=self)
        self._proc = proc.spawn(self._run)
        self.state = "started"

    def end(self):
        self._proc.kill()
        self._proc = None
        NotificationCenter().post_notification(
            "XMPPIncomingMucSessionDidEnd", sender=self, data=NotificationData(originator="local")
        )
        self.state = "terminated"

    def send_message(self, sender, body, html_body, message_id=None):
        # TODO: timestamp?
        message = GroupChatMessage(sender, self.remote_identity, body, html_body, id=message_id)
        self.xmpp_manager.send_muc_stanza(message)

    def _run(self):
        notification_center = NotificationCenter()
        while True:
            item = self.channel.wait()
            if isinstance(item, GroupChatMessage):
                notification_center.post_notification(
                    "XMPPIncomingMucSessionGotMessage", sender=self, data=NotificationData(message=item)
                )
            elif isinstance(item, MUCAvailabilityPresence):
                if item.available:
                    nickname = item.recipient.uri.resource
                    notification_center.post_notification(
                        "XMPPIncomingMucSessionChangedNickname",
                        sender=self,
                        data=NotificationData(stanza=item, nickname=nickname),
                    )
                else:
                    notification_center.post_notification(
                        "XMPPIncomingMucSessionDidEnd", sender=self, data=NotificationData(originator="local")
                    )
                    self.state = "terminated"
                    break
        self._proc = None
示例#5
0
 def start(self):
     notification_center = NotificationCenter()
     notification_center.add_observer(self, sender=self.session)
     stanza = OutgoingInvitationMessage(self.sender,
                                        self.recipient,
                                        self.inviter,
                                        id='MUC.' + uuid.uuid4().hex)
     xmpp_manager = XMPPManager()
     xmpp_manager.send_muc_stanza(stanza)
     self._timer = reactor.callLater(90, self._timeout)
     notification_center.post_notification(
         'S2XMucInvitationHandlerDidStart', sender=self)
示例#6
0
class XMPPIncomingMucSession(object):
    local_identity = WriteOnceAttribute()
    remote_identity = WriteOnceAttribute()

    def __init__(self, local_identity, remote_identity):
        self.local_identity = local_identity
        self.remote_identity = remote_identity
        self.state = None
        self.channel = coros.queue()
        self._proc = None
        from sylk.applications.xmppgateway.xmpp import XMPPManager
        self.xmpp_manager = XMPPManager()

    def start(self):
        NotificationCenter().post_notification('XMPPIncomingMucSessionDidStart', sender=self)
        self._proc = proc.spawn(self._run)
        self.state = 'started'

    def end(self):
        self._proc.kill()
        self._proc = None
        NotificationCenter().post_notification('XMPPIncomingMucSessionDidEnd', sender=self, data=NotificationData(originator='local'))
        self.state = 'terminated'

    def send_message(self, sender, body, html_body, message_id=None):
        # TODO: timestamp?
        message = GroupChatMessage(sender, self.remote_identity, body, html_body, id=message_id)
        self.xmpp_manager.send_muc_stanza(message)

    def _run(self):
        notification_center = NotificationCenter()
        while True:
            item = self.channel.wait()
            if isinstance(item, GroupChatMessage):
                notification_center.post_notification('XMPPIncomingMucSessionGotMessage', sender=self, data=NotificationData(message=item))
            elif isinstance(item, GroupChatSubject):
                notification_center.post_notification('XMPPIncomingMucSessionSubject', sender=self, data=NotificationData(message=item))
            elif isinstance(item, MUCAvailabilityPresence):
                if item.available:
                    nickname = item.recipient.uri.resource
                    notification_center.post_notification('XMPPIncomingMucSessionChangedNickname', sender=self, data=NotificationData(stanza=item, nickname=nickname))
                else:
                    notification_center.post_notification('XMPPIncomingMucSessionDidEnd', sender=self, data=NotificationData(originator='local'))
                    self.state = 'terminated'
                    break
        self._proc = None
示例#7
0
 def _NH_SIPSessionGotConferenceInfo(self, notification):
     # Translate to XMPP payload
     xmpp_manager = XMPPManager()
     own_uri = FrozenURI(self.xmpp_identity.uri.user,
                         self.xmpp_identity.uri.host)
     conference_info = notification.data.conference_info
     new_participants = set()
     for user in conference_info.users:
         user_uri = FrozenURI.parse(user.entity if user.entity.startswith((
             'sip:', 'sips:')) else 'sip:' + user.entity)
         nickname = user.display_text.value if user.display_text else user.entity
         new_participants.add((user_uri, nickname))
     # Remove participants that are no longer in the room
     for uri, nickname in self._participants - new_participants:
         sender = Identity(
             FrozenURI(self.sip_identity.uri.user,
                       self.sip_identity.uri.host, nickname))
         stanza = MUCAvailabilityPresence(sender,
                                          self.xmpp_identity,
                                          available=False)
         xmpp_manager.send_muc_stanza(stanza)
     # Send presence for current participants
     for uri, nickname in new_participants:
         if uri == own_uri:
             continue
         sender = Identity(
             FrozenURI(self.sip_identity.uri.user,
                       self.sip_identity.uri.host, nickname))
         stanza = MUCAvailabilityPresence(sender,
                                          self.xmpp_identity,
                                          available=True)
         stanza.jid = Identity(uri)
         xmpp_manager.send_muc_stanza(stanza)
     self._participants = new_participants
     # Send own status last
     sender = Identity(
         FrozenURI(self.sip_identity.uri.user, self.sip_identity.uri.host,
                   self.nickname))
     stanza = MUCAvailabilityPresence(sender,
                                      self.xmpp_identity,
                                      available=True)
     stanza.jid = self.xmpp_identity
     stanza.muc_statuses.append('110')
     xmpp_manager.send_muc_stanza(stanza)