Mercurial > libervia-web
diff libervia/web/pages/calls/_browser/__init__.py @ 1564:bd3c880f4a47
browser (calls): add camera switching:
- devices are listed on startup, and a `has_multiple_cameras` boolean is set
- based on this data, switch camera button is hidden or not
- a click/touch on the button will switch to the next available camera, and loop back to
first one at the end
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 18 Aug 2023 17:43:01 +0200 |
parents | e3449beac8d8 |
children | d282dbdd5ffd |
line wrap: on
line diff
--- a/libervia/web/pages/calls/_browser/__init__.py Thu Aug 17 16:23:01 2023 +0200 +++ b/libervia/web/pages/calls/_browser/__init__.py Fri Aug 18 17:43:01 2023 +0200 @@ -34,11 +34,13 @@ class CallUI: def __init__(self): - self.webrtc = WebRTC() - self.webrtc.screen_sharing_cb = self.on_sharing_screen - self.webrtc.on_connection_established_cb = self.on_connection_established - self.webrtc.on_reconnect_cb = self.on_reconnect - self.webrtc.on_connection_lost_cb = self.on_connection_lost + self.webrtc = WebRTC( + screen_sharing_cb=self.on_sharing_screen, + on_connection_established_cb=self.on_connection_established, + on_reconnect_cb=self.on_reconnect, + on_connection_lost_cb=self.on_connection_lost, + on_video_devices=self.on_video_devices, + ) self.mode = "search" self._status = None self._callee = None @@ -71,13 +73,14 @@ ) document["mute_audio_btn"].bind("click", self.toggle_audio_mute) document["mute_video_btn"].bind("click", self.toggle_video_mute) - self.share_desktop_btn_elt = document["share_desktop_btn"] + self.share_desktop_col_elt = document["share_desktop_column"] if hasattr(window.navigator.mediaDevices, "getDisplayMedia"): - self.share_desktop_btn_elt.classList.remove("is-hidden-touch") + self.share_desktop_col_elt.classList.remove("is-hidden-touch") # screen sharing is supported - self.share_desktop_btn_elt.bind("click", self.toggle_screen_sharing) + document["share_desktop_btn"].bind("click", self.toggle_screen_sharing) else: - self.share_desktop_btn_elt.classList.add("is-hidden") + self.share_desktop_col_elt.classList.add("is-hidden") + document["switch_camera_btn"].bind("click", self.on_switch_camera) # search self.search_elt = document["search"] @@ -309,6 +312,13 @@ def on_connection_lost(self): self.status = "connection-lost" + def on_video_devices(self, has_multiple_cameras: bool) -> None: + switch_camera_col_elt = document["switch_camera_column"] + if has_multiple_cameras: + switch_camera_col_elt.classList.remove("is-hidden", "is-hidden-desktop") + else: + switch_camera_col_elt.classList.add("is-hidden") + async def make_call(self, audio: bool = True, video: bool = True) -> None: """Start a WebRTC call @@ -444,7 +454,7 @@ if not self.search_elt.value: return # clear the search field - self.search_elt.value = '' + self.search_elt.value = "" # and dispatch the input event so items are updated self.search_elt.dispatchEvent(window.Event.new("input")) @@ -510,7 +520,7 @@ def on_sharing_screen(self, sharing: bool) -> None: """Called when screen sharing state changes""" - share_desktop_btn_elt = self.share_desktop_btn_elt + share_desktop_btn_elt = document["share_desktop_btn"] if sharing: share_desktop_btn_elt.classList.add("is-danger") share_desktop_btn_elt.classList.remove(INACTIVE_CLASS, SCREEN_OFF_CLASS) @@ -518,6 +528,9 @@ share_desktop_btn_elt.classList.remove("is-danger") share_desktop_btn_elt.classList.add(INACTIVE_CLASS, SCREEN_OFF_CLASS) + def on_switch_camera(self, __) -> None: + aio.run(self.webrtc.switch_camera()) + def _on_entity_click(self, item: dict) -> None: aio.run(self.on_entity_click(item))