summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slixmpp/plugins/__init__.py1
-rw-r--r--slixmpp/plugins/xep_0405/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0405/mix_pam.py88
-rw-r--r--slixmpp/plugins/xep_0405/stanza.py43
4 files changed, 145 insertions, 0 deletions
diff --git a/slixmpp/plugins/__init__.py b/slixmpp/plugins/__init__.py
index 3526a2a8..ab8f336d 100644
--- a/slixmpp/plugins/__init__.py
+++ b/slixmpp/plugins/__init__.py
@@ -87,6 +87,7 @@ __all__ = [
'xep_0332', # HTTP Over XMPP Transport
'xep_0369', # MIX-CORE
'xep_0377', # Spam reporting
+ 'xep_0405', # MIX-PAM
'xep_0421', # Anonymous unique occupant identifiers for MUCs
'xep_0444', # Message Reactions
]
diff --git a/slixmpp/plugins/xep_0405/__init__.py b/slixmpp/plugins/xep_0405/__init__.py
new file mode 100644
index 00000000..0a877682
--- /dev/null
+++ b/slixmpp/plugins/xep_0405/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0405.stanza import *
+from slixmpp.plugins.xep_0405.mix_pam import XEP_0405
+
+register_plugin(XEP_0405)
diff --git a/slixmpp/plugins/xep_0405/mix_pam.py b/slixmpp/plugins/xep_0405/mix_pam.py
new file mode 100644
index 00000000..cff22b51
--- /dev/null
+++ b/slixmpp/plugins/xep_0405/mix_pam.py
@@ -0,0 +1,88 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from typing import (
+ Optional,
+ Set,
+)
+
+from slixmpp import JID, Iq
+from slixmpp.exceptions import IqError, IqTimeout
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0405 import stanza
+from slixmpp.plugins.xep_0369 import stanza as mix_stanza
+
+
+BASE_NODES = [
+ 'urn:xmpp:mix:nodes:messages',
+ 'urn:xmpp:mix:nodes:participants',
+ 'urn:xmpp:mix:nodes:info',
+]
+
+
+class XEP_0405(BasePlugin):
+ '''XEP-0405: MIX-PAM'''
+
+ name = 'xep_0405'
+ description = 'MIX-PAM'
+ dependencies = {'xep_0369'}
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
+
+ async def check_server_capability(self) -> bool:
+ """Check if the server is MIX-PAM capable"""
+ result = await self.xmpp.plugin['xep_0030'].get_info(jid=self.xmpp.boundjid.bare)
+ features = result['disco_info']['features']
+ return stanza.NS in features
+
+ async def join_channel(self, room: JID, nick: str, subscribe: Optional[Set[str]] = None, *,
+ ito: Optional[JID] = None,
+ ifrom: Optional[JID] = None,
+ **iqkwargs) -> Set[str]:
+ """
+ Join a MIX channel.
+
+ :param JID room: JID of the MIX channel
+ :param str nick: Desired nickname on that channel
+ :param Set[str] subscribe: Set of nodes 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 subscribe is None:
+ subscribe = set(BASE_NODES)
+ if ito is None:
+ ito = self.xmpp.boundjid.bare
+ iq = self.xmpp.make_iq_set(ito=ito, ifrom=ifrom)
+ iq['client_join']['channel'] = room
+ iq['client_join']['mix_join']['nick'] = nick
+ for node in subscribe:
+ sub = mix_stanza.Subscribe()
+ sub['node'] = node
+ iq['client_join']['mix_join'].append(sub)
+ result = await iq.send(**iqkwargs)
+ result_nodes = {sub['node'] for sub in result['client_join']['mix_join']}
+ return result_nodes.difference(subscribe)
+
+ async def leave_channel(self, room: JID, *,
+ ito: Optional[JID] = None,
+ ifrom: Optional[JID] = None,
+ **iqkwargs) -> Iq:
+ """"
+ Leave a MIX channel
+ :param JID room: JID of the channel to leave
+ """
+ if ito is None:
+ ito = self.xmpp.boundjid.bare
+ iq = self.xmpp.make_iq_set(ito=ito, ifrom=ifrom)
+ iq['client_leave']['channel'] = room
+ iq['client_leave'].enable('mix_leave')
+ return await iq.send(**iqkwargs)
diff --git a/slixmpp/plugins/xep_0405/stanza.py b/slixmpp/plugins/xep_0405/stanza.py
new file mode 100644
index 00000000..fe221bd6
--- /dev/null
+++ b/slixmpp/plugins/xep_0405/stanza.py
@@ -0,0 +1,43 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp import JID
+from slixmpp.stanza import Iq
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+
+from slixmpp.plugins.xep_0369.stanza import (
+ Join,
+ Leave,
+)
+
+NS = 'urn:xmpp:mix:pam:2'
+
+
+class ClientJoin(ElementBase):
+ namespace = NS
+ name = 'client-join'
+ plugin_attrib = 'client_join'
+ interfaces = {'channel'}
+
+
+class ClientLeave(ElementBase):
+ namespace = NS
+ name = 'client-leave'
+ plugin_attrib = 'client_leave'
+ interfaces = {'channel'}
+
+
+def register_plugins():
+ register_stanza_plugin(Iq, ClientJoin)
+ register_stanza_plugin(ClientJoin, Join)
+
+ register_stanza_plugin(Iq, ClientLeave)
+ register_stanza_plugin(ClientLeave, Leave)