BlueGit

ict rusty-teams

Files

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

call_view.rs

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