Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0353.py @ 4332:71c939e34ca6
XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author | Syndace <me@syndace.dev> |
---|---|
date | Sat, 13 Jul 2024 18:28:28 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
3 # Libervia plugin for Jingle Message Initiation (XEP-0353) |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
19 from typing import cast |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from twisted.internet import defer |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from twisted.internet import reactor |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
22 from twisted.words.protocols.jabber import error, jid |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
23 from twisted.words.protocols.jabber import xmlstream |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
25 from libervia.backend.plugins.plugin_xep_0166.models import ApplicationData |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from wokkel import disco, iwokkel |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
27 from zope.interface import implementer |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
28 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
29 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
30 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
31 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
32 from libervia.backend.core.i18n import D_, _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4055
diff
changeset
|
33 from libervia.backend.core.log import getLogger |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
34 from libervia.backend.tools.xml_tools import element_copy |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
35 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
36 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
37 from .plugin_xep_0167 import NS_JINGLE_RTP |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
38 except ImportError: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
39 NS_JINGLE_RTP = None |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 log = getLogger(__name__) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 NS_JINGLE_MESSAGE = "urn:xmpp:jingle-message:0" |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 PLUGIN_INFO = { |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 C.PI_NAME: "Jingle Message Initiation", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 C.PI_IMPORT_NAME: "XEP-0353", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 C.PI_TYPE: "XEP", |
4183
6784d07b99c8
plugin XEP-053, component AP gateway: use the new `trigger.add_with_check` method
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
50 C.PI_MODES: C.PLUG_MODE_BOTH, |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 C.PI_PROTOCOLS: ["XEP-0353"], |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
52 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0334"], |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 C.PI_MAIN: "XEP_0353", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 C.PI_HANDLER: "yes", |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 C.PI_DESCRIPTION: _("""Implementation of Jingle Message Initiation"""), |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 } |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
59 class RejectException(exceptions.CancelError): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
60 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
61 def __init__(self, reason: str, text: str | None = None): |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
62 super().__init__(text) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
63 self.reason = reason |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
64 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
65 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
66 class TakenByOtherDeviceException(exceptions.CancelError): |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
67 reason: str = "taken_by_other_device" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
68 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
69 def __init__(self, device_jid: jid.JID): |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
70 super().__init__(device_jid.full()) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
71 self.device_jid = device_jid |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
72 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
73 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
74 class RetractException(exceptions.CancelError): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
75 pass |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
76 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
77 |
3517
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
78 class XEP_0353: |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 def __init__(self, host): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 log.info(_("plugin {name} initialization").format(name=PLUGIN_INFO[C.PI_NAME])) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
82 host.register_namespace("jingle-message", NS_JINGLE_MESSAGE) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 self._j = host.plugins["XEP-0166"] |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
84 self._h = host.plugins["XEP-0334"] |
4183
6784d07b99c8
plugin XEP-053, component AP gateway: use the new `trigger.add_with_check` method
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
85 host.trigger.add_with_check( |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
86 "XEP-0166_initiate_elt_built", |
4183
6784d07b99c8
plugin XEP-053, component AP gateway: use the new `trigger.add_with_check` method
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
87 self, |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
88 self._on_initiate_trigger, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
89 # this plugin set the resource, we want it to happen first so other triggers |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
90 # can get the full peer JID |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
91 priority=host.trigger.MAX_PRIORITY, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
92 ) |
4183
6784d07b99c8
plugin XEP-053, component AP gateway: use the new `trigger.add_with_check` method
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
93 host.trigger.add_with_check( |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
94 "XEP-0166_terminate", |
4183
6784d07b99c8
plugin XEP-053, component AP gateway: use the new `trigger.add_with_check` method
Goffi <goffi@goffi.org>
parents:
4115
diff
changeset
|
95 self, |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
96 self._terminate_trigger, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
97 priority=host.trigger.MAX_PRIORITY, |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
98 ) |
4051
c23cad65ae99
core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents:
4044
diff
changeset
|
99 host.trigger.add("message_received", self._on_message_received) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
101 def get_handler(self, client): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 return Handler() |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
104 def profile_connecting(self, client): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 # mapping from session id to deferred used to wait for destinee answer |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 client._xep_0353_pending_sessions = {} |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
108 def build_message_data(self, client, peer_jid, verb, session_id): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 mess_data = { |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
110 "from": client.jid, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
111 "to": peer_jid, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
112 "uid": "", |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
113 "message": {}, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
114 "type": C.MESS_TYPE_CHAT, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
115 "subject": {}, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
116 "extra": {}, |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
118 client.generate_message_xml(mess_data) |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
119 message_elt = mess_data["xml"] |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
120 verb_elt = message_elt.addElement((NS_JINGLE_MESSAGE, verb)) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 verb_elt["id"] = session_id |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
122 self._h.add_hint_elements(message_elt, [self._h.HINT_STORE]) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 return mess_data |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
125 async def _on_initiate_trigger( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
126 self, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
127 client: SatXMPPEntity, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
128 session: dict, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
129 iq_elt: domish.Element, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
130 jingle_elt: domish.Element, |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
131 ) -> bool: |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
132 peer_jid = session["peer_jid"] |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 if peer_jid.resource: |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 |
3652
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
136 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
137 infos = await self.host.memory.disco.get_infos(client, peer_jid) |
3652
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
138 except error.StanzaError as e: |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
139 if e.condition == "service-unavailable": |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
140 categories = {} |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
141 else: |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
142 raise e |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
143 else: |
6e34307319c0
plugin XEP-0353: fix jingle initiation on disco "Service Unavailable" error:
Goffi <goffi@goffi.org>
parents:
3651
diff
changeset
|
144 categories = {c for c, __ in infos.identities} |
3517
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
145 if "component" in categories: |
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
146 # we don't use message initiation with components |
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
147 return True |
8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
148 |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 if peer_jid.userhostJID() not in client.roster: |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 # if the contact is not in our roster, we need to send a directed presence |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 # according to XEP-0353 §3.1 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 await client.presence.available(peer_jid) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
154 mess_data = self.build_message_data(client, peer_jid, "propose", session["id"]) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
155 message_elt = mess_data["xml"] |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
156 for content_data in session["contents"].values(): |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
157 # we get the full element build by the application plugin |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
158 jingle_description_elt = content_data["application_data"]["desc_elt"] |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
159 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
160 # we need to copy the element |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
161 if jingle_description_elt.uri == NS_JINGLE_RTP: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
162 # for RTP, we only keep the root <description> element, no children |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
163 description_elt = domish.Element( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
164 (jingle_description_elt.uri, jingle_description_elt.name), |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
165 defaultUri=jingle_description_elt.defaultUri, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
166 attribs=jingle_description_elt.attributes, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
167 localPrefixes=jingle_description_elt.localPrefixes, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
168 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
169 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
170 # Otherwise we keep the children to have application useful data |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
171 description_elt = element_copy(jingle_description_elt, with_parent=False) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
172 |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
173 message_elt.propose.addChild(description_elt) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 response_d = defer.Deferred() |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 # we wait for 2 min before cancelling the session init |
4044
3900626bc100
plugin XEP-0166: refactoring, and various improvments:
Goffi <goffi@goffi.org>
parents:
4042
diff
changeset
|
176 # FIXME: let's application decide timeout? |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
177 response_d.addTimeout(2 * 60, reactor) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
178 client._xep_0353_pending_sessions[session["id"]] = response_d |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 try: |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
180 await client.send_message_data(mess_data) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 accepting_jid = await response_d |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 except defer.TimeoutError: |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
183 log.warning( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
184 _("Message initiation with {peer_jid} timed out").format( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
185 peer_jid=peer_jid |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
186 ) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
187 ) |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
188 except exceptions.CancelError as e: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
189 for content in session["contents"].values(): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
190 await content["application"].handler.jingle_preflight_cancel( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
191 client, session, e |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
192 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
193 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
194 self._j.delete_session(client, session["id"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
195 return False |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 else: |
4055
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
197 if iq_elt["to"] != accepting_jid.userhost(): |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
198 raise exceptions.InternalError( |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
199 f"<jingle> 'to' attribute ({iq_elt['to']!r}) must not differ " |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
200 f"from bare JID of the accepting entity ({accepting_jid!r}), this " |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
201 "may be a sign of an internal bug, a hack attempt, or a MITM attack!" |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
202 ) |
38819c69aa39
plugin XEP-0353: update according to XEP changes + <description> fix:
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
203 iq_elt["to"] = accepting_jid.full() |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 session["peer_jid"] = accepting_jid |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
205 finally: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
206 del client._xep_0353_pending_sessions[session["id"]] |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
209 def _terminate_trigger( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
210 self, client: SatXMPPEntity, session: dict, reason_elt: domish.Element |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
211 ) -> bool: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
212 session_id = session["id"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
213 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
214 response_d = client._xep_0353_pending_sessions[session_id] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
215 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
216 return True |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
217 # we have a XEP-0353 session, that means that we are retracting a proposed session |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
218 mess_data = self.build_message_data( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
219 client, session["peer_jid"], "retract", session_id |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
220 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
221 defer.ensureDeferred(client.send_message_data(mess_data)) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
222 response_d.errback(RetractException()) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
223 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
224 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
225 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
226 async def _on_message_received(self, client, message_elt, post_treat): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 for elt in message_elt.elements(): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 if elt.uri == NS_JINGLE_MESSAGE: |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
229 # We use ensureDeferred to process the message initiation workflow in |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
230 # parallel and to avoid blocking the message queue. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
231 defer.ensureDeferred(self._handle_mess_init(client, message_elt, elt)) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
232 return False |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 return True |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
235 async def _handle_mess_init( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
236 self, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
237 client: SatXMPPEntity, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
238 message_elt: domish.Element, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
239 mess_init_elt: domish.Element, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
240 ) -> None: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
241 if mess_init_elt.name == "propose": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
242 await self._handle_propose(client, message_elt, mess_init_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
243 elif mess_init_elt.name == "retract": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
244 self._handle_retract(client, message_elt, mess_init_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
245 elif mess_init_elt.name == "proceed": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
246 self._handle_proceed(client, message_elt, mess_init_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
247 elif mess_init_elt.name == "accept": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
248 self._handle_accept(client, message_elt, mess_init_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
249 elif mess_init_elt.name == "reject": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
250 self._handle_reject(client, message_elt, mess_init_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
251 elif mess_init_elt.name == "ringing": |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
252 await self._handle_ringing(client, message_elt, mess_init_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
253 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
254 log.warning(f"invalid element: {mess_init_elt.toXml}") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
255 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
256 def _get_sid_and_session_d( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
257 self, client: SatXMPPEntity, elt: domish.Element |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
258 ) -> tuple[str, defer.Deferred | list[defer.Deferred]]: |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
259 """Retrieve session ID and deferred or list of deferred from response element""" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
260 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
261 session_id = elt["id"] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
262 except KeyError as e: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
263 assert elt.parent is not None |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
264 log.warning(f"invalid proceed element in message_elt: {elt.parent.toXml()}") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
265 raise e |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
266 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
267 session_d = client._xep_0353_pending_sessions[session_id] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
268 except KeyError as e: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
269 log.warning( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
270 _( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
271 "no pending session found with id {session_id}, did it timed out?" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
272 ).format(session_id=session_id) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
273 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
274 raise e |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
275 return session_id, session_d |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
276 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
277 def _get_sid_and_response_d( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
278 self, client: SatXMPPEntity, elt: domish.Element |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
279 ) -> tuple[str, defer.Deferred]: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
280 """Retrieve session ID and response_d from response element""" |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
281 session_id, response_d = self._get_sid_and_session_d(client, elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
282 assert isinstance(response_d, defer.Deferred) |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
283 return session_id, response_d |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
284 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
285 def _get_sid_and_preflight_d_list( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
286 self, client: SatXMPPEntity, elt: domish.Element |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
287 ) -> tuple[str, list[defer.Deferred]]: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
288 """Retrieve session ID and list of preflight_d from response element""" |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
289 session_id, preflight_d_list = self._get_sid_and_session_d(client, elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
290 assert isinstance(preflight_d_list, list) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
291 return session_id, preflight_d_list |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
292 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
293 async def _handle_propose( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
294 self, client: SatXMPPEntity, message_elt: domish.Element, elt: domish.Element |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
295 ) -> None: |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
296 peer_jid = jid.JID(message_elt["from"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
297 local_jid = jid.JID(message_elt["to"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
298 session_id = elt["id"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
299 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
300 desc_and_apps = [ |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
301 (description_elt, self._j.get_application(description_elt.uri)) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
302 for description_elt in elt.elements() |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
303 if description_elt.name == "description" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
304 ] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
305 if not desc_and_apps: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
306 raise AttributeError |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
307 except AttributeError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
308 log.warning(f"Invalid propose element: {message_elt.toXml()}") |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
309 return |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
310 except exceptions.NotFound: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
311 log.warning( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
312 f"There is not registered application to handle this " |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
313 f"proposal: {elt.toXml()}" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
314 ) |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
315 return |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
316 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
317 if not desc_and_apps: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
318 log.warning("No application specified: {message_elt.toXml()}") |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
319 return |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
320 |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
321 cast(list[tuple[domish.Element, ApplicationData]], desc_and_apps) |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
322 desc_and_apps.sort( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
323 key=lambda desc_and_app: desc_and_app[1].priority, reverse=True |
4240
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
324 ) |
79c8a70e1813
backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
325 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
326 session = self._j.create_session( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
327 client, session_id, self._j.ROLE_RESPONDER, peer_jid, local_jid |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
328 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
329 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
330 is_in_roster = peer_jid.userhostJID() in client.roster |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
331 if is_in_roster: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
332 # we indicate that device is ringing as explained in |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
333 # https://xmpp.org/extensions/xep-0353.html#ring , but we only do that if user |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
334 # is in roster to avoid presence leak of all our devices. |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
335 mess_data = self.build_message_data(client, peer_jid, "ringing", session_id) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
336 await client.send_message_data(mess_data) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
337 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
338 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
339 for description_elt, application in desc_and_apps: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
340 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
341 preflight_d = defer.ensureDeferred( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
342 application.handler.jingle_preflight( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
343 client, session, description_elt |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
344 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
345 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
346 client._xep_0353_pending_sessions.setdefault(session_id, []).append( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
347 preflight_d |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
348 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
349 await preflight_d |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
350 except TakenByOtherDeviceException as e: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
351 log.info(f"The call has been takend by {e.device_jid}") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
352 await application.handler.jingle_preflight_cancel(client, session, e) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
353 self._j.delete_session(client, session_id) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
354 return |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
355 except exceptions.CancelError as e: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
356 log.info(f"{client.profile} refused the session: {e}") |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
357 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
358 if is_in_roster: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
359 # peer is in our roster, we send reject to them, ou other devices |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
360 # will get carbon copies |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
361 reject_dest_jid = peer_jid |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
362 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
363 # peer is not in our roster, we send the "reject" only to our own |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
364 # devices to make them stop ringing/doing notification, and we |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
365 # don't send anything to peer to avoid presence leak. |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
366 reject_dest_jid = client.jid.userhostJID() |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
367 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
368 mess_data = self.build_message_data( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
369 client, reject_dest_jid, "reject", session_id |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
370 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
371 await client.send_message_data(mess_data) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
372 self._j.delete_session(client, session_id) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
373 return |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
374 except defer.CancelledError: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
375 # raised when call is retracted before user can reply |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
376 self._j.delete_session(client, session_id) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
377 return |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
378 finally: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
379 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
380 del client._xep_0353_pending_sessions[session_id] |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
381 except KeyError: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
382 pass |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
383 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
384 if peer_jid.userhostJID() not in client.roster: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
385 await client.presence.available(peer_jid) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
386 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
387 mess_data = self.build_message_data(client, peer_jid, "proceed", session_id) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
388 await client.send_message_data(mess_data) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
389 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
390 def _handle_retract(self, client, message_elt, retract_elt): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
391 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
392 session = self._j.get_session(client, retract_elt["id"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
393 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
394 log.warning(f"invalid retract element: {message_elt.toXml()}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
395 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
396 except exceptions.NotFound: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
397 log.warning(f"no session found with ID {retract_elt['id']}") |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
398 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
399 log.debug( |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
400 f"{message_elt['from']} are retracting their proposal {retract_elt['id']}" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
401 ) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
402 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
403 cancellable_deferred = session["cancellable_deferred"] |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
404 if not cancellable_deferred: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
405 raise KeyError |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
406 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
407 self._j.delete_session(client, session["id"]) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
408 else: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
409 for d in cancellable_deferred: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
410 d.cancel() |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
411 return False |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
412 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
413 def _handle_proceed( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
414 self, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
415 client: SatXMPPEntity, |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
416 message_elt: domish.Element, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4240
diff
changeset
|
417 proceed_elt: domish.Element, |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
418 ) -> None: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
419 from_jid = jid.JID(message_elt["from"]) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
420 # session_d is the deferred of the session, it can be preflight_d or response_d |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
421 if from_jid.userhostJID() == client.jid.userhostJID(): |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
422 # an other device took the session |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
423 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
424 sid, preflight_d_list = self._get_sid_and_preflight_d_list( |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
425 client, proceed_elt |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
426 ) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
427 except KeyError: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
428 return |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
429 for preflight_d in preflight_d_list: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
430 if not preflight_d.called: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
431 preflight_d.errback(TakenByOtherDeviceException(from_jid)) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
433 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
434 session = self._j.get_session(client, sid) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
435 except exceptions.NotFound: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
436 log.warning("No session found with sid {sid!r}.") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
437 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
438 # jingle_preflight_cancel? |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
439 pass |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
440 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
441 # FIXME: Is preflight cancel handler correctly? Check if preflight_d is always |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
442 # cleaned correctly (use a timeout?) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
443 |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
444 else: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
445 try: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
446 __, response_d = self._get_sid_and_response_d(client, proceed_elt) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
447 except KeyError: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
448 return |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
449 # we have a response deferred |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4183
diff
changeset
|
450 response_d.callback(jid.JID(message_elt["from"])) |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3652
diff
changeset
|
452 def _handle_accept(self, client, message_elt, accept_elt): |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 pass |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 |
4112
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
455 def _handle_reject(self, client, message_elt, reject_elt): |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
456 try: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
457 __, response_d = self._get_sid_and_response_d(client, reject_elt) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
458 except KeyError: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
459 return True |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
460 reason_elt = self._j.get_reason_elt(reject_elt) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
461 reason, text = self._j.parse_reason_elt(reason_elt) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
462 if reason is None: |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
463 reason = "busy" |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
464 |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
465 response_d.errback(RejectException(reason, text)) |
bc60875cb3b8
plugin XEP-0166, XEP-0167, XEP-0234, XEP-0353: call events management to prepare for UI:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
466 return False |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 |
4115
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
468 async def _handle_ringing(self, client, message_elt, ringing_elt): |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
469 session_id = ringing_elt["id"] |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
470 try: |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
471 session = self._j.get_session(client, session_id) |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
472 except exceptions.NotFound: |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
473 log.warning(f"Session {session_id!r} unknown, ignoring ringing.") |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
474 return False |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
475 for __, content_data in session["contents"].items(): |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
476 await content_data["application"].handler.jingle_preflight_info( |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
477 client, session, "ringing", None |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
478 ) |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
479 |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
480 return False |
0da563780ffc
plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents:
4112
diff
changeset
|
481 |
3405
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 @implementer(iwokkel.IDisco) |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 class Handler(xmlstream.XMPPHandler): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 return [disco.DiscoFeature(NS_JINGLE_MESSAGE)] |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
ecdb3728749e
plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 return [] |