BlueGit

ict rusty-teams

Files

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

call_view.rs

call_view.rs 44.1 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 element = plain_person_tile(state, model, remote, size, now);
968 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
969}
970
971pub(super) fn plain_person_tile(
972 state: &AppState,
973 model: &CallModel,
974 remote: &Tile,
975 size: TileSize,
976 now: Instant,
977) -> AnyElement {
978 let extras = TileExtras {
979 hand: remote.hand.map(|rank| model.hand_position(rank)),
980 own: false,
981 reaction: model
982 .chip_of(&remote.mri, now)
983 .map(|chip| (chip.reaction, chip.serial)),
984 spotlight: remote.spotlight.is_some(),
985 pinned: model.is_pinned(&remote.mri),
986 };
987 person_tile_body(state, model, remote, size, now, &extras)
988}
989
990fn person_tile_body(
991 state: &AppState,
992 model: &CallModel,
993 remote: &Tile,
994 size: TileSize,
995 now: Instant,
996 extras: &TileExtras,
997) -> AnyElement {
998 let video = state
999 .call
1000 .as_ref()
1001 .filter(|_| remote.has_video || model.is_one_to_one())
1002 .and_then(|call| {
1003 call.pictures
1004 .live(&VideoKey::Person(remote.mri.clone()), now)
1005 });
1006 if let Some(image) = video {
1007 return video_tile(
1008 size,
1009 image,
1010 &remote.name,
1011 model.tile_speaking(remote),
1012 remote.muted,
1013 extras,
1014 )
1015 .into_any_element();
1016 }
1017 let waiting = remote.state == TileState::Invited;
1018 let avatar = person_avatar(
1019 &state.directory,
1020 remote.user_id.as_deref(),
1021 &remote.name,
1022 size.avatar,
1023 );
1024 let caption = model.tile_caption(remote).map(|text| {
1025 let label = div()
1026 .text_size(px(12.))
1027 .text_color(theme::text_muted())
1028 .child(text);
1029 if waiting {
1030 blinking(label)
1031 } else {
1032 label.into_any_element()
1033 }
1034 });
1035 tile(
1036 size,
1037 avatar,
1038 &remote.name,
1039 model.tile_speaking(remote),
1040 remote.muted,
1041 caption,
1042 extras,
1043 )
1044 .into_any_element()
1045}
1046
1047pub(super) fn own_tile(
1048 app: &Entity<AppState>,
1049 state: &AppState,
1050 model: &CallModel,
1051 size: TileSize,
1052 now: Instant,
1053) -> AnyElement {
1054 let own_mri = model.own_mri.clone().unwrap_or_default();
1055 let element = plain_own_tile(state, model, size, now);
1056 if own_mri.is_empty() {
1057 return element;
1058 }
1059 with_tile_menu(app, model, &own_mri, "You", true, element)
1060}
1061
1062pub(super) fn plain_own_tile(
1063 state: &AppState,
1064 model: &CallModel,
1065 size: TileSize,
1066 now: Instant,
1067) -> AnyElement {
1068 let own_mri = model.own_mri.as_deref().unwrap_or_default();
1069 let extras = TileExtras {
1070 hand: model.own_hand.map(|rank| model.hand_position(rank)),
1071 own: true,
1072 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
1073 spotlight: model.own_spotlight.is_some(),
1074 pinned: model.is_pinned(own_mri),
1075 };
1076 own_tile_body(state, model, size, now, &extras)
1077}
1078
1079fn own_tile_body(
1080 state: &AppState,
1081 model: &CallModel,
1082 size: TileSize,
1083 now: Instant,
1084 extras: &TileExtras,
1085) -> AnyElement {
1086 let me = state.directory.me.as_ref();
1087 let self_view = state
1088 .call
1089 .as_ref()
1090 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
1091 if let Some(image) = self_view {
1092 return video_tile(
1093 size,
1094 image,
1095 "You",
1096 model.local_speaking,
1097 model.muted,
1098 extras,
1099 )
1100 .into_any_element();
1101 }
1102 let avatar = person_avatar(
1103 &state.directory,
1104 me.map(|person| person.user_id.as_str()),
1105 me.map_or("You", |person| person.display_name.as_str()),
1106 size.avatar,
1107 );
1108 tile(
1109 size,
1110 avatar,
1111 "You",
1112 model.local_speaking,
1113 model.muted,
1114 None,
1115 extras,
1116 )
1117 .into_any_element()
1118}
1119
1120fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> FoldedControls {
1121 let model = &call.model;
1122 let has_more = model.kind != CallKind::Test;
1123 if !has_more {
1124 return FoldedControls::default();
1125 }
1126 let mut present = vec![Foldable::View];
1127 if model.has_reaction_controls() {
1128 present.extend([Foldable::Reactions, Foldable::RaiseHand]);
1129 }
1130 if model.kind != CallKind::Test {
1131 present.push(Foldable::People);
1132 }
1133 if call.chat_thread().is_some() {
1134 present.push(Foldable::Chat);
1135 }
1136 let fixed = fixed_controls_width(
1137 model.can_use_camera(),
1138 has_more,
1139 has_leave_menu(model),
1140 );
1141 FoldedControls {
1142 items: folded_for_width(measured_stage(call).0, fixed, &present),
1143 fullscreen,
1144 people_open: call.people_open,
1145 chat_open: call.chat_open,
1146 chat_unread: state.call_chat_unread(),
1147 }
1148}
1149
1150pub fn render_call_view(
1151 app: &Entity<AppState>,
1152 state: &AppState,
1153 chat: Option<AnyView>,
1154 fullscreen: bool,
1155 island_width: f32,
1156) -> Option<AnyElement> {
1157 let call = state.call.as_ref()?;
1158 let model = &call.model;
1159 let now = Instant::now();
1160 let (status, status_color) = status_line(model, now);
1161 let header = h_flex()
1162 .w_full()
1163 .h(px(HEADER_HEIGHT))
1164 .flex_none()
1165 .px(px(20.))
1166 .gap(px(12.))
1167 .items_center()
1168 .child(icon(IconName::Phone, 18., theme::accent_text()))
1169 .child(
1170 div()
1171 .min_w_0()
1172 .truncate()
1173 .text_size(px(16.))
1174 .font_weight(FontWeight::SEMIBOLD)
1175 .child(model.title.clone()),
1176 )
1177 .child(
1178 div()
1179 .flex_none()
1180 .text_size(px(13.))
1181 .text_color(status_color)
1182 .child(status),
1183 )
1184 .children(health_indicator(model))
1185 .children(recording_chip(model))
1186 .children(lock_chip(model))
1187 .children(room_chip(model))
1188 .child(div().flex_1())
1189 .children(return_button(app, model));
1190
1191 let hold = hold_panel(app, model);
1192 let share_stage = share_stage_element(app, state, call);
1193 let region = stage_region(app, state, call, now, hold, share_stage);
1194
1195 let folded = folded_controls(state, call, fullscreen);
1196 let controls = h_flex()
1197 .w_full()
1198 .flex_none()
1199 .py(px(16.))
1200 .px(px(CONTROLS_PADDING))
1201 .gap(px(CONTROL_GAP))
1202 .items_center()
1203 .justify_center()
1204 .child(
1205 h_flex()
1206 .debug_selector(|| "shell/islands/main/call-controls/mic".into())
1207 .h(px(CONTROL_SIZE))
1208 .items_center()
1209 .rounded_full()
1210 .bg(theme::surface_raised())
1211 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1212 .child(mic_menu_button(app, model, state.call_mic)),
1213 )
1214 .child(
1215 h_flex()
1216 .h(px(CONTROL_SIZE))
1217 .items_center()
1218 .rounded_full()
1219 .bg(theme::surface_raised())
1220 .child(camera_button(app, model))
1221 .children(camera_menu_button(app, model, CameraMenu::of(state))),
1222 )
1223 .child(share_button(
1224 app,
1225 model,
1226 ShareOptions::of(state),
1227 call.share_menu_open,
1228 ))
1229 .when(
1230 model.has_reaction_controls() && !folded.folds(Foldable::RaiseHand),
1231 |row| row.child(hand_button(app, model)),
1232 )
1233 .when(
1234 model.has_reaction_controls() && !folded.folds(Foldable::Reactions),
1235 |row| row.child(reactions_button(app, model)),
1236 )
1237 .when(!folded.folds(Foldable::View), |row| {
1238 row.child(view_button(app, model, fullscreen))
1239 })
1240 .children(more_button(app, model, &folded))
1241 .when(
1242 model.kind != CallKind::Test && !folded.folds(Foldable::People),
1243 |row| row.child(people_button(app, call.people_open, model.raised_hands())),
1244 )
1245 .when(
1246 call.chat_thread().is_some() && !folded.folds(Foldable::Chat),
1247 |row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())),
1248 )
1249 .child(
1250 leave_button(app, model, "call-leave", false)
1251 .debug_selector(|| "shell/islands/main/call-controls/leave".into()),
1252 )
1253 .when(has_leave_menu(model), |row| row.child(leave_menu(app, model)));
1254
1255 let top = v_flex()
1256 .w_full()
1257 .flex_none()
1258 .child(header)
1259 .children(lobby_banner(app, model, call.lobby_list_open))
1260 .children(lock_banner(app, model))
1261 .children(health_banner(app, model))
1262 .children(sharing_banner(app, model, state.call_share_sound))
1263 .children(consult_banner(app, state));
1264
1265 let chrome_visible = call
1266 .fullscreen
1267 .is_none_or(|fullscreen| fullscreen.chrome_visible(now));
1268 let move_app = app.clone();
1269 let base = v_flex()
1270 .relative()
1271 .flex_1()
1272 .min_w_0()
1273 .h_full()
1274 .overflow_hidden()
1275 .bg(theme::surface());
1276 let column = if fullscreen {
1277 base.on_mouse_move(move |_, _, cx| {
1278 move_app.update(cx, |state, cx| state.touch_call_chrome(cx))
1279 })
1280 .when(chrome_visible, |column| {
1281 column.child(fullscreen_chrome("call-chrome-top", app, top))
1282 })
1283 .child(region)
1284 .when(chrome_visible, |column| {
1285 column.child(fullscreen_chrome("call-chrome-bottom", app, controls))
1286 })
1287 } else {
1288 base.rounded(px(10.))
1289 .child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1290 .child(region)
1291 .child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))
1292 }
1293 .children(captions_overlay(model, now))
1294 .children(captions_hint_chip(model))
1295 .children(push_to_talk_chip(call))
1296 .children(state.transfer_picker.clone())
1297 .children(options_dialog(app, call))
1298 .children(consent_overlay(app, model));
1299 let panels: Vec<AnyElement> = chat
1300 .map(|chat| chat_panel(app, chat))
1301 .into_iter()
1302 .chain(
1303 call.transcript_open
1304 .then(|| state.transcript_panel.clone())
1305 .flatten()
1306 .map(IntoElement::into_any_element),
1307 )
1308 .chain(people_panel(app, state, call))
1309 .collect();
1310 Some(
1311 h_flex()
1312 .relative()
1313 .when(!fullscreen, |row| {
1314 row.debug_selector(|| "shell/islands/main".into())
1315 })
1316 .flex_1()
1317 .min_w_0()
1318 .h_full()
1319 .gap(px(ISLAND_GAP))
1320 .child(column)
1321 .children(side_panels(panels, island_width))
1322 .into_any_element(),
1323 )
1324}
1325
1326fn side_panels(panels: Vec<AnyElement>, island_width: f32) -> Vec<AnyElement> {
1327 if panels.is_empty() {
1328 return panels;
1329 }
1330 let panels_width = (CHAT_PANEL_WIDTH + ISLAND_GAP) * panels.len() as f32;
1331 if island_width - panels_width >= OVERLAY_BELOW {
1332 return panels;
1333 }
1334 vec![
1335 h_flex()
1336 .absolute()
1337 .top_0()
1338 .right_0()
1339 .bottom(px(CONTROLS_HEIGHT))
1340 .gap(px(ISLAND_GAP))
1341 .w(px(panels_width.min(island_width)))
1342 .children(panels)
1343 .into_any_element(),
1344 ]
1345}
1346
1347fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
1348 let hover_app = app.clone();
1349 div()
1350 .id(id)
1351 .w_full()
1352 .flex_none()
1353 .on_hover(move |hovered, _, cx| {
1354 hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))
1355 })
1356 .child(content)
1357}
1358
1359fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement {
1360 let app = app.clone();
1361 side_panel(
1362 "call-chat-panel",
1363 "Chat",
1364 "Close the chat",
1365 move |cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)),
1366 chat,
1367 )
1368 .debug_selector(|| CHAT_PANEL_TAG.into())
1369 .into_any_element()
1370}
1371
1372pub fn side_panel(
1373 panel_id: &'static str,
1374 title: &'static str,
1375 close_tooltip: &'static str,
1376 on_close: impl Fn(&mut App) + 'static,
1377 body: impl IntoElement,
1378) -> Stateful<Div> {
1379 v_flex()
1380 .id(panel_id)
1381 .w(px(CHAT_PANEL_WIDTH))
1382 .h_full()
1383 .flex_shrink(1.)
1384 .min_w_0()
1385 .rounded(px(10.))
1386 .overflow_hidden()
1387 .bg(theme::surface())
1388 .child(
1389 h_flex()
1390 .w_full()
1391 .h(px(CHAT_HEADER_HEIGHT))
1392 .flex_none()
1393 .pl(px(20.))
1394 .pr(px(12.))
1395 .items_center()
1396 .justify_between()
1397 .child(
1398 div()
1399 .text_size(px(15.))
1400 .font_weight(FontWeight::SEMIBOLD)
1401 .child(title),
1402 )
1403 .child(
1404 div()
1405 .id(ElementId::Name(format!("{panel_id}-close").into()))
1406 .size(px(28.))
1407 .flex()
1408 .items_center()
1409 .justify_center()
1410 .rounded(px(7.))
1411 .cursor_pointer()
1412 .hover(|button| button.bg(theme::row_hover()))
1413 .tooltip(move |window, cx| Tooltip::new(close_tooltip).build(window, cx))
1414 .child(icon(IconName::Close, 14., theme::text_muted()))
1415 .on_click(move |_, _, cx| on_close(cx)),
1416 ),
1417 )
1418 .child(body)
1419}