Mercurial > libervia-desktop-kivy
annotate libervia/desktop_kivy/plugins/plugin_wid_calls.py @ 510:97ab236e8f20
plugin calls: implement desktop sharing:
rel 433
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 16 Jan 2024 10:41:38 +0100 |
parents | f0ce49b360c8 |
children | 644a8d165e5a |
rev | line source |
---|---|
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 from dataclasses import dataclass |
506 | 2 from pathlib import Path |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 from typing import Optional, Callable |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from functools import partial |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # from gi.repository import GLib |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from gi.repository import GObject, Gst, GstWebRTC, GstSdp |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
8 from kivy.metrics import dp |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 try: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 from gi.overrides import Gst as _ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 except ImportError: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 print( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 "no GStreamer python overrides available, please install relevant pacakges on " |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 "your system." |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 from kivy.clock import Clock |
506 | 18 from kivy.core.audio import Sound, SoundLoader |
19 from kivy.core.window import Window | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from kivy.graphics.texture import Texture |
506 | 21 from kivy.properties import ( |
22 BooleanProperty, | |
23 ColorProperty, | |
24 NumericProperty, | |
25 ObjectProperty, | |
26 ReferenceListProperty, | |
27 ) | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from kivy.support import install_gobject_iteration |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from kivy.uix.button import Button |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from kivy.uix.image import Image |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
31 from kivy.uix.popup import Popup |
506 | 32 from kivy.uix.screenmanager import Screen |
33 from kivy.uix.widget import Widget | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 from libervia.backend.core.constants import Const as C |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from libervia.backend.core import log as logging |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 from libervia.backend.core.i18n import _ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from libervia.backend.core import exceptions |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 from libervia.backend.tools.common import data_format |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 from libervia.frontends.quick_frontend import quick_widgets |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
40 from libervia.frontends.tools import aio, display_servers, jid, webrtc |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 from libervia.desktop_kivy import G |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 from ..core import cagou_widget |
506 | 45 from ..core import common |
46 from ..core.behaviors import FilterBehavior | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 log = logging.getLogger(__name__) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 install_gobject_iteration() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 Gst.init(None) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 PLUGIN_INFO = { |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 "name": _("calls"), |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 "main": "Calls", |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 "description": _("Audio/Video calls"), |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 "icon_symbol": "phone", |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 } |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 @dataclass |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 class TextureData: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 texture: Optional[Texture] = None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 size: Optional[tuple[int, int]] = None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
506 | 69 class SearchScreen(Screen): |
70 pass | |
71 | |
72 | |
73 class InCallScreen(Screen): | |
74 pass | |
75 | |
76 | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 class CallButton(Button): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 parent_widget = ObjectProperty(None) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
506 | 81 class CallControlButton(common.SymbolButton): |
82 active = BooleanProperty(True) | |
83 background_color = ColorProperty() | |
84 margin_x = NumericProperty(0) | |
85 margin_y = NumericProperty(0) | |
86 margin = ReferenceListProperty(margin_x, margin_y) | |
87 | |
88 | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 class VideoStreamWidget(Image): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 pass |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 class WebRTC: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 """WebRTC implementation for audio and video communication. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 This class encapsulates the WebRTC functionalities required for initiating and |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 handling audio and video calls. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 @attribute test_mode: A flag to indicate whether the WebRTC instance is in test mode. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 If true, test video and audio sources will be used. Otherwise first webcam and |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 microphone available will be used. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 """ |
506 | 103 |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 test_mode: bool = False |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
106 PROXIED_PROPERTIES = { |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
107 'audio_muted', 'callee', 'desktop_sharing', 'sid', 'video_muted', 'desktop_sharing_data' |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
108 } |
509 | 109 PROXIED_METHODS = {'answer_call', 'end_call', 'on_accepted_call', 'on_ice_candidates_new', 'setup_call', 'start_pipeline'} |
110 | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 def __init__(self, parent_calls: "Calls", profile: str) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 self.parent_calls = parent_calls |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 self.profile = profile |
509 | 114 self.webrtc = webrtc.WebRTC( |
115 G.host.a_bridge, | |
116 profile, | |
117 sinks=webrtc.SINKS_TEST if self.test_mode else webrtc.SINKS_APP, | |
118 appsink_data=webrtc.AppSinkData( | |
119 local_video_cb=partial( | |
120 self.on_new_sample, | |
121 update_sample_method=self.update_sample, | |
122 video_widget=self.parent_calls.local_video | |
123 ), | |
124 remote_video_cb=partial( | |
125 self.on_new_sample, | |
126 update_sample_method=self.update_sample, | |
127 video_widget=self.parent_calls.remote_video | |
128 ) | |
129 ), | |
130 reset_cb=self.on_reset | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
509 | 132 ) |
133 self.pipeline = None | |
506 | 134 |
509 | 135 def __getattr__(self, name): |
136 if name in self.PROXIED_PROPERTIES or name in self.PROXIED_METHODS: | |
137 return getattr(self.webrtc, name) | |
138 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'") | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 |
509 | 140 def __setattr__(self, name, value): |
141 if name in self.PROXIED_PROPERTIES: | |
142 setattr(self.webrtc, name, value) | |
143 else: | |
144 super().__setattr__(name, value) | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
509 | 146 def on_reset(self): |
147 self.texture_map: dict[VideoStreamWidget, TextureData] = {} | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 def on_new_sample( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 self, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 video_sink: Gst.Element, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 update_sample_method: Callable, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 video_widget: VideoStreamWidget, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 ) -> bool: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 """Handles a new sample from the video sink. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 @param video_sink: The video sink to pull samples from. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 @param update_sample_method: The method to call for updating the sample. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 @param video_widget: The video widget (either local_video or remote_video). |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 @return: Always False |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 """ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 sample = video_sink.emit("pull-sample") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 if sample is None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 return False |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 try: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 texture_data = self.texture_map[video_widget] |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 except KeyError: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 texture_data = self.texture_map[video_widget] = TextureData() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 # Get the current video size |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 video_pad = video_sink.get_static_pad("sink") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 assert video_pad is not None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 s = video_pad.get_current_caps().get_structure(0) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 stream_size = (s.get_value("width"), s.get_value("height")) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 # Compare with the texture size |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 texture_size = texture_data.size |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 if texture_size != stream_size: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 log.debug(f"sample size update: {texture_size} => {stream_size}") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 texture_data.size = stream_size |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 # texture needs to be recreated, so we reset the one in texture_data |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 texture_data.texture = None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 Clock.schedule_once( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 partial( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 update_sample_method, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 sample=sample, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 video_widget=video_widget, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 return False |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 def update_sample( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 self, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 dt: float, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 sample: Optional[Gst.Sample], |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 video_widget: VideoStreamWidget, |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 ) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 """Updates the video sample. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 This method runs in the main thread. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 @param dt: Time delta since the last call. This is passed by Clock.schedule_once. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 @param sample: The video sample to update. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 @param texture_id: identifier of the texture data (e.g. "local" or "remote") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 @param texture: The texture object. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 @param texture_size: The texture size. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 @param video_widget: The video widget. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 """ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 if sample is None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 return |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 try: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 texture_data = self.texture_map[video_widget] |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 except KeyError: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 log.warning(f"no texture data found for {video_widget}") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 return |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 if texture_data.texture is None and texture_data.size is not None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 log.debug(f"===> creating texture for {video_widget}: {texture_data.size=}") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 texture = Texture.create(size=texture_data.size, colorfmt="rgb") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 assert texture is not None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 texture_data.texture = texture |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 texture.flip_vertical() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 video_widget.texture = texture |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 mapinfo = None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 buf = None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 try: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 buf = sample.get_buffer() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 _, mapinfo = buf.map(Gst.MapFlags.READ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 buffer = mapinfo.data.tobytes() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 if texture_data.texture is None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 log.debug("can't copy the buffer, texture is None") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 return |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 texture_data.texture.blit_buffer(buffer, colorfmt="rgb") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 assert video_widget.canvas is not None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 video_widget.canvas.ask_update() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 buf.unmap(mapinfo) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 finally: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 if buf is not None and mapinfo is not None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 buf.unmap(mapinfo) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
246 class WindowSelectButton(Button): |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
247 pass |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
248 |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
249 |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
250 class DesktopScreenDialog(Popup): |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
251 windows_buttons = ObjectProperty() |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
252 |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
253 def __init__(self, calls: "Calls", **kwargs): |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
254 super().__init__(**kwargs) |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
255 self.calls = calls |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
256 if display_servers.detect() == display_servers.X11: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
257 windows_data = display_servers.x11_list_windows() |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
258 for window_data in windows_data: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
259 log.debug(f"- X11 windows found: {window_data}") |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
260 button = WindowSelectButton( |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
261 text = window_data["title"], |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
262 on_press=partial(self.on_window_selected, xid=window_data["id"]) |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
263 ) |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
264 self.windows_buttons.add_widget(button) |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
265 |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
266 def on_window_selected(self, instance, xid: str) -> None: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
267 if xid is not None: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
268 self.calls.webrtc.desktop_sharing_data = {"xid": xid} |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
269 else: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
270 self.calls.webrtc.desktop_sharing_data = None |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
271 self.calls.desktop_sharing = True |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
272 self.dismiss() |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
273 |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 |
506 | 275 class Calls( |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
276 quick_widgets.QuickWidget, |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
277 cagou_widget.LiberviaDesktopKivyWidget, |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
278 FilterBehavior |
506 | 279 ): |
280 audio_muted = BooleanProperty(False) | |
281 call_layout = ObjectProperty() | |
282 call_screen = ObjectProperty() | |
283 fullscreen = BooleanProperty(False) | |
284 in_call = BooleanProperty(False) | |
285 incoming_call_dialog: dict[str, Widget] = {} | |
286 jid_selector = ObjectProperty() | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 local_video = ObjectProperty() |
506 | 288 remote_video = ObjectProperty() |
289 ringtone: Sound | None = None | |
290 screen_manager = ObjectProperty() | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 signals_registered = False |
506 | 292 use_header_input = True |
293 video_muted = BooleanProperty(False) | |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
294 desktop_sharing = BooleanProperty(False) |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 def __init__(self, host, target, profiles): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 quick_widgets.QuickWidget.__init__(self, G.host, target, profiles) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 cagou_widget.LiberviaDesktopKivyWidget.__init__(self) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 call_btn = CallButton( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 parent_widget=self, on_press=lambda *__: aio.run_async(self.toggle_call()) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 self.header_input_add_extra(call_btn) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 self.webrtc = WebRTC(self, self.profile) |
506 | 304 self.previous_fullscreen = None |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 self.reset_instance() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 @property |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 def sid(self): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 return self.webrtc.sid |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 |
506 | 311 def hang_up(self): |
312 if self.sid is not None: | |
313 aio.run_async(self.toggle_call()) | |
314 | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 async def toggle_call(self): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 """Toggle between making a call and hanging up. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 This function will initiate or terminate a call based on the call state. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 """ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 if self.sid is None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 # Initiate the call |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 log.info("initiating call") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 callee = jid.JID(self.header_input.text.strip()) |
506 | 324 if not callee: |
325 return | |
326 if not callee.is_valid(): | |
327 G.host.add_note( | |
328 _("Calls"), | |
329 _("Can't make a call: invalid destinee {}").format(repr(callee)), | |
330 level=C.XMLUI_DATA_LVL_ERROR | |
331 ) | |
332 return | |
333 | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 self.webrtc.callee = callee |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 await self.webrtc.setup_call("initiator") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 self.webrtc.start_pipeline() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 self.in_call = True |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 else: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 # Terminate the call |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 sid = self.sid |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 await self.end_call({"reason": "terminated"}, self.profile) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 await G.host.a_bridge.call_end(sid, "", self.profile) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 self.in_call = False |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 async def on_incoming_call( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 self, action_data: dict, action_id: str, profile: str |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 ) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 """Handle incoming call notifications. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 @param action_data: A dictionary containing data related to the incoming call |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 @param action_id: The ID corresponding to the incoming call action. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 @param profile: The profile associated with the incoming call. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 """ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 if self.sid is not None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 # FIXME: show a double remote call notification |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 log.warning("Ignoring new remote call as we are already in a call.") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 return |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 sid = action_data["session_id"] |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 self.in_call = True |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 self.webrtc.sid = sid |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 # FIXME: we accept all remote calls for now, will be changed when proper UI/UX |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 # will be implemented |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 log.warning("auto-accepting remote call") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 await G.host.a_bridge.action_launch( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 action_id, data_format.serialise({"cancelled": False}), profile |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 async def on_call_setup(self, setup_data: dict, profile: str) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 """Call has been accepted, connection can be established |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 @param session_id: Session identifier |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 @param setup_data: Data with following keys: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 role: initiator or responser |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 sdp: Session Description Protocol data |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 @param profile: Profile associated |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 """ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 try: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 role = setup_data["role"] |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 sdp = setup_data["sdp"] |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 except KeyError: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 log.error(f"Invalid setup data received: {setup_data}") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 return |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 if role == "initiator": |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 self.webrtc.on_accepted_call(sdp, profile) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 elif role == "responder": |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 await self.webrtc.answer_call(sdp, profile) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 else: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 log.error(f"Invalid role received during setup: {setup_data}") |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 def reset_instance(self) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 self.in_call = False |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 self.local_video.texture = None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 self.remote_video.texture = None |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 async def end_call(self, data: dict, profile: str) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 """End current call if any and reset the instance |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 @param data: end call data, often includes the reason of the call ending. |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 """ |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 await self.webrtc.end_call() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 self.reset_instance() |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 |
506 | 403 def on_in_call(self, instance, in_call: bool) -> None: |
404 if in_call: | |
405 self.screen_manager.transition.direction = "up" | |
406 self.screen_manager.current = "call" | |
407 else: | |
408 self.fullscreen = False | |
409 self.screen_manager.transition.direction = "down" | |
410 self.screen_manager.current = "search" | |
411 | |
509 | 412 def on_audio_muted(self, instance, muted: bool) -> None: |
413 self.webrtc.audio_muted = muted | |
414 | |
415 def on_video_muted(self, instance, muted: bool) -> None: | |
416 self.webrtc.video_muted = muted | |
417 | |
510
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
418 def on_desktop_btn_press(self) -> None: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
419 if self.desktop_sharing: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
420 self.desktop_sharing = False |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
421 else: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
422 DesktopScreenDialog(self).open() |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
423 |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
424 def on_desktop_sharing(self, instance, active: bool) -> None: |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
425 self.webrtc.desktop_sharing = active |
97ab236e8f20
plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents:
509
diff
changeset
|
426 |
506 | 427 def on_fullscreen(self, instance, fullscreen: bool) -> None: |
428 if fullscreen: | |
429 G.host.app.show_head_widget(False, animation=False) | |
430 self.call_layout.parent.remove_widget(self.call_layout) | |
431 G.host.show_extra_ui(self.call_layout) | |
432 self.previous_fullscreen = Window.fullscreen | |
433 Window.fullscreen = "auto" | |
434 else: | |
435 G.host.app.show_head_widget(True, animation=False) | |
436 G.host.close_ui() | |
437 self.call_screen.add_widget(self.call_layout) | |
438 Window.fullscreen = self.previous_fullscreen or False | |
439 | |
440 def on_header_wid_input(self): | |
441 aio.run_async(self.toggle_call()) | |
442 | |
443 def on_header_wid_input_complete(self, wid, text, **kwargs): | |
444 """we filter items when text is entered in input box""" | |
445 for layout in self.jid_selector.items_layouts: | |
446 self.do_filter( | |
447 layout, | |
448 text, | |
449 # we append nick to jid to filter on both | |
450 lambda c: c.jid + c.data.get('nick', ''), | |
451 width_cb=lambda c: c.base_width, | |
452 height_cb=lambda c: c.minimum_height, | |
453 continue_tests=[lambda c: not isinstance(c, common.ContactButton)]) | |
454 | |
455 def on_jid_select(self, contact_button): | |
456 self.header_input.text = contact_button.jid | |
457 aio.run_async(self.toggle_call()) | |
458 | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 @classmethod |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 def ice_candidates_new_handler( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 cls, sid: str, candidates_s: str, profile: str |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 ) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 for wid in G.host.get_visible_list(cls): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 if profile not in wid.profiles or sid != wid.sid: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 continue |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 wid.webrtc.on_ice_candidates_new( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 data_format.deserialise(candidates_s), |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 @classmethod |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 def call_setup_handler(cls, sid: str, setup_data_s: str, profile: str) -> None: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 for wid in G.host.get_visible_list(cls): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 if profile not in wid.profiles or sid != wid.sid: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 continue |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 aio.run_async( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 wid.on_call_setup(data_format.deserialise(setup_data_s), profile) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 ) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 @classmethod |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 def call_ended_handler(cls, sid: str, data_s: str, profile: str) -> None: |
506 | 481 if sid in cls.incoming_call_dialog: |
482 dialog_wid = cls.incoming_call_dialog.pop(sid) | |
483 G.host.del_notif_widget(dialog_wid) | |
484 G.host.add_note(_("Call cancelled"), _("The call has been cancelled.")) | |
485 | |
486 | |
499
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 for wid in G.host.get_visible_list(cls): |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 if profile not in wid.profiles or sid != wid.sid: |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 continue |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 aio.run_async(wid.end_call(data_format.deserialise(data_s), profile)) |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
492 @classmethod |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 def action_new_handler( |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 cls, action_data: dict, action_id: str, security_limit: int, profile: str |
f387992d8e37
plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 ) -> None: |
506 | 496 if profile in G.host.profiles: |
497 if cls.ringtone is None: | |
498 cls.ringtone = SoundLoader.load( | |
499 str(Path(G.host.media_dir) / "sounds/notifications/ring_1.mp3") | |
500 ) | |
501 if cls.ringtone is not None: | |
502 cls.ringtone.play() | |
503 peer_jid = jid.JID(action_data["from_jid"]).bare | |
504 sid = action_data["session_id"] | |
505 notif_body = f"{peer_jid} is calling you." | |
506 notif_title = "Incoming call" | |
507 G.host.desktop_notif(notif_body, title=notif_title, duration=10) | |
508 | |
509 def on_call_answer(accepted, __): | |
510 del cls.incoming_call_dialog[sid] | |
511 if cls.ringtone is not None: | |
512 cls.ringtone.stop() | |
513 if accepted: | |
514 wid = G.host.do_action("calls", str(peer_jid), [profile]) | |
515 aio.run_async(wid.on_incoming_call(action_data, action_id, profile)) | |
516 else: | |
517 aio.run_async( | |
518 G.host.a_bridge.action_launch( | |
519 action_id, data_format.serialise({"cancelled": True}), profile | |
520 ) | |
521 ) | |
522 | |
523 dialog_wid = G.host.show_dialog( | |
524 notif_body, notif_title, type="yes/no", answer_cb=on_call_answer | |
525 ) | |
526 cls.incoming_call_dialog[sid] = dialog_wid | |
527 | |
528 | |
529 if G.host is not None: | |
530 log.debug("registering signals") | |
531 G.host.register_signal( | |
532 "ice_candidates_new", | |
533 handler=Calls.ice_candidates_new_handler, | |
534 iface="plugin", | |
535 ) | |
536 G.host.register_signal("call_setup", handler=Calls.call_setup_handler, iface="plugin") | |
537 G.host.register_signal("call_ended", handler=Calls.call_ended_handler, iface="plugin") | |
538 G.host.register_action_handler(C.META_TYPE_CALL, Calls.action_new_handler) |