annotate libervia/desktop_kivy/plugins/plugin_wid_calls.py @ 509:f0ce49b360c8

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