BlueGit

ict rusty-teams

Files

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

call_view.rs

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