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
This commit is contained in:
Goffi 2023-08-16 18:33:28 +02:00
commit 09d88cdfe2
4 changed files with 57 additions and 1 deletions

View file

@ -43,6 +43,20 @@ class BaseApplicationHandler(abc.ABC):
"""
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,

View file

@ -387,6 +387,24 @@ class XEP_0167(BaseApplicationHandler):
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,

View file

@ -464,6 +464,15 @@ class XEP_0234(BaseApplicationHandler):
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,

View file

@ -29,7 +29,6 @@ from libervia.backend.core.constants import Const as C
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 @@ class XEP_0353:
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 @@ class XEP_0353:
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):