annotate libervia/desktop_kivy/plugins/plugin_wid_calls.py @ 512:644a8d165e5a

plugin calls: use the new binding feature of webrtc module: the new binding feature is used to update the "Desktop" button if sharing is cancelled by user, or stopped somehow. rel 434
author Goffi <goffi@goffi.org>
date Thu, 18 Jan 2024 23:31:29 +0100
parents 97ab236e8f20
children d78728d7fd6a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
18 from kivy.core.audio import Sound, SoundLoader
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
21 from kivy.properties import (
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
22 BooleanProperty,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
23 ColorProperty,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
24 NumericProperty,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
25 ObjectProperty,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
26 ReferenceListProperty,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
32 from kivy.uix.screenmanager import Screen
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
45 from ..core import common
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
69 class SearchScreen(Screen):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
70 pass
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
71
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
72
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
73 class InCallScreen(Screen):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
74 pass
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
75
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
81 class CallControlButton(common.SymbolButton):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
82 active = BooleanProperty(True)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
83 background_color = ColorProperty()
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
84 margin_x = NumericProperty(0)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
85 margin_y = NumericProperty(0)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
86 margin = ReferenceListProperty(margin_x, margin_y)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
87
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
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 }
512
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
109 PROXIED_METHODS = {'answer_call', 'bind', 'end_call', 'on_accepted_call', 'on_ice_candidates_new', 'setup_call', 'start_pipeline'}
509
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
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
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
114 self.webrtc = webrtc.WebRTC(
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
115 G.host.a_bridge,
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
116 profile,
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
117 sinks=webrtc.SINKS_TEST if self.test_mode else webrtc.SINKS_APP,
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
118 appsink_data=webrtc.AppSinkData(
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
119 local_video_cb=partial(
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
120 self.on_new_sample,
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
121 update_sample_method=self.update_sample,
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
122 video_widget=self.parent_calls.local_video
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
123 ),
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
124 remote_video_cb=partial(
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
125 self.on_new_sample,
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
126 update_sample_method=self.update_sample,
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
127 video_widget=self.parent_calls.remote_video
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
128 )
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
129 ),
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
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
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
132 )
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
133 self.pipeline = None
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
134
509
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
135 def __getattr__(self, name):
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
136 if name in self.PROXIED_PROPERTIES or name in self.PROXIED_METHODS:
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
137 return getattr(self.webrtc, name)
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
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
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
140 def __setattr__(self, name, value):
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
141 if name in self.PROXIED_PROPERTIES:
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
142 setattr(self.webrtc, name, value)
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
143 else:
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
144 super().__setattr__(name, value)
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
145
509
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
146 def on_reset(self):
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
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
512
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
246
510
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
247 class WindowSelectButton(Button):
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
248 pass
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
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
251 class DesktopScreenDialog(Popup):
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
252 windows_buttons = ObjectProperty()
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
253
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
254 def __init__(self, calls: "Calls", **kwargs):
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
255 super().__init__(**kwargs)
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
256 self.calls = calls
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
257 if display_servers.detect() == display_servers.X11:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
258 windows_data = display_servers.x11_list_windows()
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
259 for window_data in windows_data:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
260 log.debug(f"- X11 windows found: {window_data}")
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
261 button = WindowSelectButton(
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
262 text = window_data["title"],
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
263 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
264 )
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
265 self.windows_buttons.add_widget(button)
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
266
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
267 def on_window_selected(self, instance, xid: str) -> None:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
268 if xid is not None:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
269 self.calls.webrtc.desktop_sharing_data = {"xid": xid}
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
270 else:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
271 self.calls.webrtc.desktop_sharing_data = None
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
272 self.calls.desktop_sharing = True
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
273 self.dismiss()
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
274
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
275
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
276 class Calls(
510
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
277 quick_widgets.QuickWidget,
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
278 cagou_widget.LiberviaDesktopKivyWidget,
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
279 FilterBehavior
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
280 ):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
281 audio_muted = BooleanProperty(False)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
282 call_layout = ObjectProperty()
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
283 call_screen = ObjectProperty()
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
284 fullscreen = BooleanProperty(False)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
285 in_call = BooleanProperty(False)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
286 incoming_call_dialog: dict[str, Widget] = {}
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
287 jid_selector = ObjectProperty()
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 local_video = ObjectProperty()
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
289 remote_video = ObjectProperty()
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
290 ringtone: Sound | None = None
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
291 screen_manager = ObjectProperty()
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 signals_registered = False
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
293 use_header_input = True
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
294 video_muted = BooleanProperty(False)
510
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
295 desktop_sharing = BooleanProperty(False)
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
296
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 def __init__(self, host, target, profiles):
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 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
299 cagou_widget.LiberviaDesktopKivyWidget.__init__(self)
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 call_btn = CallButton(
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 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
302 )
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 self.header_input_add_extra(call_btn)
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 self.webrtc = WebRTC(self, self.profile)
512
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
305 self.webrtc.bind(
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
306 desktop_sharing=partial(setattr, self, "desktop_sharing")
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
307 )
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
308 self.previous_fullscreen = None
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 self.reset_instance()
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
310
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 @property
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 def sid(self):
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 return self.webrtc.sid
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
314
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
315 def hang_up(self):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
316 if self.sid is not None:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
317 aio.run_async(self.toggle_call())
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
318
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 async def toggle_call(self):
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 """Toggle between making a call and hanging up.
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
321
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 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
323 """
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 if self.sid is None:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 # Initiate the call
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 log.info("initiating call")
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 callee = jid.JID(self.header_input.text.strip())
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
328 if not callee:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
329 return
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
330 if not callee.is_valid():
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
331 G.host.add_note(
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
332 _("Calls"),
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
333 _("Can't make a call: invalid destinee {}").format(repr(callee)),
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
334 level=C.XMLUI_DATA_LVL_ERROR
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
335 )
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
336 return
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
337
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 self.webrtc.callee = callee
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 await self.webrtc.setup_call("initiator")
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 self.webrtc.start_pipeline()
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 self.in_call = True
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 else:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 # Terminate the call
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 sid = self.sid
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 await self.end_call({"reason": "terminated"}, self.profile)
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 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
347 self.in_call = False
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
348
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 async def on_incoming_call(
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 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
351 ) -> None:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 """Handle incoming call notifications.
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 @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
355 @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
356 @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
357 """
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 if self.sid is not None:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 # FIXME: show a double remote call notification
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 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
361 return
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 sid = action_data["session_id"]
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 self.in_call = True
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 self.webrtc.sid = sid
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 # 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
366 # will be implemented
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 log.warning("auto-accepting remote call")
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 await G.host.a_bridge.action_launch(
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 action_id, data_format.serialise({"cancelled": False}), profile
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
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 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
373 """Call has been accepted, connection can be established
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
374
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 @param session_id: Session identifier
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 @param setup_data: Data with following keys:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 role: initiator or responser
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 sdp: Session Description Protocol data
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 @param profile: Profile associated
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 """
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 try:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 role = setup_data["role"]
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 sdp = setup_data["sdp"]
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 except KeyError:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 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
386 return
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 if role == "initiator":
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 self.webrtc.on_accepted_call(sdp, profile)
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
389 elif role == "responder":
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 await self.webrtc.answer_call(sdp, profile)
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
391 else:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
392 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
393
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 def reset_instance(self) -> None:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 self.in_call = False
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
396 self.local_video.texture = None
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
397 self.remote_video.texture = None
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
398
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 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
400 """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
401
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
402 @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
403 """
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
404 await self.webrtc.end_call()
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
405 self.reset_instance()
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
406
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
407 def on_in_call(self, instance, in_call: bool) -> None:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
408 if in_call:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
409 self.screen_manager.transition.direction = "up"
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
410 self.screen_manager.current = "call"
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
411 else:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
412 self.fullscreen = False
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
413 self.screen_manager.transition.direction = "down"
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
414 self.screen_manager.current = "search"
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
415
509
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
416 def on_audio_muted(self, instance, muted: bool) -> None:
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
417 self.webrtc.audio_muted = muted
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
418
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
419 def on_video_muted(self, instance, muted: bool) -> None:
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
420 self.webrtc.video_muted = muted
f0ce49b360c8 calls: move webrtc code to core:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
421
510
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
422 def on_desktop_btn_press(self) -> None:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
423 if self.desktop_sharing:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
424 self.desktop_sharing = False
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
425 else:
512
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
426 if display_servers.detect() == display_servers.X11:
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
427 DesktopScreenDialog(self).open()
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
428 else:
644a8d165e5a plugin calls: use the new binding feature of webrtc module:
Goffi <goffi@goffi.org>
parents: 510
diff changeset
429 self.desktop_sharing = True
510
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
430
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
431 def on_desktop_sharing(self, instance, active: bool) -> None:
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
432 self.webrtc.desktop_sharing = active
97ab236e8f20 plugin calls: implement desktop sharing:
Goffi <goffi@goffi.org>
parents: 509
diff changeset
433
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
434 def on_fullscreen(self, instance, fullscreen: bool) -> None:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
435 if fullscreen:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
436 G.host.app.show_head_widget(False, animation=False)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
437 self.call_layout.parent.remove_widget(self.call_layout)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
438 G.host.show_extra_ui(self.call_layout)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
439 self.previous_fullscreen = Window.fullscreen
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
440 Window.fullscreen = "auto"
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
441 else:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
442 G.host.app.show_head_widget(True, animation=False)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
443 G.host.close_ui()
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
444 self.call_screen.add_widget(self.call_layout)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
445 Window.fullscreen = self.previous_fullscreen or False
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
446
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
447 def on_header_wid_input(self):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
448 aio.run_async(self.toggle_call())
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
449
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
450 def on_header_wid_input_complete(self, wid, text, **kwargs):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
451 """we filter items when text is entered in input box"""
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
452 for layout in self.jid_selector.items_layouts:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
453 self.do_filter(
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
454 layout,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
455 text,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
456 # we append nick to jid to filter on both
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
457 lambda c: c.jid + c.data.get('nick', ''),
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
458 width_cb=lambda c: c.base_width,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
459 height_cb=lambda c: c.minimum_height,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
460 continue_tests=[lambda c: not isinstance(c, common.ContactButton)])
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
461
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
462 def on_jid_select(self, contact_button):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
463 self.header_input.text = contact_button.jid
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
464 aio.run_async(self.toggle_call())
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
465
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
466 @classmethod
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
467 def ice_candidates_new_handler(
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
468 cls, sid: str, candidates_s: str, profile: str
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
469 ) -> None:
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
470 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
471 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
472 continue
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
473 wid.webrtc.on_ice_candidates_new(
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
474 data_format.deserialise(candidates_s),
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
475 )
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
476
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
477 @classmethod
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
478 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
479 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
480 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
481 continue
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
482 aio.run_async(
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
483 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
484 )
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
485
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
486 @classmethod
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
487 def call_ended_handler(cls, sid: str, data_s: str, profile: str) -> None:
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
488 if sid in cls.incoming_call_dialog:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
489 dialog_wid = cls.incoming_call_dialog.pop(sid)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
490 G.host.del_notif_widget(dialog_wid)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
491 G.host.add_note(_("Call cancelled"), _("The call has been cancelled."))
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
492
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
493
499
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
494 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
495 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
496 continue
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 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
498
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
499 @classmethod
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 def action_new_handler(
f387992d8e37 plugins: new "call" plugin for A/V calls:
Goffi <goffi@goffi.org>
parents:
diff changeset
501 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
502 ) -> None:
506
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
503 if profile in G.host.profiles:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
504 if cls.ringtone is None:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
505 cls.ringtone = SoundLoader.load(
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
506 str(Path(G.host.media_dir) / "sounds/notifications/ring_1.mp3")
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
507 )
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
508 if cls.ringtone is not None:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
509 cls.ringtone.play()
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
510 peer_jid = jid.JID(action_data["from_jid"]).bare
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
511 sid = action_data["session_id"]
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
512 notif_body = f"{peer_jid} is calling you."
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
513 notif_title = "Incoming call"
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
514 G.host.desktop_notif(notif_body, title=notif_title, duration=10)
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
515
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
516 def on_call_answer(accepted, __):
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
517 del cls.incoming_call_dialog[sid]
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
518 if cls.ringtone is not None:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
519 cls.ringtone.stop()
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
520 if accepted:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
521 wid = G.host.do_action("calls", str(peer_jid), [profile])
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
522 aio.run_async(wid.on_incoming_call(action_data, action_id, profile))
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
523 else:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
524 aio.run_async(
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
525 G.host.a_bridge.action_launch(
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
526 action_id, data_format.serialise({"cancelled": True}), profile
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
527 )
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
528 )
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
529
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
530 dialog_wid = G.host.show_dialog(
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
531 notif_body, notif_title, type="yes/no", answer_cb=on_call_answer
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
532 )
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
533 cls.incoming_call_dialog[sid] = dialog_wid
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
534
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
535
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
536 if G.host is not None:
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
537 log.debug("registering signals")
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
538 G.host.register_signal(
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
539 "ice_candidates_new",
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
540 handler=Calls.ice_candidates_new_handler,
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
541 iface="plugin",
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
542 )
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
543 G.host.register_signal("call_setup", handler=Calls.call_setup_handler, iface="plugin")
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
544 G.host.register_signal("call_ended", handler=Calls.call_ended_handler, iface="plugin")
0480f883f0a6 plugin calls: update UI:
Goffi <goffi@goffi.org>
parents: 499
diff changeset
545 G.host.register_action_handler(C.META_TYPE_CALL, Calls.action_new_handler)