BlueGit

ict rusty-teams

Files

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

call_view.rs

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