BlueGit

ict rusty-teams

Files

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

call_view.rs

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