annotate libervia/backend/plugins/plugin_xep_0339.py @ 4219:1b5cf2ee1d86

plugin XEP-0384, XEP-0391: download missing devices list: when a peer jid was not in our roster, devices list was not retrieved, resulting in failed en/decryption. This patch does check it and download missing devices list in necessary. There is no subscription managed yet, so the list won't be updated in case of new devices, this should be addressed at some point.
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2024 17:31:36 +0100
parents 4b842c1fb686
children 0d7bb4df2343
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4067
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia plugin
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from typing import List
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.words.xish import domish
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from wokkel import disco, iwokkel
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from zope.interface import implementer
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4067
diff changeset
26 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4067
diff changeset
27 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4067
diff changeset
28 from libervia.backend.core.core_types import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4067
diff changeset
29 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4067
diff changeset
30 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4067
diff changeset
31 from libervia.backend.tools import xml_tools
4067
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 log = getLogger(__name__)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 NS_JINGLE_RTP_SSMA = "urn:xmpp:jingle:apps:rtp:ssma:0"
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 PLUGIN_INFO = {
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_NAME: "Source-Specific Media Attributes in Jingle",
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_IMPORT_NAME: "XEP-0339",
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_TYPE: "XEP",
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_MODES: C.PLUG_MODE_BOTH,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_PROTOCOLS: ["XEP-0339"],
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_DEPENDENCIES: ["XEP-0092", "XEP-0167"],
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_RECOMMENDATIONS: [],
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 C.PI_MAIN: "XEP_0339",
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 C.PI_HANDLER: "yes",
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 C.PI_DESCRIPTION: _("""Source-Specific Media Attributes in Jingle"""),
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 }
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class XEP_0339:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 def __init__(self, host):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.host = host
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 host.trigger.add("XEP-0167_parse_sdp_a", self._parse_sdp_a_trigger)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 host.trigger.add(
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "XEP-0167_generate_sdp_content", self._generate_sdp_content_trigger
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 )
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 host.trigger.add("XEP-0167_parse_description", self._parse_description_trigger)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 host.trigger.add("XEP-0167_build_description", self._build_description_trigger)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def get_handler(self, client):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 return XEP_0339_handler()
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def _parse_sdp_a_trigger(
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 attribute: str,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 parts: List[str],
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 call_data: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 metadata: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 media_type: str,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 application_data: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 transport_data: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 ) -> None:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 """Parse "ssrc" attributes"""
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 if attribute == "ssrc":
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 assert application_data is not None
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 ssrc_id = int(parts[0])
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
79
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 if len(parts) > 1:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 name, *values = " ".join(parts[1:]).split(":", 1)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 if values:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 value = values[0] or None
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 else:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 value = None
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 application_data.setdefault("ssrc", {}).setdefault(ssrc_id, {})[
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 name
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 ] = value
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 else:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 log.warning(f"no attribute in ssrc: {' '.join(parts)}")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 application_data.setdefault("ssrc", {}).setdefault(ssrc_id, {})
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 elif attribute == "ssrc-group":
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 assert application_data is not None
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 semantics, *ssrc_ids = parts
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 ssrc_ids = [int(ssrc_id) for ssrc_id in ssrc_ids]
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 application_data.setdefault("ssrc-group", {})[semantics] = ssrc_ids
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 elif attribute == "msid":
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 assert application_data is not None
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 application_data["msid"] = " ".join(parts)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 def _generate_sdp_content_trigger(
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 self,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 session: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 local: bool,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 idx: int,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 content_data: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 sdp_lines: List[str],
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 application_data: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 app_data_key: str,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 media_data: dict,
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 media: str
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 ) -> None:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 """Generate "msid" and "ssrc" attributes"""
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 if "msid" in media_data:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 sdp_lines.append(f"a=msid:{media_data['msid']}")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 ssrc_data = media_data.get("ssrc", {})
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 ssrc_group_data = media_data.get("ssrc-group", {})
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 for ssrc_id, attributes in ssrc_data.items():
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 if not attributes:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 # there are no attributes for this SSRC ID, we add a simple line with only
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 # the SSRC ID
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 sdp_lines.append(f"a=ssrc:{ssrc_id}")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 else:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 for attr_name, attr_value in attributes.items():
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 if attr_value is not None:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 sdp_lines.append(f"a=ssrc:{ssrc_id} {attr_name}:{attr_value}")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 else:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 sdp_lines.append(f"a=ssrc:{ssrc_id} {attr_name}")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 for semantics, ssrc_ids in ssrc_group_data.items():
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 ssrc_lines = " ".join(str(ssrc_id) for ssrc_id in ssrc_ids)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 sdp_lines.append(f"a=ssrc-group:{semantics} {ssrc_lines}")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 def _parse_description_trigger(
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 self, desc_elt: domish.Element, media_data: dict
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 ) -> bool:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 """Parse the <source> and <ssrc-group> elements"""
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 for source_elt in desc_elt.elements(NS_JINGLE_RTP_SSMA, "source"):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 try:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 ssrc_id = int(source_elt["ssrc"])
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 media_data.setdefault("ssrc", {})[ssrc_id] = {}
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 for param_elt in source_elt.elements(NS_JINGLE_RTP_SSMA, "parameter"):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 name = param_elt["name"]
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 value = param_elt.getAttribute("value")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 media_data["ssrc"][ssrc_id][name] = value
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 if name == "msid" and "msid" not in media_data:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 media_data["msid"] = value
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 except (KeyError, ValueError) as e:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 log.warning(f"Error while parsing <source>: {e}\n{source_elt.toXml()}")
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
152
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 for ssrc_group_elt in desc_elt.elements(NS_JINGLE_RTP_SSMA, "ssrc-group"):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 try:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 semantics = ssrc_group_elt["semantics"]
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 semantic_ids = media_data.setdefault("ssrc-group", {})[semantics] = []
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 for source_elt in ssrc_group_elt.elements(NS_JINGLE_RTP_SSMA, "source"):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 semantic_ids.append(
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 int(source_elt["ssrc"])
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 )
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 except (KeyError, ValueError) as e:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 log.warning(
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 f"Error while parsing <ssrc-group>: {e}\n{ssrc_group_elt.toXml()}"
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 )
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
165
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 return True
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
167
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def _build_description_trigger(
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 self, desc_elt: domish.Element, media_data: dict, session: dict
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 ) -> bool:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 """Build the <source> and <ssrc-group> elements if possible"""
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 for ssrc_id, parameters in media_data.get("ssrc", {}).items():
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 if "msid" not in parameters and "msid" in media_data:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 parameters["msid"] = media_data["msid"]
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 source_elt = desc_elt.addElement((NS_JINGLE_RTP_SSMA, "source"))
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 source_elt["ssrc"] = str(ssrc_id)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 for name, value in parameters.items():
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 param_elt = source_elt.addElement((NS_JINGLE_RTP_SSMA, "parameter"))
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 param_elt["name"] = name
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 if value is not None:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 param_elt["value"] = value
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
182
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 for semantics, ssrc_ids in media_data.get("ssrc-group", {}).items():
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 ssrc_group_elt = desc_elt.addElement((NS_JINGLE_RTP_SSMA, "ssrc-group"))
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 ssrc_group_elt["semantics"] = semantics
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 for ssrc_id in ssrc_ids:
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 source_elt = ssrc_group_elt.addElement((NS_JINGLE_RTP_SSMA, "source"))
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 source_elt["ssrc"] = str(ssrc_id)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
189
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 return True
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
191
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
192
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 @implementer(iwokkel.IDisco)
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 class XEP_0339_handler(XMPPHandler):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 return [disco.DiscoFeature(NS_JINGLE_RTP_SSMA)]
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
3f62c2445df1 plugin XEP-0339: "Source-Specific Media Attributes in Jingle" implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 return []