BlueGit

ict rusty-teams

Files

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

features.rs

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