plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
This commit is contained in:
parent
09d88cdfe2
commit
d60b79b18f
2 changed files with 125 additions and 108 deletions
|
|
@ -115,19 +115,13 @@ class XEP_0167(BaseApplicationHandler):
|
|||
|
||||
# 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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
)
|
||||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
):
|
||||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
# 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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
self.host.bridge.call_ended(
|
||||
session["id"],
|
||||
data_format.serialise({"reason": "retracted"}),
|
||||
client.profile
|
||||
client.profile,
|
||||
)
|
||||
raise e
|
||||
|
||||
|
|
@ -392,13 +375,11 @@ class XEP_0167(BaseApplicationHandler):
|
|||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
|
||||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
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 @@ class XEP_0167(BaseApplicationHandler):
|
|||
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(
|
||||
|
|
|
|||
|
|
@ -439,12 +439,11 @@ def parse_sdp(sdp: str) -> dict:
|
|||
try:
|
||||
ice_candidates = first_content["transport_data"]["candidates"]
|
||||
except KeyError:
|
||||
log.warning("missing candidates in SDP")
|
||||
else:
|
||||
for idx, content in enumerate(all_media.values()):
|
||||
if idx == 0:
|
||||
continue
|
||||
content["transport_data"].setdefault("candidates", ice_candidates)
|
||||
ice_candidates = []
|
||||
for idx, content in enumerate(all_media.values()):
|
||||
if idx == 0:
|
||||
continue
|
||||
content["transport_data"].setdefault("candidates", ice_candidates)
|
||||
|
||||
return call_data
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue