BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / call / features.rs

features.rs

d39bdfed History
features.rs 10.1 KiB Download Raw
1use calling::{
2 CallCommand, CallSpec, Callee, EndKind, EndReason, HoldState,
3};
4use gpui_kit::*;
5
6use super::background::BackgroundPick;
7use super::demo::DemoCall;
8use super::health::HealthBanner;
9use super::model::{ActiveCall, BreakoutState, CallKind, CallModel, PendingMove};
10use super::recording_menu::RecordAction;
11use super::target::plan_for_chat;
12use crate::app_state::{AppEvent, AppState};
13use crate::data::is_one_on_one;
14
15const DEMO_ROOM_GUESTS: usize = 3;
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct TransferCandidate {
19 pub mri: String,
20 pub name: String,
21 pub user_id: Option<String>,
22 pub chat_id: String,
23}
24
25pub fn room_closed_move(call: &ActiveCall, reason: &EndReason) -> Option<PendingMove> {
26 let room = call.model.breakout.as_ref()?;
27 if *reason != EndReason::Remote(EndKind::RoomClosed) {
28 return None;
29 }
30 Some(return_move(room))
31}
32
33fn return_move(room: &BreakoutState) -> PendingMove {
34 PendingMove {
35 target: room.main.clone().expect("a room with a way back"),
36 title: room.main_title.clone(),
37 breakout: None,
38 }
39}
40
41impl AppState {
42 pub fn run_call_record_action(&mut self, action: RecordAction, _cx: &mut Context<Self>) {
43 let Some(call) = self
44 .call
45 .as_ref()
46 .filter(|call| call.model.action_allowed(action))
47 else {
48 return;
49 };
50 let command = match action {
51 RecordAction::Start(kind) => CallCommand::StartRecording {
52 kind,
53 title: call.model.title.clone(),
54 },
55 RecordAction::Stop(scope) => CallCommand::StopRecording { scope },
56 };
57 self.send_call_command(command);
58 }
59
60 pub fn open_call_transcript(
61 &mut self,
62 panel: AnyView,
63 cx: &mut Context<Self>,
64 ) {
65 self.transcript_panel = Some(panel);
66 self.show_call_transcript(cx);
67 }
68
69 pub(super) fn show_call_transcript(&mut self, cx: &mut Context<Self>) {
70 let Some(call) = self
71 .call
72 .as_mut()
73 .filter(|call| call.model.kind == CallKind::Meeting)
74 else {
75 return;
76 };
77 call.chat_open = false;
78 call.people_open = false;
79 call.transcript_open = true;
80 let captions_off = !call.model.captions_on();
81 if captions_off {
82 self.send_call_command(CallCommand::SetCaptions(true));
83 }
84 cx.emit(AppEvent::Call);
85 cx.notify();
86 }
87
88 pub fn close_call_transcript(&mut self, cx: &mut Context<Self>) {
89 if let Some(call) = self.call.as_mut() {
90 call.transcript_open = false;
91 }
92 self.transcript_panel = None;
93 cx.emit(AppEvent::Call);
94 cx.notify();
95 }
96
97 pub fn choose_call_caption_language(&mut self, tag: &str, cx: &mut Context<Self>) {
98 let Some(call) = self
99 .call
100 .as_mut()
101 .filter(|call| call.model.is_active() && call.model.kind == CallKind::Meeting)
102 else {
103 return;
104 };
105 call.model.choose_caption_language(tag);
106 let captions_off = !call.model.captions_on();
107 if captions_off {
108 self.send_call_command(CallCommand::SetCaptions(true));
109 }
110 self.send_ready_caption_language();
111 cx.notify();
112 }
113
114 fn send_ready_caption_language(&mut self) {
115 let language = self
116 .call
117 .as_mut()
118 .and_then(|call| call.model.take_ready_caption_language());
119 if let Some(language) = language {
120 self.send_call_command(CallCommand::SetCaptionLanguage(language));
121 }
122 }
123
124 pub fn accept_recording_notice(&mut self, _cx: &mut Context<Self>) {
125 if self
126 .call
127 .as_ref()
128 .is_some_and(|call| call.model.consent_required)
129 {
130 self.send_call_command(CallCommand::ConsentToRecording);
131 }
132 }
133
134 pub fn toggle_call_hold(&mut self, _cx: &mut Context<Self>) {
135 let Some(call) = self.call.as_ref() else {
136 return;
137 };
138 let hold = match call.model.hold {
139 HoldState::Local => false,
140 HoldState::Active if call.model.can_hold() => true,
141 _ => return,
142 };
143 self.send_call_command(CallCommand::Hold(hold));
144 }
145
146 pub fn set_call_incoming_video(&mut self, enabled: bool, cx: &mut Context<Self>) {
147 self.send_call_command(CallCommand::SetIncomingVideo(enabled));
148 cx.notify();
149 }
150
151 pub fn close_call_health_banner(&mut self, banner: HealthBanner, cx: &mut Context<Self>) {
152 if let Some(call) = self.call.as_mut() {
153 call.model.health.close_banner(banner);
154 cx.notify();
155 }
156 }
157
158 pub fn turn_off_call_effects(&mut self, cx: &mut Context<Self>) {
159 self.set_call_background(BackgroundPick::None, cx);
160 let effects = calling::CameraEffects {
161 auto_framing: false,
162 adjust_brightness: false,
163 soft_focus: false,
164 ..self.call_effects
165 };
166 self.set_call_effects(effects, cx);
167 }
168
169 pub fn open_call_whiteboard(&mut self, cx: &mut Context<Self>) {
170 let Some(call) = self
171 .call
172 .as_ref()
173 .filter(|call| call.model.can_open_whiteboard())
174 else {
175 return;
176 };
177 if let Some(url) = call.model.whiteboard_url() {
178 cx.open_url(url);
179 return;
180 }
181 let title = call.model.title.clone();
182 self.send_call_command(CallCommand::OpenWhiteboard { title });
183 }
184
185 pub fn transfer_candidates(&self) -> Vec<TransferCandidate> {
186 let peer = self
187 .call
188 .as_ref()
189 .and_then(|call| call.model.tiles.first().map(|tile| tile.mri.clone()));
190 self.sidebar
191 .chats
192 .iter()
193 .filter(|chat| is_one_on_one(chat))
194 .filter_map(|chat| {
195 let plan = plan_for_chat(chat, self.directory.me.as_ref())?;
196 let (mri, name) = plan.callees.into_iter().next()?;
197 Some(TransferCandidate {
198 user_id: mri.strip_prefix("8:orgid:").map(str::to_owned),
199 mri,
200 name,
201 chat_id: chat.id.clone(),
202 })
203 })
204 .filter(|candidate| Some(&candidate.mri) != peer.as_ref())
205 .collect()
206 }
207
208 pub fn can_transfer_call(&self) -> bool {
209 self.call
210 .as_ref()
211 .is_some_and(|call| call.model.can_transfer() && call.consult.is_none())
212 && self.held_call.is_none()
213 }
214
215 pub fn open_transfer_picker(
216 &mut self,
217 picker: AnyView,
218 cx: &mut Context<Self>,
219 ) {
220 if self.can_transfer_call() {
221 self.transfer_picker = Some(picker);
222 cx.notify();
223 }
224 }
225
226 pub fn close_transfer_picker(&mut self, cx: &mut Context<Self>) {
227 if self.transfer_picker.take().is_some() {
228 cx.notify();
229 }
230 }
231
232 pub fn transfer_call_blind(&mut self, target: TransferCandidate, cx: &mut Context<Self>) {
233 self.close_transfer_picker(cx);
234 if !self.can_transfer_call() {
235 return;
236 }
237 let callee = Callee {
238 mri: target.mri,
239 display_name: target.name,
240 };
241 self.send_call_command(CallCommand::Transfer {
242 target: callee,
243 replaces: None,
244 });
245 }
246
247 pub(super) fn begin_breakout_move(
248 &mut self,
249 moved: calling::BreakoutMove,
250 cx: &mut Context<Self>,
251 ) {
252 let Some(call) = self
253 .call
254 .as_mut()
255 .filter(|call| call.pending_move.is_none())
256 else {
257 return;
258 };
259 let (main, main_title) = match &call.model.breakout {
260 Some(room) => (
261 room.main
262 .clone()
263 .or_else(|| call.model.main_meeting.clone()),
264 room.main_title.clone(),
265 ),
266 None => (call.meeting_target.clone(), call.model.title.clone()),
267 };
268 let pending = if moved.returning {
269 PendingMove {
270 target: moved.target,
271 title: main_title,
272 breakout: None,
273 }
274 } else {
275 let breakout = BreakoutState {
276 room_name: moved.room_name.clone(),
277 main,
278 main_title,
279 };
280 PendingMove {
281 target: moved.target,
282 title: moved.room_name.clone(),
283 breakout: Some(breakout),
284 }
285 };
286 let notice = if moved.returning {
287 "Moving you back to the main meeting".to_owned()
288 } else {
289 format!("Moving you to {}", moved.room_name)
290 };
291 call.pending_move = Some(pending);
292 self.raise_notice(notice, None, cx);
293 self.send_call_command(CallCommand::Hangup);
294 }
295
296 pub fn return_to_main_meeting(&mut self, _cx: &mut Context<Self>) {
297 let Some(call) = self
298 .call
299 .as_mut()
300 .filter(|call| call.pending_move.is_none())
301 else {
302 return;
303 };
304 let Some(room) = call
305 .model
306 .breakout
307 .as_ref()
308 .filter(|room| room.main.is_some())
309 else {
310 return;
311 };
312 call.pending_move = Some(return_move(room));
313 self.send_call_command(CallCommand::Hangup);
314 }
315
316 pub(super) fn join_moved_call(&mut self, moved: PendingMove, cx: &mut Context<Self>) {
317 let demo = DemoCall::Meeting {
318 guests: super::demo::demo_guests(DEMO_ROOM_GUESTS),
319 lobby: false,
320 organizer: false,
321 };
322 let Some(handle) =
323 self.place_call(CallSpec::Meeting(moved.target.clone()), demo, false, cx)
324 else {
325 return;
326 };
327 let mut model = CallModel::meeting(&moved.title, false);
328 model.breakout = moved.breakout;
329 self.begin_call(handle, model, Some(moved.target.thread_id.clone()), cx);
330 if let Some(call) = self.call.as_mut() {
331 call.meeting_target = Some(moved.target);
332 }
333 }
334}