BlueGit

ict rusty-teams

Files

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

call_view.rs

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