BlueGit

ict rusty-teams

Files

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

call_view.rs

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