BlueGit

ict rusty-teams

Files

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

call_organizer.rs

call_organizer.rs 27.1 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_items, transcript_and_settings_items};
20use super::call_toolbar::{split_chevron, tool_face, tool_trigger};
21use super::call_view::{BANNER_HEIGHT, MENU_WIDTH};
22use super::widgets::{Corner, corner_badge, count_badge, icon};
23use crate::app_state::AppState;
24use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus, contain_size};
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 = 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_BORDER: f32 = 2.;
39const FOCUS_AVATAR: f32 = 140.;
40const CHIP_HEIGHT: f32 = 24.;
41const MORE_SIZE: 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: impl Into<SharedString>, 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.into())
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 model.is_one_to_one()
253 || model
254 .tiles
255 .iter()
256 .any(|tile| tile.mri == mri && tile.has_video)
257 {
258 let (fit_app, fit_mri) = (app.clone(), mri.to_owned());
259 let fitted = model.is_fitted(mri);
260 popup = popup.item(
261 PopupMenuItem::new(if fitted { "Fill frame" } else { "Fit to frame" })
262 .icon(if fitted { IconName::Expand } else { IconName::Shrink })
263 .on_click(move |_, _, cx| {
264 fit_app.update(cx, |state, cx| state.toggle_call_fit(&fit_mri, cx))
265 }),
266 );
267 }
268 if organizes {
269 let (spotlight_app, spotlight_mri) = (app.clone(), mri.to_owned());
270 popup = popup.item(
271 PopupMenuItem::new(if spotlighted {
272 "Stop spotlight"
273 } else {
274 "Spotlight for everyone"
275 })
276 .icon(IconName::Star)
277 .on_click(move |_, _, cx| {
278 spotlight_app.update(cx, |state, cx| {
279 state.toggle_call_spotlight(spotlight_mri.clone(), cx)
280 })
281 }),
282 );
283 }
284 if organizes {
285 let (mute_app, mute_mri) = (app.clone(), mri.to_owned());
286 popup = popup.item(
287 PopupMenuItem::new("Mute")
288 .icon(IconName::MicOff)
289 .disabled(muted)
290 .on_click(move |_, _, cx| {
291 mute_app.update(cx, |state, cx| {
292 state.mute_call_participant(mute_mri.clone(), cx)
293 })
294 }),
295 );
296 }
297 if model.can_change_roles(mri) {
298 popup = restriction_items(popup, app, model, mri);
299 }
300 if organizes && raised {
301 let (hand_app, hand_mri) = (app.clone(), mri.to_owned());
302 popup = popup.item(PopupMenuItem::new("Lower hand").on_click(move |_, _, cx| {
303 hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))
304 }));
305 }
306 if organizes {
307 let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());
308 popup = popup.separator().item(
309 PopupMenuItem::new("Remove from meeting...")
310 .icon(IconName::Close)
311 .on_click(move |_, window, cx| {
312 confirm_remove(&remove_app, &remove_mri, &remove_name, window, cx)
313 }),
314 );
315 }
316 popup
317}
318
319fn modality_item(
320 app: &Entity<AppState>,
321 mri: &str,
322 modality: Modality,
323 allowed: bool,
324) -> PopupMenuItem {
325 let (app, mri) = (app.clone(), mri.to_owned());
326 let (label, glyph) = match (modality, allowed) {
327 (Modality::Mic, true) => ("Disable mic", IconName::MicOff),
328 (Modality::Mic, false) => ("Allow mic", IconName::Mic),
329 (Modality::Camera, true) => ("Disable camera", IconName::VideoOff),
330 (Modality::Camera, false) => ("Allow camera", IconName::Video),
331 };
332 PopupMenuItem::new(label).icon(glyph).on_click(move |_, _, cx| {
333 app.update(cx, |state, cx| {
334 state.set_call_attendee_modality(mri.clone(), modality, !allowed, cx)
335 })
336 })
337}
338
339fn restriction_items(
340 popup: PopupMenu,
341 app: &Entity<AppState>,
342 model: &CallModel,
343 mri: &str,
344) -> PopupMenu {
345 let presenter = model.tile_role(mri) == Some(MeetingRole::Presenter);
346 let (role_app, role_mri) = (app.clone(), mri.to_owned());
347 popup
348 .item(modality_item(app, mri, Modality::Mic, model.attendee_allowed(mri, Modality::Mic)))
349 .item(modality_item(app, mri, Modality::Camera, model.attendee_allowed(mri, Modality::Camera)))
350 .item(
351 PopupMenuItem::new(if presenter { "Make attendee" } else { "Make presenter" })
352 .icon(IconName::Users)
353 .on_click(move |_, _, cx| {
354 let role = if presenter { MeetingRole::Attendee } else { MeetingRole::Presenter };
355 role_app.update(cx, |state, cx| state.set_call_role(role_mri.clone(), role, cx))
356 }),
357 )
358}
359
360fn more_overlay(
361 app: &Entity<AppState>,
362 model: &CallModel,
363 mri: &str,
364 name: &str,
365 own: bool,
366 group: SharedString,
367) -> Div {
368 let (app, model, mri_owned, name) =
369 (app.clone(), model.clone(), mri.to_owned(), name.to_owned());
370 div()
371 .absolute()
372 .top(px(8.))
373 .right(px(8.))
374 .opacity(0.)
375 .group_hover(group, |more| more.opacity(1.))
376 .child(
377 Button::new(SharedString::from(format!("call-tile-more-{mri}")))
378 .icon(IconName::Ellipsis)
379 .ghost()
380 .xsmall()
381 .size(px(MORE_SIZE))
382 .rounded_full()
383 .bg(black().opacity(0.55))
384 .text_color(theme::white())
385 .tooltip("More")
386 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
387 tile_menu(popup, &app, &model, &mri_owned, &name, own)
388 }),
389 )
390}
391
392/// Adds the right-click menu and a "..." button that shows while the pointer is over the tile.
393pub fn attach_tile_menu(
394 tile: Stateful<Div>,
395 app: &Entity<AppState>,
396 model: &CallModel,
397 mri: &str,
398 name: &str,
399 own: bool,
400) -> AnyElement {
401 let group = SharedString::from(format!("call-tile-group-{mri}"));
402 let (context_app, context_model, context_mri, context_name) =
403 (app.clone(), model.clone(), mri.to_owned(), name.to_owned());
404 tile.group(group.clone())
405 .relative()
406 .child(more_overlay(app, model, mri, name, own, group))
407 .context_menu(move |popup, _, _| {
408 tile_menu(
409 popup,
410 &context_app,
411 &context_model,
412 &context_mri,
413 &context_name,
414 own,
415 )
416 })
417 .into_any_element()
418}
419
420pub fn with_tile_menu(
421 app: &Entity<AppState>,
422 model: &CallModel,
423 mri: &str,
424 name: &str,
425 own: bool,
426 tile: AnyElement,
427) -> AnyElement {
428 let wrapper = div()
429 .id(SharedString::from(format!("call-tile-{mri}")))
430 .flex_none()
431 .child(tile);
432 attach_tile_menu(wrapper, app, model, mri, name, own)
433}
434
435pub fn more_button(
436 app: &Entity<AppState>,
437 model: &CallModel,
438 folded: &FoldedControls,
439) -> Option<AnyElement> {
440 if !matches!(
441 model.kind,
442 crate::call::CallKind::Meeting | crate::call::CallKind::Direct | crate::call::CallKind::Group
443 ) {
444 return None;
445 }
446 let app = app.clone();
447 let model = model.clone();
448 let folded = folded.clone();
449 let unread = folded.chat_unread;
450 let chat_folded = folded.folds(Foldable::Chat);
451 Some(
452 tool_trigger(
453 "call-more",
454 tool_face("call-more-face", IconName::Ellipsis, "More", false)
455 .relative()
456 .when(chat_folded && unread > 0, |face| {
457 face.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
458 }),
459 )
460 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, window, cx| {
461 more_menu(popup, window, cx, &app, &model, &folded)
462 })
463 .into_any_element(),
464 )
465}
466
467fn more_menu(
468 popup: PopupMenu,
469 window: &mut Window,
470 cx: &mut Context<PopupMenu>,
471 app: &Entity<AppState>,
472 model: &CallModel,
473 folded: &FoldedControls,
474) -> PopupMenu {
475 let popup = folded_items(popup.min_w(px(MENU_WIDTH)), window, cx, app, model, folded);
476 let popup = match model.kind {
477 crate::call::CallKind::Meeting => meeting_items(popup, window, cx, app, model),
478 crate::call::CallKind::Direct => one_to_one_items(popup, window, cx, app, model),
479 _ => record_items(popup, window, cx, app, model),
480 };
481 incoming_video_item(popup, app, model)
482}
483
484fn incoming_video_item(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
485 if model.health.incoming_video {
486 return popup;
487 }
488 let app = app.clone();
489 popup.item(
490 PopupMenuItem::new("Turn on incoming video")
491 .icon(IconName::Video)
492 .on_click(move |_, _, cx| {
493 app.update(cx, |state, cx| state.set_call_incoming_video(true, cx))
494 }),
495 )
496}
497
498fn one_to_one_items(
499 mut popup: PopupMenu,
500 window: &mut Window,
501 cx: &mut Context<PopupMenu>,
502 app: &Entity<AppState>,
503 model: &CallModel,
504) -> PopupMenu {
505 let (hold_app, transfer_app) = (app.clone(), app.clone());
506 let held = model.hold == HoldState::Local;
507 popup = popup.item(
508 PopupMenuItem::new(if held { "Resume" } else { "Hold" })
509 .icon(IconName::Timer)
510 .disabled(!held && !model.can_hold())
511 .on_click(move |_, _, cx| hold_app.update(cx, |state, cx| state.toggle_call_hold(cx))),
512 );
513 popup = record_items(popup, window, cx, app, model);
514 let can_transfer = model.can_transfer();
515 popup.item(
516 PopupMenuItem::new("Transfer...")
517 .icon(IconName::Forward)
518 .disabled(!can_transfer)
519 .on_click(move |_, window, cx| open_transfer_picker(&transfer_app, window, cx)),
520 )
521}
522
523fn meeting_items(
524 mut popup: PopupMenu,
525 window: &mut Window,
526 cx: &mut Context<PopupMenu>,
527 app: &Entity<AppState>,
528 model: &CallModel,
529) -> PopupMenu {
530 let (mute_app, captions_app, board_app) = (app.clone(), app.clone(), app.clone());
531 let captions_on = model.captions_on();
532 if model.organizes_meeting() {
533 popup = popup.item(
534 PopupMenuItem::new("Mute all")
535 .icon(IconName::MicOff)
536 .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))),
537 );
538 }
539 popup = record_items(popup, window, cx, app, model);
540 if model.can_open_whiteboard() {
541 popup = popup.item(
542 PopupMenuItem::new("Whiteboard")
543 .icon(IconName::Frame)
544 .on_click(move |_, _, cx| {
545 board_app.update(cx, |state, cx| state.open_call_whiteboard(cx))
546 }),
547 );
548 }
549 let popup = popup.item(
550 PopupMenuItem::new(if captions_on {
551 "Turn off live captions"
552 } else {
553 "Turn on live captions"
554 })
555 .icon(if captions_on {
556 IconName::CaptionsOff
557 } else {
558 IconName::Captions
559 })
560 .on_click(move |_, _, cx| {
561 captions_app.update(cx, |state, cx| state.toggle_call_captions(cx))
562 }),
563 );
564 transcript_and_settings_items(popup, app)
565}
566
567pub fn camera_menu_button(
568 app: &Entity<AppState>,
569 model: &CallModel,
570 backgrounds: CameraMenu,
571) -> Option<AnyElement> {
572 if !model.can_use_camera() {
573 return None;
574 }
575 let app = app.clone();
576 let model = model.clone();
577 Some(
578 split_chevron("call-camera-menu", "call-camera-menu-face")
579 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
580 camera_menu(popup, &app, &model, &backgrounds)
581 })
582 .into_any_element(),
583 )
584}
585
586fn camera_menu(
587 popup: PopupMenu,
588 app: &Entity<AppState>,
589 model: &CallModel,
590 backgrounds: &CameraMenu,
591) -> PopupMenu {
592 let camera_app = app.clone();
593 let cameras = super::call_view::device_items(
594 calling::camera_entries(&model.cameras),
595 &model.camera,
596 move |choice, cx| {
597 camera_app.update(cx, |state, cx| state.select_call_camera(choice, cx));
598 },
599 );
600 let mut popup = popup
601 .min_w(px(MENU_WIDTH))
602 .item(PopupMenuItem::label("Camera"));
603 for item in cameras {
604 popup = popup.item(item);
605 }
606 background_items(
607 effect_items(popup, app, backgrounds.effects),
608 app,
609 backgrounds,
610 )
611}
612
613pub fn captions_overlay(model: &CallModel, now: Instant) -> Option<AnyElement> {
614 let lines = model.visible_captions(now);
615 if lines.is_empty() {
616 return None;
617 }
618 let shown = CAPTION_SHOWN.as_secs_f32();
619 Some(
620 div()
621 .id("call-captions")
622 .absolute()
623 .left_0()
624 .right_0()
625 .map(|overlay| match model.view.caption_position {
626 CaptionPosition::Bottom => overlay.bottom(px(CAPTION_BOTTOM)),
627 CaptionPosition::Top => overlay.top(px(CAPTION_TOP)),
628 })
629 .flex()
630 .justify_center()
631 .px(px(24.))
632 .child(
633 v_flex()
634 .w(px(CAPTION_WIDTH))
635 .max_w_full()
636 .gap(px(4.))
637 .px(px(16.))
638 .py(px(8.))
639 .rounded(px(10.))
640 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
641 .text_color(theme::white())
642 .text_size(px(model.view.caption_size.text_size()))
643 .children(lines.into_iter().map(|line| {
644 let age = now.saturating_duration_since(line.at).as_secs_f32();
645 let fade = ((shown - age) / CAPTION_FADE_SECONDS).clamp(0., 1.);
646 h_flex()
647 .opacity(fade)
648 .gap(px(8.))
649 .items_start()
650 .child(
651 div()
652 .flex_none()
653 .font_weight(FontWeight::BOLD)
654 .child(format!("{}:", line.speaker)),
655 )
656 .child(div().flex_1().min_w_0().child(line.text.clone()))
657 })),
658 )
659 .into_any_element(),
660 )
661}
662
663fn focus_chip(label: &'static str, glyph: IconName, background: Hsla, foreground: Hsla) -> Div {
664 h_flex()
665 .h(px(CHIP_HEIGHT))
666 .px(px(8.))
667 .gap(px(4.))
668 .items_center()
669 .rounded_full()
670 .bg(background)
671 .text_color(foreground)
672 .text_size(px(12.))
673 .font_weight(FontWeight::SEMIBOLD)
674 .child(icon(glyph, 13., foreground))
675 .child(label)
676}
677
678pub fn spotlight_chip() -> Div {
679 focus_chip("Spotlight", IconName::Star, theme::amber(), dark_text())
680}
681
682pub fn pin_chip() -> Div {
683 focus_chip(
684 "Pinned",
685 IconName::Frame,
686 hsla(0., 0., 0., 0.6),
687 theme::white(),
688 )
689}
690
691pub fn render_focus_stage(
692 app: &Entity<AppState>,
693 state: &AppState,
694 focus: &Focus,
695 size: (f32, f32),
696 now: Instant,
697) -> Option<AnyElement> {
698 let call = state.call.as_ref()?;
699 let model = &call.model;
700 let me = state.directory.me.as_ref();
701 let (name, user_id, speaking, muted, key) = if focus.own {
702 (
703 "You".to_owned(),
704 me.map(|person| person.user_id.clone()),
705 model.local_speaking,
706 model.muted,
707 VideoKey::LocalCamera,
708 )
709 } else {
710 let tile = model.tiles.iter().find(|tile| tile.mri == focus.mri)?;
711 (
712 tile.name.clone(),
713 tile.user_id.clone(),
714 model.tile_speaking(tile),
715 tile.muted,
716 VideoKey::Person(tile.mri.clone()),
717 )
718 };
719 let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now);
720 let avatar_only = image.is_none();
721 let (picture_size, picture) = match image {
722 Some(image) => {
723 let pixels = image.size(0);
724 let (width, height) = contain_size(size, (pixels.width.0 as f32, pixels.height.0 as f32));
725 let picture = img(ImageSource::Render(image))
726 .size_full()
727 .object_fit(ObjectFit::Fill)
728 .rounded(px(FOCUS_RADIUS))
729 .into_any_element();
730 ((width, height), picture)
731 }
732 None => (
733 contain_size(size, (16., 9.)),
734 div()
735 .size_full()
736 .flex()
737 .items_center()
738 .justify_center()
739 .child(person_avatar(
740 &state.directory,
741 user_id.as_deref(),
742 &name,
743 FOCUS_AVATAR,
744 ))
745 .into_any_element(),
746 ),
747 };
748 let stage = div()
749 .id("call-focus-stage")
750 .relative()
751 .w(px(picture_size.0))
752 .h(px(picture_size.1))
753 .flex_none()
754 .overflow_hidden()
755 .rounded(px(FOCUS_RADIUS))
756 .when(avatar_only, |stage| stage.bg(hsla(0., 0., 0.04, 1.)))
757 .border(px(FOCUS_BORDER))
758 .border_color(if speaking {
759 theme::green()
760 } else {
761 transparent_black()
762 })
763 .child(picture)
764 .child(
765 h_flex()
766 .absolute()
767 .top(px(12.))
768 .left(px(12.))
769 .gap(px(6.))
770 .when(focus.spotlight, |chips| chips.child(spotlight_chip()))
771 .when(focus.pinned, |chips| chips.child(pin_chip())),
772 )
773 .child(
774 h_flex()
775 .absolute()
776 .left(px(8.))
777 .bottom(px(8.))
778 .gap(px(8.))
779 .px(px(8.))
780 .py(px(4.))
781 .rounded(px(6.))
782 .bg(hsla(0., 0., 0., 0.6))
783 .text_color(theme::white())
784 .text_size(px(13.))
785 .font_weight(FontWeight::SEMIBOLD)
786 .child(name.clone())
787 .when(muted, |plate| {
788 plate.child(icon(IconName::MicOff, 14., theme::red()))
789 }),
790 );
791 let stage = attach_tile_menu(stage, app, model, &focus.mri, &name, focus.own);
792 Some(
793 div()
794 .w(px(size.0))
795 .h(px(size.1))
796 .flex_none()
797 .flex()
798 .items_center()
799 .justify_center()
800 .child(stage)
801 .into_any_element(),
802 )
803}
804
805pub fn captions_state_hint(model: &CallModel) -> Option<&'static str> {
806 match model.captions {
807 CaptionState::Starting => Some("Starting live captions..."),
808 CaptionState::Failed(_) => Some("Live captions could not start"),
809 CaptionState::On | CaptionState::Off => None,
810 }
811}
812
813pub fn captions_hint_chip(model: &CallModel) -> Option<AnyElement> {
814 let text = captions_state_hint(model)?;
815 Some(
816 div()
817 .id("call-captions-hint")
818 .absolute()
819 .left_0()
820 .right_0()
821 .bottom(px(CAPTION_BOTTOM))
822 .flex()
823 .justify_center()
824 .child(
825 div()
826 .px(px(12.))
827 .py(px(6.))
828 .rounded_full()
829 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
830 .text_color(theme::white())
831 .text_size(px(13.))
832 .child(text),
833 )
834 .into_any_element(),
835 )
836}