Mercurial > libervia-backend
diff libervia/backend/plugins/plugin_xep_0167/__init__.py @ 4116:23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 21 Aug 2023 15:19:45 +0200 |
parents | 0da563780ffc |
children | 07370d2a9bde |
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0167/__init__.py Wed Aug 16 18:33:28 2023 +0200 +++ b/libervia/backend/plugins/plugin_xep_0167/__init__.py Mon Aug 21 15:19:45 2023 +0200 @@ -115,19 +115,13 @@ # args: session_id, serialised setup data (dict with keys "role" and "sdp"), # profile - host.bridge.add_signal( - "call_setup", ".plugin", signature="sss" - ) + host.bridge.add_signal("call_setup", ".plugin", signature="sss") # args: session_id, data, profile - host.bridge.add_signal( - "call_ended", ".plugin", signature="sss" - ) + host.bridge.add_signal("call_ended", ".plugin", signature="sss") # args: session_id, info_type, extra, profile - host.bridge.add_signal( - "call_info", ".plugin", signature="ssss" - ) + host.bridge.add_signal("call_info", ".plugin", signature="ssss") def get_handler(self, client): return XEP_0167_handler() @@ -194,7 +188,9 @@ except KeyError: log.warning(f"no media ID found for {media_type}: {media_data}") try: - call_data[media_type]["ice-candidates"] = transport_data["candidates"] + call_data[media_type]["ice-candidates"] = transport_data.get( + "candidates", [] + ) metadata["ice-ufrag"] = transport_data["ufrag"] metadata["ice-pwd"] = transport_data["pwd"] except KeyError: @@ -250,12 +246,7 @@ ) return sid - def _call_answer_sdp( - self, - session_id: str, - answer_sdp: str, - profile: str - ) -> None: + def _call_answer_sdp(self, session_id: str, answer_sdp: str, profile: str) -> None: client = self.host.get_client(profile) session = self._j.get_session(client, session_id) try: @@ -274,9 +265,7 @@ ): client = self.host.get_client(profile_key) return defer.ensureDeferred( - self.call_end( - client, session_id, data_format.deserialise(data_s) - ) + self.call_end(client, session_id, data_format.deserialise(data_s)) ) async def call_end( @@ -297,10 +286,7 @@ # jingle callbacks async def confirm_incoming_call( - self, - client: SatXMPPEntity, - session: dict, - call_type: str + self, client: SatXMPPEntity, session: dict, call_type: str ) -> bool: """Prompt the user for a call confirmation. @@ -341,10 +327,7 @@ return accepted async def jingle_preflight( - self, - client: SatXMPPEntity, - session: dict, - description_elt: domish.Element + self, client: SatXMPPEntity, session: dict, description_elt: domish.Element ) -> None: """Perform preflight checks for an incoming call session. @@ -380,7 +363,7 @@ self.host.bridge.call_ended( session["id"], data_format.serialise({"reason": "retracted"}), - client.profile + client.profile, ) raise e @@ -392,13 +375,11 @@ client: SatXMPPEntity, session: dict, info_type: str, - info_data: dict|None = None + info_data: dict | None = None, ) -> None: if info_type == "ringing": if not session.get("ringing", False): - self.host.bridge.call_info( - session["id"], "ringing", "", client.profile - ) + self.host.bridge.call_info(session["id"], "ringing", "", client.profile) # we indicate that the ringing has started, to avoid sending several times # the signal session["ringing"] = True @@ -406,10 +387,7 @@ log.warning(f"Unknown preflight info type: {info_type!r}") async def jingle_preflight_cancel( - self, - client: SatXMPPEntity, - session: dict, - cancel_error: exceptions.CancelError + self, client: SatXMPPEntity, session: dict, cancel_error: exceptions.CancelError ) -> None: """The call has been rejected""" # call_ended is use to send the signal only once even if there are audio and video @@ -417,20 +395,15 @@ call_ended = session.get("call_ended", False) if call_ended: return - data = { - "reason": getattr(cancel_error, "reason", "cancelled") - } + data = {"reason": getattr(cancel_error, "reason", "cancelled")} text = getattr(cancel_error, "text", None) if text: data["text"] = text self.host.bridge.call_ended( - session["id"], - data_format.serialise(data), - client.profile + session["id"], data_format.serialise(data), client.profile ) session["call_ended"] = True - def jingle_session_init( self, client: SatXMPPEntity, @@ -507,11 +480,13 @@ self.host.bridge.call_setup( session["id"], - data_format.serialise({ - "role": session["role"], - "sdp": sdp, - }), - client.profile + data_format.serialise( + { + "role": session["role"], + "sdp": sdp, + } + ), + client.profile, ) answer_sdp = await answer_sdp_d @@ -559,11 +534,13 @@ answer_sdp = mapping.generate_sdp_from_session(session) self.host.bridge.call_setup( session["id"], - data_format.serialise({ - "role": session["role"], - "sdp": answer_sdp, - }), - client.profile + data_format.serialise( + { + "role": session["role"], + "sdp": answer_sdp, + } + ), + client.profile, ) else: log.warning(f"FIXME: unmanaged action {action}") @@ -635,9 +612,7 @@ reason_elt: domish.Element, ) -> None: reason, text = self._j.parse_reason_elt(reason_elt) - data = { - "reason": reason - } + data = {"reason": reason} if text: data["text"] = text self.host.bridge.call_ended(