Ejemplo n.º 1
0
    async def join_channel(self,
                           channel: JID,
                           nick: str,
                           subscribe: Optional[Set[str]] = None,
                           *,
                           ifrom: Optional[JID] = None,
                           **iqkwargs) -> Set[str]:
        """
        Join a MIX channel.

        :param JID channel: JID of the MIX channel
        :param str nick: Desired nickname on that channel
        :param Set[str] subscribe: Set of notes to subscribe to when joining.
            If empty, all nodes will be subscribed by default.

        :rtype: Set[str]
        :return: The nodes that failed to subscribe, if any
        """
        if not subscribe:
            subscribe = set(BASE_NODES)
        iq = self.xmpp.make_iq_set(ito=channel, ifrom=ifrom)
        iq['mix_join']['nick'] = nick
        for node in subscribe:
            sub = stanza.Subscribe()
            sub['node'] = node
            iq['mix_join']['subscribe'].append(sub)
        result = await iq.send(**iqkwargs)
        result_nodes = {sub['node'] for sub in result['mix_join']}
        return result_nodes.difference(subscribe)
Ejemplo n.º 2
0
    def testMIXUpdateSub(self):
        iq = Iq()
        iq['type'] = 'set'
        iq.enable('mix_updatesub')
        sub = stanza.Subscribe()
        sub['node'] = 'urn:xmpp:mix:nodes:someothernode'
        iq['mix_updatesub'].append(sub)

        self.check(iq, """
          <iq type="set">
              <update-subscription xmlns='urn:xmpp:mix:core:1'>
                  <subscribe node='urn:xmpp:mix:nodes:someothernode'/>
              </update-subscription>
          </iq>
        """)
Ejemplo n.º 3
0
    def testMIXJoin(self):
        """Test that data is converted to base64"""
        iq = Iq()
        iq['type'] = 'set'
        for node in BASE_NODES:
            sub = stanza.Subscribe()
            sub['node'] = node
            iq['mix_join'].append(sub)
        iq['mix_join']['nick'] = 'Toto'

        self.check(iq, """
          <iq type="set">
              <join xmlns='urn:xmpp:mix:core:1'>
                  <subscribe node='urn:xmpp:mix:nodes:messages'/>
                  <subscribe node='urn:xmpp:mix:nodes:participants'/>
                  <subscribe node='urn:xmpp:mix:nodes:info'/>
                  <nick>Toto</nick>
              </join>
          </iq>
        """)
Ejemplo n.º 4
0
    async def update_subscription(self,
                                  channel: JID,
                                  subscribe: Optional[Set[str]] = None,
                                  unsubscribe: Optional[Set[str]] = None,
                                  *,
                                  ifrom: Optional[JID] = None,
                                  **iqkwargs) -> Tuple[Set[str], Set[str]]:
        """
        Update a MIX channel subscription.

        :param JID channel: JID of the MIX channel
        :param Set[str] subscribe: Set of notes to subscribe to additionally.
        :param Set[str] unsubscribe: Set of notes to unsubscribe from.
        :rtype: Tuple[Set[str], Set[str]]
        :return: A tuple containing the set of nodes that failed to subscribe
            and the set of nodes that failed to unsubscribe.
        """
        if not subscribe and not unsubscribe:
            raise ValueError("No nodes were provided.")
        unsubscribe = unsubscribe or set()
        subscribe = subscribe or set()
        iq = self.xmpp.make_iq_set(ito=channel, ifrom=ifrom)
        iq.enable('mix_updatesub')
        for node in subscribe:
            sub = stanza.Subscribe()
            sub['node'] = node
            iq['mix_updatesub'].append(sub)
        for node in unsubscribe:
            unsub = stanza.Unsubscribe()
            unsub['node'] = node
            iq['mix_updatesub'].append(unsub)
        result = await iq.send(**iqkwargs)
        for item in result['mix_updatesub']:
            if isinstance(item, stanza.Subscribe):
                subscribe.discard(item['node'])
            elif isinstance(item, stanza.Unsubscribe):
                unsubscribe.discard(item['node'])
        return (subscribe, unsubscribe)
Ejemplo n.º 5
0
    def testMIXPAMJoin(self):
        """Test that data is converted to base64"""
        iq = Iq()
        iq['type'] = 'set'
        iq['client_join']['channel'] = JID('*****@*****.**')
        for node in BASE_NODES:
            sub = mstanza.Subscribe()
            sub['node'] = node
            iq['client_join']['mix_join'].append(sub)
        iq['client_join']['mix_join']['nick'] = 'Toto'

        self.check(
            iq, """
          <iq type="set">
              <client-join xmlns='urn:xmpp:mix:pam:2' channel='*****@*****.**'>
                  <join xmlns='urn:xmpp:mix:core:1'>
                      <subscribe node='urn:xmpp:mix:nodes:messages'/>
                      <subscribe node='urn:xmpp:mix:nodes:participants'/>
                      <subscribe node='urn:xmpp:mix:nodes:info'/>
                      <nick>Toto</nick>
                  </join>
              </client-join>
          </iq>
        """)