BlueGit

ict rusty-teams

Files

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

call_organizer.rs

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