BlueGit

ict rusty-teams

Files

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

call_view.rs

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