Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0298.py @ 4298:060d695ae98e
plugin XEP-0106, tools (common/email): type hints.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Sep 2024 17:44:08 +0200 |
parents | a0ed5c976bf8 |
children |
rev | line source |
---|---|
4292
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Libervia plugin to handle events |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from urllib.parse import quote, unquote |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from twisted.words.protocols.jabber import jid |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.words.xish import domish |
4294
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
23 from libervia.backend.core.core_types import SatXMPPEntity |
4292
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from libervia.backend.core.i18n import _ |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from libervia.backend.core.constants import Const as C |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from libervia.backend.core.log import getLogger |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from wokkel import disco, iwokkel |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from zope.interface import implementer |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
4294
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
31 from libervia.backend.plugins.plugin_xep_0166 import XEP_0166 |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
32 |
4292
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 log = getLogger(__name__) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 PLUGIN_INFO = { |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_NAME: "Events", |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 C.PI_IMPORT_NAME: "XEP-0298", |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_TYPE: "XEP", |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_MODES: C.PLUG_MODE_BOTH, |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_PROTOCOLS: [], |
4294
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
42 C.PI_DEPENDENCIES: ["XEP-0167"], |
4292
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_MAIN: "XEP_0298", |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 C.PI_HANDLER: "yes", |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 C.PI_DESCRIPTION: _( |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 "Delivering Conference Information to Jingle Participants (Coin). This plugin " |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 "is used to associate metadata about uses an call states in multi-party calls." |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 ), |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 } |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 NS_COIN = "urn:xmpp:coin:1" |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 NS_CONFERENCE_INFO = "urn:ietf:params:xml:ns:conference-info" |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 class XEP_0298: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 namespace = NS_COIN |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def __init__(self, host): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization") |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self.host = host |
4294
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
61 self._j: XEP_0166 = host.plugins["XEP-0166"] |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
62 host.trigger.add( |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
63 "XEP-0167_jingle_session_init", self._jingle_session_init_trigger |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
64 ) |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
65 host.trigger.add("XEP-0167_jingle_handler", self._jingle_handler_trigger) |
4292
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 def get_handler(self, client): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 return CoinHandler(self) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
4294
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
70 def _jingle_session_init_trigger( |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
71 self, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
72 client: SatXMPPEntity, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
73 session: dict, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
74 content_name: str, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
75 media: str, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
76 media_data: dict, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
77 desc_elt: domish.Element, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
78 ) -> None: |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
79 """Check for the presence of "user" metadata, and add relevant elements.""" |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
80 if client.profile == "conferences": |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
81 if content_name != next(iter(session["contents"].keys())): |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
82 # We only apply metadata for the first content, as it is global. |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
83 return |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
84 try: |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
85 user = session["metadata"]["user"] |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
86 except KeyError: |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
87 return |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
88 jingle_elt = session["jingle_elt"] |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
89 conference_info_elt = self.add_conference_info(jingle_elt, True) |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
90 self.add_user(conference_info_elt, user) |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
91 |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
92 async def _jingle_handler_trigger( |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
93 self, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
94 client: SatXMPPEntity, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
95 action: str, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
96 session: dict, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
97 content_name: str, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
98 desc_elt: domish.Element, |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
99 ) -> None: |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
100 # this is a session metadata, so we only generate it on the first content |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
101 if action == self._j.A_PREPARE_CONFIRMATION and content_name == next( |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
102 iter(session["contents"]) |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
103 ): |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
104 jingle_elt = session["jingle_elt"] |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
105 infos = self.parse(jingle_elt) |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
106 try: |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
107 user = infos["info"]["users"][0] |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
108 except (KeyError, IndexError): |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
109 pass |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
110 else: |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
111 session.setdefault("metadata", {})["peer_user"] = user |
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
112 |
4292
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 def add_conference_info( |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 self, jingle_elt: domish.Element, is_focus: bool = False, **kwargs |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 ) -> domish.Element: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 """Create and return a <conference_info> element |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 @param jingle_elt: parent element |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 @param kwargs: attributes of the element. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 @return: created <conference-info> element. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 """ |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 conference_info_elt = jingle_elt.addElement( |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 (NS_CONFERENCE_INFO, "conference-info"), |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 ) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 if is_focus: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 conference_info_elt["isfocus"] = C.BOOL_TRUE |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 conference_info_elt.attributes.update(kwargs) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 return conference_info_elt |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 def add_user( |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 self, conference_info_elt: domish.Element, entity: jid.JID |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 ) -> domish.Element: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 """Add an user to a cconference info element. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 If the parent <users> doesn't exist, it will be created. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 @param conference_info_elt: <conference-info> element where the <user> element |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 need to be added |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 @param entity: XMPP JID to use as entity. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 @return: created <user> element. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 """ |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 try: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 users_elt = next(conference_info_elt.elements(NS_CONFERENCE_INFO, "users")) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 except StopIteration: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 users_elt = conference_info_elt.addElement("users") |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 user_elt = users_elt.addElement("user") |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 user_elt["entity"] = f"xmpp:{quote(entity.userhost())}" |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 return user_elt |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 def parse(self, jingle_elt: domish.Element) -> dict: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 """Parse a Jingle element and return a dictionary with conference info if present. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 @param jingle_elt: Jingle element to parse. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 @return: Dictionary with "info" key if conference info is found. |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 """ |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 try: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 conference_info_elt = next( |
4294
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4292
diff
changeset
|
158 jingle_elt.elements(NS_CONFERENCE_INFO, "conference-info") |
4292
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 ) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 except StopIteration: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 return {} |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 users = [] |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 try: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 users_elt = next(conference_info_elt.elements(NS_CONFERENCE_INFO, "users")) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 for user_elt in users_elt.elements(NS_CONFERENCE_INFO, "user"): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 entity = user_elt.getAttribute("entity") |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if entity.startswith("xmpp:"): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 try: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 entity = jid.JID(unquote(entity[5:])) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 users.append(entity) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 except Exception as e: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 log.warning(f"Failed to parse entity {entity!r}: {e}") |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 else: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 log.warning(f"Ignoring non-XMPP entity {entity!r}") |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 except StopIteration: |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 pass |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 return {"info": {"users": users}} |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 @implementer(iwokkel.IDisco) |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 class CoinHandler(XMPPHandler): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 def __init__(self, plugin_parent): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 self.plugin_parent = plugin_parent |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 return [ |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 disco.DiscoFeature(NS_COIN), |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 ] |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
dd0891d0b22b
plugin XEP-0298: Delivering Conference Information to Jingle Participants (Coin) implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 return [] |