BlueGit

ict rusty-teams

Files

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

call_view.rs

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