Mercurial > libervia-web
annotate libervia/web/pages/calls/_browser/__init__.py @ 1601:d07838fc9d99
minor updates
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 11 May 2024 13:57:49 +0200 |
parents | 0a4433a343a3 |
children | 6feac4a25e60 |
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 |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
7 from javascript import JSObject |
1549
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 import JID |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
9 from jid_search import JidSearch |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 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
|
11 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
|
12 from webrtc import WebRTC |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 log.warning = log.warn |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 profile = window.profile or "" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 bridge = Bridge() |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 GATHER_TIMEOUT = 10000 |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
18 ALLOWED_STATUSES = ( |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
19 None, |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
20 "dialing", |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
21 "ringing", |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
22 "in-call", |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
23 "on-hold", |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
24 "connecting", |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
25 "connection-lost", |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
26 "reconnecting", |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
27 ) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
28 AUDIO = "audio" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
29 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
|
30 ALLOWED_CALL_MODES = {AUDIO, VIDEO} |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
31 INACTIVE_CLASS = "inactive" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
32 MUTED_CLASS = "muted" |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
33 SCREEN_OFF_CLASS = "screen-off" |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
36 class CallUI: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 def __init__(self): |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
38 self.webrtc = WebRTC( |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
39 screen_sharing_cb=self.on_sharing_screen, |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
40 on_connection_established_cb=self.on_connection_established, |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
41 on_reconnect_cb=self.on_reconnect, |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
42 on_connection_lost_cb=self.on_connection_lost, |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
43 on_video_devices=self.on_video_devices, |
1565
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
44 on_reset_cb=self.on_reset_cb, |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
45 ) |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
46 # mapping of file sending |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
47 self.files_webrtc: list[dict] = [] |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
48 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
|
49 self._status = None |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
50 self._callee: JID|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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 bridge.register_signal("call_ended", self._on_call_ended) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
65 # 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
|
66 self._call_mode = VIDEO |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
67 document["video_call_btn"].bind("click", lambda __: aio.run(self.make_call())) |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
68 document["audio_call_btn"].bind( |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
69 "click", lambda __: aio.run(self.make_call(video=False)) |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
70 ) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
71 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
|
72 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
73 # other buttons |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
74 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
|
75 document["exit_full_screen_btn"].bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
76 "click", lambda __: self.toggle_fullscreen() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 ) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
78 document["mute_audio_btn"].bind("click", self.toggle_audio_mute) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
79 document["mute_video_btn"].bind("click", self.toggle_video_mute) |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
80 self.share_desktop_col_elt = document["share_desktop_column"] |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
81 if hasattr(window.navigator.mediaDevices, "getDisplayMedia"): |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
82 self.share_desktop_col_elt.classList.remove("is-hidden-touch") |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
83 # screen sharing is supported |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
84 document["share_desktop_btn"].bind("click", self.toggle_screen_sharing) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
85 else: |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
86 self.share_desktop_col_elt.classList.add("is-hidden") |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
87 document["switch_camera_btn"].bind("click", self.on_switch_camera) |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
88 document["send_file_btn"].bind("click", self.on_send_file) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
89 document["send_file_input"].bind("change", self._on_send_input_change) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
91 # search |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
92 self.search_elt = document["search"] |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
93 self.jid_search = JidSearch( |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
94 self.search_elt, |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
95 document["contacts"], |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
96 click_cb=self._on_entity_click, |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
97 template="call/search_item.html", |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
98 options={ |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
99 "no_group": True, |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
100 "extra_cb": { |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
101 ".dropdown-trigger": lambda evt, item: aio.run( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
102 self.on_entity_action(evt, "menu", item) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
103 ), |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
104 ".click-to-video": lambda evt, item: aio.run( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
105 self.on_entity_action(evt, VIDEO, item) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
106 ), |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
107 ".click-to-audio": lambda evt, item: aio.run( |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
108 self.on_entity_action(evt, AUDIO, item) |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
109 ), |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
110 }, |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
111 }, |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 ) |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
113 document["clear_search_btn"].bind("click", self.on_clear_search) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
115 # 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
|
116 self.incoming_call_dialog_elt = None |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
118 @property |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
119 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
|
120 return self.webrtc.sid |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
122 @sid.setter |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
123 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
|
124 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
|
125 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
126 @property |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
127 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
|
128 return self._status |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
130 @status.setter |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 raise Exception( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
135 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
|
136 ) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
137 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
|
138 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
|
139 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 self.call_status_wrapper_elt <= status_elt |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
147 self._status = new_status |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
149 @property |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
150 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
|
151 return self._call_mode |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
153 @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
|
154 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
|
155 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
|
156 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
|
157 return |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
164 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
|
165 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
166 raise ValueError("Invalid call mode") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
168 def set_avatar(self, entity_jid: JID | str) -> None: |
1562
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
169 """Set the avatar element from entity_jid |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
170 |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
171 @param entity_jid: bare jid of the entity |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
172 """ |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
173 call_avatar_elt = self.call_avatar_tpl.get_elt( |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
174 { |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
175 "entity": str(entity_jid), |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
176 "identities": cache.identities, |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
177 } |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
178 ) |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
179 self.call_avatar_wrapper_elt.clear() |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
180 self.call_avatar_wrapper_elt <= call_avatar_elt |
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
181 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
182 def _on_action_new( |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 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
|
184 ) -> None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 """Called when a call is received |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 @param action_data_s: Action data serialized |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 @param action_id: Unique identifier for the action |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 @param security_limit: Security limit for the action |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 @param profile: Profile associated with the action |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 """ |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 action_data = json.loads(action_data_s) |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
193 if action_data.get("type") == "confirm" and action_data.get("subtype") == "file": |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
194 aio.run(self.on_file_preflight(action_data, action_id)) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
195 elif action_data.get("type") == "file": |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
196 aio.run(self.on_file_proposal(action_data, action_id)) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
197 elif action_data.get("type") != "call": |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 return |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
199 else: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
200 aio.run(self.on_action_new(action_data, action_id)) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
201 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
202 def get_human_size(self, size: int|float) -> str: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
203 """Return size in human-friendly size using SI units""" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
204 units = ["o","Kio","Mio","Gio"] |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
205 for idx, unit in enumerate(units): |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
206 if size < 1024.0 or idx == len(units)-1: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
207 return f"{size:.2f}{unit}" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
208 size /= 1024.0 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
209 raise Exception("Internal Error: this line should never be reached.") |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
210 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
211 async def request_file_permission(self, action_data: dict) -> bool: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
212 """Request permission to download a file.""" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
213 peer_jid = JID(action_data["from_jid"]).bare |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
214 await cache.fill_identities([peer_jid]) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
215 identity = cache.identities[peer_jid] |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
216 peer_name = identity["nicknames"][0] |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
217 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
218 file_data = action_data.get("file_data", {}) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
219 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
220 file_name = file_data.get('name') |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
221 file_size = file_data.get('size') |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
222 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
223 if file_name: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
224 file_name_msg = 'wants to send you the file "{file_name}"'.format( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
225 file_name=file_name |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
226 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
227 else: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
228 file_name_msg = 'wants to send you an unnamed file' |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
229 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
230 if file_size is not None: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
231 file_size_msg = "which has a size of {file_size_human}".format( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
232 file_size_human=self.get_human_size(file_size) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
233 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
234 else: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
235 file_size_msg = "which has an unknown size" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
236 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
237 file_description = file_data.get('desc') |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
238 if file_description: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
239 description_msg = " Description: {}.".format(file_description) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
240 else: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
241 description_msg = "" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
242 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
243 file_data = action_data.get("file_data", {}) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
244 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
245 file_accept_dlg = dialog.Confirm( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
246 "{peer_name} ({peer_jid}) {file_name_msg} {file_size_msg}.{description_msg} Do you " |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
247 "accept?".format( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
248 peer_name=peer_name, |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
249 peer_jid=peer_jid, |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
250 file_name_msg=file_name_msg, |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
251 file_size_msg=file_size_msg, |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
252 description_msg=description_msg |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
253 ), |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
254 ok_label="Download", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
255 cancel_label="Reject" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
256 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
257 return await file_accept_dlg.ashow() |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
258 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
259 async def on_file_preflight(self, action_data: dict, action_id: str) -> None: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
260 """Handle a file preflight (proposal made to all devices).""" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
261 # FIXME: temporarily done in call page, will be moved to notifications handler to |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
262 # make it work anywhere. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
263 accepted = await self.request_file_permission(action_data) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
264 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
265 await bridge.action_launch( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
266 action_id, json.dumps({"answer": str(accepted).lower()}) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
267 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
268 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
269 async def on_file_proposal(self, action_data: dict, action_id: str) -> None: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
270 """Handle a file proposal. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
271 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
272 This is a proposal made specifically to this device, a opposed to |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
273 ``on_file_preflight``. File may already have been accepted during preflight. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
274 """ |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
275 # FIXME: as for on_file_preflight, this will be moved to notification handler. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
276 if not action_data.get("webrtc", False): |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
277 peer_jid = JID(action_data["from_jid"]).bare |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
278 # We try to do a not-too-technical warning about webrtc not being supported. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
279 dialog.notification.show( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
280 f"A file sending from {peer_jid} can't be accepted because it is not " |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
281 "compatible with web browser direct transfer (WebRTC).", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
282 level="warning", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
283 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
284 # We don't explicitly refuse the file proposal, because it may be accepted and |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
285 # supported by other frontends. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
286 # TODO: Check if any other frontend is connected for this profile, and refuse |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
287 # the file if none is. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
288 return |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
289 if action_data.get("file_accepted", False): |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
290 # File proposal has already been accepted in preflight. |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
291 accepted = True |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
292 else: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
293 accepted = await self.request_file_permission(action_data) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
294 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
295 if accepted: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
296 sid = action_data["session_id"] |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
297 webrtc = WebRTC( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
298 file_only=True, |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
299 extra_data={"file_data": action_data.get("file_data", {})} |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
300 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
301 webrtc.sid = sid |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
302 self.files_webrtc.append({ |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
303 "webrtc": webrtc, |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
304 }) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
305 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
306 await bridge.action_launch( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
307 action_id, json.dumps({"answer": str(accepted).lower()}) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
308 ) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
309 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
310 async def on_action_new(self, action_data: dict, action_id: str) -> None: |
1562
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
311 peer_jid = JID(action_data["from_jid"]).bare |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
312 call_type = action_data["sub_type"] |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
313 call_emoji = "📹" if call_type == VIDEO else "📞" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
314 log.info(f"{peer_jid} wants to start a call ({call_type}).") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 if self.sid is not None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 log.warning( |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 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
|
318 f"{peer_jid}" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
321 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
|
322 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
|
323 identity = cache.identities[peer_jid] |
1562
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
324 self._callee = peer_jid |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
325 peer_name = identity["nicknames"][0] |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
327 # 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
|
328 self.audio_player_elt.play() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
330 # 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
|
331 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
332 self.incoming_call_dialog_elt = dialog.Confirm( |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
333 f"{peer_name} is calling you ({call_emoji}{call_type}).", 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
|
334 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
335 accepted = await self.incoming_call_dialog_elt.ashow() |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
336 except dialog.CancelError as e: |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
337 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
|
338 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
|
339 self.sid = None |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
340 match e.reason: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
341 case "busy": |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
342 dialog.notification.show( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
343 f"{peer_name} can't answer your call", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
344 level="info", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
345 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
346 case "taken_by_other_device": |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
347 device = e.text |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
348 dialog.notification.show( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
349 f"The call has been taken on another device ({device}).", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
350 level="info", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
351 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
352 case _: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
353 dialog.notification.show( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
354 f"{peer_name} has cancelled the call", |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
355 level="info" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
356 ) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
357 return |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
359 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
|
360 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
361 # 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
|
362 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
|
363 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
|
364 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
365 if accepted: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
366 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
|
367 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
368 # Answer the call |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
369 self.call_mode = call_type |
1562
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
370 self.set_avatar(peer_jid) |
1561
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
371 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
|
372 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
|
373 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
374 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
|
375 self.sid = None |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
376 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
|
377 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 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
|
379 """Call has been terminated |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 @param session_id: Session identifier |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 @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
|
383 @param profile: Profile associated |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 """ |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 if self.sid is None: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 log.debug("there are no calls in progress") |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 return |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 if session_id != self.sid: |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 log.debug( |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 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
|
391 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
393 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
|
394 |
1560
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
395 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
|
396 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
|
397 return |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
398 if info_type == "ringing": |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
399 self.status = "ringing" |
84f312be53b4
browser (calls): handle "ringing" info message and update status when received
Goffi <goffi@goffi.org>
parents:
1557
diff
changeset
|
400 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
401 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
|
402 """Called when we have received answer SDP from responder |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
404 @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
|
405 @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
|
406 @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
|
407 """ |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
408 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
|
409 |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
410 async def on_call_setup( |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
411 self, session_id: str, setup_data: dict, profile: str |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
412 ) -> None: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 """Call has been accepted, connection can be established |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 @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
|
416 @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
|
417 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
|
418 sdp: Session Description Protocol data |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 @param profile: Profile associated |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 """ |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
421 if self.sid == session_id: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
422 webrtc = self.webrtc |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
423 else: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
424 for file_webrtc in self.files_webrtc: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
425 webrtc = file_webrtc["webrtc"] |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
426 if webrtc.sid == session_id: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
427 break |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
428 else: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
429 log.debug( |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
430 f"Call ignored due to different session ID ({self.sid=} {session_id=})" |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
431 ) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
432 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
433 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
434 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
|
435 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
|
436 except KeyError: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
437 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
438 f"Invalid setup data received: {setup_data}", level="error" |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 ) |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 return |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
441 if role == "initiator": |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
442 await webrtc.accept_call(session_id, sdp, profile) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
443 elif role == "responder": |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
444 await webrtc.answer_call(session_id, sdp, profile) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
445 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
446 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
447 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
|
448 ) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 return |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 |
1561
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
451 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
|
452 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
|
453 |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
454 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
|
455 self.status = "reconnecting" |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
456 |
7dbb131bbb9e
browser (calls): update status on various events (connection established, connection lost, etc.)
Goffi <goffi@goffi.org>
parents:
1560
diff
changeset
|
457 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
|
458 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
|
459 |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
460 def on_video_devices(self, has_multiple_cameras: bool) -> None: |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
461 switch_camera_col_elt = document["switch_camera_column"] |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
462 if has_multiple_cameras: |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
463 switch_camera_col_elt.classList.remove("is-hidden", "is-hidden-desktop") |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
464 else: |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
465 switch_camera_col_elt.classList.add("is-hidden") |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
466 |
1565
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
467 def on_reset_cb(self) -> None: |
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
468 """Call when webRTC connection is reset, we reset buttons statuses""" |
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
469 document["full_screen_btn"].classList.remove("is-hidden") |
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
470 document["exit_full_screen_btn"].classList.add("is-hidden") |
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
471 for btn_elt in document["mute_audio_btn"], document["mute_video_btn"]: |
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
472 btn_elt.classList.remove(INACTIVE_CLASS, MUTED_CLASS, "is-warning") |
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
473 btn_elt.classList.add("is-success") |
d282dbdd5ffd
browser (calls): restore UI state on reset:
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
474 |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 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
|
476 """Start a WebRTC call |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 @param audio: True if an audio flux is required |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 @param video: True if a video flux is required |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 """ |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
481 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
|
482 try: |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
483 callee_jid = JID(self.search_elt.value.strip()) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
484 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
|
485 raise ValueError |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
486 except ValueError: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
487 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
488 "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
|
489 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
490 return |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
492 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
|
493 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
|
494 self.status = "dialing" |
1562
4afafce0c4c9
browser (calls): correctly display avatar and entity in status on incoming call
Goffi <goffi@goffi.org>
parents:
1561
diff
changeset
|
495 self.set_avatar(callee_jid) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
497 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
|
498 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
|
499 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
500 async def end_call(self, data: dict) -> None: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 """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
|
502 # 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
|
503 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
|
504 self.audio_player_elt.currentTime = 0 |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
505 reason = data.get("reason", "") |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
506 text = data.get("text", "") |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
507 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
508 if self.incoming_call_dialog_elt is not None: |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
509 self.incoming_call_dialog_elt.cancel(reason, text) |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
510 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
|
511 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
512 self.switch_mode("search") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
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 await self.webrtc.end_call() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
517 async def hang_up(self) -> None: |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 """Terminate the call""" |
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
519 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
|
520 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
|
521 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
|
522 return |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
523 await self.end_call({"reason": "terminated"}) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
524 await bridge.call_end(session_id, "") |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
526 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
|
527 self, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
528 element, |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
529 remove=None, |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
530 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
|
531 ): |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
532 """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
|
533 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
534 @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
|
535 @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
|
536 @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
|
537 """ |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
538 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
539 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
|
540 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
|
541 if add: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
542 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
|
543 add = [add] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
544 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
|
545 if remove: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
546 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
|
547 remove = [remove] |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
548 element.classList.remove(*remove) |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
549 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
|
550 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
551 return handler |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
553 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
|
554 """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
|
555 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
|
556 return |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
557 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
|
558 # 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
|
559 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
|
560 self.search_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
561 "animationend", |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
562 self._handle_animation_end( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
563 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
|
564 ), |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
565 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
566 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
|
567 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
|
568 self.call_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
569 "animationend", |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
570 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
|
571 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 self.search_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
578 "animationend", |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
579 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
|
580 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
|
581 remove=["fade-out-y", "animation-reverse"], |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
582 ), |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
583 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
584 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
|
585 self.call_container_elt.bind( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
586 "animationend", |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
587 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
|
588 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
|
589 remove=["slide-in", "animation-reverse"], |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
590 add="is-hidden", |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
591 ), |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
592 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
593 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
|
594 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
595 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
|
596 |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
597 def on_clear_search(self, ev) -> None: |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
598 """Clear the search input and trigger its 'input' event. |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
599 |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
600 @param ev: the event object from the button click. |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
601 """ |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
602 if not self.search_elt.value: |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
603 return |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
604 # clear the search field |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
605 self.search_elt.value = "" |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
606 # and dispatch the input event so items are updated |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
607 self.search_elt.dispatchEvent(window.Event.new("input")) |
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
608 |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
609 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
|
610 """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
|
611 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
612 @param fullscreen: if set, determine the fullscreen state; otherwise, |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
613 the fullscreen mode will be toggled. |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
614 """ |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
615 do_fullscreen = ( |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
616 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
|
617 ) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
619 try: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
620 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
|
621 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
|
622 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
|
623 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
|
624 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
|
625 else: |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
626 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
|
627 document.exitFullscreen() |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
628 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
|
629 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
|
630 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
631 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
|
632 dialog.notification.show( |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
633 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
|
634 ) |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 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
|
640 btn_elt.classList.remove("is-success") |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
641 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
|
642 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
|
643 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
|
644 level="info", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
645 delay=2, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
646 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
647 else: |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
648 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
|
649 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
|
650 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 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
|
655 btn_elt.classList.remove("is-success") |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 level="info", |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
660 delay=2, |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
661 ) |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
662 else: |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
663 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
|
664 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
|
665 |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
666 def toggle_screen_sharing(self, evt): |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
667 aio.run(self.webrtc.toggle_screen_sharing()) |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
668 |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
669 def on_sharing_screen(self, sharing: bool) -> None: |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
670 """Called when screen sharing state changes""" |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
671 share_desktop_btn_elt = document["share_desktop_btn"] |
1553
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
672 if sharing: |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
673 share_desktop_btn_elt.classList.add("is-danger") |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
674 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
|
675 else: |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
676 share_desktop_btn_elt.classList.remove("is-danger") |
83c2a6faa2ae
browser (calls): screen sharing implementation:
Goffi <goffi@goffi.org>
parents:
1549
diff
changeset
|
677 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
|
678 |
1564
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
679 def on_switch_camera(self, __) -> None: |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
680 aio.run(self.webrtc.switch_camera()) |
bd3c880f4a47
browser (calls): add camera switching:
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
681 |
1600
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
682 def on_send_file(self, __) -> None: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
683 document["send_file_input"].click() |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
684 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
685 def _on_send_input_change(self, evt) -> None: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
686 aio.run(self.on_send_input_change(evt)) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
687 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
688 async def on_send_input_change(self, evt) -> None: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
689 assert self._callee is not None |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
690 files = evt.currentTarget.files |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
691 for file in files: |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
692 webrtc = WebRTC(file_only=True) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
693 self.files_webrtc.append({ |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
694 "file": file, |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
695 "webrtc": webrtc |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
696 }) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
697 await webrtc.send_file(self._callee, file) |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
698 |
0a4433a343a3
browser (calls): implement WebRTC file sharing:
Goffi <goffi@goffi.org>
parents:
1565
diff
changeset
|
699 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
700 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
|
701 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
|
702 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
703 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
|
704 """Set entity JID to search bar, and start the call""" |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
705 self.search_elt.value = item["entity"] |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
706 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
707 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
|
708 |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
709 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
|
710 """Handle extra actions on search items""" |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
711 evt.stopPropagation() |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
712 if action == "menu": |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
713 evt.currentTarget.parent.classList.toggle("is-active") |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
714 elif action in (VIDEO, AUDIO): |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
715 self.search_elt.value = item["entity"] |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
716 # we want the dropdown to be inactive |
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
717 evt.currentTarget.closest(".dropdown").classList.remove("is-active") |
1563
e3449beac8d8
browser (calls): Add clear search + formatting
Goffi <goffi@goffi.org>
parents:
1562
diff
changeset
|
718 await self.make_call(video=action == VIDEO) |
1557
855729ef75f2
browser (calls): improve call buttons:
Goffi <goffi@goffi.org>
parents:
1553
diff
changeset
|
719 |
1549
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
720 |
e47c24204449
browser (calls): update call to handle search, control buttons, and better UI/UX:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
721 CallUI() |
1517
b8ed9726525b
browser: "calls" implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
722 loading.remove_loading_screen() |