BlueGit

ict rusty-teams

Files

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

call_view.rs

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