diff libervia/web/pages/calls/_browser/__init__.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 84f312be53b4
children 4afafce0c4c9
line wrap: on
line diff
--- a/libervia/web/pages/calls/_browser/__init__.py	Wed Aug 16 18:34:07 2023 +0200
+++ b/libervia/web/pages/calls/_browser/__init__.py	Thu Aug 17 14:58:21 2023 +0200
@@ -14,7 +14,7 @@
 profile = window.profile or ""
 bridge = Bridge()
 GATHER_TIMEOUT = 10000
-ALLOWED_STATUSES = (None, "dialing", "ringing")
+ALLOWED_STATUSES = (None, "dialing", "ringing", "in-call", "on-hold", "connecting", "connection-lost", "reconnecting")
 AUDIO = "audio"
 VIDEO = "video"
 ALLOWED_CALL_MODES = {AUDIO, VIDEO}
@@ -27,6 +27,9 @@
     def __init__(self):
         self.webrtc = WebRTC()
         self.webrtc.screen_sharing_cb = self.on_sharing_screen
+        self.webrtc.on_connection_established_cb = self.on_connection_established
+        self.webrtc.on_reconnect_cb = self.on_reconnect
+        self.webrtc.on_connection_lost_cb = self.on_connection_lost
         self.mode = "search"
         self._status = None
         self._callee = None
@@ -203,6 +206,7 @@
             log.debug(f"Call SID: {sid}")
 
             # Answer the call
+            self.status = "connecting"
             self.switch_mode("call")
         else:
             log.info(f"your are declining the call from {peer_jid}")
@@ -275,6 +279,15 @@
             )
             return
 
+    def on_connection_established(self):
+        self.status = "in-call"
+
+    def on_reconnect(self):
+        self.status = "reconnecting"
+
+    def on_connection_lost(self):
+        self.status = "connection-lost"
+
     async def make_call(self, audio: bool = True, video: bool = True) -> None:
         """Start a WebRTC call