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_submenu, transcript_and_settings_items};
20use super::call_view::{BANNER_HEIGHT, CONTROL_SIZE, MENU_WIDTH, round_control};
21use super::widgets::{Corner, corner_badge, count_badge, icon};
22use crate::app_state::AppState;
23use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus, contain_size};
24use crate::notice::truncated;
25use crate::theme;
26
27const BANNER_TEXT: f32 = 13.;
28const PILL_HEIGHT: f32 = 26.;
29const LOBBY_LIST_WIDTH: f32 = 340.;
30const LOBBY_NAME_LIMIT: usize = 28;
31const CAPTION_WIDTH: f32 = 720.;
32const CAPTION_BOTTOM: f32 = 2. * 16. + CONTROL_SIZE + 16.;
33const CAPTION_TOP: f32 = 72.;
34const CAPTION_FADE_SECONDS: f32 = 1.;
35const CAPTION_BACKGROUND: f32 = 0.72;
36const FOCUS_RADIUS: f32 = 12.;
37const FOCUS_BORDER: f32 = 2.;
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: 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 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(8.))
357 .right(px(8.))
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.item(
500 PopupMenuItem::new("Transfer...")
501 .icon(IconName::Forward)
502 .disabled(!can_transfer)
503 .on_click(move |_, window, cx| open_transfer_picker(&transfer_app, window, cx)),
504 )
505}
506
507fn meeting_items(
508 mut popup: PopupMenu,
509 window: &mut Window,
510 cx: &mut Context<PopupMenu>,
511 app: &Entity<AppState>,
512 model: &CallModel,
513) -> PopupMenu {
514 let (mute_app, captions_app, board_app) = (app.clone(), app.clone(), app.clone());
515 let captions_on = model.captions_on();
516 if model.organizes_meeting() {
517 popup = popup.item(
518 PopupMenuItem::new("Mute all")
519 .icon(IconName::MicOff)
520 .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))),
521 );
522 }
523 if model.can_record() {
524 popup = record_submenu(popup, window, cx, app, model);
525 }
526 if model.can_open_whiteboard() {
527 popup = popup.item(
528 PopupMenuItem::new("Whiteboard")
529 .icon(IconName::Frame)
530 .on_click(move |_, _, cx| {
531 board_app.update(cx, |state, cx| state.open_call_whiteboard(cx))
532 }),
533 );
534 }
535 let popup = popup.item(
536 PopupMenuItem::new(if captions_on {
537 "Turn off live captions"
538 } else {
539 "Turn on live captions"
540 })
541 .icon(if captions_on {
542 IconName::CaptionsOff
543 } else {
544 IconName::Captions
545 })
546 .on_click(move |_, _, cx| {
547 captions_app.update(cx, |state, cx| state.toggle_call_captions(cx))
548 }),
549 );
550 transcript_and_settings_items(popup, app)
551}
552
553pub fn chevron_button(button_id: &'static str, face_id: &'static str) -> Button {
554 Button::new(button_id)
555 .ghost()
556 .p_0()
557 .w(px(CAMERA_MENU_WIDTH))
558 .h(px(super::call_view::CONTROL_SIZE))
559 .rounded_full()
560 .child(
561 div()
562 .id(face_id)
563 .w(px(CAMERA_MENU_WIDTH))
564 .h(px(super::call_view::CONTROL_SIZE))
565 .flex()
566 .items_center()
567 .justify_center()
568 .child(icon(IconName::ChevronUp, 16., theme::text())),
569 )
570}
571
572pub fn camera_menu_button(
573 app: &Entity<AppState>,
574 model: &CallModel,
575 backgrounds: CameraMenu,
576) -> Option<AnyElement> {
577 if !model.can_use_camera() {
578 return None;
579 }
580 let app = app.clone();
581 let model = model.clone();
582 Some(
583 chevron_button("call-camera-menu", "call-camera-menu-face")
584 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
585 camera_menu(popup, &app, &model, &backgrounds)
586 })
587 .into_any_element(),
588 )
589}
590
591fn camera_menu(
592 popup: PopupMenu,
593 app: &Entity<AppState>,
594 model: &CallModel,
595 backgrounds: &CameraMenu,
596) -> PopupMenu {
597 let camera_app = app.clone();
598 let cameras = super::call_view::device_items(
599 calling::camera_entries(&model.cameras),
600 &model.camera,
601 move |choice, cx| {
602 camera_app.update(cx, |state, cx| state.select_call_camera(choice, cx));
603 },
604 );
605 let mut popup = popup
606 .min_w(px(MENU_WIDTH))
607 .item(PopupMenuItem::label("Camera"));
608 for item in cameras {
609 popup = popup.item(item);
610 }
611 background_items(
612 effect_items(popup, app, backgrounds.effects),
613 app,
614 backgrounds,
615 )
616}
617
618pub fn captions_overlay(model: &CallModel, now: Instant) -> Option<AnyElement> {
619 let lines = model.visible_captions(now);
620 if lines.is_empty() {
621 return None;
622 }
623 let shown = CAPTION_SHOWN.as_secs_f32();
624 Some(
625 div()
626 .id("call-captions")
627 .absolute()
628 .left_0()
629 .right_0()
630 .map(|overlay| match model.view.caption_position {
631 CaptionPosition::Bottom => overlay.bottom(px(CAPTION_BOTTOM)),
632 CaptionPosition::Top => overlay.top(px(CAPTION_TOP)),
633 })
634 .flex()
635 .justify_center()
636 .px(px(24.))
637 .child(
638 v_flex()
639 .w(px(CAPTION_WIDTH))
640 .max_w_full()
641 .gap(px(4.))
642 .px(px(16.))
643 .py(px(8.))
644 .rounded(px(10.))
645 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
646 .text_color(theme::white())
647 .text_size(px(model.view.caption_size.text_size()))
648 .children(lines.into_iter().map(|line| {
649 let age = now.saturating_duration_since(line.at).as_secs_f32();
650 let fade = ((shown - age) / CAPTION_FADE_SECONDS).clamp(0., 1.);
651 h_flex()
652 .opacity(fade)
653 .gap(px(8.))
654 .items_start()
655 .child(
656 div()
657 .flex_none()
658 .font_weight(FontWeight::BOLD)
659 .child(format!("{}:", line.speaker)),
660 )
661 .child(div().flex_1().min_w_0().child(line.text.clone()))
662 })),
663 )
664 .into_any_element(),
665 )
666}
667
668fn focus_chip(label: &'static str, glyph: IconName, background: Hsla, foreground: Hsla) -> Div {
669 h_flex()
670 .h(px(CHIP_HEIGHT))
671 .px(px(8.))
672 .gap(px(4.))
673 .items_center()
674 .rounded_full()
675 .bg(background)
676 .text_color(foreground)
677 .text_size(px(12.))
678 .font_weight(FontWeight::SEMIBOLD)
679 .child(icon(glyph, 13., foreground))
680 .child(label)
681}
682
683pub fn spotlight_chip() -> Div {
684 focus_chip("Spotlight", IconName::Star, theme::amber(), dark_text())
685}
686
687pub fn pin_chip() -> Div {
688 focus_chip(
689 "Pinned",
690 IconName::Frame,
691 hsla(0., 0., 0., 0.6),
692 theme::white(),
693 )
694}
695
696pub fn render_focus_stage(
697 app: &Entity<AppState>,
698 state: &AppState,
699 focus: &Focus,
700 size: (f32, f32),
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 avatar_only = image.is_none();
726 let (picture_size, picture) = match image {
727 Some(image) => {
728 let pixels = image.size(0);
729 let (width, height) = contain_size(size, (pixels.width.0 as f32, pixels.height.0 as f32));
730 let picture = img(ImageSource::Render(image))
731 .size_full()
732 .object_fit(ObjectFit::Fill)
733 .rounded(px(FOCUS_RADIUS))
734 .into_any_element();
735 ((width, height), picture)
736 }
737 None => (
738 contain_size(size, (16., 9.)),
739 div()
740 .size_full()
741 .flex()
742 .items_center()
743 .justify_center()
744 .child(person_avatar(
745 &state.directory,
746 user_id.as_deref(),
747 &name,
748 FOCUS_AVATAR,
749 ))
750 .into_any_element(),
751 ),
752 };
753 let stage = div()
754 .id("call-focus-stage")
755 .relative()
756 .w(px(picture_size.0))
757 .h(px(picture_size.1))
758 .flex_none()
759 .overflow_hidden()
760 .rounded(px(FOCUS_RADIUS))
761 .when(avatar_only, |stage| stage.bg(hsla(0., 0., 0.04, 1.)))
762 .border(px(FOCUS_BORDER))
763 .border_color(if speaking {
764 theme::green()
765 } else {
766 transparent_black()
767 })
768 .child(picture)
769 .child(
770 h_flex()
771 .absolute()
772 .top(px(12.))
773 .left(px(12.))
774 .gap(px(6.))
775 .when(focus.spotlight, |chips| chips.child(spotlight_chip()))
776 .when(focus.pinned, |chips| chips.child(pin_chip())),
777 )
778 .child(
779 h_flex()
780 .absolute()
781 .left(px(8.))
782 .bottom(px(8.))
783 .gap(px(8.))
784 .px(px(8.))
785 .py(px(4.))
786 .rounded(px(6.))
787 .bg(hsla(0., 0., 0., 0.6))
788 .text_color(theme::white())
789 .text_size(px(13.))
790 .font_weight(FontWeight::SEMIBOLD)
791 .child(name.clone())
792 .when(muted, |plate| {
793 plate.child(icon(IconName::MicOff, 14., theme::red()))
794 }),
795 );
796 let stage = attach_tile_menu(stage, app, model, &focus.mri, &name, focus.own);
797 Some(
798 div()
799 .w(px(size.0))
800 .h(px(size.1))
801 .flex_none()
802 .flex()
803 .items_center()
804 .justify_center()
805 .child(stage)
806 .into_any_element(),
807 )
808}
809
810pub fn captions_state_hint(model: &CallModel) -> Option<&'static str> {
811 match model.captions {
812 CaptionState::Starting => Some("Starting live captions..."),
813 CaptionState::Failed(_) => Some("Live captions could not start"),
814 CaptionState::On | CaptionState::Off => None,
815 }
816}
817
818pub fn captions_hint_chip(model: &CallModel) -> Option<AnyElement> {
819 let text = captions_state_hint(model)?;
820 Some(
821 div()
822 .id("call-captions-hint")
823 .absolute()
824 .left_0()
825 .right_0()
826 .bottom(px(CAPTION_BOTTOM))
827 .flex()
828 .justify_center()
829 .child(
830 div()
831 .px(px(12.))
832 .py(px(6.))
833 .rounded_full()
834 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
835 .text_color(theme::white())
836 .text_size(px(13.))
837 .child(text),
838 )
839 .into_any_element(),
840 )
841}