annotate libervia/backend/plugins/plugin_misc_remote_control.py @ 4281:9e63e02318ec

core: show warning instead of exception in case of missing dependency when loading plugins
author Goffi <goffi@goffi.org>
date Fri, 12 Jul 2024 18:53:00 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia: an XMPP client
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from twisted.internet import defer
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from twisted.words.protocols.jabber import jid
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.words.xish import domish
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from wokkel import disco, iwokkel
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from zope.interface import implementer
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from libervia.backend.core import exceptions
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from libervia.backend.core.constants import Const as C
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from libervia.backend.core.core_types import SatXMPPEntity
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from libervia.backend.core.i18n import D_, _
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from libervia.backend.core.log import getLogger
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from libervia.backend.tools import xml_tools
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from libervia.backend.tools.common import data_format
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from .plugin_xep_0166 import BaseApplicationHandler
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 log = getLogger(__name__)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 NS_REMOTE_CONTROL = "urn:xmpp:jingle:apps:remote-control:0"
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 PLUGIN_INFO = {
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_NAME: "Jingle Remove Control",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_IMPORT_NAME: "RemoteControl",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_TYPE: C.PLUG_TYPE_MISC,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_PROTOCOLS: [],
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0167"],
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 C.PI_MAIN: "RemoteControl",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 C.PI_HANDLER: "yes",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 C.PI_DESCRIPTION: _("""Remote control devices with Jingle."""),
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 }
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 class RemoteControl(BaseApplicationHandler):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def __init__(self, host):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 log.info(f'Plugin "{PLUGIN_INFO[C.PI_NAME]}" initialization')
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.host = host
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 # FIXME: to be removed once host is accessible from global var
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self._j = host.plugins["XEP-0166"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 # We need higher priority than XEP-0167 application, as we have a RemoteControl
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 # session and not a call one when this application is used.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self._j.register_application(NS_REMOTE_CONTROL, self, priority=1000)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self._rtp = host.plugins["XEP-0167"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 host.register_namespace("remote-control", NS_REMOTE_CONTROL)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 host.bridge.add_method(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 "remote_control_start",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 ".plugin",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 in_sign="sss",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 out_sign="s",
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 method=self._remote_control_start,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 async_=True,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 )
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def get_handler(self, client):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 return RemoteControl_handler()
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
75
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 # bridge methods
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
77
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def _remote_control_start(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 peer_jid_s: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 extra_s: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 profile: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 ) -> defer.Deferred[str]:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 client = self.host.get_client(profile)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 extra = data_format.deserialise(extra_s)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
86 d = defer.ensureDeferred(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
87 self.remote_control_start(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
88 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
89 jid.JID(peer_jid_s),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
90 extra,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
91 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
92 )
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 d.addCallback(data_format.serialise)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 return d
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 async def remote_control_start(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
97 self, client: SatXMPPEntity, peer_jid: jid.JID, extra: dict
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 ) -> dict:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 """Start a remote control session.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 @param peer_jid: destinee jid
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 @return: progress id
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 """
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 if not extra:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
105 raise exceptions.DataError('"extra" must be set.')
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 # webrtc is always used for remote control
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 extra["webrtc"] = True
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 content = {
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 "app_ns": NS_REMOTE_CONTROL,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 # XXX: for now only unidirectional device exist, but future extensions mays be
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 # bidirectional, and which case "senders" would be set to "both"
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 "senders": self._j.ROLE_INITIATOR,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 "app_kwargs": {
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 "extra": extra,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 },
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 }
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 try:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 call_data = content["app_kwargs"]["extra"]["call_data"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 except KeyError:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 raise exceptions.DataError('"call_data" must be set in "extra".')
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
121
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 metadata = self._rtp.parse_call_data(call_data)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 try:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 application_data = call_data["application"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 except KeyError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
126 raise exceptions.DataError('"call_data" must have an application media.')
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 try:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 content["transport_data"] = {
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 "sctp-port": metadata["sctp-port"],
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 "max-message-size": metadata.get("max-message-size", 65536),
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 "local_ice_data": {
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 "ufrag": metadata["ice-ufrag"],
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 "pwd": metadata["ice-pwd"],
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 "candidates": application_data.pop("ice-candidates"),
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 "fingerprint": application_data.pop("fingerprint", {}),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
136 },
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 }
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 name = application_data.get("id")
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 if name:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 content["name"] = name
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 except KeyError as e:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 raise exceptions.DataError(f"Mandatory key is missing: {e}")
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 contents = [content]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 contents.extend(self._rtp.get_contents(call_data, metadata))
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 session_id = await self._j.initiate(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 client,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 peer_jid,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 contents,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 call_type=C.META_SUBTYPE_CALL_REMOTE_CONTROL,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 metadata=metadata,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 peer_metadata={},
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 )
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 return {"session_id": session_id}
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
154
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 # jingle callbacks
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 def _get_confirm_msg(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 client: SatXMPPEntity,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 peer_jid: jid.JID,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 ) -> tuple[bool, str, str]:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 """Get confirmation message to display to user.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 This is the message to show when a remote-control request is received."""
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 if client.roster and peer_jid.userhostJID() not in client.roster:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 is_in_roster = False
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 confirm_msg = D_(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 "Somebody not in your contact list ({peer_jid}) wants to control "
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 "remotely this device. Accepting this will give full control of your "
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 " device to this person, and leak your presence and probably your IP "
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 "address. Do not accept if you don't trust this person!\n"
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 "Do you accept?"
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 ).format(peer_jid=peer_jid)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 confirm_title = D_("Remote Control Request From an Unknown Contact")
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 else:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 is_in_roster = True
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 confirm_msg = D_(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 "{peer_jid} wants to control your device. Accepting will give full "
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 "control of your device, like if they were in front of your computer. "
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 "Only accept if you absolute trust this person.\n"
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 "Do you accept?"
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 ).format(peer_jid=peer_jid)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 confirm_title = D_("Remote Control Request.")
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 return (is_in_roster, confirm_msg, confirm_title)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
186
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 async def jingle_preflight(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 self, client: SatXMPPEntity, session: dict, description_elt: domish.Element
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 ) -> None:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 """Perform preflight checks for an incoming call session.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
191
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 Check if the calls is audio only or audio/video, then, prompts the user for
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 confirmation.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
194
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 @param client: The client instance.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 @param session: Jingle session.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 @param description_elt: The description element. It's parent attribute is used to
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 determine check siblings to see if it's an audio only or audio/video call.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
199
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 @raises exceptions.CancelError: If the user doesn't accept the incoming call.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 """
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 session_id = session["id"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 peer_jid = session["peer_jid"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
204
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
205 is_in_roster, confirm_msg, confirm_title = self._get_confirm_msg(client, peer_jid)
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 if is_in_roster:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 action_type = C.META_TYPE_CONFIRM
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 else:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 action_type = C.META_TYPE_NOT_IN_ROSTER_LEAK
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
210
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 action_extra = {
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 "type": action_type,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 "session_id": session_id,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 "from_jid": peer_jid.full(),
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 }
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 action_extra["subtype"] = C.META_TYPE_REMOTE_CONTROL
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 accepted = await xml_tools.defer_confirm(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 self.host,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 confirm_msg,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 confirm_title,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 profile=client.profile,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
222 action_extra=action_extra,
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 )
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 if accepted:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 session["pre_accepted"] = True
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 return accepted
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
227
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 async def jingle_preflight_info(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 self,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 client: SatXMPPEntity,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 session: dict,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 info_type: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 info_data: dict | None = None,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 ) -> None:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 pass
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
236
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 async def jingle_preflight_cancel(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 self, client: SatXMPPEntity, session: dict, cancel_error: exceptions.CancelError
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 ) -> None:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 """The remote control has been rejected"""
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 def jingle_session_init(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
243 self, client: SatXMPPEntity, session: dict, content_name: str, extra: dict
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 ) -> domish.Element:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 """Initializes a jingle session.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
246
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 @param client: The client instance.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 @param session: Jingle session.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 @param content_name: Name of the content.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 @param extra: Extra data.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 @return: <description> element.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 """
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 desc_elt = domish.Element((NS_REMOTE_CONTROL, "description"))
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 devices = extra.get("devices") or {}
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 for name, data in devices.items():
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 device_elt = desc_elt.addElement((NS_REMOTE_CONTROL, "device"))
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 device_elt["type"] = name
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 return desc_elt
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
259
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 async def jingle_request_confirmation(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 self,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 client: SatXMPPEntity,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 action: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 session: dict,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 content_name: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 desc_elt: domish.Element,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 ) -> bool:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 """Requests confirmation from the user for a Jingle session's incoming call.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
269
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 This method checks the content type of the Jingle session (audio or video)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 based on the session's contents. Confirmation is requested only for the first
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 content; subsequent contents are automatically accepted. This means, in practice,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 that the call confirmation is prompted only once for both audio and video
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 contents.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
275
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 @param client: The client instance.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 @param action: The action type associated with the Jingle session.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 @param session: Jingle session.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 @param content_name: Name of the content being checked.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 @param desc_elt: The description element associated with the content.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
281
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 @return: True if the call is accepted by the user, False otherwise.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 """
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 content_data = session["contents"][content_name]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 role = session["role"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
286
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 if role == self._j.ROLE_INITIATOR:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 raise NotImplementedError
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 return True
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 elif role == self._j.ROLE_RESPONDER:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 # We are the controlled entity.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 return await self._remote_control_request_conf(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 client, session, content_data, content_name
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 )
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
296 raise exceptions.InternalError(f"Invalid role {role!r}")
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
297
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 async def _remote_control_request_conf(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 self,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 client: SatXMPPEntity,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 session: dict,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 content_data: dict,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 content_name: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 ) -> bool:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 """Handle user permission."""
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 peer_jid = session["peer_jid"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 pre_accepted = session.get("pre_accepted", False)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 __, confirm_msg, confirm_title = self._get_confirm_msg(client, peer_jid)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 contents = session["contents"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 action_extra = {
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 "pre_accepted": pre_accepted,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 "type": C.META_TYPE_REMOTE_CONTROL,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 "devices": content_data["application_data"]["devices"],
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 "session_id": session["id"],
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 "from_jid": peer_jid.full(),
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 }
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 for name, content in contents.items():
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 if name == content_name:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 continue
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 if content["application"].namespace == self._rtp.namespace:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 media = content["application_data"]["media"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 action_extra.setdefault("screenshare", {})[media] = {}
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
323
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 return await xml_tools.defer_confirm(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 self.host,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 confirm_msg,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 confirm_title,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 profile=client.profile,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4241
diff changeset
329 action_extra=action_extra,
4241
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 )
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
331
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 async def jingle_handler(self, client, action, session, content_name, desc_elt):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 content_data = session["contents"][content_name]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 application_data = content_data["application_data"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 if action == self._j.A_PREPARE_CONFIRMATION:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 devices = application_data["devices"] = {}
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 for device_elt in desc_elt.elements(NS_REMOTE_CONTROL, "device"):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 try:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 device_type = device_elt.attributes["type"]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 except KeyError:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 log.warning(f"Invalide device element: {device_elt.toXml()}")
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 else:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 # The dict holds data for current type of devices. For now it is unused
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 # has the spec doesn't define any device data, but it may be used by
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 # future extensions.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 devices[device_type] = {}
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 elif action == self._j.A_SESSION_INITIATE:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 # FIXME: for now we automatically accept keyboard, mouse and wheel and nothing
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 # else. Must actually reflect user choices and local devices.
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 to_remove = []
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 for device_elt in desc_elt.elements(NS_REMOTE_CONTROL, "device"):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 if device_elt.getAttribute("type") not in ("keyboard", "wheel", "mouse"):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 to_remove.append(device_elt)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 for elt in to_remove:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 elt.parent.children.remove(elt)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
356
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 return desc_elt
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
358
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 def jingle_terminate(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 self,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 client: SatXMPPEntity,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 action: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 session: dict,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 content_name: str,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 reason_elt: domish.Element,
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 ) -> None:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 reason, text = self._j.parse_reason_elt(reason_elt)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 data = {"reason": reason}
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 if text:
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 data["text"] = text
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 self.host.bridge.call_ended(
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 session["id"], data_format.serialise(data), client.profile
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 )
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
374
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
375
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 @implementer(iwokkel.IDisco)
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 class RemoteControl_handler(XMPPHandler):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 return [disco.DiscoFeature(NS_REMOTE_CONTROL)]
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
380
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
898db6daf0d0 core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 return []