From a33f20d3925c8bf91e3fed9bf7e78be4d4b06e36 Mon Sep 17 00:00:00 2001 From: Fabien Danieau Date: Thu, 23 Nov 2023 18:03:06 +0100 Subject: [PATCH] bug #31: code cherry picked from aiortc_adapter to better handle an ice candidate --- src/gst_signalling/gst_abstract_role.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gst_signalling/gst_abstract_role.py b/src/gst_signalling/gst_abstract_role.py index 0d404ea..a276fff 100644 --- a/src/gst_signalling/gst_abstract_role.py +++ b/src/gst_signalling/gst_abstract_role.py @@ -10,6 +10,8 @@ import pyee from typing import Any, Dict, NamedTuple, Optional +from aiortc.sdp import candidate_from_sdp + from .gst_signalling import GstSignalling @@ -118,10 +120,15 @@ async def peer_for_session( await pc.setRemoteDescription(obj) elif "ice" in message: - obj = object_from_string(json.dumps(message["ice"])) - if isinstance(obj, RTCIceCandidate): - self.logger.info("Received ice candidate") - pc.addIceCandidate(obj) + message = message["ice"] + if message["candidate"] == "": + self.logger.info("Received empty candidate, ignoring") + return None + + obj = candidate_from_sdp(message["candidate"].split(":", 1)[1]) + obj.sdpMLineIndex = message["sdpMLineIndex"] + + await pc.addIceCandidate(obj) async def close_session(self, session_id: str) -> None: session = self.sessions.pop(session_id)