annotate libervia/backend/plugins/plugin_xep_0353.py @ 4262:d366d90a71aa

component AP Gateway: log invalid account in case of error.
author Goffi <goffi@goffi.org>
date Wed, 12 Jun 2024 22:34:19 +0200
parents 79c8a70e1813
children 0d7bb4df2343
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3405
diff changeset
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
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
61 def __init__(self, reason: str, text: str|None = 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
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(
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
210 self,
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 client: SatXMPPEntity,
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: dict,
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 reason_elt: domish.Element
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 ) -> 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
215 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
216 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
217 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
218 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
219 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
220 # 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
221 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
222 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
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 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
225 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
226
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
227 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
228
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
229 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
230 for elt in message_elt.elements():
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 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
232 # 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
233 # 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
234 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
235 return False
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 return True
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
237
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
238 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
239 self,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
240 client: SatXMPPEntity,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
241 message_elt: domish.Element,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
242 mess_init_elt: domish.Element
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
243 ) -> None:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
244 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
245 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
246 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 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
255 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
256 else:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
257 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
258
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
259 def _get_sid_and_session_d(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
260 self,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
261 client: SatXMPPEntity,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
262 elt: domish.Element
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
263 ) -> tuple[str, defer.Deferred|list[defer.Deferred]]:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
264 """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
265 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
266 session_id = elt["id"]
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
267 except KeyError as e:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
268 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
269 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
270 raise e
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
271 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
272 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
273 except KeyError as e:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
274 log.warning(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
275 _(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
276 "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
277 ).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
278 )
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
279 raise e
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
280 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
281
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
282 def _get_sid_and_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
283 self,
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 client: SatXMPPEntity,
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
285 elt: domish.Element
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
286 ) -> 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
287 """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
288 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
289 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
290 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
291
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
292 def _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
293 self,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
294 client: SatXMPPEntity,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
295 elt: domish.Element
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
296 ) -> 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
297 """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
298 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
299 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
300 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
301
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
302 async def _handle_propose(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
303 self,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
304 client: SatXMPPEntity,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
305 message_elt: domish.Element,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
306 elt: domish.Element
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
307 ) -> 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
308 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
309 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
310 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
311 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
312 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
313 (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
314 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
315 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
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 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 )
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
327 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
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 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
330 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
331 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
332
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
333 cast(list[tuple[domish.Element, ApplicationData]], desc_and_apps)
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
334 desc_and_apps.sort(
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
335 key=lambda desc_and_app: desc_and_app[1].priority,
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
336 reverse=True
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
337 )
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
338
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
339 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
340 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
341 )
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
342
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
343 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
344 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
345 # 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
346 # 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
347 # 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
348 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
349 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
350
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
351 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
352 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
353 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
354 preflight_d = defer.ensureDeferred(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
355 application.handler.jingle_preflight(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
356 client, session, description_elt
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
357 )
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
358 )
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
359 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
360 preflight_d
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
361 )
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
362 await preflight_d
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
363 except TakenByOtherDeviceException as e:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
364 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
365 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
366 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
367 return
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
368 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
369 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
370
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
371 if is_in_roster:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
372 # 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
373 # will get carbon copies
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
374 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
375 else:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
376 # 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
377 # 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
378 # 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
379 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
380
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
381 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
382 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
383 )
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
384 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
385 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
386 return
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
387 except defer.CancelledError:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
388 # 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
389 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
390 return
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
391 finally:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
392 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
393 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
394 except KeyError:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
395 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
396
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 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
398 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
399
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 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
401 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
402
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 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
404 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
405 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
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 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
408 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
409 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
410 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
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 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
413 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
414 )
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
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
426 def _handle_proceed(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
427 self,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
428 client: SatXMPPEntity,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
429 message_elt: domish.Element,
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
430 proceed_elt: domish.Element
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
431 ) -> None:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
432 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
433 # 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
434 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
435 # 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
436 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
437 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
438 client, proceed_elt
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
439 )
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
440 except KeyError:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
441 return
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
442 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
443 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
444 preflight_d.errback(TakenByOtherDeviceException(from_jid))
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
445
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
446 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
447 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
448 except exceptions.NotFound:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
449 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
450 else:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
451 # jingle_preflight_cancel?
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
452 pass
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
453
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
454 # 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
455 # 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
456
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
457 else:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
458 try:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
459 __, 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
460 except KeyError:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
461 return
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4183
diff changeset
462 # 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
463 response_d.callback(jid.JID(message_elt["from"]))
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
464
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3652
diff changeset
465 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
466 pass
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
467
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
468 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
469 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
470 __, 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
471 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
472 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
473 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
474 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
475 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
476 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
477
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
478 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
479 return False
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
480
4115
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
481 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
482 session_id = ringing_elt["id"]
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
483 try:
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
484 session = self._j.get_session(client, session_id)
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
485 except exceptions.NotFound:
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
486 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
487 return False
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
488 for __, content_data in session["contents"].items():
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
489 await content_data["application"].handler.jingle_preflight_info(
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
490 client, session, "ringing", None
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
491 )
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
492
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
493 return False
0da563780ffc plugin XEP-0167, XEP-0353: handle ringing:
Goffi <goffi@goffi.org>
parents: 4112
diff changeset
494
3405
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
495
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
496 @implementer(iwokkel.IDisco)
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 class Handler(xmlstream.XMPPHandler):
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
499 return [disco.DiscoFeature(NS_JINGLE_MESSAGE)]
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
500
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
501 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
ecdb3728749e plugin XEP-0353: Jingle Message Initiation implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
502 return []