# HG changeset patch # User Goffi # Date 1692203608 -7200 # Node ID 0da563780ffc525596fe29e65b67c9bef405a257 # Parent 79ec7d7beef3b7bdb70856544fd1a2778aa00c64 plugin XEP-0167, XEP-0353: handle ringing: - add a `jingle_preflight_info` method in the Jingle Application model to handle this kind of information - XEP-0353 is calling `jingle_preflight_info` when a `ringing` message is received - XEP-0167 use this information to send a `ringing` info to frontends diff -r 79ec7d7beef3 -r 0da563780ffc libervia/backend/plugins/plugin_xep_0166/models.py --- a/libervia/backend/plugins/plugin_xep_0166/models.py Wed Aug 16 18:28:32 2023 +0200 +++ b/libervia/backend/plugins/plugin_xep_0166/models.py Wed Aug 16 18:33:28 2023 +0200 @@ -44,6 +44,20 @@ pass @abc.abstractmethod + async def jingle_preflight_info( + self, + client: SatXMPPEntity, + session: dict, + info_type: str, + info_data: dict|None = None + ) -> None: + """Called when we have new information during preflight + + Notably used by XEP-0353 to signal ringing + """ + pass + + @abc.abstractmethod async def jingle_preflight_cancel( self, client: SatXMPPEntity, diff -r 79ec7d7beef3 -r 0da563780ffc libervia/backend/plugins/plugin_xep_0167/__init__.py --- a/libervia/backend/plugins/plugin_xep_0167/__init__.py Wed Aug 16 18:28:32 2023 +0200 +++ b/libervia/backend/plugins/plugin_xep_0167/__init__.py Wed Aug 16 18:33:28 2023 +0200 @@ -387,6 +387,24 @@ if not accepted: raise exceptions.CancelError("User declined the incoming call.") + async def jingle_preflight_info( + self, + client: SatXMPPEntity, + session: dict, + info_type: str, + 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 + ) + # we indicate that the ringing has started, to avoid sending several times + # the signal + session["ringing"] = True + else: + log.warning(f"Unknown preflight info type: {info_type!r}") + async def jingle_preflight_cancel( self, client: SatXMPPEntity, diff -r 79ec7d7beef3 -r 0da563780ffc libervia/backend/plugins/plugin_xep_0234.py --- a/libervia/backend/plugins/plugin_xep_0234.py Wed Aug 16 18:28:32 2023 +0200 +++ b/libervia/backend/plugins/plugin_xep_0234.py Wed Aug 16 18:33:28 2023 +0200 @@ -464,6 +464,15 @@ session["file_accepted"] = True return accepted + async def jingle_preflight_info( + self, + client: SatXMPPEntity, + session: dict, + info_type: str, + info_data: dict|None = None + ) -> None: + pass + async def jingle_preflight_cancel( self, client: SatXMPPEntity, diff -r 79ec7d7beef3 -r 0da563780ffc libervia/backend/plugins/plugin_xep_0353.py --- a/libervia/backend/plugins/plugin_xep_0353.py Wed Aug 16 18:28:32 2023 +0200 +++ b/libervia/backend/plugins/plugin_xep_0353.py Wed Aug 16 18:33:28 2023 +0200 @@ -29,7 +29,6 @@ from libervia.backend.core.core_types import SatXMPPEntity from libervia.backend.core.i18n import D_, _ from libervia.backend.core.log import getLogger -from libervia.backend.tools import xml_tools log = getLogger(__name__) @@ -215,6 +214,8 @@ return self._handle_accept(client, message_elt, elt) elif elt.name == "reject": return self._handle_reject(client, message_elt, elt) + elif elt.name == "ringing": + return await self._handle_ringing(client, message_elt, elt) else: log.warning(f"invalid element: {elt.toXml}") return True @@ -367,6 +368,20 @@ response_d.errback(RejectException(reason, text)) return False + async def _handle_ringing(self, client, message_elt, ringing_elt): + session_id = ringing_elt["id"] + try: + session = self._j.get_session(client, session_id) + except exceptions.NotFound: + log.warning(f"Session {session_id!r} unknown, ignoring ringing.") + return False + for __, content_data in session["contents"].items(): + await content_data["application"].handler.jingle_preflight_info( + client, session, "ringing", None + ) + + return False + @implementer(iwokkel.IDisco) class Handler(xmlstream.XMPPHandler):