annotate libervia/backend/plugins/plugin_xep_0167/mapping.py @ 4272:89a0999884ac default tip @

cli (list/set): add "--comments" argument.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:46:55 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
4058
adb9dc9c8114 plugin XEP-0167: fix wrong copy/pasted header
Goffi <goffi@goffi.org>
parents: 4056
diff changeset
3 # Libervia: an XMPP client
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import base64
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from typing import Any, Dict, Optional
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.words.xish import domish
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4058
diff changeset
24 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4058
diff changeset
25 from libervia.backend.core.log import getLogger
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from .constants import NS_JINGLE_RTP
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 log = getLogger(__name__)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 host = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 def senders_to_sdp(senders: str, session: dict) -> str:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 """Returns appropriate SDP attribute corresponding to Jingle senders attribute"""
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 if senders == "both":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 return "a=sendrecv"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 elif senders == "none":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 return "a=inactive"
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
40 elif session["role"] != senders:
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 return "a=sendonly"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 else:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 return "a=recvonly"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
46 def generate_sdp_from_session(session: dict, local: bool = False, port: int = 9) -> str:
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 """Generate an SDP string from session data.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 @param session: A dictionary containing the session data. It should have the
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 following structure:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 "contents": {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "<content_id>": {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "application_data": {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "media": <str: "audio" or "video">,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "local_data": <media_data dict>,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "peer_data": <media_data dict>,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 ...
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 },
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "transport_data": {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 "local_ice_data": <ice_data dict>,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 "peer_ice_data": <ice_data dict>,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 ...
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 },
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 ...
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 },
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 ...
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 @param local: A boolean value indicating whether to generate SDP for the local or
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 peer entity. If True, the method will generate SDP for the local entity,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 otherwise for the peer entity. Generally the local SDP is received from frontends
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 and not needed in backend, except for debugging purpose.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 @param port: The preferred port for communications.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
76
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 @return: The generated SDP string.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 """
4121
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
79 contents = session["contents"]
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 sdp_lines = ["v=0"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
81
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 # Add originator (o=) line after the version (v=) line
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 username = base64.b64encode(session["local_jid"].full().encode()).decode()
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 session_id = "1" # Increment this for each session
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 session_version = "1" # Increment this when the session is updated
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 network_type = "IN"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 address_type = "IP4"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 connection_address = "0.0.0.0"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 o_line = (
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 f"o={username} {session_id} {session_version} {network_type} {address_type} "
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 f"{connection_address}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 sdp_lines.append(o_line)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 # Add the mandatory "s=" and t=" lines
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 sdp_lines.append("s=-")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 sdp_lines.append("t=0 0")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 # stream direction
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 all_senders = {c["senders"] for c in session["contents"].values()}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 # if we don't have a common senders for all contents, we set them at media level
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 senders = all_senders.pop() if len(all_senders) == 1 else None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 sdp_lines.append("a=msid-semantic:WMS *")
4121
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
105 sdp_lines.append("a=ice-options:trickle")
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 host.trigger.point(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 "XEP-0167_generate_sdp_session",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 session,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 local,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 sdp_lines,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
112 triggers_no_cancel=True,
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 )
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
114 content_names = sorted(contents)
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
116 for content_name, content_data in [
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
117 (n, contents[n]) for n in content_names
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
118 ]: # contents.items():
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 app_data_key = "local_data" if local else "peer_data"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 application_data = content_data["application_data"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 media_data = application_data[app_data_key]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 media = application_data["media"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 payload_types = media_data.get("payload_types", {})
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
124
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 # Generate m= line
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
126 if media == "application":
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
127 transport = "UDP/DTLS/SCTP"
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
128 m_line = f"m={media} {port} {transport} webrtc-datachannel"
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
129 else:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
130 transport = "UDP/TLS/RTP/SAVPF"
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
131 payload_type_ids = [str(pt_id) for pt_id in payload_types]
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
132 m_line = f"m={media} {port} {transport} {' '.join(payload_type_ids)}"
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 sdp_lines.append(m_line)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
134
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 sdp_lines.append(f"c={network_type} {address_type} {connection_address}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
136
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 sdp_lines.append(f"a=mid:{content_name}")
4121
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
138 if senders is not None:
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
139 sdp_lines.append(senders_to_sdp(senders, session))
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 # stream direction
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 if senders is None:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 sdp_lines.append(senders_to_sdp(content_data["senders"], session))
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 # Generate a= lines for rtpmap and fmtp
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 for pt_id, pt in payload_types.items():
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 name = pt["name"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 clockrate = pt.get("clockrate", "")
4121
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
149
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
150 # Check if "channels" is in pt and append it to the line
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
151 channels = pt.get("channels")
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
152 if channels:
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
153 sdp_lines.append(f"a=rtpmap:{pt_id} {name}/{clockrate}/{channels}")
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
154 else:
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
155 sdp_lines.append(f"a=rtpmap:{pt_id} {name}/{clockrate}")
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 if "ptime" in pt:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 sdp_lines.append(f"a=ptime:{pt['ptime']}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
159
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 if "parameters" in pt:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 fmtp_params = ";".join([f"{k}={v}" for k, v in pt["parameters"].items()])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 sdp_lines.append(f"a=fmtp:{pt_id} {fmtp_params}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 if "bandwidth" in media_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 sdp_lines.append(f"a=b:{media_data['bandwidth']}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
166
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 if media_data.get("rtcp-mux"):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 sdp_lines.append("a=rtcp-mux")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
169
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 # Generate a= lines for fingerprint, ICE ufrag, pwd and candidates
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 ice_data_key = "local_ice_data" if local else "peer_ice_data"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 ice_data = content_data["transport_data"][ice_data_key]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
173
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 if "fingerprint" in ice_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 fingerprint_data = ice_data["fingerprint"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 sdp_lines.append(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 f"a=fingerprint:{fingerprint_data['hash']} "
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 f"{fingerprint_data['fingerprint']}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 sdp_lines.append(f"a=setup:{fingerprint_data['setup']}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
181
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 sdp_lines.append(f"a=ice-ufrag:{ice_data['ufrag']}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 sdp_lines.append(f"a=ice-pwd:{ice_data['pwd']}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 for candidate in ice_data["candidates"]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 foundation = candidate["foundation"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 component_id = candidate["component_id"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 transport = candidate["transport"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 priority = candidate["priority"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 address = candidate["address"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 candidate_port = candidate["port"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 candidate_type = candidate["type"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
193
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 candidate_line = (
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 f"a=candidate:{foundation} {component_id} {transport} {priority} "
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 f"{address} {candidate_port} typ {candidate_type}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 if "rel_addr" in candidate and "rel_port" in candidate:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 candidate_line += (
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 f" raddr {candidate['rel_addr']} rport {candidate['rel_port']}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 if "generation" in candidate:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 candidate_line += f" generation {candidate['generation']}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
206
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 if "network" in candidate:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 candidate_line += f" network {candidate['network']}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
209
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 sdp_lines.append(candidate_line)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
211
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 # Generate a= lines for encryption
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 if "encryption" in media_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 for enc_data in media_data["encryption"]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 crypto_suite = enc_data["crypto-suite"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 key_params = enc_data["key-params"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 session_params = enc_data.get("session-params", "")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 tag = enc_data["tag"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
219
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 crypto_line = f"a=crypto:{tag} {crypto_suite} {key_params}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 if session_params:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 crypto_line += f" {session_params}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 sdp_lines.append(crypto_line)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
224
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 host.trigger.point(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 "XEP-0167_generate_sdp_content",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 session,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 local,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 content_name,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 content_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 sdp_lines,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 application_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 app_data_key,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 media_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 media,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
236 triggers_no_cancel=True,
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
238
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 # Combine SDP lines and return the result
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 return "\r\n".join(sdp_lines) + "\r\n"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
241
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
242
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
243 def parse_sdp(sdp: str, role: str) -> dict:
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 """Parse SDP string.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
245
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 @param sdp: The SDP string to parse.
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
247 @param role: Role of the entities which produces the SDP.
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 @return: A dictionary containing parsed session data.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 """
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 # FIXME: to be removed once host is accessible from global var
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 assert host is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 lines = sdp.strip().split("\r\n")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 # session metadata
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 metadata: Dict[str, Any] = {}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 call_data = {"metadata": metadata}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
256
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 media_type = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 media_data: Optional[Dict[str, Any]] = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 application_data: Optional[Dict[str, Any]] = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 transport_data: Optional[Dict[str, Any]] = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 fingerprint_data: Optional[Dict[str, str]] = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 ice_pwd: Optional[str] = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 ice_ufrag: Optional[str] = None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 payload_types: Optional[Dict[int, dict]] = None
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
265 # default value, will be be modified by SDP
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
266 senders: str = "both"
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
267
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 for line in lines:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 try:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 parts = line.split()
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 prefix = parts[0][:2] # Extract the 'a=', 'm=', etc., prefix
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 parts[0] = parts[0][2:] # Remove the prefix from the first element
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
273
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 if prefix == "m=":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 media_type = parts[0]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 port = int(parts[1])
4231
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
277 application_data = {"media": media_type}
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
278 if media_type in ("video", "audio"):
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
279 payload_types = application_data["payload_types"] = {}
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
280 for payload_type_id in [int(pt_id) for pt_id in parts[3:]]:
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
281 payload_type = {"id": payload_type_id}
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
282 payload_types[payload_type_id] = payload_type
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
283 elif media_type == "application":
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
284 if parts[3] != "webrtc-datachannel":
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
285 raise NotImplementedError(
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
286 f"{media_type!r} application is not supported"
e11b13418ba6 plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents: 4121
diff changeset
287 )
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
288
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 transport_data = {"port": port}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 if fingerprint_data is not None:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 transport_data["fingerprint"] = fingerprint_data
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 if ice_pwd is not None:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 transport_data["pwd"] = ice_pwd
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 if ice_ufrag is not None:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 transport_data["ufrag"] = ice_ufrag
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 media_data = call_data[media_type] = {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 "application_data": application_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 "transport_data": transport_data,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
299 "senders": senders,
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
301
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 elif prefix == "a=":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 if ":" in parts[0]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 attribute, parts[0] = parts[0].split(":", 1)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 else:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 attribute = parts[0]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
307
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 if (
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 media_type is None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 or application_data is None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 or transport_data is None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 ) and not (
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 attribute
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 in (
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 "sendrecv",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 "sendonly",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 "recvonly",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 "inactive",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 "fingerprint",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 "group",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 "ice-options",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 "msid-semantic",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 "ice-pwd",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 "ice-ufrag",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 ):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 log.warning(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 "Received attribute before media description, this is "
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 f"invalid: {line}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 continue
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
332
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 if attribute == "mid":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 assert media_data is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 try:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 media_data["id"] = parts[0]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 except IndexError:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 log.warning(f"invalid media ID: {line}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
339
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 elif attribute == "rtpmap":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 assert application_data is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 assert payload_types is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 pt_id = int(parts[0])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 codec_info = parts[1].split("/")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 codec = codec_info[0]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 clockrate = int(codec_info[1])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 payload_type = {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 "id": pt_id,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 "name": codec,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 "clockrate": clockrate,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 # Handle optional channel count
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 if len(codec_info) > 2:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 channels = int(codec_info[2])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 payload_type["channels"] = channels
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
356
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 payload_types.setdefault(pt_id, {}).update(payload_type)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
358
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 elif attribute == "fmtp":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 assert payload_types is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 pt_id = int(parts[0])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 params = parts[1].split(";")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 try:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 payload_type = payload_types[pt_id]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 except KeyError:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 raise ValueError(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 f"Can find content type {pt_id}, ignoring: {line}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
369
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 try:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 payload_type["parameters"] = {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 name: value
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 for name, value in (param.split("=") for param in params)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 except ValueError:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 payload_type.setdefault("exra-parameters", []).extend(params)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
377
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 elif attribute == "candidate":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 assert transport_data is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 candidate = {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 "foundation": parts[0],
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 "component_id": int(parts[1]),
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 "transport": parts[2],
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 "priority": int(parts[3]),
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 "address": parts[4],
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 "port": int(parts[5]),
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 "type": parts[7],
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
389
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 for part in parts[8:]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
391 if part == "raddr":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
392 candidate["rel_addr"] = parts[parts.index(part) + 1]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
393 elif part == "rport":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 candidate["rel_port"] = int(parts[parts.index(part) + 1])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 elif part == "generation":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
396 candidate["generation"] = parts[parts.index(part) + 1]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
397 elif part == "network":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
398 candidate["network"] = parts[parts.index(part) + 1]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
399
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
400 transport_data.setdefault("candidates", []).append(candidate)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
401
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
402 elif attribute == "fingerprint":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
403 algorithm, fingerprint = parts[0], parts[1]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
404 fingerprint_data = {"hash": algorithm, "fingerprint": fingerprint}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
405 if transport_data is not None:
4121
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
406 transport_data.setdefault("fingerprint", {}).update(
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
407 fingerprint_data
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
408 )
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
409 elif attribute == "setup":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
410 assert transport_data is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
411 setup = parts[0]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
412 transport_data.setdefault("fingerprint", {})["setup"] = setup
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
413
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
414 elif attribute == "b":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
415 assert application_data is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
416 bandwidth = int(parts[0])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
417 application_data["bandwidth"] = bandwidth
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
418
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
419 elif attribute == "rtcp-mux":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
420 assert application_data is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
421 application_data["rtcp-mux"] = True
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
422
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
423 elif attribute == "ice-ufrag":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
424 if transport_data is not None:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
425 transport_data["ufrag"] = parts[0]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
426
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
427 elif attribute == "ice-pwd":
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
428 if transport_data is not None:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
429 transport_data["pwd"] = parts[0]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
430
4240
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
431 elif attribute in ("sendrecv", "sendonly", "recvonly", "inactive"):
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
432 if attribute == "sendrecv":
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
433 value = "both"
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
434 elif attribute == "sendonly":
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
435 value = role
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
436 elif attribute == "recvonly":
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
437 value = "responder" if role == "initiator" else "initiator"
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
438 else:
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
439 value = "none"
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
440
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
441 if application_data is None:
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
442 # this is a global value, we use is as new default value
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
443 senders = value
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
444 else:
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
445 # this is a media specific value, it will replace the one used as
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
446 # default for this media
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
447 application_data["senders"] = value
79c8a70e1813 backend, frontend: prepare remote control:
Goffi <goffi@goffi.org>
parents: 4231
diff changeset
448
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
449 host.trigger.point(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
450 "XEP-0167_parse_sdp_a",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
451 attribute,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
452 parts,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
453 call_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
454 metadata,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
455 media_type,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
456 application_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
457 transport_data,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
458 triggers_no_cancel=True,
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
459 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
460
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
461 except ValueError as e:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
462 raise ValueError(f"Could not parse line. Invalid format ({e}): {line}") from e
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
463 except IndexError as e:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
464 raise IndexError(f"Incomplete line. Missing data: {line}") from e
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
465
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
466 # we remove private data (data starting with _, used by some plugins (e.g. XEP-0294)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
467 # to handle session data at media level))
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
468 for key in [k for k in call_data if k.startswith("_")]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
469 log.debug(f"cleaning remaining private data {key!r}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
470 del call_data[key]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
471
4121
b2709504586a plugin XEP-0167: mapping adjustments:
Goffi <goffi@goffi.org>
parents: 4116
diff changeset
472 # FIXME: is this really useful?
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
473 # ICE candidates may only be specified for the first media, this
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
474 # duplicate the candidate for the other in this case
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
475 all_media = {k: v for k, v in call_data.items() if k in ("audio", "video")}
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
476 if len(all_media) > 1 and not all(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
477 "candidates" in c["transport_data"] for c in all_media.values()
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
478 ):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
479 first_content = next(iter(all_media.values()))
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
480 try:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
481 ice_candidates = first_content["transport_data"]["candidates"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
482 except KeyError:
4116
23fa52acf72c plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
483 ice_candidates = []
23fa52acf72c plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
484 for idx, content in enumerate(all_media.values()):
23fa52acf72c plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
485 if idx == 0:
23fa52acf72c plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
486 continue
23fa52acf72c plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
487 content["transport_data"].setdefault("candidates", ice_candidates)
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
488
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
489 return call_data
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
490
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
491
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
492 def build_description(media: str, media_data: dict, session: dict) -> domish.Element:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
493 """Generate <description> element from media data
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
494
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
495 @param media: media type ("audio" or "video")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
496
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 @param media_data: A dictionary containing the media description data.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 The keys and values are described below:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
499
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 - ssrc (str, optional): The synchronization source identifier.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
501 - payload_types (list): A list of dictionaries, each representing a payload
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
502 type.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
503 Each dictionary may contain the following keys:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
504 - channels (str, optional): Number of audio channels.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
505 - clockrate (str, optional): Clock rate of the media.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
506 - id (str): The unique identifier of the payload type.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
507 - maxptime (str, optional): Maximum packet time.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
508 - name (str, optional): Name of the codec.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
509 - ptime (str, optional): Preferred packet time.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
510 - parameters (dict, optional): A dictionary of codec-specific parameters.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
511 Key-value pairs represent the parameter name and value, respectively.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
512 - bandwidth (str, optional): The bandwidth type.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
513 - rtcp-mux (bool, optional): Indicates whether RTCP multiplexing is enabled or
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
514 not.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
515 - encryption (list, optional): A list of dictionaries, each representing an
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
516 encryption method.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
517 Each dictionary may contain the following keys:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
518 - tag (str): The unique identifier of the encryption method.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
519 - crypto-suite (str): The encryption suite in use.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
520 - key-params (str): Key parameters for the encryption suite.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
521 - session-params (str, optional): Session parameters for the encryption
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
522 suite.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
523
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
524 @return: A <description> element.
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
525 """
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
526 # FIXME: to be removed once host is accessible from global var
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
527 assert host is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
528
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
529 desc_elt = domish.Element((NS_JINGLE_RTP, "description"), attribs={"media": media})
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
530
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
531 for pt_id, pt_data in media_data.get("payload_types", {}).items():
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
532 payload_type_elt = desc_elt.addElement("payload-type")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
533 payload_type_elt["id"] = str(pt_id)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
534 for attr in ["channels", "clockrate", "maxptime", "name", "ptime"]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
535 if attr in pt_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
536 payload_type_elt[attr] = str(pt_data[attr])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
537
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
538 if "parameters" in pt_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
539 for param_name, param_value in pt_data["parameters"].items():
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
540 param_elt = payload_type_elt.addElement("parameter")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
541 param_elt["name"] = param_name
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
542 param_elt["value"] = param_value
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
543 host.trigger.point(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
544 "XEP-0167_build_description_payload_type",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
545 desc_elt,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
546 media_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
547 pt_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
548 payload_type_elt,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
549 triggers_no_cancel=True,
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
550 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
551
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
552 if "bandwidth" in media_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
553 bandwidth_elt = desc_elt.addElement("bandwidth")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
554 bandwidth_elt["type"] = media_data["bandwidth"]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
555
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
556 if media_data.get("rtcp-mux"):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
557 desc_elt.addElement("rtcp-mux")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
558
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
559 # Add encryption element
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
560 if "encryption" in media_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
561 encryption_elt = desc_elt.addElement("encryption")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
562 # we always want require encryption if the `encryption` data is present
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
563 encryption_elt["required"] = "1"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
564 for enc_data in media_data["encryption"]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
565 crypto_elt = encryption_elt.addElement("crypto")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
566 for attr in ["tag", "crypto-suite", "key-params", "session-params"]:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
567 if attr in enc_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
568 crypto_elt[attr] = enc_data[attr]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
569
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
570 host.trigger.point(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
571 "XEP-0167_build_description",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
572 desc_elt,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
573 media_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
574 session,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
575 triggers_no_cancel=True,
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
576 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
577
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
578 return desc_elt
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
579
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
580
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
581 def parse_description(desc_elt: domish.Element) -> dict:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
582 """Parse <desciption> to a dict
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
583
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
584 @param desc_elt: <description> element
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
585 @return: media data as in [build_description]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
586 """
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
587 # FIXME: to be removed once host is accessible from global var
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
588 assert host is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
589
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
590 media_data = {}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
591 if desc_elt.hasAttribute("ssrc"):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
592 media_data.setdefault("ssrc", {})[desc_elt["ssrc"]] = {}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
593
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
594 payload_types = {}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
595 for payload_type_elt in desc_elt.elements(NS_JINGLE_RTP, "payload-type"):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
596 payload_type_data = {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
597 attr: payload_type_elt[attr]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
598 for attr in [
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
599 "channels",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
600 "clockrate",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
601 "maxptime",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
602 "name",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
603 "ptime",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
604 ]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
605 if payload_type_elt.hasAttribute(attr)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
606 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
607 try:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
608 pt_id = int(payload_type_elt["id"])
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
609 except KeyError:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
610 log.warning(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
611 f"missing ID in payload type, ignoring: {payload_type_elt.toXml()}"
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
612 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
613 continue
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
614
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
615 parameters = {}
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
616 for param_elt in payload_type_elt.elements(NS_JINGLE_RTP, "parameter"):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
617 param_name = param_elt.getAttribute("name")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
618 param_value = param_elt.getAttribute("value")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
619 if not param_name or param_value is None:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
620 log.warning(f"invalid parameter: {param_elt.toXml()}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
621 continue
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
622 parameters[param_name] = param_value
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
623
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
624 if parameters:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
625 payload_type_data["parameters"] = parameters
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
626
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
627 host.trigger.point(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
628 "XEP-0167_parse_description_payload_type",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
629 desc_elt,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
630 media_data,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
631 payload_type_elt,
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
632 payload_type_data,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
633 triggers_no_cancel=True,
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
634 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
635 payload_types[pt_id] = payload_type_data
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
636
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
637 # bandwidth
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
638 media_data["payload_types"] = payload_types
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
639 try:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
640 bandwidth_elt = next(desc_elt.elements(NS_JINGLE_RTP, "bandwidth"))
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
641 except StopIteration:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
642 pass
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
643 else:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
644 bandwidth = bandwidth_elt.getAttribute("type")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
645 if not bandwidth:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
646 log.warning(f"invalid bandwidth: {bandwidth_elt.toXml}")
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
647 else:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
648 media_data["bandwidth"] = bandwidth
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
649
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
650 # rtcp-mux
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
651 rtcp_mux_elt = next(desc_elt.elements(NS_JINGLE_RTP, "rtcp-mux"), None)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
652 media_data["rtcp-mux"] = rtcp_mux_elt is not None
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
653
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
654 # Encryption
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
655 encryption_data = []
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
656 encryption_elt = next(desc_elt.elements(NS_JINGLE_RTP, "encryption"), None)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
657 if encryption_elt:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
658 media_data["encryption_required"] = C.bool(
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
659 encryption_elt.getAttribute("required", C.BOOL_FALSE)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
660 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
661
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
662 for crypto_elt in encryption_elt.elements(NS_JINGLE_RTP, "crypto"):
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
663 crypto_data = {
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
664 attr: crypto_elt[attr]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
665 for attr in [
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
666 "crypto-suite",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
667 "key-params",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
668 "session-params",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
669 "tag",
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
670 ]
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
671 if crypto_elt.hasAttribute(attr)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
672 }
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
673 encryption_data.append(crypto_data)
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
674
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
675 if encryption_data:
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
676 media_data["encryption"] = encryption_data
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
677
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
678 host.trigger.point(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4240
diff changeset
679 "XEP-0167_parse_description", desc_elt, media_data, triggers_no_cancel=True
4056
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
680 )
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
681
1c4f4aa36d98 plugin XEP-0167: Jingle RTP Sessions implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
682 return media_data