BlueGit

ict rusty-teams

Files

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

call_view.rs

call_view.rs 37.3 KiB Download Raw
1use std::sync::Arc;
2use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
3
4use calling::{DeviceEntry, Reaction, VideoKey};
5use gpui_kit::assets::IconName;
6use gpui_kit::component::{
7 button::{Button, ButtonVariants as _},
8 h_flex,
9 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
10 popover::Popover,
11 switch::Switch,
12 tooltip::Tooltip,
13 v_flex,
14};
15use gpui_kit::prelude::FluentBuilder as _;
16use gpui_kit::*;
17
18use super::avatar::person_avatar;
19use super::call_extras::{
20 BackgroundMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button,
21 room_chip, whiteboard_stage,
22};
23use super::call_organizer::{
24 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
25 more_button, pin_chip, render_focus_stage, spotlight_chip, with_tile_menu,
26};
27use super::call_stage::render_stage;
28use super::conversation::ConversationView;
29use super::shell::ISLAND_GAP;
30use super::widgets::{Corner, corner_badge, count_badge, icon};
31use crate::app_state::AppState;
32use crate::call::REACTION_SHOWN;
33use crate::call::TileSize;
34use crate::call::{
35 CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
36 tile_size,
37};
38use crate::rows::reaction_glyph as chat_reaction_glyph;
39use crate::theme;
40
41const HEADER_HEIGHT: f32 = 60.;
42const RING_WIDTH: f32 = 3.;
43const RING_GAP: f32 = 4.;
44pub(super) const CONTROL_SIZE: f32 = 44.;
45const CONTROL_ICON: f32 = 20.;
46pub(super) const MENU_WIDTH: f32 = 280.;
47const PULSE_PERIOD: Duration = Duration::from_millis(1400);
48const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
49const BLINK_DIMMED_OPACITY: f32 = 0.45;
50const DISABLED_OPACITY: f32 = 0.4;
51const TILE_GAP: f32 = 20.;
52const GRID_PADDING: f32 = 24.;
53const STRIP_TILE: TileSize = TileSize {
54 width: 232.,
55 height: 131.,
56 avatar: 56.,
57};
58const STRIP_GAP: f32 = 12.;
59const STRIP_VISIBLE: f32 = 4.;
60const TILE_RADIUS: f32 = 12.;
61const NAME_PLATE_BACKGROUND: f32 = 0.6;
62pub const NO_MICROPHONE_HINT: &str = "No microphone found";
63const AUDIO_OFF_HINT: &str = "Audio is off for this meeting";
64pub const NO_CAMERA_HINT: &str = "No camera found";
65pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";
66pub const NO_WINDOWS_HINT: &str = "No windows found";
67pub(super) const BANNER_HEIGHT: f32 = 40.;
68const MAX_WINDOW_ITEMS: usize = 12;
69pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
70pub const CHAT_PANEL_WIDTH: f32 = 320.;
71const CHAT_HEADER_HEIGHT: f32 = 48.;
72const REACTION_RISE: f32 = 24.;
73const REACTION_FADE_FROM: f32 = 0.75;
74const REACTION_CELL: f32 = 40.;
75const SHARE_SOUND_LABEL: &str = "Include computer sound";
76
77pub fn reaction_glyph(reaction: Reaction) -> String {
78 match reaction {
79 Reaction::Applause => "\u{1F44F}".to_owned(),
80 other => chat_reaction_glyph(other.name()),
81 }
82}
83
84#[derive(Default)]
85struct TileExtras {
86 hand: Option<usize>,
87 own: bool,
88 reaction: Option<(Reaction, u64)>,
89 spotlight: bool,
90 pinned: bool,
91}
92
93fn hand_badge(position: usize, own: bool) -> Div {
94 h_flex()
95 .h(px(24.))
96 .px(px(8.))
97 .gap(px(4.))
98 .items_center()
99 .rounded_full()
100 .bg(theme::amber())
101 .text_color(hsla(0., 0., 0.08, 1.))
102 .text_size(px(12.))
103 .font_weight(FontWeight::SEMIBOLD)
104 .child(if own {
105 "Hand raised".to_owned()
106 } else {
107 format!("Hand {position}")
108 })
109}
110
111fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {
112 div()
113 .absolute()
114 .right(px(12.))
115 .bottom(px(32.))
116 .size(px(36.))
117 .flex()
118 .items_center()
119 .justify_center()
120 .rounded_full()
121 .bg(theme::popup())
122 .text_size(px(20.))
123 .child(reaction_glyph(reaction))
124 .with_animation(
125 ("call-reaction", serial as usize),
126 Animation::new(REACTION_SHOWN),
127 |chip, delta| {
128 let fade = ((delta - REACTION_FADE_FROM) / (1. - REACTION_FADE_FROM)).clamp(0., 1.);
129 chip.bottom(px(32. + REACTION_RISE * delta))
130 .opacity(1. - fade)
131 },
132 )
133 .into_any_element()
134}
135
136fn tile_overlays(extras: &TileExtras) -> Vec<AnyElement> {
137 let badges = (extras.hand.is_some() || extras.spotlight || extras.pinned).then(|| {
138 h_flex()
139 .absolute()
140 .top(px(8.))
141 .left(px(8.))
142 .gap(px(6.))
143 .children(extras.hand.map(|position| hand_badge(position, extras.own)))
144 .when(extras.spotlight, |row| row.child(spotlight_chip()))
145 .when(extras.pinned, |row| row.child(pin_chip()))
146 .into_any_element()
147 });
148 let reaction = extras
149 .reaction
150 .map(|(reaction, serial)| reaction_chip(reaction, serial));
151 badges.into_iter().chain(reaction).collect()
152}
153
154pub fn status_line(model: &CallModel, now: Instant) -> (String, Hsla) {
155 if model.lobby {
156 (LOBBY_TEXT.to_owned(), theme::amber())
157 } else if model.is_connecting() {
158 (model.connecting_text().to_owned(), theme::text_muted())
159 } else if model.is_reconnecting() {
160 ("Reconnecting...".to_owned(), theme::amber())
161 } else {
162 (model.timer_text(now), theme::text_muted())
163 }
164}
165
166pub fn pulsing(element: impl IntoElement + 'static, id: &'static str) -> AnyElement {
167 div()
168 .child(element)
169 .with_animation(
170 id,
171 Animation::new(PULSE_PERIOD).repeat(),
172 |element, delta| {
173 let wave = 1. - (delta * 2. - 1.).abs();
174 element.opacity(0.45 + 0.55 * wave)
175 },
176 )
177 .into_any_element()
178}
179
180fn blinking(element: impl IntoElement + 'static) -> AnyElement {
181 let dimmed = SystemTime::now()
182 .duration_since(UNIX_EPOCH)
183 .is_ok_and(|elapsed| (elapsed.as_millis() / BLINK_HALF_PERIOD.as_millis()) % 2 == 1);
184 div()
185 .child(element)
186 .opacity(if dimmed { BLINK_DIMMED_OPACITY } else { 1. })
187 .into_any_element()
188}
189
190fn speaking_ring(avatar: AnyElement, speaking: bool) -> Div {
191 div()
192 .p(px(RING_GAP))
193 .rounded_full()
194 .border(px(RING_WIDTH))
195 .border_color(if speaking {
196 theme::green()
197 } else {
198 transparent_black()
199 })
200 .child(avatar)
201}
202
203fn mute_badge() -> Div {
204 div()
205 .absolute()
206 .top(px(8.))
207 .right(px(8.))
208 .size(px(24.))
209 .flex()
210 .items_center()
211 .justify_center()
212 .rounded_full()
213 .bg(theme::red())
214 .child(icon(IconName::MicOff, 13., theme::white()))
215}
216
217fn video_tile(
218 size: TileSize,
219 image: Arc<RenderImage>,
220 name: &str,
221 speaking: bool,
222 muted: bool,
223 extras: &TileExtras,
224) -> Div {
225 div()
226 .relative()
227 .w(px(size.width))
228 .h(px(size.height))
229 .flex_none()
230 .overflow_hidden()
231 .rounded(px(TILE_RADIUS))
232 .bg(theme::row_hover())
233 .border_2()
234 .border_color(if speaking {
235 theme::green()
236 } else {
237 transparent_black()
238 })
239 .child(
240 img(ImageSource::Render(image))
241 .size_full()
242 .object_fit(ObjectFit::Cover)
243 .rounded(px(TILE_RADIUS)),
244 )
245 .child(
246 div()
247 .absolute()
248 .left(px(8.))
249 .bottom(px(8.))
250 .max_w(px(size.width - 24.))
251 .truncate()
252 .px(px(8.))
253 .py(px(4.))
254 .rounded(px(6.))
255 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
256 .text_size(px(12.))
257 .font_weight(FontWeight::SEMIBOLD)
258 .text_color(theme::white())
259 .child(name.to_owned()),
260 )
261 .when(muted, |tile| tile.child(mute_badge()))
262 .children(tile_overlays(extras))
263}
264
265fn tile(
266 size: TileSize,
267 avatar: AnyElement,
268 name: &str,
269 speaking: bool,
270 muted: bool,
271 caption: Option<AnyElement>,
272 extras: &TileExtras,
273) -> Div {
274 let badge = div()
275 .absolute()
276 .top(px(8.))
277 .right(px(8.))
278 .size(px(24.))
279 .flex()
280 .items_center()
281 .justify_center()
282 .rounded_full()
283 .bg(theme::red())
284 .child(icon(IconName::MicOff, 13., theme::white()));
285 v_flex()
286 .relative()
287 .w(px(size.width))
288 .h(px(size.height))
289 .items_center()
290 .justify_center()
291 .gap(px(12.))
292 .rounded(px(12.))
293 .bg(theme::row_hover())
294 .child(speaking_ring(avatar, speaking))
295 .child(
296 v_flex()
297 .items_center()
298 .gap(px(2.))
299 .max_w(px(size.width - 16.))
300 .child(
301 div()
302 .max_w_full()
303 .truncate()
304 .text_size(px(14.))
305 .font_weight(FontWeight::SEMIBOLD)
306 .child(name.to_owned()),
307 )
308 .children(caption),
309 )
310 .when(muted, |tile| tile.child(badge))
311 .children(tile_overlays(extras))
312}
313
314fn overflow_tile(size: TileSize, hidden: usize) -> Div {
315 v_flex()
316 .w(px(size.width))
317 .h(px(size.height))
318 .items_center()
319 .justify_center()
320 .rounded(px(12.))
321 .bg(theme::row_hover())
322 .child(
323 div()
324 .text_size(px(size.avatar * 0.5))
325 .font_weight(FontWeight::SEMIBOLD)
326 .text_color(theme::text_muted())
327 .child(format!("+{hidden}")),
328 )
329}
330
331fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
332 div()
333 .id(id)
334 .size(px(CONTROL_SIZE))
335 .flex()
336 .flex_none()
337 .items_center()
338 .justify_center()
339 .rounded_full()
340 .bg(background)
341 .cursor_pointer()
342 .hover(|button| button.opacity(0.85))
343}
344
345pub(super) fn round_control(
346 id: &'static str,
347 glyph: IconName,
348 background: Hsla,
349 foreground: Hsla,
350) -> Stateful<Div> {
351 control_shell(id, background).child(icon(glyph, CONTROL_ICON, foreground))
352}
353
354pub fn mute_button(
355 app: &Entity<AppState>,
356 model: &CallModel,
357 id: &'static str,
358 size: f32,
359) -> Stateful<Div> {
360 let (glyph, background, foreground) = if model.muted {
361 (IconName::MicOff, theme::red(), theme::white())
362 } else {
363 (IconName::Mic, theme::surface_raised(), theme::text())
364 };
365 let button = round_control(id, glyph, background, foreground).size(px(size));
366 if !model.can_unmute() {
367 let hint = if model.audio_off {
368 AUDIO_OFF_HINT
369 } else {
370 NO_MICROPHONE_HINT
371 };
372 return button
373 .opacity(DISABLED_OPACITY)
374 .cursor_default()
375 .tooltip(move |window, cx| Tooltip::new(hint).build(window, cx));
376 }
377 let app = app.clone();
378 button.on_click(move |_, _, cx| {
379 cx.stop_propagation();
380 app.update(cx, |state, cx| state.toggle_call_mute(cx));
381 })
382}
383
384pub fn leave_button(
385 app: &Entity<AppState>,
386 model: &CallModel,
387 id: &'static str,
388 compact: bool,
389) -> Stateful<Div> {
390 let label = if model.is_connecting() {
391 "Cancel"
392 } else {
393 "Leave"
394 };
395 let app = app.clone();
396 h_flex()
397 .id(id)
398 .h(px(if compact { 28. } else { CONTROL_SIZE }))
399 .px(px(if compact { 10. } else { 20. }))
400 .gap(px(8.))
401 .flex_none()
402 .items_center()
403 .justify_center()
404 .rounded_full()
405 .bg(theme::red())
406 .text_color(theme::white())
407 .text_size(px(if compact { 12. } else { 14. }))
408 .font_weight(FontWeight::SEMIBOLD)
409 .cursor_pointer()
410 .hover(|button| button.opacity(0.85))
411 .child(icon(
412 IconName::PhoneOff,
413 if compact { 14. } else { 18. },
414 theme::white(),
415 ))
416 .child(label)
417 .on_click(move |_, _, cx| {
418 cx.stop_propagation();
419 app.update(cx, |state, cx| state.leave_call(cx));
420 })
421}
422
423pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
424 let (glyph, background, foreground) = if model.camera_on {
425 (IconName::Video, theme::accent(), theme::on_accent())
426 } else {
427 (IconName::VideoOff, theme::surface_raised(), theme::text())
428 };
429 let button = round_control("call-camera", glyph, background, foreground);
430 if !model.can_use_camera() {
431 return button
432 .opacity(DISABLED_OPACITY)
433 .cursor_default()
434 .tooltip(|window, cx| Tooltip::new(NO_CAMERA_HINT).build(window, cx));
435 }
436 let app = app.clone();
437 button.on_click(move |_, _, cx| {
438 cx.stop_propagation();
439 app.update(cx, |state, cx| state.toggle_call_camera(cx));
440 })
441}
442
443fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
444 let app = app.clone();
445 PopupMenuItem::element(move |_, _| {
446 h_flex()
447 .id("call-share-sound-row")
448 .w_full()
449 .gap(px(16.))
450 .items_center()
451 .justify_between()
452 .child(SHARE_SOUND_LABEL)
453 .child(Switch::new("call-share-sound").checked(sound))
454 })
455 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
456}
457
458fn share_items(
459 popup: PopupMenu,
460 app: &Entity<AppState>,
461 model: &CallModel,
462 sound: bool,
463) -> PopupMenu {
464 let screens = model.screens();
465 let single_screen = screens.len() == 1;
466 let mut popup = popup
467 .min_w(px(MENU_WIDTH))
468 .item(sound_switch_item(app, sound))
469 .separator();
470 for (index, source) in screens.into_iter().enumerate() {
471 let label = if single_screen {
472 "Share entire screen".to_owned()
473 } else {
474 format!("Share screen {}", index + 1)
475 };
476 let source = source.clone();
477 let app = app.clone();
478 popup = popup.item(PopupMenuItem::new(label).icon(IconName::Monitor).on_click(
479 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
480 ));
481 }
482 popup = popup
483 .separator()
484 .item(PopupMenuItem::label("Share a window..."));
485 let windows = model.windows();
486 if windows.is_empty() {
487 return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));
488 }
489 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
490 let label = source.label();
491 let source = source.clone();
492 let app = app.clone();
493 popup = popup.item(
494 PopupMenuItem::new(label)
495 .icon(IconName::AppWindow)
496 .on_click(move |_, _, cx| {
497 app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))
498 }),
499 );
500 }
501 popup
502}
503
504fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyElement {
505 if model.local_share.is_some() {
506 let app = app.clone();
507 return round_control(
508 "call-share-stop",
509 IconName::ScreenShareOff,
510 theme::accent(),
511 theme::on_accent(),
512 )
513 .tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))
514 .on_click(move |_, _, cx| {
515 cx.stop_propagation();
516 app.update(cx, |state, cx| state.stop_call_share(cx));
517 })
518 .into_any_element();
519 }
520 let face = round_control(
521 "call-share-face",
522 IconName::ScreenShare,
523 theme::surface_raised(),
524 theme::text(),
525 );
526 if !model.can_share() {
527 return face
528 .opacity(DISABLED_OPACITY)
529 .cursor_default()
530 .tooltip(|window, cx| Tooltip::new(NO_SHARE_HINT).build(window, cx))
531 .into_any_element();
532 }
533 let app = app.clone();
534 let model = model.clone();
535 Button::new("call-share")
536 .ghost()
537 .p_0()
538 .size(px(CONTROL_SIZE))
539 .rounded_full()
540 .child(face)
541 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
542 share_items(popup, &app, &model, sound)
543 })
544 .into_any_element()
545}
546
547fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Option<AnyElement> {
548 let label = model.local_share.as_ref()?;
549 let sound_app = app.clone();
550 let app = app.clone();
551 Some(
552 h_flex()
553 .id("call-sharing-banner")
554 .w_full()
555 .h(px(BANNER_HEIGHT))
556 .flex_none()
557 .px(px(20.))
558 .gap(px(12.))
559 .items_center()
560 .justify_center()
561 .bg(theme::accent())
562 .text_color(theme::on_accent())
563 .text_size(px(13.))
564 .font_weight(FontWeight::SEMIBOLD)
565 .child(icon(IconName::ScreenShare, 16., theme::on_accent()))
566 .child(format!("You are sharing: {label}"))
567 .child(
568 div()
569 .id("call-sharing-sound")
570 .h(px(26.))
571 .px(px(12.))
572 .flex()
573 .items_center()
574 .rounded_full()
575 .bg(theme::on_accent().opacity(0.2))
576 .cursor_pointer()
577 .hover(|button| button.opacity(0.9))
578 .child(if sound {
579 "Computer sound on"
580 } else {
581 "Computer sound off"
582 })
583 .on_click(move |_, _, cx| {
584 sound_app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))
585 }),
586 )
587 .child(
588 div()
589 .id("call-sharing-stop")
590 .h(px(26.))
591 .px(px(12.))
592 .flex()
593 .items_center()
594 .rounded_full()
595 .bg(theme::on_accent())
596 .text_color(theme::accent())
597 .cursor_pointer()
598 .hover(|button| button.opacity(0.9))
599 .child("Stop sharing")
600 .on_click(move |_, _, cx| {
601 app.update(cx, |state, cx| state.stop_call_share(cx))
602 }),
603 )
604 .into_any_element(),
605 )
606}
607
608fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {
609 let app = app.clone();
610 let (background, foreground) = if open {
611 (theme::accent(), theme::on_accent())
612 } else {
613 (theme::surface_raised(), theme::text())
614 };
615 round_control("call-chat", IconName::MessageCircle, background, foreground)
616 .relative()
617 .tooltip(move |window, cx| {
618 Tooltip::new(if open {
619 "Close the chat"
620 } else {
621 "Open the chat"
622 })
623 .build(window, cx)
624 })
625 .when(unread > 0, |button| {
626 button.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
627 })
628 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))
629}
630
631fn hand_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
632 let raised = model.own_hand.is_some();
633 let background = if raised {
634 theme::accent()
635 } else {
636 theme::surface_raised()
637 };
638 let foreground = if raised {
639 theme::on_accent()
640 } else {
641 theme::text()
642 };
643 let button = control_shell("call-hand", background).child(icon(
644 IconName::Hand,
645 CONTROL_ICON,
646 foreground,
647 ));
648 let tooltip = if raised { "Lower hand" } else { "Raise hand" };
649 let button = button.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx));
650 if !model.can_react() {
651 return button.opacity(DISABLED_OPACITY).cursor_default();
652 }
653 let app = app.clone();
654 button.on_click(move |_, _, cx| {
655 cx.stop_propagation();
656 app.update(cx, |state, cx| state.toggle_call_hand(cx));
657 })
658}
659
660fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
661 let face = control_shell("call-reactions-face", theme::surface_raised()).child(icon(
662 IconName::FaceSlightlySmiling,
663 CONTROL_ICON,
664 theme::text(),
665 ));
666 if !model.can_react() {
667 return face
668 .opacity(DISABLED_OPACITY)
669 .cursor_default()
670 .into_any_element();
671 }
672 let app = app.clone();
673 Popover::new("call-reactions-popover")
674 .anchor(Anchor::BottomLeft)
675 .offset(px(10.))
676 .trigger(
677 Button::new("call-reactions")
678 .ghost()
679 .p_0()
680 .size(px(CONTROL_SIZE))
681 .rounded_full()
682 .child(face),
683 )
684 .content(move |_, _, cx| {
685 let popover = cx.entity().downgrade();
686 h_flex()
687 .id("call-reactions-row")
688 .gap(px(4.))
689 .children(Reaction::ALL.into_iter().map(|reaction| {
690 let app = app.clone();
691 let popover = popover.clone();
692 div()
693 .id(reaction.name())
694 .size(px(REACTION_CELL))
695 .flex()
696 .items_center()
697 .justify_center()
698 .rounded(px(8.))
699 .text_size(px(24.))
700 .cursor_pointer()
701 .hover(|cell| cell.bg(theme::border_strong()))
702 .child(reaction_glyph(reaction))
703 .on_click(move |_, window, cx| {
704 app.update(cx, |state, cx| state.send_call_reaction(reaction, cx));
705 popover
706 .update(cx, |state, cx| state.dismiss(window, cx))
707 .ok();
708 })
709 }))
710 })
711 .into_any_element()
712}
713
714fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
715 let leave_app = app.clone();
716 let end_app = app.clone();
717 let can_end = model.can_end_meeting;
718 let lower_app = app.clone();
719 let can_lower_all = model.can_lower_hands() && model.any_hand_raised();
720 Button::new("call-leave-menu")
721 .ghost()
722 .p_0()
723 .size(px(CONTROL_SIZE))
724 .rounded_full()
725 .child(round_control(
726 "call-leave-menu-face",
727 IconName::ChevronUp,
728 theme::surface_raised(),
729 theme::text(),
730 ))
731 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
732 let leave_app = leave_app.clone();
733 let end_app = end_app.clone();
734 let lower_app = lower_app.clone();
735 let popup = popup.min_w(px(MENU_WIDTH)).item(
736 PopupMenuItem::new("Leave")
737 .icon(IconName::PhoneOff)
738 .on_click(move |_, _, cx| {
739 leave_app.update(cx, |state, cx| state.leave_call(cx))
740 }),
741 );
742 let popup = if can_lower_all {
743 popup.item(
744 PopupMenuItem::new("Lower all hands").on_click(move |_, _, cx| {
745 lower_app.update(cx, |state, cx| state.lower_all_call_hands(cx))
746 }),
747 )
748 } else {
749 popup
750 };
751 if can_end {
752 popup.item(
753 PopupMenuItem::new("End meeting for everyone")
754 .icon(IconName::PhoneOff)
755 .on_click(move |_, _, cx| {
756 end_app.update(cx, |state, cx| state.end_meeting_for_all(cx))
757 }),
758 )
759 } else {
760 popup
761 }
762 })
763}
764
765pub(super) fn device_items(
766 entries: Vec<DeviceEntry>,
767 selected: &calling::DeviceChoice,
768 pick: impl Fn(calling::DeviceChoice, &mut App) + Clone + 'static,
769) -> Vec<PopupMenuItem> {
770 entries
771 .into_iter()
772 .map(|entry| {
773 let pick = pick.clone();
774 let choice = entry.choice.clone();
775 PopupMenuItem::new(entry.label)
776 .checked(&entry.choice == selected)
777 .on_click(move |_, _, cx| pick(choice.clone(), cx))
778 })
779 .collect()
780}
781
782fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
783 if model.audio_off {
784 return popup.item(PopupMenuItem::new(AUDIO_OFF_HINT).disabled(true));
785 }
786 let input_app = app.clone();
787 let output_app = app.clone();
788 let inputs = device_items(
789 model.devices.input_entries(),
790 &model.input,
791 move |choice, cx| {
792 input_app.update(cx, |state, cx| state.select_call_input(choice, cx));
793 },
794 );
795 let outputs = device_items(
796 model.devices.output_entries(),
797 &model.output,
798 move |choice, cx| {
799 output_app.update(cx, |state, cx| state.select_call_output(choice, cx));
800 },
801 );
802 let mut popup = popup
803 .min_w(px(MENU_WIDTH))
804 .item(PopupMenuItem::label("Microphone"));
805 if model.listen_only {
806 popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true));
807 } else {
808 for item in inputs {
809 popup = popup.item(item);
810 }
811 }
812 popup = popup.separator().item(PopupMenuItem::label("Speaker"));
813 for item in outputs {
814 popup = popup.item(item);
815 }
816 popup
817}
818
819fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
820 let app = app.clone();
821 let model = model.clone();
822 chevron_button("call-mic-menu", "call-mic-menu-face")
823 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
824 devices_menu(popup, &app, &model)
825 })
826}
827
828fn person_tile(
829 app: &Entity<AppState>,
830 state: &AppState,
831 model: &CallModel,
832 remote: &Tile,
833 size: TileSize,
834 now: Instant,
835) -> AnyElement {
836 let extras = TileExtras {
837 hand: remote.hand.map(|rank| model.hand_position(rank)),
838 own: false,
839 reaction: model
840 .chip_of(&remote.mri, now)
841 .map(|chip| (chip.reaction, chip.serial)),
842 spotlight: remote.spotlight.is_some(),
843 pinned: model.is_pinned(&remote.mri),
844 };
845 let element = person_tile_body(state, model, remote, size, now, &extras);
846 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
847}
848
849fn person_tile_body(
850 state: &AppState,
851 model: &CallModel,
852 remote: &Tile,
853 size: TileSize,
854 now: Instant,
855 extras: &TileExtras,
856) -> AnyElement {
857 let video = state
858 .call
859 .as_ref()
860 .filter(|_| remote.has_video || model.is_one_to_one())
861 .and_then(|call| {
862 call.pictures
863 .live(&VideoKey::Person(remote.mri.clone()), now)
864 });
865 if let Some(image) = video {
866 return video_tile(
867 size,
868 image,
869 &remote.name,
870 model.tile_speaking(remote),
871 remote.muted,
872 extras,
873 )
874 .into_any_element();
875 }
876 let waiting = remote.state == TileState::Invited;
877 let avatar = person_avatar(
878 &state.directory,
879 remote.user_id.as_deref(),
880 &remote.name,
881 size.avatar,
882 );
883 let caption = model.tile_caption(remote).map(|text| {
884 let label = div()
885 .text_size(px(12.))
886 .text_color(theme::text_muted())
887 .child(text);
888 if waiting {
889 blinking(label)
890 } else {
891 label.into_any_element()
892 }
893 });
894 tile(
895 size,
896 avatar,
897 &remote.name,
898 model.tile_speaking(remote),
899 remote.muted,
900 caption,
901 extras,
902 )
903 .into_any_element()
904}
905
906fn own_tile(
907 app: &Entity<AppState>,
908 state: &AppState,
909 model: &CallModel,
910 size: TileSize,
911 now: Instant,
912) -> AnyElement {
913 let own_mri = model.own_mri.clone().unwrap_or_default();
914 let extras = TileExtras {
915 hand: model.own_hand.map(|rank| model.hand_position(rank)),
916 own: true,
917 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
918 spotlight: model.own_spotlight.is_some(),
919 pinned: model.is_pinned(&own_mri),
920 };
921 let element = own_tile_body(state, model, size, now, &extras);
922 if own_mri.is_empty() {
923 return element;
924 }
925 with_tile_menu(app, model, &own_mri, "You", true, element)
926}
927
928fn own_tile_body(
929 state: &AppState,
930 model: &CallModel,
931 size: TileSize,
932 now: Instant,
933 extras: &TileExtras,
934) -> AnyElement {
935 let me = state.directory.me.as_ref();
936 let self_view = state
937 .call
938 .as_ref()
939 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
940 if let Some(image) = self_view {
941 return video_tile(
942 size,
943 image,
944 "You",
945 model.local_speaking,
946 model.muted,
947 extras,
948 )
949 .into_any_element();
950 }
951 let avatar = person_avatar(
952 &state.directory,
953 me.map(|person| person.user_id.as_str()),
954 me.map_or("You", |person| person.display_name.as_str()),
955 size.avatar,
956 );
957 tile(
958 size,
959 avatar,
960 "You",
961 model.local_speaking,
962 model.muted,
963 None,
964 extras,
965 )
966 .into_any_element()
967}
968
969fn remote_tiles(
970 app: &Entity<AppState>,
971 state: &AppState,
972 model: &CallModel,
973 size: TileSize,
974 hidden_cap: GridLayout,
975 now: Instant,
976) -> Vec<AnyElement> {
977 let visible = model.visible_tiles();
978 let mut cells: Vec<AnyElement> = visible
979 .iter()
980 .take(hidden_cap.shown_others)
981 .map(|remote| person_tile(app, state, model, remote, size, now))
982 .collect();
983 if hidden_cap.hidden > 0 {
984 cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());
985 }
986 cells
987}
988
989fn people_strip(
990 app: &Entity<AppState>,
991 state: &AppState,
992 model: &CallModel,
993 now: Instant,
994 focused: Option<&str>,
995) -> Stateful<Div> {
996 let mut cells: Vec<AnyElement> = model
997 .strip_tiles()
998 .into_iter()
999 .filter(|remote| Some(remote.mri.as_str()) != focused)
1000 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
1001 .collect();
1002 if focused.is_none() || focused != model.own_mri.as_deref() {
1003 let own_index = model.own_cell_index(cells.len());
1004 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
1005 }
1006 v_flex()
1007 .id("call-strip")
1008 .flex_none()
1009 .w(px(STRIP_TILE.width))
1010 .max_h(px(
1011 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
1012 ))
1013 .gap(px(STRIP_GAP))
1014 .overflow_y_scroll()
1015 .children(cells)
1016}
1017
1018pub fn render_call_view(
1019 app: &Entity<AppState>,
1020 state: &AppState,
1021 chat: Option<Entity<ConversationView>>,
1022) -> Option<AnyElement> {
1023 let call = state.call.as_ref()?;
1024 let model = &call.model;
1025 let now = Instant::now();
1026 let (status, status_color) = status_line(model, now);
1027 let header = h_flex()
1028 .w_full()
1029 .h(px(HEADER_HEIGHT))
1030 .flex_none()
1031 .px(px(20.))
1032 .gap(px(12.))
1033 .items_center()
1034 .child(icon(IconName::Phone, 18., theme::accent_text()))
1035 .child(
1036 div()
1037 .min_w_0()
1038 .truncate()
1039 .text_size(px(16.))
1040 .font_weight(FontWeight::SEMIBOLD)
1041 .child(model.title.clone()),
1042 )
1043 .child(
1044 div()
1045 .flex_none()
1046 .text_size(px(13.))
1047 .text_color(status_color)
1048 .child(status),
1049 )
1050 .children(recording_chip(model))
1051 .children(room_chip(model))
1052 .child(div().flex_1())
1053 .children(return_button(app, model));
1054
1055 let max_tiles = if chat.is_some() {
1056 CHAT_OPEN_TILES
1057 } else {
1058 MAX_TILES
1059 };
1060 let layout = grid_layout(model.visible_tiles().len(), max_tiles);
1061 let cells_for_size = if chat.is_some() {
1062 MAX_TILES
1063 } else {
1064 layout.shown_others + usize::from(layout.hidden > 0) + 1
1065 };
1066 let size = tile_size(cells_for_size);
1067 let mut cells = remote_tiles(app, state, model, size, layout, now);
1068 let own_index = model.own_cell_index(cells.len());
1069 cells.insert(own_index, own_tile(app, state, model, size, now));
1070 let focus = model.focus().filter(|_| model.screen_sharer.is_none());
1071 let stage = render_stage(app, state, false)
1072 .or_else(|| whiteboard_stage(app, model))
1073 .or_else(|| {
1074 focus
1075 .as_ref()
1076 .and_then(|focus| render_focus_stage(app, state, focus, now))
1077 });
1078 let hold = hold_panel(app, model);
1079 let focused = focus.as_ref().map(|focus| focus.mri.as_str());
1080
1081 let controls = h_flex()
1082 .w_full()
1083 .flex_none()
1084 .py(px(16.))
1085 .gap(px(12.))
1086 .items_center()
1087 .justify_center()
1088 .child(
1089 h_flex()
1090 .h(px(CONTROL_SIZE))
1091 .items_center()
1092 .rounded_full()
1093 .bg(theme::surface_raised())
1094 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1095 .child(mic_menu_button(app, model)),
1096 )
1097 .child(
1098 h_flex()
1099 .h(px(CONTROL_SIZE))
1100 .items_center()
1101 .rounded_full()
1102 .bg(theme::surface_raised())
1103 .child(camera_button(app, model))
1104 .children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1105 )
1106 .child(share_button(app, model, state.call_share_sound))
1107 .when(model.has_reaction_controls(), |row| {
1108 row.child(hand_button(app, model))
1109 .child(reactions_button(app, model))
1110 })
1111 .children(more_button(app, model))
1112 .when(call.chat_thread().is_some(), |row| {
1113 row.child(chat_button(app, call.chat_open, state.call_chat_unread()))
1114 })
1115 .child(leave_button(app, model, "call-leave", false))
1116 .when(model.kind == CallKind::Meeting, |row| {
1117 row.child(leave_menu(app, model))
1118 });
1119
1120 let column = v_flex()
1121 .relative()
1122 .flex_1()
1123 .min_w_0()
1124 .h_full()
1125 .rounded(px(10.))
1126 .overflow_hidden()
1127 .bg(theme::surface())
1128 .child(header)
1129 .children(lobby_banner(app, model))
1130 .children(sharing_banner(app, model, state.call_share_sound))
1131 .children(consult_banner(app, state))
1132 .child(match stage {
1133 _ if hold.is_some() => hold.expect("checked above"),
1134 Some(stage) => h_flex()
1135 .flex_1()
1136 .min_h_0()
1137 .p(px(GRID_PADDING))
1138 .gap(px(TILE_GAP))
1139 .items_center()
1140 .child(stage)
1141 .child(people_strip(app, state, model, now, focused))
1142 .into_any_element(),
1143 None => h_flex()
1144 .id("call-grid")
1145 .flex_1()
1146 .min_h_0()
1147 .overflow_y_scroll()
1148 .flex_wrap()
1149 .content_center()
1150 .p(px(GRID_PADDING))
1151 .gap(px(TILE_GAP))
1152 .items_center()
1153 .justify_center()
1154 .children(cells)
1155 .into_any_element(),
1156 })
1157 .child(controls)
1158 .children(captions_overlay(model, now))
1159 .children(captions_hint_chip(model))
1160 .children(state.transfer_picker.clone())
1161 .children(consent_overlay(app, model));
1162 Some(
1163 h_flex()
1164 .debug_selector(|| "shell/islands/main".into())
1165 .flex_1()
1166 .min_w_0()
1167 .h_full()
1168 .gap(px(ISLAND_GAP))
1169 .child(column)
1170 .children(chat.map(|chat| chat_panel(app, chat)))
1171 .into_any_element(),
1172 )
1173}
1174
1175fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1176 let app = app.clone();
1177 v_flex()
1178 .id("call-chat-panel")
1179 .w(px(CHAT_PANEL_WIDTH))
1180 .h_full()
1181 .flex_none()
1182 .rounded(px(10.))
1183 .overflow_hidden()
1184 .bg(theme::surface())
1185 .child(
1186 h_flex()
1187 .w_full()
1188 .h(px(CHAT_HEADER_HEIGHT))
1189 .flex_none()
1190 .pl(px(20.))
1191 .pr(px(12.))
1192 .items_center()
1193 .justify_between()
1194 .child(
1195 div()
1196 .text_size(px(15.))
1197 .font_weight(FontWeight::SEMIBOLD)
1198 .child("Chat"),
1199 )
1200 .child(
1201 div()
1202 .id("call-chat-close")
1203 .size(px(28.))
1204 .flex()
1205 .items_center()
1206 .justify_center()
1207 .rounded(px(7.))
1208 .cursor_pointer()
1209 .hover(|button| button.bg(theme::row_hover()))
1210 .tooltip(|window, cx| Tooltip::new("Close the chat").build(window, cx))
1211 .child(icon(IconName::Close, 14., theme::text_muted()))
1212 .on_click(move |_, _, cx| {
1213 app.update(cx, |state, cx| state.toggle_call_chat(cx))
1214 }),
1215 ),
1216 )
1217 .child(chat)
1218 .into_any_element()
1219}