BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / call_organizer.rs

call_organizer.rs

call_organizer.rs 26.4 KiB Download Raw
1use std::sync::Arc;
2use std::time::Instant;
3
4use calling::{CaptionState, HoldState, MeetingRole, Modality, VideoKey};
5use gpui_kit::assets::IconName;
6use gpui_kit::component::button::{Button, ButtonVariants as _};
7use gpui_kit::component::dialog::DialogFooter;
8use gpui_kit::component::menu::{ContextMenuExt as _, DropdownMenu as _, PopupMenu, PopupMenuItem};
9use gpui_kit::component::popover::Popover;
10use gpui_kit::component::{Sizable as _, WindowExt as _, h_flex, v_flex};
11use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::*;
13
14use super::avatar::person_avatar;
15use super::call_control_fold::{Foldable, FoldedControls, folded_items};
16use super::call_extras::{
17 CameraMenu, background_items, effect_items, open_transfer_picker,
18};
19use super::call_record::{record_submenu, transcript_and_settings_items};
20use super::call_people::add_people_item;
21use super::call_view::{BANNER_HEIGHT, CONTROL_SIZE, MENU_WIDTH, round_control};
22use super::widgets::{Corner, corner_badge, count_badge, icon};
23use crate::app_state::AppState;
24use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus};
25use crate::notice::truncated;
26use crate::theme;
27
28const BANNER_TEXT: f32 = 13.;
29const PILL_HEIGHT: f32 = 26.;
30const LOBBY_LIST_WIDTH: f32 = 340.;
31const LOBBY_NAME_LIMIT: usize = 28;
32const CAPTION_WIDTH: f32 = 720.;
33const CAPTION_BOTTOM: f32 = 2. * 16. + CONTROL_SIZE + 16.;
34const CAPTION_TOP: f32 = 72.;
35const CAPTION_FADE_SECONDS: f32 = 1.;
36const CAPTION_BACKGROUND: f32 = 0.72;
37const FOCUS_RADIUS: f32 = 12.;
38const FOCUS_AVATAR: f32 = 140.;
39const CHIP_HEIGHT: f32 = 24.;
40const MORE_SIZE: f32 = 28.;
41pub(super) const CAMERA_MENU_WIDTH: f32 = 28.;
42const NAME_LIMIT: usize = 32;
43
44fn dark_text() -> Hsla {
45 hsla(0., 0., 0.08, 1.)
46}
47
48pub(super) fn pill(id: impl Into<ElementId>, label: &'static str, filled: bool) -> Stateful<Div> {
49 let (background, foreground) = if filled {
50 (dark_text(), theme::white())
51 } else {
52 (dark_text().opacity(0.12), dark_text())
53 };
54 div()
55 .id(id)
56 .h(px(PILL_HEIGHT))
57 .px(px(12.))
58 .flex()
59 .flex_none()
60 .items_center()
61 .rounded_full()
62 .bg(background)
63 .text_color(foreground)
64 .text_size(px(BANNER_TEXT))
65 .font_weight(FontWeight::SEMIBOLD)
66 .cursor_pointer()
67 .hover(|button| button.opacity(0.85))
68 .child(label)
69}
70
71pub fn lobby_text(waiting: usize) -> String {
72 match waiting {
73 1 => "1 person is waiting in the lobby".to_owned(),
74 count => format!("{count} people are waiting in the lobby"),
75 }
76}
77
78fn lobby_list(app: &Entity<AppState>, guests: &[(String, String)]) -> Div {
79 v_flex()
80 .w(px(LOBBY_LIST_WIDTH))
81 .gap(px(6.))
82 .children(guests.iter().map(|(mri, name)| {
83 let (admit_app, deny_app) = (app.clone(), app.clone());
84 let (admit_mri, deny_mri) = (mri.clone(), mri.clone());
85 h_flex()
86 .w_full()
87 .gap(px(8.))
88 .items_center()
89 .child(
90 div()
91 .flex_1()
92 .min_w_0()
93 .truncate()
94 .text_size(px(14.))
95 .child(truncated(name, LOBBY_NAME_LIMIT)),
96 )
97 .child(
98 Button::new(SharedString::from(format!("lobby-admit-{mri}")))
99 .label("Admit")
100 .on_click(move |_, _, cx| {
101 admit_app.update(cx, |state, cx| {
102 state.admit_call_guest(admit_mri.clone(), cx)
103 })
104 }),
105 )
106 .child(
107 Button::new(SharedString::from(format!("lobby-deny-{mri}")))
108 .label("Deny")
109 .ghost()
110 .on_click(move |_, _, cx| {
111 deny_app
112 .update(cx, |state, cx| state.deny_call_guest(deny_mri.clone(), cx))
113 }),
114 )
115 }))
116}
117
118pub fn lobby_banner(
119 app: &Entity<AppState>,
120 model: &CallModel,
121 list_open: bool,
122) -> Option<AnyElement> {
123 if !model.can_admit() {
124 return None;
125 }
126 let guests: Vec<(String, String)> = model
127 .lobby_guests()
128 .into_iter()
129 .map(|tile| (tile.mri.clone(), tile.name.clone()))
130 .collect();
131 if guests.is_empty() {
132 return None;
133 }
134 let list_app = app.clone();
135 let open_app = app.clone();
136 let admit_app = app.clone();
137 Some(
138 h_flex()
139 .id("call-lobby-banner")
140 .w_full()
141 .h(px(BANNER_HEIGHT))
142 .flex_none()
143 .px(px(20.))
144 .gap(px(12.))
145 .items_center()
146 .justify_center()
147 .bg(theme::amber())
148 .text_color(dark_text())
149 .text_size(px(BANNER_TEXT))
150 .font_weight(FontWeight::SEMIBOLD)
151 .child(lobby_text(guests.len()))
152 .child(
153 Popover::new("call-lobby-popover")
154 .anchor(Anchor::TopLeft)
155 .offset(px(8.))
156 .open(list_open)
157 .on_open_change(move |open, _, cx| {
158 open_app.update(cx, |state, cx| state.set_call_lobby_list(*open, cx))
159 })
160 .trigger(
161 Button::new("call-lobby-view")
162 .ghost()
163 .p_0()
164 .h(px(PILL_HEIGHT))
165 .rounded_full()
166 .child(pill("call-lobby-view-face", "View", false)),
167 )
168 .content(move |_, _, _| lobby_list(&list_app, &guests)),
169 )
170 .child(
171 pill("call-lobby-admit-all", "Admit all", true).on_click(move |_, _, cx| {
172 admit_app.update(cx, |state, cx| state.admit_all_call_guests(cx))
173 }),
174 )
175 .into_any_element(),
176 )
177}
178
179fn confirm_remove(
180 app: &Entity<AppState>,
181 mri: &str,
182 name: &str,
183 window: &mut Window,
184 cx: &mut App,
185) {
186 let app = app.clone();
187 let mri = mri.to_owned();
188 let heading = format!("Remove {} from the meeting?", truncated(name, NAME_LIMIT));
189 window.open_alert_dialog(cx, move |alert, _, _| {
190 let app = app.clone();
191 let mri = mri.clone();
192 let cancel = Button::new("remove-cancel")
193 .label("Cancel")
194 .on_click(|_, window, cx| window.close_dialog(cx));
195 let remove = Button::new("remove-confirm")
196 .label("Remove")
197 .danger()
198 .on_click(move |_, window, cx| {
199 app.update(cx, |state, cx| {
200 state.remove_call_participant(mri.clone(), cx)
201 });
202 window.close_dialog(cx);
203 });
204 alert
205 .title(heading.clone())
206 .description("They leave the call and can only come back if they join again.")
207 .footer(DialogFooter::new().child(cancel).child(remove))
208 .on_ok(|_, _, _| false)
209 });
210}
211
212fn own_tile_items(popup: PopupMenu, app: &Entity<AppState>) -> PopupMenu {
213 let hide_app = app.clone();
214 popup.min_w(px(MENU_WIDTH)).item(
215 PopupMenuItem::new("Hide for me")
216 .icon(IconName::EyeOff)
217 .on_click(move |_, _, cx| {
218 hide_app.update(cx, |state, cx| state.set_call_hide_me(true, cx))
219 }),
220 )
221}
222
223pub fn tile_menu(
224 popup: PopupMenu,
225 app: &Entity<AppState>,
226 model: &CallModel,
227 mri: &str,
228 name: &str,
229 own: bool,
230) -> PopupMenu {
231 if own {
232 return own_tile_items(popup, app);
233 }
234 let pinned = model.is_pinned(mri);
235 let spotlighted = model.is_spotlighted(mri);
236 let organizes = model.organizes_meeting();
237 let raised = model
238 .tiles
239 .iter()
240 .any(|tile| tile.mri == mri && tile.hand.is_some());
241 let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);
242 let mut popup = popup.min_w(px(MENU_WIDTH));
243 let pin_app = app.clone();
244 let pin_mri = mri.to_owned();
245 popup = popup.item(
246 PopupMenuItem::new(if pinned { "Unpin" } else { "Pin for me" })
247 .icon(IconName::Frame)
248 .on_click(move |_, _, cx| {
249 pin_app.update(cx, |state, cx| state.toggle_call_pin(&pin_mri, cx))
250 }),
251 );
252 if organizes {
253 let (spotlight_app, spotlight_mri) = (app.clone(), mri.to_owned());
254 popup = popup.item(
255 PopupMenuItem::new(if spotlighted {
256 "Stop spotlight"
257 } else {
258 "Spotlight for everyone"
259 })
260 .icon(IconName::Star)
261 .on_click(move |_, _, cx| {
262 spotlight_app.update(cx, |state, cx| {
263 state.toggle_call_spotlight(spotlight_mri.clone(), cx)
264 })
265 }),
266 );
267 }
268 if organizes {
269 let (mute_app, mute_mri) = (app.clone(), mri.to_owned());
270 popup = popup.item(
271 PopupMenuItem::new("Mute")
272 .icon(IconName::MicOff)
273 .disabled(muted)
274 .on_click(move |_, _, cx| {
275 mute_app.update(cx, |state, cx| {
276 state.mute_call_participant(mute_mri.clone(), cx)
277 })
278 }),
279 );
280 }
281 if model.can_change_roles(mri) {
282 popup = restriction_items(popup, app, model, mri);
283 }
284 if organizes && raised {
285 let (hand_app, hand_mri) = (app.clone(), mri.to_owned());
286 popup = popup.item(PopupMenuItem::new("Lower hand").on_click(move |_, _, cx| {
287 hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))
288 }));
289 }
290 if organizes {
291 let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());
292 popup = popup.separator().item(
293 PopupMenuItem::new("Remove from meeting...")
294 .icon(IconName::Close)
295 .on_click(move |_, window, cx| {
296 confirm_remove(&remove_app, &remove_mri, &remove_name, window, cx)
297 }),
298 );
299 }
300 popup
301}
302
303fn modality_item(
304 app: &Entity<AppState>,
305 mri: &str,
306 modality: Modality,
307 allowed: bool,
308) -> PopupMenuItem {
309 let (app, mri) = (app.clone(), mri.to_owned());
310 let (label, glyph) = match (modality, allowed) {
311 (Modality::Mic, true) => ("Disable mic", IconName::MicOff),
312 (Modality::Mic, false) => ("Allow mic", IconName::Mic),
313 (Modality::Camera, true) => ("Disable camera", IconName::VideoOff),
314 (Modality::Camera, false) => ("Allow camera", IconName::Video),
315 };
316 PopupMenuItem::new(label).icon(glyph).on_click(move |_, _, cx| {
317 app.update(cx, |state, cx| {
318 state.set_call_attendee_modality(mri.clone(), modality, !allowed, cx)
319 })
320 })
321}
322
323fn restriction_items(
324 popup: PopupMenu,
325 app: &Entity<AppState>,
326 model: &CallModel,
327 mri: &str,
328) -> PopupMenu {
329 let presenter = model.tile_role(mri) == Some(MeetingRole::Presenter);
330 let (role_app, role_mri) = (app.clone(), mri.to_owned());
331 popup
332 .item(modality_item(app, mri, Modality::Mic, model.attendee_allowed(mri, Modality::Mic)))
333 .item(modality_item(app, mri, Modality::Camera, model.attendee_allowed(mri, Modality::Camera)))
334 .item(
335 PopupMenuItem::new(if presenter { "Make attendee" } else { "Make presenter" })
336 .icon(IconName::Users)
337 .on_click(move |_, _, cx| {
338 let role = if presenter { MeetingRole::Attendee } else { MeetingRole::Presenter };
339 role_app.update(cx, |state, cx| state.set_call_role(role_mri.clone(), role, cx))
340 }),
341 )
342}
343
344fn more_overlay(
345 app: &Entity<AppState>,
346 model: &CallModel,
347 mri: &str,
348 name: &str,
349 own: bool,
350 group: SharedString,
351) -> Div {
352 let (app, model, mri_owned, name) =
353 (app.clone(), model.clone(), mri.to_owned(), name.to_owned());
354 div()
355 .absolute()
356 .top(px(6.))
357 .right(px(38.))
358 .opacity(0.)
359 .group_hover(group, |more| more.opacity(1.))
360 .child(
361 Button::new(SharedString::from(format!("call-tile-more-{mri}")))
362 .icon(IconName::Ellipsis)
363 .ghost()
364 .xsmall()
365 .size(px(MORE_SIZE))
366 .rounded_full()
367 .bg(black().opacity(0.55))
368 .text_color(theme::white())
369 .tooltip("More")
370 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
371 tile_menu(popup, &app, &model, &mri_owned, &name, own)
372 }),
373 )
374}
375
376/// Adds the right-click menu and a "..." button that shows while the pointer is over the tile.
377pub fn attach_tile_menu(
378 tile: Stateful<Div>,
379 app: &Entity<AppState>,
380 model: &CallModel,
381 mri: &str,
382 name: &str,
383 own: bool,
384) -> AnyElement {
385 let group = SharedString::from(format!("call-tile-group-{mri}"));
386 let (context_app, context_model, context_mri, context_name) =
387 (app.clone(), model.clone(), mri.to_owned(), name.to_owned());
388 tile.group(group.clone())
389 .relative()
390 .child(more_overlay(app, model, mri, name, own, group))
391 .context_menu(move |popup, _, _| {
392 tile_menu(
393 popup,
394 &context_app,
395 &context_model,
396 &context_mri,
397 &context_name,
398 own,
399 )
400 })
401 .into_any_element()
402}
403
404pub fn with_tile_menu(
405 app: &Entity<AppState>,
406 model: &CallModel,
407 mri: &str,
408 name: &str,
409 own: bool,
410 tile: AnyElement,
411) -> AnyElement {
412 let wrapper = div()
413 .id(SharedString::from(format!("call-tile-{mri}")))
414 .flex_none()
415 .child(tile);
416 attach_tile_menu(wrapper, app, model, mri, name, own)
417}
418
419pub fn more_button(
420 app: &Entity<AppState>,
421 model: &CallModel,
422 folded: &FoldedControls,
423) -> Option<AnyElement> {
424 let in_meeting = model.kind == crate::call::CallKind::Meeting;
425 if !in_meeting && !model.is_one_to_one() {
426 return None;
427 }
428 let app = app.clone();
429 let model = model.clone();
430 let folded = folded.clone();
431 let unread = folded.chat_unread;
432 let chat_folded = folded.folds(Foldable::Chat);
433 Some(
434 Button::new("call-more")
435 .ghost()
436 .p_0()
437 .size(px(CONTROL_SIZE))
438 .rounded_full()
439 .child(
440 round_control(
441 "call-more-face",
442 IconName::Ellipsis,
443 theme::surface_raised(),
444 theme::text(),
445 )
446 .relative()
447 .when(chat_folded && unread > 0, |face| {
448 face.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
449 }),
450 )
451 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, window, cx| {
452 more_menu(popup, window, cx, &app, &model, &folded)
453 })
454 .into_any_element(),
455 )
456}
457
458fn more_menu(
459 popup: PopupMenu,
460 window: &mut Window,
461 cx: &mut Context<PopupMenu>,
462 app: &Entity<AppState>,
463 model: &CallModel,
464 folded: &FoldedControls,
465) -> PopupMenu {
466 let popup = folded_items(popup.min_w(px(MENU_WIDTH)), window, cx, app, model, folded);
467 let popup = if model.is_one_to_one() {
468 one_to_one_items(popup, app, model)
469 } else {
470 meeting_items(popup, window, cx, app, model)
471 };
472 incoming_video_item(popup, app, model)
473}
474
475fn incoming_video_item(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
476 if model.health.incoming_video {
477 return popup;
478 }
479 let app = app.clone();
480 popup.item(
481 PopupMenuItem::new("Turn on incoming video")
482 .icon(IconName::Video)
483 .on_click(move |_, _, cx| {
484 app.update(cx, |state, cx| state.set_call_incoming_video(true, cx))
485 }),
486 )
487}
488
489fn one_to_one_items(mut popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
490 let (hold_app, transfer_app) = (app.clone(), app.clone());
491 let held = model.hold == HoldState::Local;
492 popup = popup.item(
493 PopupMenuItem::new(if held { "Resume" } else { "Hold" })
494 .icon(IconName::Timer)
495 .disabled(!held && !model.can_hold())
496 .on_click(move |_, _, cx| hold_app.update(cx, |state, cx| state.toggle_call_hold(cx))),
497 );
498 let can_transfer = model.can_transfer();
499 popup = popup.item(add_people_item(app, model));
500 popup.item(
501 PopupMenuItem::new("Transfer...")
502 .icon(IconName::Forward)
503 .disabled(!can_transfer)
504 .on_click(move |_, window, cx| open_transfer_picker(&transfer_app, window, cx)),
505 )
506}
507
508fn meeting_items(
509 mut popup: PopupMenu,
510 window: &mut Window,
511 cx: &mut Context<PopupMenu>,
512 app: &Entity<AppState>,
513 model: &CallModel,
514) -> PopupMenu {
515 let (mute_app, captions_app, board_app) = (app.clone(), app.clone(), app.clone());
516 let captions_on = model.captions_on();
517 if model.organizes_meeting() {
518 popup = popup.item(
519 PopupMenuItem::new("Mute all")
520 .icon(IconName::MicOff)
521 .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))),
522 );
523 }
524 if model.can_record() {
525 popup = record_submenu(popup, window, cx, app, model);
526 }
527 if model.can_open_whiteboard() {
528 popup = popup.item(
529 PopupMenuItem::new("Whiteboard")
530 .icon(IconName::Frame)
531 .on_click(move |_, _, cx| {
532 board_app.update(cx, |state, cx| state.open_call_whiteboard(cx))
533 }),
534 );
535 }
536 let popup = popup.item(
537 PopupMenuItem::new(if captions_on {
538 "Turn off live captions"
539 } else {
540 "Turn on live captions"
541 })
542 .icon(if captions_on {
543 IconName::CaptionsOff
544 } else {
545 IconName::Captions
546 })
547 .on_click(move |_, _, cx| {
548 captions_app.update(cx, |state, cx| state.toggle_call_captions(cx))
549 }),
550 );
551 transcript_and_settings_items(popup, app)
552}
553
554pub fn chevron_button(button_id: &'static str, face_id: &'static str) -> Button {
555 Button::new(button_id)
556 .ghost()
557 .p_0()
558 .w(px(CAMERA_MENU_WIDTH))
559 .h(px(super::call_view::CONTROL_SIZE))
560 .rounded_full()
561 .child(
562 div()
563 .id(face_id)
564 .w(px(CAMERA_MENU_WIDTH))
565 .h(px(super::call_view::CONTROL_SIZE))
566 .flex()
567 .items_center()
568 .justify_center()
569 .child(icon(IconName::ChevronUp, 16., theme::text())),
570 )
571}
572
573pub fn camera_menu_button(
574 app: &Entity<AppState>,
575 model: &CallModel,
576 backgrounds: CameraMenu,
577) -> Option<AnyElement> {
578 if !model.can_use_camera() {
579 return None;
580 }
581 let app = app.clone();
582 let model = model.clone();
583 Some(
584 chevron_button("call-camera-menu", "call-camera-menu-face")
585 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
586 camera_menu(popup, &app, &model, &backgrounds)
587 })
588 .into_any_element(),
589 )
590}
591
592fn camera_menu(
593 popup: PopupMenu,
594 app: &Entity<AppState>,
595 model: &CallModel,
596 backgrounds: &CameraMenu,
597) -> PopupMenu {
598 let camera_app = app.clone();
599 let cameras = super::call_view::device_items(
600 calling::camera_entries(&model.cameras),
601 &model.camera,
602 move |choice, cx| {
603 camera_app.update(cx, |state, cx| state.select_call_camera(choice, cx));
604 },
605 );
606 let mut popup = popup
607 .min_w(px(MENU_WIDTH))
608 .item(PopupMenuItem::label("Camera"));
609 for item in cameras {
610 popup = popup.item(item);
611 }
612 background_items(
613 effect_items(popup, app, backgrounds.effects),
614 app,
615 backgrounds,
616 )
617}
618
619pub fn captions_overlay(model: &CallModel, now: Instant) -> Option<AnyElement> {
620 let lines = model.visible_captions(now);
621 if lines.is_empty() {
622 return None;
623 }
624 let shown = CAPTION_SHOWN.as_secs_f32();
625 Some(
626 div()
627 .id("call-captions")
628 .absolute()
629 .left_0()
630 .right_0()
631 .map(|overlay| match model.view.caption_position {
632 CaptionPosition::Bottom => overlay.bottom(px(CAPTION_BOTTOM)),
633 CaptionPosition::Top => overlay.top(px(CAPTION_TOP)),
634 })
635 .flex()
636 .justify_center()
637 .px(px(24.))
638 .child(
639 v_flex()
640 .w(px(CAPTION_WIDTH))
641 .max_w_full()
642 .gap(px(4.))
643 .px(px(16.))
644 .py(px(8.))
645 .rounded(px(10.))
646 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
647 .text_color(theme::white())
648 .text_size(px(model.view.caption_size.text_size()))
649 .children(lines.into_iter().map(|line| {
650 let age = now.saturating_duration_since(line.at).as_secs_f32();
651 let fade = ((shown - age) / CAPTION_FADE_SECONDS).clamp(0., 1.);
652 h_flex()
653 .opacity(fade)
654 .gap(px(8.))
655 .items_start()
656 .child(
657 div()
658 .flex_none()
659 .font_weight(FontWeight::BOLD)
660 .child(format!("{}:", line.speaker)),
661 )
662 .child(div().flex_1().min_w_0().child(line.text.clone()))
663 })),
664 )
665 .into_any_element(),
666 )
667}
668
669fn focus_chip(label: &'static str, glyph: IconName, background: Hsla, foreground: Hsla) -> Div {
670 h_flex()
671 .h(px(CHIP_HEIGHT))
672 .px(px(8.))
673 .gap(px(4.))
674 .items_center()
675 .rounded_full()
676 .bg(background)
677 .text_color(foreground)
678 .text_size(px(12.))
679 .font_weight(FontWeight::SEMIBOLD)
680 .child(icon(glyph, 13., foreground))
681 .child(label)
682}
683
684pub fn spotlight_chip() -> Div {
685 focus_chip("Spotlight", IconName::Star, theme::amber(), dark_text())
686}
687
688pub fn pin_chip() -> Div {
689 focus_chip(
690 "Pinned",
691 IconName::Frame,
692 hsla(0., 0., 0., 0.6),
693 theme::white(),
694 )
695}
696
697pub fn render_focus_stage(
698 app: &Entity<AppState>,
699 state: &AppState,
700 focus: &Focus,
701 now: Instant,
702) -> Option<AnyElement> {
703 let call = state.call.as_ref()?;
704 let model = &call.model;
705 let me = state.directory.me.as_ref();
706 let (name, user_id, speaking, muted, key) = if focus.own {
707 (
708 "You".to_owned(),
709 me.map(|person| person.user_id.clone()),
710 model.local_speaking,
711 model.muted,
712 VideoKey::LocalCamera,
713 )
714 } else {
715 let tile = model.tiles.iter().find(|tile| tile.mri == focus.mri)?;
716 (
717 tile.name.clone(),
718 tile.user_id.clone(),
719 model.tile_speaking(tile),
720 tile.muted,
721 VideoKey::Person(tile.mri.clone()),
722 )
723 };
724 let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now);
725 let picture = match image {
726 Some(image) => img(ImageSource::Render(image))
727 .size_full()
728 .object_fit(ObjectFit::Contain)
729 .into_any_element(),
730 None => div()
731 .size_full()
732 .flex()
733 .items_center()
734 .justify_center()
735 .child(person_avatar(
736 &state.directory,
737 user_id.as_deref(),
738 &name,
739 FOCUS_AVATAR,
740 ))
741 .into_any_element(),
742 };
743 let stage = div()
744 .id("call-focus-stage")
745 .relative()
746 .flex_1()
747 .min_w_0()
748 .h_full()
749 .overflow_hidden()
750 .rounded(px(FOCUS_RADIUS))
751 .bg(hsla(0., 0., 0.04, 1.))
752 .border_2()
753 .border_color(if speaking {
754 theme::green()
755 } else {
756 transparent_black()
757 })
758 .child(picture)
759 .child(
760 h_flex()
761 .absolute()
762 .top(px(12.))
763 .left(px(12.))
764 .gap(px(6.))
765 .when(focus.spotlight, |chips| chips.child(spotlight_chip()))
766 .when(focus.pinned, |chips| chips.child(pin_chip())),
767 )
768 .child(
769 h_flex()
770 .absolute()
771 .left(px(12.))
772 .bottom(px(12.))
773 .gap(px(8.))
774 .px(px(8.))
775 .py(px(4.))
776 .rounded(px(6.))
777 .bg(hsla(0., 0., 0., 0.6))
778 .text_color(theme::white())
779 .text_size(px(13.))
780 .font_weight(FontWeight::SEMIBOLD)
781 .child(name.clone())
782 .when(muted, |plate| {
783 plate.child(icon(IconName::MicOff, 14., theme::red()))
784 }),
785 );
786 Some(attach_tile_menu(
787 stage, app, model, &focus.mri, &name, focus.own,
788 ))
789}
790
791pub fn captions_state_hint(model: &CallModel) -> Option<&'static str> {
792 match model.captions {
793 CaptionState::Starting => Some("Starting live captions..."),
794 CaptionState::Failed(_) => Some("Live captions could not start"),
795 CaptionState::On | CaptionState::Off => None,
796 }
797}
798
799pub fn captions_hint_chip(model: &CallModel) -> Option<AnyElement> {
800 let text = captions_state_hint(model)?;
801 Some(
802 div()
803 .id("call-captions-hint")
804 .absolute()
805 .left_0()
806 .right_0()
807 .bottom(px(CAPTION_BOTTOM))
808 .flex()
809 .justify_center()
810 .child(
811 div()
812 .px(px(12.))
813 .py(px(6.))
814 .rounded_full()
815 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
816 .text_color(theme::white())
817 .text_size(px(13.))
818 .child(text),
819 )
820 .into_any_element(),
821 )
822}