comparison libervia/web/pages/calls/_browser/webrtc.py @ 1561:7dbb131bbb9e

browser (calls): update status on various events (connection established, connection lost, etc.)
author Goffi <goffi@goffi.org>
date Thu, 17 Aug 2023 14:58:21 +0200
parents 410064b31dca
children e3449beac8d8
comparison
equal deleted inserted replaced
1560:84f312be53b4 1561:7dbb131bbb9e
17 class WebRTC: 17 class WebRTC:
18 def __init__(self): 18 def __init__(self):
19 self.reset_instance() 19 self.reset_instance()
20 bridge.register_signal("ice_candidates_new", self._on_ice_candidates_new) 20 bridge.register_signal("ice_candidates_new", self._on_ice_candidates_new)
21 bridge.register_signal("ice_restart", self._on_ice_restart) 21 bridge.register_signal("ice_restart", self._on_ice_restart)
22 self.on_connection_established_cb = None
23 self.on_reconnect_cb = None
24 self.on_connection_lost_cb = None
22 self.is_audio_muted = None 25 self.is_audio_muted = None
23 self.is_video_muted = None 26 self.is_video_muted = None
24 self._is_sharing_screen = False 27 self._is_sharing_screen = False
25 self.screen_sharing_cb = None 28 self.screen_sharing_cb = None
26 self.local_video_elt = document["local_video"] 29 self.local_video_elt = document["local_video"]
190 def on_ice_connection_state_change(self, event): 193 def on_ice_connection_state_change(self, event):
191 """Log ICE connection change, mainly used for debugging""" 194 """Log ICE connection change, mainly used for debugging"""
192 state = self._peer_connection.iceConnectionState 195 state = self._peer_connection.iceConnectionState
193 log.info(f"ICE Connection State changed to: {state}") 196 log.info(f"ICE Connection State changed to: {state}")
194 197
195 if state == "failed": 198 if state == "connected":
199 if self.on_connection_established_cb is not None:
200 self.on_connection_established_cb()
201 elif state == "failed":
196 log.error("ICE connection failed. Check network connectivity and ICE configurations.") 202 log.error("ICE connection failed. Check network connectivity and ICE configurations.")
197 elif state == "disconnected": 203 elif state == "disconnected":
198 log.warning("ICE connection was disconnected.") 204 log.warning("ICE connection was disconnected.")
205 if self.on_connection_lost_cb is not None:
206 self.on_connection_lost_cb()
199 207
200 def on_ice_candidate_error(self, event): 208 def on_ice_candidate_error(self, event):
201 """Log ICE error, useful for debugging""" 209 """Log ICE error, useful for debugging"""
202 log.error(f"ICE Candidate Error: {event.errorText} (Code: {event.errorCode})") 210 log.error(f"ICE Candidate Error: {event.errorText} (Code: {event.errorCode})")
203 log.debug( 211 log.debug(
427 def _on_ice_restart(self, sid: str, side: str, profile: str): 435 def _on_ice_restart(self, sid: str, side: str, profile: str):
428 if sid != self.sid: 436 if sid != self.sid:
429 log.debug(f"ignoring peer ice candidates for {sid=} ({self.sid=}).") 437 log.debug(f"ignoring peer ice candidates for {sid=} ({self.sid=}).")
430 return 438 return
431 log.debug("ICE has been restarted") 439 log.debug("ICE has been restarted")
440 if self.on_reconnect_cb is not None:
441 self.on_reconnect_cb()
432 442
433 async def on_ice_candidates_new(self, candidates: dict) -> None: 443 async def on_ice_candidates_new(self, candidates: dict) -> None:
434 """Called when new ICE canidates are received from peer 444 """Called when new ICE canidates are received from peer
435 445
436 @param candidates: Dictionary containing new ICE candidates 446 @param candidates: Dictionary containing new ICE candidates