Mercurial > libervia-web
annotate 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 |
rev | line source |
---|---|
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 import json |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 from bridge import AsyncBridge as Bridge |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
4 from browser import aio, console as log, document, window |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
5 from cache import cache |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
6 import dialog |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
7 from jid import JID |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
8 from jid_search import JidSearch |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 import loading |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
10 from template import Template |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
11 from webrtc import WebRTC |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 log.warning = log.warn |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 profile = window.profile or "" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 bridge = Bridge() |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GATHER_TIMEOUT = 10000 |
1561
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
17 ALLOWED_STATUSES = (None, "dialing", "ringing", "in-call", "on-hold", "connecting", "connection-lost", "reconnecting") |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
18 AUDIO = "audio" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
19 VIDEO = "video" |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
20 ALLOWED_CALL_MODES = {AUDIO, VIDEO} |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
21 INACTIVE_CLASS = "inactive" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
22 MUTED_CLASS = "muted" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
23 SCREEN_OFF_CLASS = "screen-off" |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
26 class CallUI: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 def __init__(self): |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
28 self.webrtc = WebRTC() |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
29 self.webrtc.screen_sharing_cb = self.on_sharing_screen |
1561
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
30 self.webrtc.on_connection_established_cb = self.on_connection_established |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
31 self.webrtc.on_reconnect_cb = self.on_reconnect |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
32 self.webrtc.on_connection_lost_cb = self.on_connection_lost |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
33 self.mode = "search" |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
34 self._status = None |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
35 self._callee = None |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
36 self.contacts_elt = document["contacts"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
37 self.search_container_elt = document["search_container"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
38 self.call_container_elt = document["call_container"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
39 self.call_box_elt = document["call_box"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
40 self.call_avatar_wrapper_elt = document["call_avatar_wrapper"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
41 self.call_status_wrapper_elt = document["call_status_wrapper"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
42 self.call_avatar_tpl = Template("call/call_avatar.html") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
43 self.call_status_tpl = Template("call/call_status.html") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
44 self.audio_player_elt = document["audio_player"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
45 bridge.register_signal("action_new", self._on_action_new) |
1560
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
46 bridge.register_signal("call_info", self._on_call_info) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
47 bridge.register_signal("call_setup", self._on_call_setup) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
48 bridge.register_signal("call_ended", self._on_call_ended) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
50 # call/hang up buttons |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
51 self._call_mode = VIDEO |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
52 document["video_call_btn"].bind( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
53 "click", |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
54 lambda __: aio.run(self.make_call()) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
55 |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
56 ) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
57 document["audio_call_btn"].bind( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
58 "click", |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
59 lambda __: aio.run(self.make_call(video=False)) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
60 |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
61 ) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
62 document["hangup_btn"].bind("click", lambda __: aio.run(self.hang_up())) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
64 # other buttons |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
65 document["full_screen_btn"].bind("click", lambda __: self.toggle_fullscreen()) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
66 document["exit_full_screen_btn"].bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
67 "click", lambda __: self.toggle_fullscreen() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 ) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
69 document["mute_audio_btn"].bind("click", self.toggle_audio_mute) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
70 document["mute_video_btn"].bind("click", self.toggle_video_mute) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
71 self.share_desktop_btn_elt = document["share_desktop_btn"] |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
72 if hasattr(window.navigator.mediaDevices, "getDisplayMedia"): |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
73 self.share_desktop_btn_elt.classList.remove("is-hidden-touch") |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
74 # screen sharing is supported |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
75 self.share_desktop_btn_elt.bind("click", self.toggle_screen_sharing) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
76 else: |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
77 self.share_desktop_btn_elt.classList.add("is-hidden") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
79 # search |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
80 self.jid_search = JidSearch( |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
81 document["search"], |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
82 document["contacts"], |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
83 click_cb=self._on_entity_click, |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
84 template="call/search_item.html", |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
85 options={ |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
86 "no_group": True, |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
87 "extra_cb": { |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
88 ".dropdown-trigger": lambda evt, item: aio.run( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
89 self.on_entity_action(evt, "menu", item) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
90 ), |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
91 ".click-to-video": lambda evt, item: aio.run( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
92 self.on_entity_action(evt, VIDEO, item) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
93 ), |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
94 ".click-to-audio": lambda evt, item: aio.run( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
95 self.on_entity_action(evt, AUDIO, item) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
96 ), |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
97 } |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
98 } |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
101 # incoming call dialog |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
102 self.incoming_call_dialog_elt = None |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
104 @property |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
105 def sid(self) -> str | None: |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
106 return self.webrtc.sid |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
108 @sid.setter |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
109 def sid(self, new_sid) -> None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
110 self.webrtc.sid = new_sid |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
111 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
112 @property |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
113 def status(self): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
114 return self._status |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
116 @status.setter |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
117 def status(self, new_status): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
118 if new_status != self._status: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
119 if new_status not in ALLOWED_STATUSES: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
120 raise Exception( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
121 f"INTERNAL ERROR: this status is not allowed: {new_status!r}" |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
122 ) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
123 tpl_data = {"entity": self._callee, "status": new_status} |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
124 if self._callee is not None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
125 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
126 tpl_data["name"] = cache.identities[self._callee]["nicknames"][0] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
127 except (KeyError, IndexError): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
128 tpl_data["name"] = str(self._callee) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
129 status_elt = self.call_status_tpl.get_elt(tpl_data) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
130 self.call_status_wrapper_elt.clear() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
131 self.call_status_wrapper_elt <= status_elt |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
133 self._status = new_status |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
135 @property |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
136 def call_mode(self): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
137 return self._call_mode |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
139 @call_mode.setter |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
140 def call_mode(self, mode): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
141 if mode in ALLOWED_CALL_MODES: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
142 if self._call_mode == mode: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
143 return |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
144 self._call_mode = mode |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
145 with_video = mode == VIDEO |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
146 for elt in self.call_box_elt.select(".is-video-only"): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
147 if with_video: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
148 elt.classList.remove("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
149 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
150 elt.classList.add("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
151 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
152 raise ValueError("Invalid call mode") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
154 def _on_action_new( |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 self, action_data_s: str, action_id: str, security_limit: int, profile: str |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 ) -> None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 """Called when a call is received |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 @param action_data_s: Action data serialized |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 @param action_id: Unique identifier for the action |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 @param security_limit: Security limit for the action |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 @param profile: Profile associated with the action |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 """ |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 action_data = json.loads(action_data_s) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 if action_data.get("type") != "call": |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
167 aio.run(self.on_action_new(action_data, action_id)) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
168 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
169 async def on_action_new(self, action_data: dict, action_id: str) -> None: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 peer_jid = action_data["from_jid"] |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
171 log.info(f"{peer_jid} wants to start a call ({action_data['sub_type']})") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 if self.sid is not None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 log.warning( |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 f"already in a call ({self.sid}), can't receive a new call from " |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 f"{peer_jid}" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
178 sid = self.sid = action_data["session_id"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
179 await cache.fill_identities([peer_jid]) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
180 identity = cache.identities[peer_jid] |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
181 peer_name = identity["nicknames"][0] |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
183 # we start the ring |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
184 self.audio_player_elt.play() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
186 # and ask user if we take the call |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
187 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
188 self.incoming_call_dialog_elt = dialog.Confirm( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
189 f"{peer_name} is calling you.", ok_label="Answer", cancel_label="Reject" |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
190 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
191 accepted = await self.incoming_call_dialog_elt.ashow() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
192 except dialog.CancelError: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
193 log.info("Call has been cancelled") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
194 self.incoming_call_dialog_elt = None |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
195 self.sid = None |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
196 dialog.notification.show(f"{peer_name} has cancelled the call", level="info") |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
197 return |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
199 self.incoming_call_dialog_elt = None |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
200 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
201 # we stop the ring |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
202 self.audio_player_elt.pause() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
203 self.audio_player_elt.currentTime = 0 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
204 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
205 if accepted: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
206 log.debug(f"Call SID: {sid}") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
207 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
208 # Answer the call |
1561
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
209 self.status = "connecting" |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
210 self.switch_mode("call") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
211 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
212 log.info(f"your are declining the call from {peer_jid}") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
213 self.sid = None |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
214 await bridge.action_launch(action_id, json.dumps({"cancelled": not accepted})) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 def _on_call_ended(self, session_id: str, data_s: str, profile: str) -> None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 """Call has been terminated |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 @param session_id: Session identifier |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 @param data_s: Serialised additional data on why the call has ended |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 @param profile: Profile associated |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 """ |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 if self.sid is None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 log.debug("there are no calls in progress") |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 return |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 if session_id != self.sid: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 log.debug( |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 f"ignoring call_ended not linked to our call ({self.sid}): {session_id}" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
231 aio.run(self.end_call(json.loads(data_s))) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
232 |
1560
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
233 def _on_call_info(self, session_id: str, info_type, info_data_s: str, profile: str): |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
234 if self.sid != session_id: |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
235 return |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
236 if info_type == "ringing": |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
237 self.status = "ringing" |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
238 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
239 def _on_call_setup(self, session_id: str, setup_data_s: str, profile: str) -> None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
240 """Called when we have received answer SDP from responder |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
242 @param session_id: Session identifier |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
243 @param sdp: Session Description Protocol data |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
244 @param profile: Profile associated with the action |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
245 """ |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
246 aio.run(self.on_call_setup(session_id, json.loads(setup_data_s), profile)) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
247 |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
248 async def on_call_setup( |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
249 self, session_id: str, setup_data: dict, profile: str |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
250 ) -> None: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 """Call has been accepted, connection can be established |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 @param session_id: Session identifier |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
254 @param setup_data: Data with following keys: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
255 role: initiator or responser |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
256 sdp: Session Description Protocol data |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 @param profile: Profile associated |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 """ |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 if self.sid != session_id: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 log.debug( |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 f"Call ignored due to different session ID ({self.sid=} {session_id=})" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
264 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
265 role = setup_data["role"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
266 sdp = setup_data["sdp"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
267 except KeyError: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
268 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
269 f"Invalid setup data received: {setup_data}", level="error" |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
272 if role == "initiator": |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
273 await self.webrtc.accept_call(session_id, sdp, profile) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
274 elif role == "responder": |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
275 await self.webrtc.answer_call(session_id, sdp, profile) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
276 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
277 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
278 f"Invalid role received during setup: {setup_data}", level="error" |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
279 ) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 return |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 |
1561
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
282 def on_connection_established(self): |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
283 self.status = "in-call" |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
284 |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
285 def on_reconnect(self): |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
286 self.status = "reconnecting" |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
287 |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
288 def on_connection_lost(self): |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
289 self.status = "connection-lost" |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
290 |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 async def make_call(self, audio: bool = True, video: bool = True) -> None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 """Start a WebRTC call |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 @param audio: True if an audio flux is required |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 @param video: True if a video flux is required |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 """ |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
297 self.call_mode = VIDEO if video else AUDIO |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
298 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
299 callee_jid = JID(document["search"].value.strip()) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
300 if not callee_jid.is_valid: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
301 raise ValueError |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
302 except ValueError: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
303 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
304 "Invalid identifier, please use a valid callee identifier", level="error" |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
305 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
306 return |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
308 self._callee = callee_jid |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
309 await cache.fill_identities([callee_jid]) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
310 self.status = "dialing" |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
311 call_avatar_elt = self.call_avatar_tpl.get_elt( |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
312 { |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
313 "entity": str(callee_jid), |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
314 "identities": cache.identities, |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
315 } |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
316 ) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
317 self.call_avatar_wrapper_elt.clear() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
318 self.call_avatar_wrapper_elt <= call_avatar_elt |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
320 self.switch_mode("call") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
321 await self.webrtc.make_call(callee_jid, audio, video) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
322 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
323 async def end_call(self, data: dict) -> None: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 """Stop streaming and clean instance""" |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
325 # if there is any ringing, we stop it |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
326 self.audio_player_elt.pause() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
327 self.audio_player_elt.currentTime = 0 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
328 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
329 if self.incoming_call_dialog_elt is not None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
330 self.incoming_call_dialog_elt.cancel() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
331 self.incoming_call_dialog_elt = None |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
332 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
333 self.switch_mode("search") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
335 if data.get("reason") == "busy": |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
336 assert self._callee is not None |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
337 peer_name = cache.identities[self._callee]["nicknames"][0] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
338 dialog.notification.show( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
339 f"{peer_name} can't answer your call", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
340 level="info", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
341 ) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
343 await self.webrtc.end_call() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
345 async def hang_up(self) -> None: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 """Terminate the call""" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 session_id = self.sid |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
348 if not session_id: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
349 log.warning("Can't hand_up, not call in progress") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
350 return |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
351 await self.end_call({"reason": "terminated"}) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
352 await bridge.call_end(session_id, "") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
354 def _handle_animation_end( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
355 self, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
356 element, |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
357 remove=None, |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
358 add=None, |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
359 ): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
360 """Return a handler that removes specified classes and the event handler. |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
362 @param element: The element to operate on. |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
363 @param remove: List of class names to remove from the element. |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
364 @param add: List of class names to add to the element. |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
365 """ |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
366 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
367 def handler(__, remove=remove, add=add): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
368 log.info(f"animation end OK {element=}") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
369 if add: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
370 if isinstance(add, str): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
371 add = [add] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
372 element.classList.add(*add) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
373 if remove: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
374 if isinstance(remove, str): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
375 remove = [remove] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
376 element.classList.remove(*remove) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
377 element.unbind("animationend", handler) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
378 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
379 return handler |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
381 def switch_mode(self, mode: str) -> None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
382 """Handles the user interface changes""" |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
383 if mode == self.mode: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
384 return |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
385 if mode == "call": |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
386 # Hide contacts with fade-out animation and bring up the call box |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
387 self.search_container_elt.classList.add("fade-out-y") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
388 self.search_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
389 "animationend", |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
390 self._handle_animation_end( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
391 self.search_container_elt, remove="fade-out-y", add="is-hidden" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
392 ), |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
393 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
394 self.call_container_elt.classList.remove("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
395 self.call_container_elt.classList.add("slide-in") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
396 self.call_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
397 "animationend", |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
398 self._handle_animation_end(self.call_container_elt, remove="slide-in"), |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
399 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
400 self.mode = mode |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
401 elif mode == "search": |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
402 self.toggle_fullscreen(False) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
403 self.search_container_elt.classList.add("fade-out-y", "animation-reverse") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
404 self.search_container_elt.classList.remove("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
405 self.search_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
406 "animationend", |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
407 self._handle_animation_end( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
408 self.search_container_elt, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
409 remove=["fade-out-y", "animation-reverse"], |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
410 ), |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
411 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
412 self.call_container_elt.classList.add("slide-in", "animation-reverse") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
413 self.call_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
414 "animationend", |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
415 self._handle_animation_end( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
416 self.call_container_elt, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
417 remove=["slide-in", "animation-reverse"], |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
418 add="is-hidden", |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
419 ), |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
420 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
421 self.mode = mode |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
422 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
423 log.error(f"Internal Error: Unknown call mode: {mode}") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
424 |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
425 def toggle_fullscreen(self, fullscreen: bool | None = None): |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
426 """Toggle fullscreen mode for video elements. |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
427 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
428 @param fullscreen: if set, determine the fullscreen state; otherwise, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
429 the fullscreen mode will be toggled. |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
430 """ |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
431 do_fullscreen = ( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
432 document.fullscreenElement is None if fullscreen is None else fullscreen |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
433 ) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
435 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
436 if do_fullscreen: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
437 if document.fullscreenElement is None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
438 self.call_box_elt.requestFullscreen() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
439 document["full_screen_btn"].classList.add("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
440 document["exit_full_screen_btn"].classList.remove("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
441 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
442 if document.fullscreenElement is not None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
443 document.exitFullscreen() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
444 document["full_screen_btn"].classList.remove("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
445 document["exit_full_screen_btn"].classList.add("is-hidden") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
446 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
447 except Exception as e: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
448 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
449 f"An error occurred while toggling fullscreen: {e}", level="error" |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
450 ) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
452 def toggle_audio_mute(self, evt): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
453 is_muted = self.webrtc.toggle_audio_mute() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
454 btn_elt = evt.currentTarget |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
455 if is_muted: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
456 btn_elt.classList.remove("is-success") |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
457 btn_elt.classList.add(INACTIVE_CLASS, MUTED_CLASS, "is-warning") |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
458 dialog.notification.show( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
459 f"audio is now muted", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
460 level="info", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
461 delay=2, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
462 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
463 else: |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
464 btn_elt.classList.remove(INACTIVE_CLASS, MUTED_CLASS, "is-warning") |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
465 btn_elt.classList.add("is-success") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
466 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
467 def toggle_video_mute(self, evt): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
468 is_muted = self.webrtc.toggle_video_mute() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
469 btn_elt = evt.currentTarget |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
470 if is_muted: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
471 btn_elt.classList.remove("is-success") |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
472 btn_elt.classList.add(INACTIVE_CLASS, MUTED_CLASS, "is-warning") |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
473 dialog.notification.show( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
474 f"video is now muted", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
475 level="info", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
476 delay=2, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
477 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
478 else: |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
479 btn_elt.classList.remove(INACTIVE_CLASS, MUTED_CLASS, "is-warning") |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
480 btn_elt.classList.add("is-success") |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
481 |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
482 def toggle_screen_sharing(self, evt): |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
483 aio.run(self.webrtc.toggle_screen_sharing()) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
484 |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
485 def on_sharing_screen(self, sharing: bool) -> None: |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
486 """Called when screen sharing state changes""" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
487 share_desktop_btn_elt = self.share_desktop_btn_elt |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
488 if sharing: |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
489 share_desktop_btn_elt.classList.add("is-danger") |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
490 share_desktop_btn_elt.classList.remove(INACTIVE_CLASS, SCREEN_OFF_CLASS) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
491 else: |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
492 share_desktop_btn_elt.classList.remove("is-danger") |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
493 share_desktop_btn_elt.classList.add(INACTIVE_CLASS, SCREEN_OFF_CLASS) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
494 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
495 def _on_entity_click(self, item: dict) -> None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
496 aio.run(self.on_entity_click(item)) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
497 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
498 async def on_entity_click(self, item: dict) -> None: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
499 """Set entity JID to search bar, and start the call""" |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
500 document["search"].value = item["entity"] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
501 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
502 await self.make_call() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
503 |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
504 async def on_entity_action(self, evt, action: str, item: dict) -> None: |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
505 """Handle extra actions on search items""" |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
506 evt.stopPropagation() |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
507 if action == "menu": |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
508 evt.currentTarget.parent.classList.toggle("is-active") |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
509 elif action in (VIDEO, AUDIO): |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
510 document["search"].value = item["entity"] |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
511 # we want the dropdown to be inactive |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
512 evt.currentTarget.closest(".dropdown").classList.remove("is-active") |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
513 await self.make_call(video=action==VIDEO) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
514 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
515 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
516 CallUI() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 loading.remove_loading_screen() |