BlueGit

ict rusty-teams

Files

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

call_view.rs

merge: call audio options
metis Daniel Däschle · pushed by metis · 7 weeks ago
7da9ed2a History
call_view.rs 38.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_extras::{
20 BackgroundMenu, 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_stage::render_stage;
30use super::call_view_menu::view_button;
31use super::conversation::ConversationView;
32use super::shell::ISLAND_GAP;
33use super::widgets::{Corner, corner_badge, count_badge, icon};
34use crate::app_state::AppState;
35use crate::call::REACTION_SHOWN;
36use crate::call::TileSize;
37use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState};
38use crate::rows::reaction_glyph as chat_reaction_glyph;
39use crate::theme;
40
41const HEADER_HEIGHT: f32 = 60.;
42const RING_WIDTH: f32 = 3.;
43const RING_GAP: f32 = 4.;
44pub(super) const CONTROL_SIZE: f32 = 44.;
45const CONTROL_ICON: f32 = 20.;
46pub(super) const MENU_WIDTH: f32 = 280.;
47const PULSE_PERIOD: Duration = Duration::from_millis(1400);
48const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
49const BLINK_DIMMED_OPACITY: f32 = 0.45;
50pub(super) const DISABLED_OPACITY: f32 = 0.4;
51pub(super) const TILE_GAP: f32 = 20.;
52pub(super) const GRID_PADDING: f32 = 24.;
53pub(super) const STRIP_TILE: TileSize = TileSize {
54 width: 232.,
55 height: 131.,
56 avatar: 56.,
57};
58pub(super) const STRIP_GAP: f32 = 12.;
59pub(super) const STRIP_VISIBLE: f32 = 4.;
60const TILE_RADIUS: f32 = 12.;
61const NAME_PLATE_BACKGROUND: f32 = 0.6;
62pub const NO_MICROPHONE_HINT: &str = "No microphone found";
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 const CHAT_PANEL_WIDTH: f32 = 320.;
70const CHAT_HEADER_HEIGHT: f32 = 48.;
71const REACTION_RISE: f32 = 24.;
72const REACTION_FADE_FROM: f32 = 0.75;
73const REACTION_CELL: f32 = 40.;
74const SHARE_SOUND_LABEL: &str = "Include computer sound";
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 return button
354 .opacity(DISABLED_OPACITY)
355 .cursor_default()
356 .tooltip(|window, cx| Tooltip::new(NO_MICROPHONE_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
404pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
405 let (glyph, background, foreground) = if model.camera_on {
406 (IconName::Video, theme::accent(), theme::on_accent())
407 } else {
408 (IconName::VideoOff, theme::surface_raised(), theme::text())
409 };
410 let button = round_control("call-camera", glyph, background, foreground);
411 if !model.can_use_camera() {
412 return button
413 .opacity(DISABLED_OPACITY)
414 .cursor_default()
415 .tooltip(|window, cx| Tooltip::new(NO_CAMERA_HINT).build(window, cx));
416 }
417 let app = app.clone();
418 button.on_click(move |_, _, cx| {
419 cx.stop_propagation();
420 app.update(cx, |state, cx| state.toggle_call_camera(cx));
421 })
422}
423
424fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
425 let app = app.clone();
426 PopupMenuItem::element(move |_, _| {
427 h_flex()
428 .id("call-share-sound-row")
429 .w_full()
430 .gap(px(16.))
431 .items_center()
432 .justify_between()
433 .child(SHARE_SOUND_LABEL)
434 .child(Switch::new("call-share-sound").checked(sound))
435 })
436 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
437}
438
439fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
440 let app = app.clone();
441 PopupMenuItem::element(move |_, _| {
442 h_flex()
443 .id("call-music-mode-row")
444 .w_full()
445 .gap(px(16.))
446 .items_center()
447 .justify_between()
448 .child(MUSIC_MODE_LABEL)
449 .child(Switch::new("call-music-mode").checked(mic.music_mode))
450 })
451 .on_click(move |_, _, cx| {
452 app.update(cx, |state, cx| {
453 let settings = MicSettings {
454 music_mode: !mic.music_mode,
455 ..state.call_mic
456 };
457 state.set_call_mic(settings, cx)
458 })
459 })
460}
461
462fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {
463 call.push_to_talk.is_held().then(|| {
464 div()
465 .id("call-push-to-talk")
466 .absolute()
467 .top(px(HEADER_HEIGHT + PUSH_TO_TALK_TOP))
468 .left_0()
469 .right_0()
470 .flex()
471 .justify_center()
472 .child(
473 div()
474 .debug_selector(|| "call/push-to-talk".into())
475 .px(px(12.))
476 .py(px(6.))
477 .rounded_full()
478 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
479 .text_color(theme::white())
480 .text_size(px(13.))
481 .child(PUSH_TO_TALK_HINT),
482 )
483 .into_any_element()
484 })
485}
486
487fn share_items(
488 popup: PopupMenu,
489 app: &Entity<AppState>,
490 model: &CallModel,
491 sound: bool,
492) -> PopupMenu {
493 let screens = model.screens();
494 let single_screen = screens.len() == 1;
495 let mut popup = popup
496 .min_w(px(MENU_WIDTH))
497 .item(sound_switch_item(app, sound))
498 .separator();
499 for (index, source) in screens.into_iter().enumerate() {
500 let label = if single_screen {
501 "Share entire screen".to_owned()
502 } else {
503 format!("Share screen {}", index + 1)
504 };
505 let source = source.clone();
506 let app = app.clone();
507 popup = popup.item(PopupMenuItem::new(label).icon(IconName::Monitor).on_click(
508 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
509 ));
510 }
511 popup = popup
512 .separator()
513 .item(PopupMenuItem::label("Share a window..."));
514 let windows = model.windows();
515 if windows.is_empty() {
516 return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));
517 }
518 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
519 let label = source.label();
520 let source = source.clone();
521 let app = app.clone();
522 popup = popup.item(
523 PopupMenuItem::new(label)
524 .icon(IconName::AppWindow)
525 .on_click(move |_, _, cx| {
526 app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))
527 }),
528 );
529 }
530 popup
531}
532
533fn share_button(
534 app: &Entity<AppState>,
535 model: &CallModel,
536 sound: bool,
537 menu_open: bool,
538) -> AnyElement {
539 if model.local_share.is_some() {
540 let app = app.clone();
541 return round_control(
542 "call-share-stop",
543 IconName::ScreenShareOff,
544 theme::accent(),
545 theme::on_accent(),
546 )
547 .tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))
548 .on_click(move |_, _, cx| {
549 cx.stop_propagation();
550 app.update(cx, |state, cx| state.stop_call_share(cx));
551 })
552 .into_any_element();
553 }
554 let face = round_control(
555 "call-share-face",
556 IconName::ScreenShare,
557 theme::surface_raised(),
558 theme::text(),
559 );
560 if !model.can_share() {
561 return face
562 .opacity(DISABLED_OPACITY)
563 .cursor_default()
564 .tooltip(|window, cx| Tooltip::new(NO_SHARE_HINT).build(window, cx))
565 .into_any_element();
566 }
567 let app = app.clone();
568 let open_app = app.clone();
569 let model = model.clone();
570 Button::new("call-share")
571 .ghost()
572 .p_0()
573 .size(px(CONTROL_SIZE))
574 .rounded_full()
575 .child(face)
576 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
577 share_items(popup, &app, &model, sound)
578 })
579 .open(menu_open)
580 .on_open_change(move |open, _, cx| {
581 open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx))
582 })
583 .into_any_element()
584}
585
586fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Option<AnyElement> {
587 let label = model.local_share.as_ref()?;
588 let sound_app = app.clone();
589 let app = app.clone();
590 Some(
591 h_flex()
592 .id("call-sharing-banner")
593 .w_full()
594 .h(px(BANNER_HEIGHT))
595 .flex_none()
596 .px(px(20.))
597 .gap(px(12.))
598 .items_center()
599 .justify_center()
600 .bg(theme::accent())
601 .text_color(theme::on_accent())
602 .text_size(px(13.))
603 .font_weight(FontWeight::SEMIBOLD)
604 .child(icon(IconName::ScreenShare, 16., theme::on_accent()))
605 .child(format!("You are sharing: {label}"))
606 .child(
607 div()
608 .id("call-sharing-sound")
609 .h(px(26.))
610 .px(px(12.))
611 .flex()
612 .items_center()
613 .rounded_full()
614 .bg(theme::on_accent().opacity(0.2))
615 .cursor_pointer()
616 .hover(|button| button.opacity(0.9))
617 .child(if sound {
618 "Computer sound on"
619 } else {
620 "Computer sound off"
621 })
622 .on_click(move |_, _, cx| {
623 sound_app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))
624 }),
625 )
626 .child(
627 div()
628 .id("call-sharing-stop")
629 .h(px(26.))
630 .px(px(12.))
631 .flex()
632 .items_center()
633 .rounded_full()
634 .bg(theme::on_accent())
635 .text_color(theme::accent())
636 .cursor_pointer()
637 .hover(|button| button.opacity(0.9))
638 .child("Stop sharing")
639 .on_click(move |_, _, cx| {
640 app.update(cx, |state, cx| state.stop_call_share(cx))
641 }),
642 )
643 .into_any_element(),
644 )
645}
646
647fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {
648 let app = app.clone();
649 let (background, foreground) = if open {
650 (theme::accent(), theme::on_accent())
651 } else {
652 (theme::surface_raised(), theme::text())
653 };
654 round_control("call-chat", IconName::MessageCircle, background, foreground)
655 .relative()
656 .tooltip(move |window, cx| {
657 Tooltip::new(if open {
658 "Close the chat"
659 } else {
660 "Open the chat"
661 })
662 .build(window, cx)
663 })
664 .when(unread > 0, |button| {
665 button.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
666 })
667 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))
668}
669
670fn hand_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
671 let raised = model.own_hand.is_some();
672 let background = if raised {
673 theme::accent()
674 } else {
675 theme::surface_raised()
676 };
677 let foreground = if raised {
678 theme::on_accent()
679 } else {
680 theme::text()
681 };
682 let button = control_shell("call-hand", background).child(icon(
683 IconName::Hand,
684 CONTROL_ICON,
685 foreground,
686 ));
687 let tooltip = if raised { "Lower hand" } else { "Raise hand" };
688 let button = button.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx));
689 if !model.can_react() {
690 return button.opacity(DISABLED_OPACITY).cursor_default();
691 }
692 let app = app.clone();
693 button.on_click(move |_, _, cx| {
694 cx.stop_propagation();
695 app.update(cx, |state, cx| state.toggle_call_hand(cx));
696 })
697}
698
699fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
700 let face = control_shell("call-reactions-face", theme::surface_raised()).child(icon(
701 IconName::FaceSlightlySmiling,
702 CONTROL_ICON,
703 theme::text(),
704 ));
705 if !model.can_react() {
706 return face
707 .opacity(DISABLED_OPACITY)
708 .cursor_default()
709 .into_any_element();
710 }
711 let app = app.clone();
712 Popover::new("call-reactions-popover")
713 .anchor(Anchor::BottomLeft)
714 .offset(px(10.))
715 .trigger(
716 Button::new("call-reactions")
717 .ghost()
718 .p_0()
719 .size(px(CONTROL_SIZE))
720 .rounded_full()
721 .child(face),
722 )
723 .content(move |_, _, cx| {
724 let popover = cx.entity().downgrade();
725 h_flex()
726 .id("call-reactions-row")
727 .gap(px(4.))
728 .children(Reaction::ALL.into_iter().map(|reaction| {
729 let app = app.clone();
730 let popover = popover.clone();
731 div()
732 .id(reaction.name())
733 .size(px(REACTION_CELL))
734 .flex()
735 .items_center()
736 .justify_center()
737 .rounded(px(8.))
738 .text_size(px(24.))
739 .cursor_pointer()
740 .hover(|cell| cell.bg(theme::border_strong()))
741 .child(reaction_glyph(reaction))
742 .on_click(move |_, window, cx| {
743 app.update(cx, |state, cx| state.send_call_reaction(reaction, cx));
744 popover
745 .update(cx, |state, cx| state.dismiss(window, cx))
746 .ok();
747 })
748 }))
749 })
750 .into_any_element()
751}
752
753fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
754 let leave_app = app.clone();
755 let end_app = app.clone();
756 let can_end = model.can_end_meeting;
757 let lower_app = app.clone();
758 let can_lower_all = model.can_lower_hands() && model.any_hand_raised();
759 Button::new("call-leave-menu")
760 .ghost()
761 .p_0()
762 .size(px(CONTROL_SIZE))
763 .rounded_full()
764 .child(round_control(
765 "call-leave-menu-face",
766 IconName::ChevronUp,
767 theme::surface_raised(),
768 theme::text(),
769 ))
770 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
771 let leave_app = leave_app.clone();
772 let end_app = end_app.clone();
773 let lower_app = lower_app.clone();
774 let popup = popup.min_w(px(MENU_WIDTH)).item(
775 PopupMenuItem::new("Leave")
776 .icon(IconName::PhoneOff)
777 .on_click(move |_, _, cx| {
778 leave_app.update(cx, |state, cx| state.leave_call(cx))
779 }),
780 );
781 let popup = if can_lower_all {
782 popup.item(
783 PopupMenuItem::new("Lower all hands").on_click(move |_, _, cx| {
784 lower_app.update(cx, |state, cx| state.lower_all_call_hands(cx))
785 }),
786 )
787 } else {
788 popup
789 };
790 if can_end {
791 popup.item(
792 PopupMenuItem::new("End meeting for everyone")
793 .icon(IconName::PhoneOff)
794 .on_click(move |_, _, cx| {
795 end_app.update(cx, |state, cx| state.end_meeting_for_all(cx))
796 }),
797 )
798 } else {
799 popup
800 }
801 })
802}
803
804pub(super) fn device_items(
805 entries: Vec<DeviceEntry>,
806 selected: &calling::DeviceChoice,
807 pick: impl Fn(calling::DeviceChoice, &mut App) + Clone + 'static,
808) -> Vec<PopupMenuItem> {
809 entries
810 .into_iter()
811 .map(|entry| {
812 let pick = pick.clone();
813 let choice = entry.choice.clone();
814 PopupMenuItem::new(entry.label)
815 .checked(&entry.choice == selected)
816 .on_click(move |_, _, cx| pick(choice.clone(), cx))
817 })
818 .collect()
819}
820
821fn devices_menu(
822 popup: PopupMenu,
823 app: &Entity<AppState>,
824 model: &CallModel,
825 mic: MicSettings,
826) -> PopupMenu {
827 let input_app = app.clone();
828 let output_app = app.clone();
829 let inputs = device_items(
830 model.devices.input_entries(),
831 &model.input,
832 move |choice, cx| {
833 input_app.update(cx, |state, cx| state.select_call_input(choice, cx));
834 },
835 );
836 let outputs = device_items(
837 model.devices.output_entries(),
838 &model.output,
839 move |choice, cx| {
840 output_app.update(cx, |state, cx| state.select_call_output(choice, cx));
841 },
842 );
843 let mut popup = popup
844 .min_w(px(MENU_WIDTH))
845 .item(PopupMenuItem::label("Microphone"));
846 if model.listen_only {
847 popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true));
848 } else {
849 for item in inputs {
850 popup = popup.item(item);
851 }
852 }
853 popup = popup
854 .separator()
855 .item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL));
856 for level in NoiseSuppression::ALL {
857 let level_app = app.clone();
858 popup = popup.item(
859 PopupMenuItem::new(level.label())
860 .checked(level == mic.noise_suppression)
861 .disabled(mic.music_mode)
862 .on_click(move |_, _, cx| {
863 level_app.update(cx, |state, cx| {
864 let settings = MicSettings {
865 noise_suppression: level,
866 ..state.call_mic
867 };
868 state.set_call_mic(settings, cx)
869 })
870 }),
871 );
872 }
873 popup = popup
874 .item(music_mode_item(app, mic))
875 .separator()
876 .item(PopupMenuItem::label("Speaker"));
877 for item in outputs {
878 popup = popup.item(item);
879 }
880 popup
881}
882
883fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {
884 let app = app.clone();
885 let model = model.clone();
886 chevron_button("call-mic-menu", "call-mic-menu-face")
887 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
888 devices_menu(popup, &app, &model, mic)
889 })
890}
891
892pub(super) fn person_tile(
893 app: &Entity<AppState>,
894 state: &AppState,
895 model: &CallModel,
896 remote: &Tile,
897 size: TileSize,
898 now: Instant,
899) -> AnyElement {
900 let extras = TileExtras {
901 hand: remote.hand.map(|rank| model.hand_position(rank)),
902 own: false,
903 reaction: model
904 .chip_of(&remote.mri, now)
905 .map(|chip| (chip.reaction, chip.serial)),
906 spotlight: remote.spotlight.is_some(),
907 pinned: model.is_pinned(&remote.mri),
908 };
909 let element = person_tile_body(state, model, remote, size, now, &extras);
910 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
911}
912
913fn person_tile_body(
914 state: &AppState,
915 model: &CallModel,
916 remote: &Tile,
917 size: TileSize,
918 now: Instant,
919 extras: &TileExtras,
920) -> AnyElement {
921 let video = state
922 .call
923 .as_ref()
924 .filter(|_| remote.has_video || model.is_one_to_one())
925 .and_then(|call| {
926 call.pictures
927 .live(&VideoKey::Person(remote.mri.clone()), now)
928 });
929 if let Some(image) = video {
930 return video_tile(
931 size,
932 image,
933 &remote.name,
934 model.tile_speaking(remote),
935 remote.muted,
936 extras,
937 )
938 .into_any_element();
939 }
940 let waiting = remote.state == TileState::Invited;
941 let avatar = person_avatar(
942 &state.directory,
943 remote.user_id.as_deref(),
944 &remote.name,
945 size.avatar,
946 );
947 let caption = model.tile_caption(remote).map(|text| {
948 let label = div()
949 .text_size(px(12.))
950 .text_color(theme::text_muted())
951 .child(text);
952 if waiting {
953 blinking(label)
954 } else {
955 label.into_any_element()
956 }
957 });
958 tile(
959 size,
960 avatar,
961 &remote.name,
962 model.tile_speaking(remote),
963 remote.muted,
964 caption,
965 extras,
966 )
967 .into_any_element()
968}
969
970pub(super) fn own_tile(
971 app: &Entity<AppState>,
972 state: &AppState,
973 model: &CallModel,
974 size: TileSize,
975 now: Instant,
976) -> AnyElement {
977 let own_mri = model.own_mri.clone().unwrap_or_default();
978 let extras = TileExtras {
979 hand: model.own_hand.map(|rank| model.hand_position(rank)),
980 own: true,
981 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
982 spotlight: model.own_spotlight.is_some(),
983 pinned: model.is_pinned(&own_mri),
984 };
985 let element = own_tile_body(state, model, size, now, &extras);
986 if own_mri.is_empty() {
987 return element;
988 }
989 with_tile_menu(app, model, &own_mri, "You", true, element)
990}
991
992fn own_tile_body(
993 state: &AppState,
994 model: &CallModel,
995 size: TileSize,
996 now: Instant,
997 extras: &TileExtras,
998) -> AnyElement {
999 let me = state.directory.me.as_ref();
1000 let self_view = state
1001 .call
1002 .as_ref()
1003 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
1004 if let Some(image) = self_view {
1005 return video_tile(
1006 size,
1007 image,
1008 "You",
1009 model.local_speaking,
1010 model.muted,
1011 extras,
1012 )
1013 .into_any_element();
1014 }
1015 let avatar = person_avatar(
1016 &state.directory,
1017 me.map(|person| person.user_id.as_str()),
1018 me.map_or("You", |person| person.display_name.as_str()),
1019 size.avatar,
1020 );
1021 tile(
1022 size,
1023 avatar,
1024 "You",
1025 model.local_speaking,
1026 model.muted,
1027 None,
1028 extras,
1029 )
1030 .into_any_element()
1031}
1032
1033pub fn render_call_view(
1034 app: &Entity<AppState>,
1035 state: &AppState,
1036 chat: Option<Entity<ConversationView>>,
1037 fullscreen: bool,
1038) -> Option<AnyElement> {
1039 let call = state.call.as_ref()?;
1040 let model = &call.model;
1041 let now = Instant::now();
1042 let (status, status_color) = status_line(model, now);
1043 let header = h_flex()
1044 .w_full()
1045 .h(px(HEADER_HEIGHT))
1046 .flex_none()
1047 .px(px(20.))
1048 .gap(px(12.))
1049 .items_center()
1050 .child(icon(IconName::Phone, 18., theme::accent_text()))
1051 .child(
1052 div()
1053 .min_w_0()
1054 .truncate()
1055 .text_size(px(16.))
1056 .font_weight(FontWeight::SEMIBOLD)
1057 .child(model.title.clone()),
1058 )
1059 .child(
1060 div()
1061 .flex_none()
1062 .text_size(px(13.))
1063 .text_color(status_color)
1064 .child(status),
1065 )
1066 .children(health_indicator(model))
1067 .children(recording_chip(model))
1068 .children(room_chip(model))
1069 .child(div().flex_1())
1070 .children(return_button(app, model));
1071
1072 let hold = hold_panel(app, model);
1073 let share_stage = render_stage(app, state, false).or_else(|| whiteboard_stage(app, model));
1074 let region = stage_region(app, state, call, now, hold, share_stage);
1075
1076 let controls = h_flex()
1077 .w_full()
1078 .flex_none()
1079 .py(px(16.))
1080 .gap(px(12.))
1081 .items_center()
1082 .justify_center()
1083 .child(
1084 h_flex()
1085 .h(px(CONTROL_SIZE))
1086 .items_center()
1087 .rounded_full()
1088 .bg(theme::surface_raised())
1089 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1090 .child(mic_menu_button(app, model, state.call_mic)),
1091 )
1092 .child(
1093 h_flex()
1094 .h(px(CONTROL_SIZE))
1095 .items_center()
1096 .rounded_full()
1097 .bg(theme::surface_raised())
1098 .child(camera_button(app, model))
1099 .children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1100 )
1101 .child(share_button(
1102 app,
1103 model,
1104 state.call_share_sound,
1105 call.share_menu_open,
1106 ))
1107 .when(model.has_reaction_controls(), |row| {
1108 row.child(hand_button(app, model))
1109 .child(reactions_button(app, model))
1110 })
1111 .child(view_button(app, model, fullscreen))
1112 .children(more_button(app, model))
1113 .when(call.chat_thread().is_some(), |row| {
1114 row.child(chat_button(app, call.chat_open, state.call_chat_unread()))
1115 })
1116 .child(leave_button(app, model, "call-leave", false))
1117 .when(model.kind == CallKind::Meeting, |row| {
1118 row.child(leave_menu(app, model))
1119 });
1120
1121 let top = v_flex()
1122 .w_full()
1123 .flex_none()
1124 .child(header)
1125 .children(lobby_banner(app, model, call.lobby_list_open))
1126 .children(health_banner(app, model))
1127 .children(sharing_banner(app, model, state.call_share_sound))
1128 .children(consult_banner(app, state));
1129
1130 let chrome_visible = call
1131 .fullscreen
1132 .is_none_or(|fullscreen| fullscreen.chrome_visible(now));
1133 let move_app = app.clone();
1134 let base = v_flex()
1135 .relative()
1136 .flex_1()
1137 .min_w_0()
1138 .h_full()
1139 .overflow_hidden()
1140 .bg(theme::surface());
1141 let column = if fullscreen {
1142 base.on_mouse_move(move |_, _, cx| {
1143 move_app.update(cx, |state, cx| state.touch_call_chrome(cx))
1144 })
1145 .when(chrome_visible, |column| {
1146 column.child(fullscreen_chrome("call-chrome-top", app, top))
1147 })
1148 .child(region)
1149 .when(chrome_visible, |column| {
1150 column.child(fullscreen_chrome("call-chrome-bottom", app, controls))
1151 })
1152 } else {
1153 base.rounded(px(10.))
1154 .child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1155 .child(region)
1156 .child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))
1157 }
1158 .children(captions_overlay(model, now))
1159 .children(captions_hint_chip(model))
1160 .children(push_to_talk_chip(call))
1161 .children(state.transfer_picker.clone())
1162 .children(consent_overlay(app, model));
1163 Some(
1164 h_flex()
1165 .when(!fullscreen, |row| {
1166 row.debug_selector(|| "shell/islands/main".into())
1167 })
1168 .flex_1()
1169 .min_w_0()
1170 .h_full()
1171 .gap(px(ISLAND_GAP))
1172 .child(column)
1173 .children(chat.map(|chat| chat_panel(app, chat)))
1174 .into_any_element(),
1175 )
1176}
1177
1178fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
1179 let hover_app = app.clone();
1180 div()
1181 .id(id)
1182 .w_full()
1183 .flex_none()
1184 .on_hover(move |hovered, _, cx| {
1185 hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))
1186 })
1187 .child(content)
1188}
1189
1190fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1191 let app = app.clone();
1192 v_flex()
1193 .id("call-chat-panel")
1194 .w(px(CHAT_PANEL_WIDTH))
1195 .h_full()
1196 .flex_none()
1197 .rounded(px(10.))
1198 .overflow_hidden()
1199 .bg(theme::surface())
1200 .child(
1201 h_flex()
1202 .w_full()
1203 .h(px(CHAT_HEADER_HEIGHT))
1204 .flex_none()
1205 .pl(px(20.))
1206 .pr(px(12.))
1207 .items_center()
1208 .justify_between()
1209 .child(
1210 div()
1211 .text_size(px(15.))
1212 .font_weight(FontWeight::SEMIBOLD)
1213 .child("Chat"),
1214 )
1215 .child(
1216 div()
1217 .id("call-chat-close")
1218 .size(px(28.))
1219 .flex()
1220 .items_center()
1221 .justify_center()
1222 .rounded(px(7.))
1223 .cursor_pointer()
1224 .hover(|button| button.bg(theme::row_hover()))
1225 .tooltip(|window, cx| Tooltip::new("Close the chat").build(window, cx))
1226 .child(icon(IconName::Close, 14., theme::text_muted()))
1227 .on_click(move |_, _, cx| {
1228 app.update(cx, |state, cx| state.toggle_call_chat(cx))
1229 }),
1230 ),
1231 )
1232 .child(chat)
1233 .into_any_element()
1234}