comparison 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
comparison
equal deleted inserted replaced
1560:84f312be53b4 1561:7dbb131bbb9e
12 12
13 log.warning = log.warn 13 log.warning = log.warn
14 profile = window.profile or "" 14 profile = window.profile or ""
15 bridge = Bridge() 15 bridge = Bridge()
16 GATHER_TIMEOUT = 10000 16 GATHER_TIMEOUT = 10000
17 ALLOWED_STATUSES = (None, "dialing", "ringing") 17 ALLOWED_STATUSES = (None, "dialing", "ringing", "in-call", "on-hold", "connecting", "connection-lost", "reconnecting")
18 AUDIO = "audio" 18 AUDIO = "audio"
19 VIDEO = "video" 19 VIDEO = "video"
20 ALLOWED_CALL_MODES = {AUDIO, VIDEO} 20 ALLOWED_CALL_MODES = {AUDIO, VIDEO}
21 INACTIVE_CLASS = "inactive" 21 INACTIVE_CLASS = "inactive"
22 MUTED_CLASS = "muted" 22 MUTED_CLASS = "muted"
25 25
26 class CallUI: 26 class CallUI:
27 def __init__(self): 27 def __init__(self):
28 self.webrtc = WebRTC() 28 self.webrtc = WebRTC()
29 self.webrtc.screen_sharing_cb = self.on_sharing_screen 29 self.webrtc.screen_sharing_cb = self.on_sharing_screen
30 self.webrtc.on_connection_established_cb = self.on_connection_established
31 self.webrtc.on_reconnect_cb = self.on_reconnect
32 self.webrtc.on_connection_lost_cb = self.on_connection_lost
30 self.mode = "search" 33 self.mode = "search"
31 self._status = None 34 self._status = None
32 self._callee = None 35 self._callee = None
33 self.contacts_elt = document["contacts"] 36 self.contacts_elt = document["contacts"]
34 self.search_container_elt = document["search_container"] 37 self.search_container_elt = document["search_container"]
201 204
202 if accepted: 205 if accepted:
203 log.debug(f"Call SID: {sid}") 206 log.debug(f"Call SID: {sid}")
204 207
205 # Answer the call 208 # Answer the call
209 self.status = "connecting"
206 self.switch_mode("call") 210 self.switch_mode("call")
207 else: 211 else:
208 log.info(f"your are declining the call from {peer_jid}") 212 log.info(f"your are declining the call from {peer_jid}")
209 self.sid = None 213 self.sid = None
210 await bridge.action_launch(action_id, json.dumps({"cancelled": not accepted})) 214 await bridge.action_launch(action_id, json.dumps({"cancelled": not accepted}))
272 else: 276 else:
273 dialog.notification.show( 277 dialog.notification.show(
274 f"Invalid role received during setup: {setup_data}", level="error" 278 f"Invalid role received during setup: {setup_data}", level="error"
275 ) 279 )
276 return 280 return
281
282 def on_connection_established(self):
283 self.status = "in-call"
284
285 def on_reconnect(self):
286 self.status = "reconnecting"
287
288 def on_connection_lost(self):
289 self.status = "connection-lost"
277 290
278 async def make_call(self, audio: bool = True, video: bool = True) -> None: 291 async def make_call(self, audio: bool = True, video: bool = True) -> None:
279 """Start a WebRTC call 292 """Start a WebRTC call
280 293
281 @param audio: True if an audio flux is required 294 @param audio: True if an audio flux is required