Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_misc_remote_control.py @ 4249:ba46d6a0ff3a
doc: style/typos/URL fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 31 May 2024 11:08:20 +0200 |
parents | 898db6daf0d0 |
children | 0d7bb4df2343 |
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 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 class RemoteControl(BaseApplicationHandler): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self, host): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 log.info(f'Plugin "{PLUGIN_INFO[C.PI_NAME]}" initialization') |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.host = host |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 # FIXME: to be removed once host is accessible from global var |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self._j = host.plugins["XEP-0166"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 # 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
|
61 # session and not a call one when this application is used. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 self._j.register_application(NS_REMOTE_CONTROL, self, priority=1000) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self._rtp = host.plugins["XEP-0167"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 host.register_namespace("remote-control", NS_REMOTE_CONTROL) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 host.bridge.add_method( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 "remote_control_start", |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 ".plugin", |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 in_sign="sss", |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 out_sign="s", |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 method=self._remote_control_start, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 async_=True, |
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 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def get_handler(self, client): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 return RemoteControl_handler() |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 # bridge methods |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 def _remote_control_start( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 peer_jid_s: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 extra_s: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 profile: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 ) -> defer.Deferred[str]: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 client = self.host.get_client(profile) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 extra = data_format.deserialise(extra_s) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 d = defer.ensureDeferred(self.remote_control_start( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 client, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 jid.JID(peer_jid_s), |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 extra, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 )) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 d.addCallback(data_format.serialise) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 return d |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 async def remote_control_start( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 client: SatXMPPEntity, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 peer_jid: jid.JID, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 extra: dict |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 ) -> dict: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 """Start a remote control session. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 @param peer_jid: destinee jid |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 @return: progress id |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 """ |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 if not extra: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 raise exceptions.DataError( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 '"extra" must be set.' |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 # webrtc is always used for remote control |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 extra["webrtc"] = True |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 content = { |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 "app_ns": NS_REMOTE_CONTROL, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 # 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
|
115 # bidirectional, and which case "senders" would be set to "both" |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 "senders": self._j.ROLE_INITIATOR, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 "app_kwargs": { |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 "extra": extra, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 }, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 } |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 try: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 call_data = content["app_kwargs"]["extra"]["call_data"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 except KeyError: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 raise exceptions.DataError('"call_data" must be set in "extra".') |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 metadata = self._rtp.parse_call_data(call_data) |
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 application_data = call_data["application"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 except KeyError: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 raise exceptions.DataError( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 '"call_data" must have an application media.' |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 try: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 content["transport_data"] = { |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 "sctp-port": metadata["sctp-port"], |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 "max-message-size": metadata.get("max-message-size", 65536), |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 "local_ice_data": { |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 "ufrag": metadata["ice-ufrag"], |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 "pwd": metadata["ice-pwd"], |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 "candidates": application_data.pop("ice-candidates"), |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 "fingerprint": application_data.pop("fingerprint", {}), |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 } |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 } |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 name = application_data.get("id") |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 if name: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 content["name"] = name |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 except KeyError as e: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 raise exceptions.DataError(f"Mandatory key is missing: {e}") |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 contents = [content] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 contents.extend(self._rtp.get_contents(call_data, metadata)) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 session_id = await self._j.initiate( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 client, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 peer_jid, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 contents, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 call_type=C.META_SUBTYPE_CALL_REMOTE_CONTROL, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 metadata=metadata, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 peer_metadata={}, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 return {"session_id": session_id} |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 # jingle callbacks |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 def _get_confirm_msg( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 client: SatXMPPEntity, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 peer_jid: jid.JID, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 ) -> tuple[bool, str, str]: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 """Get confirmation message to display to user. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 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
|
171 if client.roster and peer_jid.userhostJID() not in client.roster: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 is_in_roster = False |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 confirm_msg = D_( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 "Somebody not in your contact list ({peer_jid}) wants to control " |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 "remotely this device. Accepting this will give full control of your " |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 " 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
|
177 "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
|
178 "Do you accept?" |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 ).format(peer_jid=peer_jid) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 confirm_title = D_("Remote Control Request From an Unknown Contact") |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 else: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 is_in_roster = True |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 confirm_msg = D_( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 "{peer_jid} wants to control your device. Accepting will give full " |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 "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
|
186 "Only accept if you absolute trust this person.\n" |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 "Do you accept?" |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 ).format(peer_jid=peer_jid) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 confirm_title = D_("Remote Control Request.") |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 return (is_in_roster, confirm_msg, confirm_title) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 async def jingle_preflight( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 self, client: SatXMPPEntity, session: dict, description_elt: domish.Element |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 ) -> None: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 """Perform preflight checks for an incoming call session. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 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
|
199 confirmation. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 @param client: The client instance. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 @param session: Jingle session. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 @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
|
204 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
|
205 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 @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
|
207 """ |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 session_id = session["id"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 peer_jid = session["peer_jid"] |
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 is_in_roster, confirm_msg, confirm_title = self._get_confirm_msg( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 client, peer_jid |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 if is_in_roster: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 action_type = C.META_TYPE_CONFIRM |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 else: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 action_type = C.META_TYPE_NOT_IN_ROSTER_LEAK |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 action_extra = { |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 "type": action_type, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 "session_id": session_id, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 "from_jid": peer_jid.full(), |
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 action_extra["subtype"] = C.META_TYPE_REMOTE_CONTROL |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 accepted = await xml_tools.defer_confirm( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 self.host, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 confirm_msg, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 confirm_title, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 profile=client.profile, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 action_extra=action_extra |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 if accepted: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 session["pre_accepted"] = True |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 return accepted |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 async def jingle_preflight_info( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 client: SatXMPPEntity, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 session: dict, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 info_type: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 info_data: dict | None = None, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 ) -> None: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 pass |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 async def jingle_preflight_cancel( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 self, client: SatXMPPEntity, session: dict, cancel_error: exceptions.CancelError |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 ) -> None: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 """The remote control has been rejected""" |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 def jingle_session_init( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 client: SatXMPPEntity, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 session: dict, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 content_name: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 extra: dict |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 ) -> domish.Element: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 """Initializes a jingle session. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 @param client: The client instance. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 @param session: Jingle session. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 @param content_name: Name of the content. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 @param extra: Extra data. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 @return: <description> element. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 """ |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 desc_elt = domish.Element((NS_REMOTE_CONTROL, "description")) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 devices = extra.get("devices") or {} |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 for name, data in devices.items(): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 device_elt = desc_elt.addElement((NS_REMOTE_CONTROL, "device")) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 device_elt["type"] = name |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 return desc_elt |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 async def jingle_request_confirmation( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 client: SatXMPPEntity, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 action: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 session: dict, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 content_name: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 desc_elt: domish.Element, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 ) -> bool: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 """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
|
281 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 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
|
283 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
|
284 content; subsequent contents are automatically accepted. This means, in practice, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 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
|
286 contents. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 @param client: The client instance. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 @param action: The action type associated with the Jingle session. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 @param session: Jingle session. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 @param content_name: Name of the content being checked. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 @param desc_elt: The description element associated with the content. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 @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
|
295 """ |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 content_data = session["contents"][content_name] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 role = session["role"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 if role == self._j.ROLE_INITIATOR: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 raise NotImplementedError |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 return True |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 elif role == self._j.ROLE_RESPONDER: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 # We are the controlled entity. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 return await self._remote_control_request_conf( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 client, session, content_data, content_name |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 else: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 raise exceptions.InternalError( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 f"Invalid role {role!r}" |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 async def _remote_control_request_conf( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 client: SatXMPPEntity, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 session: dict, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 content_data: dict, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 content_name: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 ) -> bool: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 """Handle user permission.""" |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 peer_jid = session["peer_jid"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 pre_accepted = session.get("pre_accepted", False) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 __, confirm_msg, confirm_title = self._get_confirm_msg(client, peer_jid) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 contents = session["contents"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 action_extra = { |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 "pre_accepted": pre_accepted, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 "type": C.META_TYPE_REMOTE_CONTROL, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 "devices": content_data["application_data"]["devices"], |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 "session_id": session["id"], |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 "from_jid": peer_jid.full(), |
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 for name, content in contents.items(): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 if name == content_name: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 continue |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 if content["application"].namespace == self._rtp.namespace: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 media = content["application_data"]["media"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 action_extra.setdefault("screenshare", {})[media] = {} |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 return await xml_tools.defer_confirm( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 self.host, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 confirm_msg, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 confirm_title, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 profile=client.profile, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 action_extra=action_extra |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 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
|
347 content_data = session["contents"][content_name] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 application_data = content_data["application_data"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 if action == self._j.A_PREPARE_CONFIRMATION: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 devices = application_data["devices"] = {} |
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 try: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 device_type = device_elt.attributes["type"] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 except KeyError: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 log.warning(f"Invalide device element: {device_elt.toXml()}") |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 else: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 # 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
|
358 # 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
|
359 # future extensions. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 devices[device_type] = {} |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 elif action == self._j.A_SESSION_INITIATE: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 # 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
|
363 # else. Must actually reflect user choices and local devices. |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 to_remove = [] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 for device_elt in desc_elt.elements(NS_REMOTE_CONTROL, "device"): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 if device_elt.getAttribute("type") not in ("keyboard", "wheel", "mouse"): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 to_remove.append(device_elt) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 for elt in to_remove: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 elt.parent.children.remove(elt) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 return desc_elt |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 def jingle_terminate( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 self, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 client: SatXMPPEntity, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 action: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 session: dict, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 content_name: str, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 reason_elt: domish.Element, |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 ) -> None: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 reason, text = self._j.parse_reason_elt(reason_elt) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 data = {"reason": reason} |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 if text: |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 data["text"] = text |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 self.host.bridge.call_ended( |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 session["id"], data_format.serialise(data), client.profile |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 ) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 @implementer(iwokkel.IDisco) |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 class RemoteControl_handler(XMPPHandler): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 return [disco.DiscoFeature(NS_REMOTE_CONTROL)] |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
898db6daf0d0
core: Jingle Remote Control implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 return [] |