BlueGit

ict rusty-teams

Files

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

call_organizer.rs

call_organizer.rs 27.3 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_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 if !matches!(
425 model.kind,
426 crate::call::CallKind::Meeting | crate::call::CallKind::Direct | crate::call::CallKind::Group
427 ) {
428 return None;
429 }
430 let app = app.clone();
431 let model = model.clone();
432 let folded = folded.clone();
433 let unread = folded.chat_unread;
434 let chat_folded = folded.folds(Foldable::Chat);
435 Some(
436 Button::new("call-more")
437 .ghost()
438 .p_0()
439 .size(px(CONTROL_SIZE))
440 .rounded_full()
441 .child(
442 round_control(
443 "call-more-face",
444 IconName::Ellipsis,
445 theme::surface_raised(),
446 theme::text(),
447 )
448 .relative()
449 .when(chat_folded && unread > 0, |face| {
450 face.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
451 }),
452 )
453 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, window, cx| {
454 more_menu(popup, window, cx, &app, &model, &folded)
455 })
456 .into_any_element(),
457 )
458}
459
460fn more_menu(
461 popup: PopupMenu,
462 window: &mut Window,
463 cx: &mut Context<PopupMenu>,
464 app: &Entity<AppState>,
465 model: &CallModel,
466 folded: &FoldedControls,
467) -> PopupMenu {
468 let popup = folded_items(popup.min_w(px(MENU_WIDTH)), window, cx, app, model, folded);
469 let popup = match model.kind {
470 crate::call::CallKind::Meeting => meeting_items(popup, window, cx, app, model),
471 crate::call::CallKind::Direct => one_to_one_items(popup, window, cx, app, model),
472 _ => record_items(popup, window, cx, app, model),
473 };
474 incoming_video_item(popup, app, model)
475}
476
477fn incoming_video_item(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
478 if model.health.incoming_video {
479 return popup;
480 }
481 let app = app.clone();
482 popup.item(
483 PopupMenuItem::new("Turn on incoming video")
484 .icon(IconName::Video)
485 .on_click(move |_, _, cx| {
486 app.update(cx, |state, cx| state.set_call_incoming_video(true, cx))
487 }),
488 )
489}
490
491fn one_to_one_items(
492 mut popup: PopupMenu,
493 window: &mut Window,
494 cx: &mut Context<PopupMenu>,
495 app: &Entity<AppState>,
496 model: &CallModel,
497) -> PopupMenu {
498 let (hold_app, transfer_app) = (app.clone(), app.clone());
499 let held = model.hold == HoldState::Local;
500 popup = popup.item(
501 PopupMenuItem::new(if held { "Resume" } else { "Hold" })
502 .icon(IconName::Timer)
503 .disabled(!held && !model.can_hold())
504 .on_click(move |_, _, cx| hold_app.update(cx, |state, cx| state.toggle_call_hold(cx))),
505 );
506 popup = record_items(popup, window, cx, app, model);
507 let can_transfer = model.can_transfer();
508 popup.item(
509 PopupMenuItem::new("Transfer...")
510 .icon(IconName::Forward)
511 .disabled(!can_transfer)
512 .on_click(move |_, window, cx| open_transfer_picker(&transfer_app, window, cx)),
513 )
514}
515
516fn meeting_items(
517 mut popup: PopupMenu,
518 window: &mut Window,
519 cx: &mut Context<PopupMenu>,
520 app: &Entity<AppState>,
521 model: &CallModel,
522) -> PopupMenu {
523 let (mute_app, captions_app, board_app) = (app.clone(), app.clone(), app.clone());
524 let captions_on = model.captions_on();
525 if model.organizes_meeting() {
526 popup = popup.item(
527 PopupMenuItem::new("Mute all")
528 .icon(IconName::MicOff)
529 .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))),
530 );
531 }
532 popup = record_items(popup, window, cx, app, model);
533 if model.can_open_whiteboard() {
534 popup = popup.item(
535 PopupMenuItem::new("Whiteboard")
536 .icon(IconName::Frame)
537 .on_click(move |_, _, cx| {
538 board_app.update(cx, |state, cx| state.open_call_whiteboard(cx))
539 }),
540 );
541 }
542 let popup = popup.item(
543 PopupMenuItem::new(if captions_on {
544 "Turn off live captions"
545 } else {
546 "Turn on live captions"
547 })
548 .icon(if captions_on {
549 IconName::CaptionsOff
550 } else {
551 IconName::Captions
552 })
553 .on_click(move |_, _, cx| {
554 captions_app.update(cx, |state, cx| state.toggle_call_captions(cx))
555 }),
556 );
557 transcript_and_settings_items(popup, app)
558}
559
560pub fn chevron_button(button_id: &'static str, face_id: &'static str) -> Button {
561 Button::new(button_id)
562 .ghost()
563 .p_0()
564 .w(px(CAMERA_MENU_WIDTH))
565 .h(px(super::call_view::CONTROL_SIZE))
566 .rounded_full()
567 .child(
568 div()
569 .id(face_id)
570 .w(px(CAMERA_MENU_WIDTH))
571 .h(px(super::call_view::CONTROL_SIZE))
572 .flex()
573 .items_center()
574 .justify_center()
575 .child(icon(IconName::ChevronUp, 16., theme::text())),
576 )
577}
578
579pub fn camera_menu_button(
580 app: &Entity<AppState>,
581 model: &CallModel,
582 backgrounds: CameraMenu,
583) -> Option<AnyElement> {
584 if !model.can_use_camera() {
585 return None;
586 }
587 let app = app.clone();
588 let model = model.clone();
589 Some(
590 chevron_button("call-camera-menu", "call-camera-menu-face")
591 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
592 camera_menu(popup, &app, &model, &backgrounds)
593 })
594 .into_any_element(),
595 )
596}
597
598fn camera_menu(
599 popup: PopupMenu,
600 app: &Entity<AppState>,
601 model: &CallModel,
602 backgrounds: &CameraMenu,
603) -> PopupMenu {
604 let camera_app = app.clone();
605 let cameras = super::call_view::device_items(
606 calling::camera_entries(&model.cameras),
607 &model.camera,
608 move |choice, cx| {
609 camera_app.update(cx, |state, cx| state.select_call_camera(choice, cx));
610 },
611 );
612 let mut popup = popup
613 .min_w(px(MENU_WIDTH))
614 .item(PopupMenuItem::label("Camera"));
615 for item in cameras {
616 popup = popup.item(item);
617 }
618 background_items(
619 effect_items(popup, app, backgrounds.effects),
620 app,
621 backgrounds,
622 )
623}
624
625pub fn captions_overlay(model: &CallModel, now: Instant) -> Option<AnyElement> {
626 let lines = model.visible_captions(now);
627 if lines.is_empty() {
628 return None;
629 }
630 let shown = CAPTION_SHOWN.as_secs_f32();
631 Some(
632 div()
633 .id("call-captions")
634 .absolute()
635 .left_0()
636 .right_0()
637 .map(|overlay| match model.view.caption_position {
638 CaptionPosition::Bottom => overlay.bottom(px(CAPTION_BOTTOM)),
639 CaptionPosition::Top => overlay.top(px(CAPTION_TOP)),
640 })
641 .flex()
642 .justify_center()
643 .px(px(24.))
644 .child(
645 v_flex()
646 .w(px(CAPTION_WIDTH))
647 .max_w_full()
648 .gap(px(4.))
649 .px(px(16.))
650 .py(px(8.))
651 .rounded(px(10.))
652 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
653 .text_color(theme::white())
654 .text_size(px(model.view.caption_size.text_size()))
655 .children(lines.into_iter().map(|line| {
656 let age = now.saturating_duration_since(line.at).as_secs_f32();
657 let fade = ((shown - age) / CAPTION_FADE_SECONDS).clamp(0., 1.);
658 h_flex()
659 .opacity(fade)
660 .gap(px(8.))
661 .items_start()
662 .child(
663 div()
664 .flex_none()
665 .font_weight(FontWeight::BOLD)
666 .child(format!("{}:", line.speaker)),
667 )
668 .child(div().flex_1().min_w_0().child(line.text.clone()))
669 })),
670 )
671 .into_any_element(),
672 )
673}
674
675fn focus_chip(label: &'static str, glyph: IconName, background: Hsla, foreground: Hsla) -> Div {
676 h_flex()
677 .h(px(CHIP_HEIGHT))
678 .px(px(8.))
679 .gap(px(4.))
680 .items_center()
681 .rounded_full()
682 .bg(background)
683 .text_color(foreground)
684 .text_size(px(12.))
685 .font_weight(FontWeight::SEMIBOLD)
686 .child(icon(glyph, 13., foreground))
687 .child(label)
688}
689
690pub fn spotlight_chip() -> Div {
691 focus_chip("Spotlight", IconName::Star, theme::amber(), dark_text())
692}
693
694pub fn pin_chip() -> Div {
695 focus_chip(
696 "Pinned",
697 IconName::Frame,
698 hsla(0., 0., 0., 0.6),
699 theme::white(),
700 )
701}
702
703pub fn render_focus_stage(
704 app: &Entity<AppState>,
705 state: &AppState,
706 focus: &Focus,
707 size: (f32, f32),
708 now: Instant,
709) -> Option<AnyElement> {
710 let call = state.call.as_ref()?;
711 let model = &call.model;
712 let me = state.directory.me.as_ref();
713 let (name, user_id, speaking, muted, key) = if focus.own {
714 (
715 "You".to_owned(),
716 me.map(|person| person.user_id.clone()),
717 model.local_speaking,
718 model.muted,
719 VideoKey::LocalCamera,
720 )
721 } else {
722 let tile = model.tiles.iter().find(|tile| tile.mri == focus.mri)?;
723 (
724 tile.name.clone(),
725 tile.user_id.clone(),
726 model.tile_speaking(tile),
727 tile.muted,
728 VideoKey::Person(tile.mri.clone()),
729 )
730 };
731 let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now);
732 let avatar_only = image.is_none();
733 let (picture_size, picture) = match image {
734 Some(image) => {
735 let pixels = image.size(0);
736 let (width, height) = contain_size(size, (pixels.width.0 as f32, pixels.height.0 as f32));
737 let picture = img(ImageSource::Render(image))
738 .size_full()
739 .object_fit(ObjectFit::Fill)
740 .rounded(px(FOCUS_RADIUS))
741 .into_any_element();
742 ((width, height), picture)
743 }
744 None => (
745 contain_size(size, (16., 9.)),
746 div()
747 .size_full()
748 .flex()
749 .items_center()
750 .justify_center()
751 .child(person_avatar(
752 &state.directory,
753 user_id.as_deref(),
754 &name,
755 FOCUS_AVATAR,
756 ))
757 .into_any_element(),
758 ),
759 };
760 let stage = div()
761 .id("call-focus-stage")
762 .relative()
763 .w(px(picture_size.0))
764 .h(px(picture_size.1))
765 .flex_none()
766 .overflow_hidden()
767 .rounded(px(FOCUS_RADIUS))
768 .when(avatar_only, |stage| stage.bg(hsla(0., 0., 0.04, 1.)))
769 .border(px(FOCUS_BORDER))
770 .border_color(if speaking {
771 theme::green()
772 } else {
773 transparent_black()
774 })
775 .child(picture)
776 .child(
777 h_flex()
778 .absolute()
779 .top(px(12.))
780 .left(px(12.))
781 .gap(px(6.))
782 .when(focus.spotlight, |chips| chips.child(spotlight_chip()))
783 .when(focus.pinned, |chips| chips.child(pin_chip())),
784 )
785 .child(
786 h_flex()
787 .absolute()
788 .left(px(8.))
789 .bottom(px(8.))
790 .gap(px(8.))
791 .px(px(8.))
792 .py(px(4.))
793 .rounded(px(6.))
794 .bg(hsla(0., 0., 0., 0.6))
795 .text_color(theme::white())
796 .text_size(px(13.))
797 .font_weight(FontWeight::SEMIBOLD)
798 .child(name.clone())
799 .when(muted, |plate| {
800 plate.child(icon(IconName::MicOff, 14., theme::red()))
801 }),
802 );
803 let stage = attach_tile_menu(stage, app, model, &focus.mri, &name, focus.own);
804 Some(
805 div()
806 .w(px(size.0))
807 .h(px(size.1))
808 .flex_none()
809 .flex()
810 .items_center()
811 .justify_center()
812 .child(stage)
813 .into_any_element(),
814 )
815}
816
817pub fn captions_state_hint(model: &CallModel) -> Option<&'static str> {
818 match model.captions {
819 CaptionState::Starting => Some("Starting live captions..."),
820 CaptionState::Failed(_) => Some("Live captions could not start"),
821 CaptionState::On | CaptionState::Off => None,
822 }
823}
824
825pub fn captions_hint_chip(model: &CallModel) -> Option<AnyElement> {
826 let text = captions_state_hint(model)?;
827 Some(
828 div()
829 .id("call-captions-hint")
830 .absolute()
831 .left_0()
832 .right_0()
833 .bottom(px(CAPTION_BOTTOM))
834 .flex()
835 .justify_center()
836 .child(
837 div()
838 .px(px(12.))
839 .py(px(6.))
840 .rounded_full()
841 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
842 .text_color(theme::white())
843 .text_size(px(13.))
844 .child(text),
845 )
846 .into_any_element(),
847 )
848}