changeset 1559:410064b31dca

browser (calls): add some logs useful for debugging
author Goffi <goffi@goffi.org>
date Wed, 16 Aug 2023 16:52:53 +0200
parents 2f2250ddad23
children 84f312be53b4
files libervia/web/pages/calls/_browser/webrtc.py libervia/web/server/server.py
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/web/pages/calls/_browser/webrtc.py	Tue Aug 15 17:30:20 2023 +0200
+++ b/libervia/web/pages/calls/_browser/webrtc.py	Wed Aug 16 16:52:53 2023 +0200
@@ -18,6 +18,7 @@
     def __init__(self):
         self.reset_instance()
         bridge.register_signal("ice_candidates_new", self._on_ice_candidates_new)
+        bridge.register_signal("ice_restart", self._on_ice_restart)
         self.is_audio_muted = None
         self.is_video_muted = None
         self._is_sharing_screen = False
@@ -186,6 +187,23 @@
         else:
             log.debug("All ICE candidates gathered")
 
+    def on_ice_connection_state_change(self, event):
+        """Log ICE connection change, mainly used for debugging"""
+        state = self._peer_connection.iceConnectionState
+        log.info(f"ICE Connection State changed to: {state}")
+
+        if state == "failed":
+            log.error("ICE connection failed. Check network connectivity and ICE configurations.")
+        elif state == "disconnected":
+            log.warning("ICE connection was disconnected.")
+
+    def on_ice_candidate_error(self, event):
+        """Log ICE error, useful for debugging"""
+        log.error(f"ICE Candidate Error: {event.errorText} (Code: {event.errorCode})")
+        log.debug(
+            f"URL: {event.url}, Host candidate: {event.hostCandidate}, Port: {event.port}"
+        )
+
     def _set_media_types(self, offer):
         """Sets media types from offer SDP
 
@@ -240,7 +258,12 @@
         peer_connection = window.RTCPeerConnection.new(rtc_configuration)
         peer_connection.addEventListener("track", self.on_track)
         peer_connection.addEventListener("negotiationneeded", self.on_negotiation_needed)
+        peer_connection.addEventListener(
+            "iceconnectionstatechange",
+            self.on_ice_connection_state_change
+        )
         peer_connection.addEventListener("icecandidate", self.on_ice_candidate)
+        peer_connection.addEventListener("icecandidateerror", self.on_ice_candidate_error)
         peer_connection.addEventListener(
             "icegatheringstatechange", self.on_ice_gathering_state_change
         )
@@ -401,6 +424,12 @@
         candidates = json.loads(candidates_s)
         aio.run(self.on_ice_candidates_new(candidates))
 
+    def _on_ice_restart(self, sid: str, side: str, profile: str):
+        if sid != self.sid:
+            log.debug(f"ignoring peer ice candidates for {sid=} ({self.sid=}).")
+            return
+        log.debug("ICE has been restarted")
+
     async def on_ice_candidates_new(self, candidates: dict) -> None:
         """Called when new ICE canidates are received from peer
 
--- a/libervia/web/server/server.py	Tue Aug 15 17:30:20 2023 +0200
+++ b/libervia/web/server/server.py	Wed Aug 16 16:52:53 2023 +0200
@@ -570,6 +570,7 @@
         self.bridge.register_signal(
             "ps_event_raw", partial(LiberviaPage.on_node_event, self), "plugin"
         )
+
         self.bridge.register_signal(
             "message_new", partial(self.on_signal, "message_new")
         )
@@ -583,6 +584,9 @@
             "ice_candidates_new", partial(self.on_signal, "ice_candidates_new"), "plugin"
         )
         self.bridge.register_signal(
+            "ice_restart", partial(self.on_signal, "ice_restart"), "plugin"
+        )
+        self.bridge.register_signal(
             "action_new", self.action_new_handler,
         )