BlueGit

ict rusty-teams

Files

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

call_view.rs

call_view.rs 37.1 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, lobby_banner, more_button, pin_chip,
25 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::{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";
63pub const NO_CAMERA_HINT: &str = "No camera found";
64pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";
65pub const NO_WINDOWS_HINT: &str = "No windows found";
66pub(super) const BANNER_HEIGHT: f32 = 40.;
67const MAX_WINDOW_ITEMS: usize = 12;
68pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
69pub const CHAT_PANEL_WIDTH: f32 = 320.;
70const CHAT_HEADER_HEIGHT: f32 = 48.;
71const REACTION_RISE: f32 = 24.;
72const REACTION_FADE_FROM: f32 = 0.75;
73const REACTION_CELL: f32 = 40.;
74const SHARE_SOUND_LABEL: &str = "Include computer sound";
75
76pub fn reaction_glyph(reaction: Reaction) -> String {
77 match reaction {
78 Reaction::Applause => "\u{1F44F}".to_owned(),
79 other => chat_reaction_glyph(other.name()),
80 }
81}
82
83#[derive(Default)]
84struct TileExtras {
85 hand: Option<usize>,
86 own: bool,
87 reaction: Option<(Reaction, u64)>,
88 spotlight: bool,
89 pinned: bool,
90}
91
92fn hand_badge(position: usize, own: bool) -> Div {
93 h_flex()
94 .h(px(24.))
95 .px(px(8.))
96 .gap(px(4.))
97 .items_center()
98 .rounded_full()
99 .bg(theme::amber())
100 .text_color(hsla(0., 0., 0.08, 1.))
101 .text_size(px(12.))
102 .font_weight(FontWeight::SEMIBOLD)
103 .child(if own {
104 "Hand raised".to_owned()
105 } else {
106 format!("Hand {position}")
107 })
108}
109
110fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {
111 div()
112 .absolute()
113 .right(px(12.))
114 .bottom(px(32.))
115 .size(px(36.))
116 .flex()
117 .items_center()
118 .justify_center()
119 .rounded_full()
120 .bg(theme::popup())
121 .text_size(px(20.))
122 .child(reaction_glyph(reaction))
123 .with_animation(
124 ("call-reaction", serial as usize),
125 Animation::new(REACTION_SHOWN),
126 |chip, delta| {
127 let fade = ((delta - REACTION_FADE_FROM) / (1. - REACTION_FADE_FROM)).clamp(0., 1.);
128 chip.bottom(px(32. + REACTION_RISE * delta))
129 .opacity(1. - fade)
130 },
131 )
132 .into_any_element()
133}
134
135fn tile_overlays(extras: &TileExtras) -> Vec<AnyElement> {
136 let badges = (extras.hand.is_some() || extras.spotlight || extras.pinned).then(|| {
137 h_flex()
138 .absolute()
139 .top(px(8.))
140 .left(px(8.))
141 .gap(px(6.))
142 .children(extras.hand.map(|position| hand_badge(position, extras.own)))
143 .when(extras.spotlight, |row| row.child(spotlight_chip()))
144 .when(extras.pinned, |row| row.child(pin_chip()))
145 .into_any_element()
146 });
147 let reaction = extras
148 .reaction
149 .map(|(reaction, serial)| reaction_chip(reaction, serial));
150 badges.into_iter().chain(reaction).collect()
151}
152
153pub fn status_line(model: &CallModel, now: Instant) -> (String, Hsla) {
154 if model.lobby {
155 (LOBBY_TEXT.to_owned(), theme::amber())
156 } else if model.is_connecting() {
157 (model.connecting_text().to_owned(), theme::text_muted())
158 } else if model.is_reconnecting() {
159 ("Reconnecting...".to_owned(), theme::amber())
160 } else {
161 (model.timer_text(now), theme::text_muted())
162 }
163}
164
165pub fn pulsing(element: impl IntoElement + 'static, id: &'static str) -> AnyElement {
166 div()
167 .child(element)
168 .with_animation(
169 id,
170 Animation::new(PULSE_PERIOD).repeat(),
171 |element, delta| {
172 let wave = 1. - (delta * 2. - 1.).abs();
173 element.opacity(0.45 + 0.55 * wave)
174 },
175 )
176 .into_any_element()
177}
178
179fn blinking(element: impl IntoElement + 'static) -> AnyElement {
180 let dimmed = SystemTime::now()
181 .duration_since(UNIX_EPOCH)
182 .is_ok_and(|elapsed| (elapsed.as_millis() / BLINK_HALF_PERIOD.as_millis()) % 2 == 1);
183 div()
184 .child(element)
185 .opacity(if dimmed { BLINK_DIMMED_OPACITY } else { 1. })
186 .into_any_element()
187}
188
189fn speaking_ring(avatar: AnyElement, speaking: bool) -> Div {
190 div()
191 .p(px(RING_GAP))
192 .rounded_full()
193 .border(px(RING_WIDTH))
194 .border_color(if speaking {
195 theme::green()
196 } else {
197 transparent_black()
198 })
199 .child(avatar)
200}
201
202fn mute_badge() -> Div {
203 div()
204 .absolute()
205 .top(px(8.))
206 .right(px(8.))
207 .size(px(24.))
208 .flex()
209 .items_center()
210 .justify_center()
211 .rounded_full()
212 .bg(theme::red())
213 .child(icon(IconName::MicOff, 13., theme::white()))
214}
215
216fn video_tile(
217 size: TileSize,
218 image: Arc<RenderImage>,
219 name: &str,
220 speaking: bool,
221 muted: bool,
222 extras: &TileExtras,
223) -> Div {
224 div()
225 .relative()
226 .w(px(size.width))
227 .h(px(size.height))
228 .flex_none()
229 .overflow_hidden()
230 .rounded(px(TILE_RADIUS))
231 .bg(theme::row_hover())
232 .border_2()
233 .border_color(if speaking {
234 theme::green()
235 } else {
236 transparent_black()
237 })
238 .child(
239 img(ImageSource::Render(image))
240 .size_full()
241 .object_fit(ObjectFit::Cover)
242 .rounded(px(TILE_RADIUS)),
243 )
244 .child(
245 div()
246 .absolute()
247 .left(px(8.))
248 .bottom(px(8.))
249 .max_w(px(size.width - 24.))
250 .truncate()
251 .px(px(8.))
252 .py(px(4.))
253 .rounded(px(6.))
254 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
255 .text_size(px(12.))
256 .font_weight(FontWeight::SEMIBOLD)
257 .text_color(theme::white())
258 .child(name.to_owned()),
259 )
260 .when(muted, |tile| tile.child(mute_badge()))
261 .children(tile_overlays(extras))
262}
263
264fn tile(
265 size: TileSize,
266 avatar: AnyElement,
267 name: &str,
268 speaking: bool,
269 muted: bool,
270 caption: Option<AnyElement>,
271 extras: &TileExtras,
272) -> Div {
273 let badge = div()
274 .absolute()
275 .top(px(8.))
276 .right(px(8.))
277 .size(px(24.))
278 .flex()
279 .items_center()
280 .justify_center()
281 .rounded_full()
282 .bg(theme::red())
283 .child(icon(IconName::MicOff, 13., theme::white()));
284 v_flex()
285 .relative()
286 .w(px(size.width))
287 .h(px(size.height))
288 .items_center()
289 .justify_center()
290 .gap(px(12.))
291 .rounded(px(12.))
292 .bg(theme::row_hover())
293 .child(speaking_ring(avatar, speaking))
294 .child(
295 v_flex()
296 .items_center()
297 .gap(px(2.))
298 .max_w(px(size.width - 16.))
299 .child(
300 div()
301 .max_w_full()
302 .truncate()
303 .text_size(px(14.))
304 .font_weight(FontWeight::SEMIBOLD)
305 .child(name.to_owned()),
306 )
307 .children(caption),
308 )
309 .when(muted, |tile| tile.child(badge))
310 .children(tile_overlays(extras))
311}
312
313fn overflow_tile(size: TileSize, hidden: usize) -> Div {
314 v_flex()
315 .w(px(size.width))
316 .h(px(size.height))
317 .items_center()
318 .justify_center()
319 .rounded(px(12.))
320 .bg(theme::row_hover())
321 .child(
322 div()
323 .text_size(px(size.avatar * 0.5))
324 .font_weight(FontWeight::SEMIBOLD)
325 .text_color(theme::text_muted())
326 .child(format!("+{hidden}")),
327 )
328}
329
330fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
331 div()
332 .id(id)
333 .size(px(CONTROL_SIZE))
334 .flex()
335 .flex_none()
336 .items_center()
337 .justify_center()
338 .rounded_full()
339 .bg(background)
340 .cursor_pointer()
341 .hover(|button| button.opacity(0.85))
342}
343
344pub(super) fn round_control(
345 id: &'static str,
346 glyph: IconName,
347 background: Hsla,
348 foreground: Hsla,
349) -> Stateful<Div> {
350 control_shell(id, background).child(icon(glyph, CONTROL_ICON, foreground))
351}
352
353pub fn mute_button(
354 app: &Entity<AppState>,
355 model: &CallModel,
356 id: &'static str,
357 size: f32,
358) -> Stateful<Div> {
359 let (glyph, background, foreground) = if model.muted {
360 (IconName::MicOff, theme::red(), theme::white())
361 } else {
362 (IconName::Mic, theme::surface_raised(), theme::text())
363 };
364 let button = round_control(id, glyph, background, foreground).size(px(size));
365 if !model.can_unmute() {
366 return button
367 .opacity(DISABLED_OPACITY)
368 .cursor_default()
369 .tooltip(|window, cx| Tooltip::new(NO_MICROPHONE_HINT).build(window, cx));
370 }
371 let app = app.clone();
372 button.on_click(move |_, _, cx| {
373 cx.stop_propagation();
374 app.update(cx, |state, cx| state.toggle_call_mute(cx));
375 })
376}
377
378pub fn leave_button(
379 app: &Entity<AppState>,
380 model: &CallModel,
381 id: &'static str,
382 compact: bool,
383) -> Stateful<Div> {
384 let label = if model.is_connecting() {
385 "Cancel"
386 } else {
387 "Leave"
388 };
389 let app = app.clone();
390 h_flex()
391 .id(id)
392 .h(px(if compact { 28. } else { CONTROL_SIZE }))
393 .px(px(if compact { 10. } else { 20. }))
394 .gap(px(8.))
395 .flex_none()
396 .items_center()
397 .justify_center()
398 .rounded_full()
399 .bg(theme::red())
400 .text_color(theme::white())
401 .text_size(px(if compact { 12. } else { 14. }))
402 .font_weight(FontWeight::SEMIBOLD)
403 .cursor_pointer()
404 .hover(|button| button.opacity(0.85))
405 .child(icon(
406 IconName::PhoneOff,
407 if compact { 14. } else { 18. },
408 theme::white(),
409 ))
410 .child(label)
411 .on_click(move |_, _, cx| {
412 cx.stop_propagation();
413 app.update(cx, |state, cx| state.leave_call(cx));
414 })
415}
416
417pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
418 let (glyph, background, foreground) = if model.camera_on {
419 (IconName::Video, theme::accent(), theme::on_accent())
420 } else {
421 (IconName::VideoOff, theme::surface_raised(), theme::text())
422 };
423 let button = round_control("call-camera", glyph, background, foreground);
424 if !model.can_use_camera() {
425 return button
426 .opacity(DISABLED_OPACITY)
427 .cursor_default()
428 .tooltip(|window, cx| Tooltip::new(NO_CAMERA_HINT).build(window, cx));
429 }
430 let app = app.clone();
431 button.on_click(move |_, _, cx| {
432 cx.stop_propagation();
433 app.update(cx, |state, cx| state.toggle_call_camera(cx));
434 })
435}
436
437fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
438 let app = app.clone();
439 PopupMenuItem::element(move |_, _| {
440 h_flex()
441 .id("call-share-sound-row")
442 .w_full()
443 .gap(px(16.))
444 .items_center()
445 .justify_between()
446 .child(SHARE_SOUND_LABEL)
447 .child(Switch::new("call-share-sound").checked(sound))
448 })
449 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
450}
451
452fn share_items(
453 popup: PopupMenu,
454 app: &Entity<AppState>,
455 model: &CallModel,
456 sound: bool,
457) -> PopupMenu {
458 let screens = model.screens();
459 let single_screen = screens.len() == 1;
460 let mut popup = popup
461 .min_w(px(MENU_WIDTH))
462 .item(sound_switch_item(app, sound))
463 .separator();
464 for (index, source) in screens.into_iter().enumerate() {
465 let label = if single_screen {
466 "Share entire screen".to_owned()
467 } else {
468 format!("Share screen {}", index + 1)
469 };
470 let source = source.clone();
471 let app = app.clone();
472 popup = popup.item(PopupMenuItem::new(label).icon(IconName::Monitor).on_click(
473 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
474 ));
475 }
476 popup = popup
477 .separator()
478 .item(PopupMenuItem::label("Share a window..."));
479 let windows = model.windows();
480 if windows.is_empty() {
481 return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));
482 }
483 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
484 let label = source.label();
485 let source = source.clone();
486 let app = app.clone();
487 popup = popup.item(
488 PopupMenuItem::new(label)
489 .icon(IconName::AppWindow)
490 .on_click(move |_, _, cx| {
491 app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))
492 }),
493 );
494 }
495 popup
496}
497
498fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyElement {
499 if model.local_share.is_some() {
500 let app = app.clone();
501 return round_control(
502 "call-share-stop",
503 IconName::ScreenShareOff,
504 theme::accent(),
505 theme::on_accent(),
506 )
507 .tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))
508 .on_click(move |_, _, cx| {
509 cx.stop_propagation();
510 app.update(cx, |state, cx| state.stop_call_share(cx));
511 })
512 .into_any_element();
513 }
514 let face = round_control(
515 "call-share-face",
516 IconName::ScreenShare,
517 theme::surface_raised(),
518 theme::text(),
519 );
520 if !model.can_share() {
521 return face
522 .opacity(DISABLED_OPACITY)
523 .cursor_default()
524 .tooltip(|window, cx| Tooltip::new(NO_SHARE_HINT).build(window, cx))
525 .into_any_element();
526 }
527 let app = app.clone();
528 let model = model.clone();
529 Button::new("call-share")
530 .ghost()
531 .p_0()
532 .size(px(CONTROL_SIZE))
533 .rounded_full()
534 .child(face)
535 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
536 share_items(popup, &app, &model, sound)
537 })
538 .into_any_element()
539}
540
541fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Option<AnyElement> {
542 let label = model.local_share.as_ref()?;
543 let sound_app = app.clone();
544 let app = app.clone();
545 Some(
546 h_flex()
547 .id("call-sharing-banner")
548 .w_full()
549 .h(px(BANNER_HEIGHT))
550 .flex_none()
551 .px(px(20.))
552 .gap(px(12.))
553 .items_center()
554 .justify_center()
555 .bg(theme::accent())
556 .text_color(theme::on_accent())
557 .text_size(px(13.))
558 .font_weight(FontWeight::SEMIBOLD)
559 .child(icon(IconName::ScreenShare, 16., theme::on_accent()))
560 .child(format!("You are sharing: {label}"))
561 .child(
562 div()
563 .id("call-sharing-sound")
564 .h(px(26.))
565 .px(px(12.))
566 .flex()
567 .items_center()
568 .rounded_full()
569 .bg(theme::on_accent().opacity(0.2))
570 .cursor_pointer()
571 .hover(|button| button.opacity(0.9))
572 .child(if sound {
573 "Computer sound on"
574 } else {
575 "Computer sound off"
576 })
577 .on_click(move |_, _, cx| {
578 sound_app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))
579 }),
580 )
581 .child(
582 div()
583 .id("call-sharing-stop")
584 .h(px(26.))
585 .px(px(12.))
586 .flex()
587 .items_center()
588 .rounded_full()
589 .bg(theme::on_accent())
590 .text_color(theme::accent())
591 .cursor_pointer()
592 .hover(|button| button.opacity(0.9))
593 .child("Stop sharing")
594 .on_click(move |_, _, cx| {
595 app.update(cx, |state, cx| state.stop_call_share(cx))
596 }),
597 )
598 .into_any_element(),
599 )
600}
601
602fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {
603 let app = app.clone();
604 let (background, foreground) = if open {
605 (theme::accent(), theme::on_accent())
606 } else {
607 (theme::surface_raised(), theme::text())
608 };
609 round_control("call-chat", IconName::MessageCircle, background, foreground)
610 .relative()
611 .tooltip(move |window, cx| {
612 Tooltip::new(if open {
613 "Close the chat"
614 } else {
615 "Open the chat"
616 })
617 .build(window, cx)
618 })
619 .when(unread > 0, |button| {
620 button.child(
621 div()
622 .absolute()
623 .top(px(-4.))
624 .right(px(-4.))
625 .child(count_badge(unread, false)),
626 )
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 let input_app = app.clone();
784 let output_app = app.clone();
785 let inputs = device_items(
786 model.devices.input_entries(),
787 &model.input,
788 move |choice, cx| {
789 input_app.update(cx, |state, cx| state.select_call_input(choice, cx));
790 },
791 );
792 let outputs = device_items(
793 model.devices.output_entries(),
794 &model.output,
795 move |choice, cx| {
796 output_app.update(cx, |state, cx| state.select_call_output(choice, cx));
797 },
798 );
799 let mut popup = popup
800 .min_w(px(MENU_WIDTH))
801 .item(PopupMenuItem::label("Microphone"));
802 if model.listen_only {
803 popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true));
804 } else {
805 for item in inputs {
806 popup = popup.item(item);
807 }
808 }
809 popup = popup.separator().item(PopupMenuItem::label("Speaker"));
810 for item in outputs {
811 popup = popup.item(item);
812 }
813 popup
814}
815
816fn devices_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
817 let app = app.clone();
818 let model = model.clone();
819 Button::new("call-devices")
820 .ghost()
821 .p_0()
822 .size(px(CONTROL_SIZE))
823 .rounded_full()
824 .child(round_control(
825 "call-devices-face",
826 IconName::Volume2,
827 theme::surface_raised(),
828 theme::text(),
829 ))
830 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
831 devices_menu(popup, &app, &model)
832 })
833}
834
835fn person_tile(
836 app: &Entity<AppState>,
837 state: &AppState,
838 model: &CallModel,
839 remote: &Tile,
840 size: TileSize,
841 now: Instant,
842) -> AnyElement {
843 let extras = TileExtras {
844 hand: remote.hand.map(|rank| model.hand_position(rank)),
845 own: false,
846 reaction: model
847 .chip_of(&remote.mri, now)
848 .map(|chip| (chip.reaction, chip.serial)),
849 spotlight: remote.spotlight.is_some(),
850 pinned: model.is_pinned(&remote.mri),
851 };
852 let element = person_tile_body(state, model, remote, size, now, &extras);
853 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
854}
855
856fn person_tile_body(
857 state: &AppState,
858 model: &CallModel,
859 remote: &Tile,
860 size: TileSize,
861 now: Instant,
862 extras: &TileExtras,
863) -> AnyElement {
864 let video = state
865 .call
866 .as_ref()
867 .filter(|_| remote.has_video || model.is_one_to_one())
868 .and_then(|call| {
869 call.pictures
870 .live(&VideoKey::Person(remote.mri.clone()), now)
871 });
872 if let Some(image) = video {
873 return video_tile(
874 size,
875 image,
876 &remote.name,
877 model.tile_speaking(remote),
878 remote.muted,
879 extras,
880 )
881 .into_any_element();
882 }
883 let waiting = remote.state == TileState::Invited;
884 let avatar = person_avatar(
885 &state.directory,
886 remote.user_id.as_deref(),
887 &remote.name,
888 size.avatar,
889 );
890 let caption = model.tile_caption(remote).map(|text| {
891 let label = div()
892 .text_size(px(12.))
893 .text_color(theme::text_muted())
894 .child(text);
895 if waiting {
896 blinking(label)
897 } else {
898 label.into_any_element()
899 }
900 });
901 tile(
902 size,
903 avatar,
904 &remote.name,
905 model.tile_speaking(remote),
906 remote.muted,
907 caption,
908 extras,
909 )
910 .into_any_element()
911}
912
913fn own_tile(
914 app: &Entity<AppState>,
915 state: &AppState,
916 model: &CallModel,
917 size: TileSize,
918 now: Instant,
919) -> AnyElement {
920 let own_mri = model.own_mri.clone().unwrap_or_default();
921 let extras = TileExtras {
922 hand: model.own_hand.map(|rank| model.hand_position(rank)),
923 own: true,
924 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
925 spotlight: model.own_spotlight.is_some(),
926 pinned: model.is_pinned(&own_mri),
927 };
928 let element = own_tile_body(state, model, size, now, &extras);
929 if own_mri.is_empty() {
930 return element;
931 }
932 with_tile_menu(app, model, &own_mri, "You", true, element)
933}
934
935fn own_tile_body(
936 state: &AppState,
937 model: &CallModel,
938 size: TileSize,
939 now: Instant,
940 extras: &TileExtras,
941) -> AnyElement {
942 let me = state.directory.me.as_ref();
943 let self_view = state
944 .call
945 .as_ref()
946 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
947 if let Some(image) = self_view {
948 return video_tile(
949 size,
950 image,
951 "You",
952 model.local_speaking,
953 model.muted,
954 extras,
955 )
956 .into_any_element();
957 }
958 let avatar = person_avatar(
959 &state.directory,
960 me.map(|person| person.user_id.as_str()),
961 me.map_or("You", |person| person.display_name.as_str()),
962 size.avatar,
963 );
964 tile(
965 size,
966 avatar,
967 "You",
968 model.local_speaking,
969 model.muted,
970 None,
971 extras,
972 )
973 .into_any_element()
974}
975
976fn remote_tiles(
977 app: &Entity<AppState>,
978 state: &AppState,
979 model: &CallModel,
980 size: TileSize,
981 hidden_cap: GridLayout,
982 now: Instant,
983) -> Vec<AnyElement> {
984 let visible = model.visible_tiles();
985 let mut cells: Vec<AnyElement> = visible
986 .iter()
987 .take(hidden_cap.shown_others)
988 .map(|remote| person_tile(app, state, model, remote, size, now))
989 .collect();
990 if hidden_cap.hidden > 0 {
991 cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());
992 }
993 cells
994}
995
996fn people_strip(
997 app: &Entity<AppState>,
998 state: &AppState,
999 model: &CallModel,
1000 now: Instant,
1001 focused: Option<&str>,
1002) -> Stateful<Div> {
1003 let mut cells: Vec<AnyElement> = model
1004 .strip_tiles()
1005 .into_iter()
1006 .filter(|remote| Some(remote.mri.as_str()) != focused)
1007 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
1008 .collect();
1009 if focused.is_none() || focused != model.own_mri.as_deref() {
1010 let own_index = model.own_cell_index(cells.len());
1011 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
1012 }
1013 v_flex()
1014 .id("call-strip")
1015 .flex_none()
1016 .w(px(STRIP_TILE.width))
1017 .max_h(px(
1018 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
1019 ))
1020 .gap(px(STRIP_GAP))
1021 .overflow_y_scroll()
1022 .children(cells)
1023}
1024
1025pub fn render_call_view(
1026 app: &Entity<AppState>,
1027 state: &AppState,
1028 chat: Option<Entity<ConversationView>>,
1029) -> Option<AnyElement> {
1030 let call = state.call.as_ref()?;
1031 let model = &call.model;
1032 let now = Instant::now();
1033 let (status, status_color) = status_line(model, now);
1034 let header = h_flex()
1035 .w_full()
1036 .h(px(HEADER_HEIGHT))
1037 .flex_none()
1038 .px(px(20.))
1039 .gap(px(12.))
1040 .items_center()
1041 .child(icon(IconName::Phone, 18., theme::accent_text()))
1042 .child(
1043 div()
1044 .min_w_0()
1045 .truncate()
1046 .text_size(px(16.))
1047 .font_weight(FontWeight::SEMIBOLD)
1048 .child(model.title.clone()),
1049 )
1050 .child(
1051 div()
1052 .flex_none()
1053 .text_size(px(13.))
1054 .text_color(status_color)
1055 .child(status),
1056 )
1057 .children(recording_chip(model))
1058 .children(room_chip(model))
1059 .child(div().flex_1())
1060 .children(return_button(app, model));
1061
1062 let max_tiles = if chat.is_some() {
1063 CHAT_OPEN_TILES
1064 } else {
1065 MAX_TILES
1066 };
1067 let layout = grid_layout(model.visible_tiles().len(), max_tiles);
1068 let cells_for_size = if chat.is_some() {
1069 MAX_TILES
1070 } else {
1071 layout.shown_others + usize::from(layout.hidden > 0) + 1
1072 };
1073 let size = tile_size(cells_for_size);
1074 let mut cells = remote_tiles(app, state, model, size, layout, now);
1075 let own_index = model.own_cell_index(cells.len());
1076 cells.insert(own_index, own_tile(app, state, model, size, now));
1077 let focus = model.focus().filter(|_| model.screen_sharer.is_none());
1078 let stage = render_stage(app, state, false)
1079 .or_else(|| whiteboard_stage(app, model))
1080 .or_else(|| {
1081 focus
1082 .as_ref()
1083 .and_then(|focus| render_focus_stage(app, state, focus, now))
1084 });
1085 let hold = hold_panel(app, model);
1086 let focused = focus.as_ref().map(|focus| focus.mri.as_str());
1087
1088 let controls = h_flex()
1089 .w_full()
1090 .flex_none()
1091 .py(px(16.))
1092 .gap(px(12.))
1093 .items_center()
1094 .justify_center()
1095 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1096 .child(
1097 h_flex()
1098 .h(px(CONTROL_SIZE))
1099 .items_center()
1100 .rounded_full()
1101 .bg(theme::surface_raised())
1102 .child(camera_button(app, model))
1103 .children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1104 )
1105 .child(share_button(app, model, state.call_share_sound))
1106 .when(model.has_reaction_controls(), |row| {
1107 row.child(hand_button(app, model))
1108 .child(reactions_button(app, model))
1109 })
1110 .child(devices_button(app, model))
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 .flex_1()
1165 .min_w_0()
1166 .h_full()
1167 .gap(px(ISLAND_GAP))
1168 .child(column)
1169 .children(chat.map(|chat| chat_panel(app, chat)))
1170 .into_any_element(),
1171 )
1172}
1173
1174fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1175 let app = app.clone();
1176 v_flex()
1177 .id("call-chat-panel")
1178 .w(px(CHAT_PANEL_WIDTH))
1179 .h_full()
1180 .flex_none()
1181 .rounded(px(10.))
1182 .overflow_hidden()
1183 .bg(theme::surface())
1184 .child(
1185 h_flex()
1186 .w_full()
1187 .h(px(CHAT_HEADER_HEIGHT))
1188 .flex_none()
1189 .pl(px(20.))
1190 .pr(px(12.))
1191 .items_center()
1192 .justify_between()
1193 .child(
1194 div()
1195 .text_size(px(15.))
1196 .font_weight(FontWeight::SEMIBOLD)
1197 .child("Chat"),
1198 )
1199 .child(
1200 div()
1201 .id("call-chat-close")
1202 .size(px(28.))
1203 .flex()
1204 .items_center()
1205 .justify_center()
1206 .rounded(px(7.))
1207 .cursor_pointer()
1208 .hover(|button| button.bg(theme::row_hover()))
1209 .tooltip(|window, cx| Tooltip::new("Close the chat").build(window, cx))
1210 .child(icon(IconName::Close, 14., theme::text_muted()))
1211 .on_click(move |_, _, cx| {
1212 app.update(cx, |state, cx| state.toggle_call_chat(cx))
1213 }),
1214 ),
1215 )
1216 .child(chat)
1217 .into_any_element()
1218}