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, 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";
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(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
621 })
622 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))
623}
624
625fn hand_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
626 let raised = model.own_hand.is_some();
627 let background = if raised {
628 theme::accent()
629 } else {
630 theme::surface_raised()
631 };
632 let foreground = if raised {
633 theme::on_accent()
634 } else {
635 theme::text()
636 };
637 let button = control_shell("call-hand", background).child(icon(
638 IconName::Hand,
639 CONTROL_ICON,
640 foreground,
641 ));
642 let tooltip = if raised { "Lower hand" } else { "Raise hand" };
643 let button = button.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx));
644 if !model.can_react() {
645 return button.opacity(DISABLED_OPACITY).cursor_default();
646 }
647 let app = app.clone();
648 button.on_click(move |_, _, cx| {
649 cx.stop_propagation();
650 app.update(cx, |state, cx| state.toggle_call_hand(cx));
651 })
652}
653
654fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
655 let face = control_shell("call-reactions-face", theme::surface_raised()).child(icon(
656 IconName::FaceSlightlySmiling,
657 CONTROL_ICON,
658 theme::text(),
659 ));
660 if !model.can_react() {
661 return face
662 .opacity(DISABLED_OPACITY)
663 .cursor_default()
664 .into_any_element();
665 }
666 let app = app.clone();
667 Popover::new("call-reactions-popover")
668 .anchor(Anchor::BottomLeft)
669 .offset(px(10.))
670 .trigger(
671 Button::new("call-reactions")
672 .ghost()
673 .p_0()
674 .size(px(CONTROL_SIZE))
675 .rounded_full()
676 .child(face),
677 )
678 .content(move |_, _, cx| {
679 let popover = cx.entity().downgrade();
680 h_flex()
681 .id("call-reactions-row")
682 .gap(px(4.))
683 .children(Reaction::ALL.into_iter().map(|reaction| {
684 let app = app.clone();
685 let popover = popover.clone();
686 div()
687 .id(reaction.name())
688 .size(px(REACTION_CELL))
689 .flex()
690 .items_center()
691 .justify_center()
692 .rounded(px(8.))
693 .text_size(px(24.))
694 .cursor_pointer()
695 .hover(|cell| cell.bg(theme::border_strong()))
696 .child(reaction_glyph(reaction))
697 .on_click(move |_, window, cx| {
698 app.update(cx, |state, cx| state.send_call_reaction(reaction, cx));
699 popover
700 .update(cx, |state, cx| state.dismiss(window, cx))
701 .ok();
702 })
703 }))
704 })
705 .into_any_element()
706}
707
708fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
709 let leave_app = app.clone();
710 let end_app = app.clone();
711 let can_end = model.can_end_meeting;
712 let lower_app = app.clone();
713 let can_lower_all = model.can_lower_hands() && model.any_hand_raised();
714 Button::new("call-leave-menu")
715 .ghost()
716 .p_0()
717 .size(px(CONTROL_SIZE))
718 .rounded_full()
719 .child(round_control(
720 "call-leave-menu-face",
721 IconName::ChevronUp,
722 theme::surface_raised(),
723 theme::text(),
724 ))
725 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
726 let leave_app = leave_app.clone();
727 let end_app = end_app.clone();
728 let lower_app = lower_app.clone();
729 let popup = popup.min_w(px(MENU_WIDTH)).item(
730 PopupMenuItem::new("Leave")
731 .icon(IconName::PhoneOff)
732 .on_click(move |_, _, cx| {
733 leave_app.update(cx, |state, cx| state.leave_call(cx))
734 }),
735 );
736 let popup = if can_lower_all {
737 popup.item(
738 PopupMenuItem::new("Lower all hands").on_click(move |_, _, cx| {
739 lower_app.update(cx, |state, cx| state.lower_all_call_hands(cx))
740 }),
741 )
742 } else {
743 popup
744 };
745 if can_end {
746 popup.item(
747 PopupMenuItem::new("End meeting for everyone")
748 .icon(IconName::PhoneOff)
749 .on_click(move |_, _, cx| {
750 end_app.update(cx, |state, cx| state.end_meeting_for_all(cx))
751 }),
752 )
753 } else {
754 popup
755 }
756 })
757}
758
759pub(super) fn device_items(
760 entries: Vec<DeviceEntry>,
761 selected: &calling::DeviceChoice,
762 pick: impl Fn(calling::DeviceChoice, &mut App) + Clone + 'static,
763) -> Vec<PopupMenuItem> {
764 entries
765 .into_iter()
766 .map(|entry| {
767 let pick = pick.clone();
768 let choice = entry.choice.clone();
769 PopupMenuItem::new(entry.label)
770 .checked(&entry.choice == selected)
771 .on_click(move |_, _, cx| pick(choice.clone(), cx))
772 })
773 .collect()
774}
775
776fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
777 let input_app = app.clone();
778 let output_app = app.clone();
779 let inputs = device_items(
780 model.devices.input_entries(),
781 &model.input,
782 move |choice, cx| {
783 input_app.update(cx, |state, cx| state.select_call_input(choice, cx));
784 },
785 );
786 let outputs = device_items(
787 model.devices.output_entries(),
788 &model.output,
789 move |choice, cx| {
790 output_app.update(cx, |state, cx| state.select_call_output(choice, cx));
791 },
792 );
793 let mut popup = popup
794 .min_w(px(MENU_WIDTH))
795 .item(PopupMenuItem::label("Microphone"));
796 if model.listen_only {
797 popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true));
798 } else {
799 for item in inputs {
800 popup = popup.item(item);
801 }
802 }
803 popup = popup.separator().item(PopupMenuItem::label("Speaker"));
804 for item in outputs {
805 popup = popup.item(item);
806 }
807 popup
808}
809
810fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
811 let app = app.clone();
812 let model = model.clone();
813 chevron_button("call-mic-menu", "call-mic-menu-face")
814 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
815 devices_menu(popup, &app, &model)
816 })
817}
818
819fn person_tile(
820 app: &Entity<AppState>,
821 state: &AppState,
822 model: &CallModel,
823 remote: &Tile,
824 size: TileSize,
825 now: Instant,
826) -> AnyElement {
827 let extras = TileExtras {
828 hand: remote.hand.map(|rank| model.hand_position(rank)),
829 own: false,
830 reaction: model
831 .chip_of(&remote.mri, now)
832 .map(|chip| (chip.reaction, chip.serial)),
833 spotlight: remote.spotlight.is_some(),
834 pinned: model.is_pinned(&remote.mri),
835 };
836 let element = person_tile_body(state, model, remote, size, now, &extras);
837 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
838}
839
840fn person_tile_body(
841 state: &AppState,
842 model: &CallModel,
843 remote: &Tile,
844 size: TileSize,
845 now: Instant,
846 extras: &TileExtras,
847) -> AnyElement {
848 let video = state
849 .call
850 .as_ref()
851 .filter(|_| remote.has_video || model.is_one_to_one())
852 .and_then(|call| {
853 call.pictures
854 .live(&VideoKey::Person(remote.mri.clone()), now)
855 });
856 if let Some(image) = video {
857 return video_tile(
858 size,
859 image,
860 &remote.name,
861 model.tile_speaking(remote),
862 remote.muted,
863 extras,
864 )
865 .into_any_element();
866 }
867 let waiting = remote.state == TileState::Invited;
868 let avatar = person_avatar(
869 &state.directory,
870 remote.user_id.as_deref(),
871 &remote.name,
872 size.avatar,
873 );
874 let caption = model.tile_caption(remote).map(|text| {
875 let label = div()
876 .text_size(px(12.))
877 .text_color(theme::text_muted())
878 .child(text);
879 if waiting {
880 blinking(label)
881 } else {
882 label.into_any_element()
883 }
884 });
885 tile(
886 size,
887 avatar,
888 &remote.name,
889 model.tile_speaking(remote),
890 remote.muted,
891 caption,
892 extras,
893 )
894 .into_any_element()
895}
896
897fn own_tile(
898 app: &Entity<AppState>,
899 state: &AppState,
900 model: &CallModel,
901 size: TileSize,
902 now: Instant,
903) -> AnyElement {
904 let own_mri = model.own_mri.clone().unwrap_or_default();
905 let extras = TileExtras {
906 hand: model.own_hand.map(|rank| model.hand_position(rank)),
907 own: true,
908 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
909 spotlight: model.own_spotlight.is_some(),
910 pinned: model.is_pinned(&own_mri),
911 };
912 let element = own_tile_body(state, model, size, now, &extras);
913 if own_mri.is_empty() {
914 return element;
915 }
916 with_tile_menu(app, model, &own_mri, "You", true, element)
917}
918
919fn own_tile_body(
920 state: &AppState,
921 model: &CallModel,
922 size: TileSize,
923 now: Instant,
924 extras: &TileExtras,
925) -> AnyElement {
926 let me = state.directory.me.as_ref();
927 let self_view = state
928 .call
929 .as_ref()
930 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
931 if let Some(image) = self_view {
932 return video_tile(
933 size,
934 image,
935 "You",
936 model.local_speaking,
937 model.muted,
938 extras,
939 )
940 .into_any_element();
941 }
942 let avatar = person_avatar(
943 &state.directory,
944 me.map(|person| person.user_id.as_str()),
945 me.map_or("You", |person| person.display_name.as_str()),
946 size.avatar,
947 );
948 tile(
949 size,
950 avatar,
951 "You",
952 model.local_speaking,
953 model.muted,
954 None,
955 extras,
956 )
957 .into_any_element()
958}
959
960fn remote_tiles(
961 app: &Entity<AppState>,
962 state: &AppState,
963 model: &CallModel,
964 size: TileSize,
965 hidden_cap: GridLayout,
966 now: Instant,
967) -> Vec<AnyElement> {
968 let visible = model.visible_tiles();
969 let mut cells: Vec<AnyElement> = visible
970 .iter()
971 .take(hidden_cap.shown_others)
972 .map(|remote| person_tile(app, state, model, remote, size, now))
973 .collect();
974 if hidden_cap.hidden > 0 {
975 cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());
976 }
977 cells
978}
979
980fn people_strip(
981 app: &Entity<AppState>,
982 state: &AppState,
983 model: &CallModel,
984 now: Instant,
985 focused: Option<&str>,
986) -> Stateful<Div> {
987 let mut cells: Vec<AnyElement> = model
988 .strip_tiles()
989 .into_iter()
990 .filter(|remote| Some(remote.mri.as_str()) != focused)
991 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
992 .collect();
993 if focused.is_none() || focused != model.own_mri.as_deref() {
994 let own_index = model.own_cell_index(cells.len());
995 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
996 }
997 v_flex()
998 .id("call-strip")
999 .flex_none()
1000 .w(px(STRIP_TILE.width))
1001 .max_h(px(
1002 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
1003 ))
1004 .gap(px(STRIP_GAP))
1005 .overflow_y_scroll()
1006 .children(cells)
1007}
1008
1009pub fn render_call_view(
1010 app: &Entity<AppState>,
1011 state: &AppState,
1012 chat: Option<Entity<ConversationView>>,
1013) -> Option<AnyElement> {
1014 let call = state.call.as_ref()?;
1015 let model = &call.model;
1016 let now = Instant::now();
1017 let (status, status_color) = status_line(model, now);
1018 let header = h_flex()
1019 .w_full()
1020 .h(px(HEADER_HEIGHT))
1021 .flex_none()
1022 .px(px(20.))
1023 .gap(px(12.))
1024 .items_center()
1025 .child(icon(IconName::Phone, 18., theme::accent_text()))
1026 .child(
1027 div()
1028 .min_w_0()
1029 .truncate()
1030 .text_size(px(16.))
1031 .font_weight(FontWeight::SEMIBOLD)
1032 .child(model.title.clone()),
1033 )
1034 .child(
1035 div()
1036 .flex_none()
1037 .text_size(px(13.))
1038 .text_color(status_color)
1039 .child(status),
1040 )
1041 .children(recording_chip(model))
1042 .children(room_chip(model))
1043 .child(div().flex_1())
1044 .children(return_button(app, model));
1045
1046 let max_tiles = if chat.is_some() {
1047 CHAT_OPEN_TILES
1048 } else {
1049 MAX_TILES
1050 };
1051 let layout = grid_layout(model.visible_tiles().len(), max_tiles);
1052 let cells_for_size = if chat.is_some() {
1053 MAX_TILES
1054 } else {
1055 layout.shown_others + usize::from(layout.hidden > 0) + 1
1056 };
1057 let size = tile_size(cells_for_size);
1058 let mut cells = remote_tiles(app, state, model, size, layout, now);
1059 let own_index = model.own_cell_index(cells.len());
1060 cells.insert(own_index, own_tile(app, state, model, size, now));
1061 let focus = model.focus().filter(|_| model.screen_sharer.is_none());
1062 let stage = render_stage(app, state, false)
1063 .or_else(|| whiteboard_stage(app, model))
1064 .or_else(|| {
1065 focus
1066 .as_ref()
1067 .and_then(|focus| render_focus_stage(app, state, focus, now))
1068 });
1069 let hold = hold_panel(app, model);
1070 let focused = focus.as_ref().map(|focus| focus.mri.as_str());
1071
1072 let controls = h_flex()
1073 .w_full()
1074 .flex_none()
1075 .py(px(16.))
1076 .gap(px(12.))
1077 .items_center()
1078 .justify_center()
1079 .child(
1080 h_flex()
1081 .h(px(CONTROL_SIZE))
1082 .items_center()
1083 .rounded_full()
1084 .bg(theme::surface_raised())
1085 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1086 .child(mic_menu_button(app, model)),
1087 )
1088 .child(
1089 h_flex()
1090 .h(px(CONTROL_SIZE))
1091 .items_center()
1092 .rounded_full()
1093 .bg(theme::surface_raised())
1094 .child(camera_button(app, model))
1095 .children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1096 )
1097 .child(share_button(app, model, state.call_share_sound))
1098 .when(model.has_reaction_controls(), |row| {
1099 row.child(hand_button(app, model))
1100 .child(reactions_button(app, model))
1101 })
1102 .children(more_button(app, model))
1103 .when(call.chat_thread().is_some(), |row| {
1104 row.child(chat_button(app, call.chat_open, state.call_chat_unread()))
1105 })
1106 .child(leave_button(app, model, "call-leave", false))
1107 .when(model.kind == CallKind::Meeting, |row| {
1108 row.child(leave_menu(app, model))
1109 });
1110
1111 let column = v_flex()
1112 .relative()
1113 .flex_1()
1114 .min_w_0()
1115 .h_full()
1116 .rounded(px(10.))
1117 .overflow_hidden()
1118 .bg(theme::surface())
1119 .child(header)
1120 .children(lobby_banner(app, model))
1121 .children(sharing_banner(app, model, state.call_share_sound))
1122 .children(consult_banner(app, state))
1123 .child(match stage {
1124 _ if hold.is_some() => hold.expect("checked above"),
1125 Some(stage) => h_flex()
1126 .flex_1()
1127 .min_h_0()
1128 .p(px(GRID_PADDING))
1129 .gap(px(TILE_GAP))
1130 .items_center()
1131 .child(stage)
1132 .child(people_strip(app, state, model, now, focused))
1133 .into_any_element(),
1134 None => h_flex()
1135 .id("call-grid")
1136 .flex_1()
1137 .min_h_0()
1138 .overflow_y_scroll()
1139 .flex_wrap()
1140 .content_center()
1141 .p(px(GRID_PADDING))
1142 .gap(px(TILE_GAP))
1143 .items_center()
1144 .justify_center()
1145 .children(cells)
1146 .into_any_element(),
1147 })
1148 .child(controls)
1149 .children(captions_overlay(model, now))
1150 .children(captions_hint_chip(model))
1151 .children(state.transfer_picker.clone())
1152 .children(consent_overlay(app, model));
1153 Some(
1154 h_flex()
1155 .debug_selector(|| "shell/islands/main".into())
1156 .flex_1()
1157 .min_w_0()
1158 .h_full()
1159 .gap(px(ISLAND_GAP))
1160 .child(column)
1161 .children(chat.map(|chat| chat_panel(app, chat)))
1162 .into_any_element(),
1163 )
1164}
1165
1166fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1167 let app = app.clone();
1168 v_flex()
1169 .id("call-chat-panel")
1170 .w(px(CHAT_PANEL_WIDTH))
1171 .h_full()
1172 .flex_none()
1173 .rounded(px(10.))
1174 .overflow_hidden()
1175 .bg(theme::surface())
1176 .child(
1177 h_flex()
1178 .w_full()
1179 .h(px(CHAT_HEADER_HEIGHT))
1180 .flex_none()
1181 .pl(px(20.))
1182 .pr(px(12.))
1183 .items_center()
1184 .justify_between()
1185 .child(
1186 div()
1187 .text_size(px(15.))
1188 .font_weight(FontWeight::SEMIBOLD)
1189 .child("Chat"),
1190 )
1191 .child(
1192 div()
1193 .id("call-chat-close")
1194 .size(px(28.))
1195 .flex()
1196 .items_center()
1197 .justify_center()
1198 .rounded(px(7.))
1199 .cursor_pointer()
1200 .hover(|button| button.bg(theme::row_hover()))
1201 .tooltip(|window, cx| Tooltip::new("Close the chat").build(window, cx))
1202 .child(icon(IconName::Close, 14., theme::text_muted()))
1203 .on_click(move |_, _, cx| {
1204 app.update(cx, |state, cx| state.toggle_call_chat(cx))
1205 }),
1206 ),
1207 )
1208 .child(chat)
1209 .into_any_element()
1210}