BlueGit

ict rusty-teams

Files

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

call_view.rs

call_view.rs 34.7 KiB Download Raw
1use std::sync::Arc;
2use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
3
4use calling::{DeviceEntry, 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::{BackgroundMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button, room_chip, whiteboard_stage};
20use super::call_organizer::{camera_menu_button, captions_hint_chip, captions_overlay, lobby_banner, more_button, pin_chip, render_focus_stage, spotlight_chip, with_tile_menu};
21use super::call_stage::render_stage;
22use super::conversation::ConversationView;
23use super::widgets::{count_badge, icon, symbol};
24use crate::app_state::AppState;
25use crate::call::TileSize;
26use crate::call::{CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout, tile_size};
27use crate::call::REACTION_SHOWN;
28use crate::rows::reaction_glyph as chat_reaction_glyph;
29use crate::theme;
30
31const HEADER_HEIGHT: f32 = 60.;
32const RING_WIDTH: f32 = 3.;
33const RING_GAP: f32 = 4.;
34pub(super) const CONTROL_SIZE: f32 = 44.;
35const CONTROL_ICON: f32 = 20.;
36pub(super) const MENU_WIDTH: f32 = 280.;
37const PULSE_PERIOD: Duration = Duration::from_millis(1400);
38const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
39const BLINK_DIMMED_OPACITY: f32 = 0.45;
40const DISABLED_OPACITY: f32 = 0.4;
41const TILE_GAP: f32 = 20.;
42const GRID_PADDING: f32 = 24.;
43const STRIP_TILE: TileSize = TileSize {
44 width: 232.,
45 height: 131.,
46 avatar: 56.,
47};
48const STRIP_GAP: f32 = 10.;
49const STRIP_VISIBLE: f32 = 4.;
50const TILE_RADIUS: f32 = 12.;
51const NAME_PLATE_BACKGROUND: f32 = 0.6;
52pub const NO_MICROPHONE_HINT: &str = "No microphone found";
53pub const NO_CAMERA_HINT: &str = "No camera found";
54pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";
55pub const NO_WINDOWS_HINT: &str = "No windows found";
56pub(super) const BANNER_HEIGHT: f32 = 40.;
57const MAX_WINDOW_ITEMS: usize = 12;
58pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
59pub const CHAT_PANEL_WIDTH: f32 = 320.;
60const CHAT_HEADER_HEIGHT: f32 = 48.;
61const HAND_GLYPH: &str = "\u{270B}";
62const REACTION_RISE: f32 = 24.;
63const REACTION_FADE_FROM: f32 = 0.75;
64const REACTION_CELL: f32 = 40.;
65const SHARE_SOUND_LABEL: &str = "Include computer sound";
66
67pub fn reaction_glyph(reaction: Reaction) -> String {
68 match reaction {
69 Reaction::Applause => "\u{1F44F}".to_owned(),
70 other => chat_reaction_glyph(other.name()),
71 }
72}
73
74#[derive(Default)]
75struct TileExtras {
76 hand: Option<usize>,
77 own: bool,
78 reaction: Option<(Reaction, u64)>,
79 spotlight: bool,
80 pinned: bool,
81}
82
83fn hand_badge(position: usize, own: bool) -> Div {
84 h_flex()
85 .h(px(24.))
86 .px(px(8.))
87 .gap(px(4.))
88 .items_center()
89 .rounded_full()
90 .bg(theme::amber())
91 .text_color(hsla(0., 0., 0.08, 1.))
92 .text_size(px(12.))
93 .font_weight(FontWeight::SEMIBOLD)
94 .child(if own { "Hand raised".to_owned() } else { format!("Hand {position}") })
95}
96
97fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {
98 div()
99 .absolute()
100 .right(px(12.))
101 .bottom(px(34.))
102 .size(px(36.))
103 .flex()
104 .items_center()
105 .justify_center()
106 .rounded_full()
107 .bg(theme::surface_raised())
108 .border_1()
109 .border_color(theme::border_strong())
110 .text_size(px(20.))
111 .child(reaction_glyph(reaction))
112 .with_animation(
113 ("call-reaction", serial as usize),
114 Animation::new(REACTION_SHOWN),
115 |chip, delta| {
116 let fade = ((delta - REACTION_FADE_FROM) / (1. - REACTION_FADE_FROM)).clamp(0., 1.);
117 chip.bottom(px(34. + REACTION_RISE * delta)).opacity(1. - fade)
118 },
119 )
120 .into_any_element()
121}
122
123fn tile_overlays(extras: &TileExtras) -> Vec<AnyElement> {
124 let badges = (extras.hand.is_some() || extras.spotlight || extras.pinned).then(|| {
125 h_flex()
126 .absolute()
127 .top(px(10.))
128 .left(px(10.))
129 .gap(px(6.))
130 .children(extras.hand.map(|position| hand_badge(position, extras.own)))
131 .when(extras.spotlight, |row| row.child(spotlight_chip()))
132 .when(extras.pinned, |row| row.child(pin_chip()))
133 .into_any_element()
134 });
135 let reaction = extras.reaction.map(|(reaction, serial)| reaction_chip(reaction, serial));
136 badges.into_iter().chain(reaction).collect()
137}
138
139pub fn status_line(model: &CallModel, now: Instant) -> (String, Hsla) {
140 if model.lobby {
141 (LOBBY_TEXT.to_owned(), theme::amber())
142 } else if model.is_connecting() {
143 (model.connecting_text().to_owned(), theme::text_muted())
144 } else if model.is_reconnecting() {
145 ("Reconnecting...".to_owned(), theme::amber())
146 } else {
147 (model.timer_text(now), theme::text_muted())
148 }
149}
150
151pub fn pulsing(element: impl IntoElement + 'static, id: &'static str) -> AnyElement {
152 div()
153 .child(element)
154 .with_animation(
155 id,
156 Animation::new(PULSE_PERIOD).repeat(),
157 |element, delta| {
158 let wave = 1. - (delta * 2. - 1.).abs();
159 element.opacity(0.45 + 0.55 * wave)
160 },
161 )
162 .into_any_element()
163}
164
165fn blinking(element: impl IntoElement + 'static) -> AnyElement {
166 let dimmed = SystemTime::now().duration_since(UNIX_EPOCH).is_ok_and(|elapsed| (elapsed.as_millis() / BLINK_HALF_PERIOD.as_millis()) % 2 == 1);
167 div().child(element).opacity(if dimmed { BLINK_DIMMED_OPACITY } else { 1. }).into_any_element()
168}
169
170fn speaking_ring(avatar: AnyElement, speaking: bool) -> Div {
171 div()
172 .p(px(RING_GAP))
173 .rounded_full()
174 .border(px(RING_WIDTH))
175 .border_color(if speaking {
176 theme::green()
177 } else {
178 transparent_black()
179 })
180 .child(avatar)
181}
182
183fn mute_badge() -> Div {
184 div()
185 .absolute()
186 .top(px(10.))
187 .right(px(10.))
188 .size(px(24.))
189 .flex()
190 .items_center()
191 .justify_center()
192 .rounded_full()
193 .bg(theme::red())
194 .child(icon(IconName::MicOff, 13., theme::white()))
195}
196
197fn video_tile(size: TileSize, image: Arc<RenderImage>, name: &str, speaking: bool, muted: bool, extras: &TileExtras) -> Div {
198 div()
199 .relative()
200 .w(px(size.width))
201 .h(px(size.height))
202 .flex_none()
203 .overflow_hidden()
204 .rounded(px(TILE_RADIUS))
205 .bg(theme::surface())
206 .border_2()
207 .border_color(if speaking { theme::green() } else { transparent_black() })
208 .child(
209 img(ImageSource::Render(image))
210 .size_full()
211 .object_fit(ObjectFit::Cover)
212 .rounded(px(TILE_RADIUS)),
213 )
214 .child(
215 div()
216 .absolute()
217 .left(px(8.))
218 .bottom(px(8.))
219 .max_w(px(size.width - 24.))
220 .truncate()
221 .px(px(8.))
222 .py(px(3.))
223 .rounded(px(6.))
224 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
225 .text_size(px(12.))
226 .font_weight(FontWeight::SEMIBOLD)
227 .text_color(theme::white())
228 .child(name.to_owned()),
229 )
230 .when(muted, |tile| tile.child(mute_badge()))
231 .children(tile_overlays(extras))
232}
233
234fn tile(
235 size: TileSize,
236 avatar: AnyElement,
237 name: &str,
238 speaking: bool,
239 muted: bool,
240 caption: Option<AnyElement>,
241 extras: &TileExtras,
242) -> Div {
243 let badge = div()
244 .absolute()
245 .top(px(10.))
246 .right(px(10.))
247 .size(px(24.))
248 .flex()
249 .items_center()
250 .justify_center()
251 .rounded_full()
252 .bg(theme::red())
253 .child(icon(IconName::MicOff, 13., theme::white()));
254 v_flex()
255 .relative()
256 .w(px(size.width))
257 .h(px(size.height))
258 .items_center()
259 .justify_center()
260 .gap(px(12.))
261 .rounded(px(12.))
262 .bg(theme::surface())
263 .border_1()
264 .border_color(theme::border())
265 .child(speaking_ring(avatar, speaking))
266 .child(
267 v_flex()
268 .items_center()
269 .gap(px(2.))
270 .max_w(px(size.width - 16.))
271 .child(
272 div()
273 .max_w_full()
274 .truncate()
275 .text_size(px(14.))
276 .font_weight(FontWeight::SEMIBOLD)
277 .child(name.to_owned()),
278 )
279 .children(caption),
280 )
281 .when(muted, |tile| tile.child(badge))
282 .children(tile_overlays(extras))
283}
284
285fn overflow_tile(size: TileSize, hidden: usize) -> Div {
286 v_flex()
287 .w(px(size.width))
288 .h(px(size.height))
289 .items_center()
290 .justify_center()
291 .rounded(px(12.))
292 .bg(theme::surface())
293 .border_1()
294 .border_color(theme::border())
295 .child(
296 div()
297 .text_size(px(size.avatar * 0.5))
298 .font_weight(FontWeight::SEMIBOLD)
299 .text_color(theme::text_muted())
300 .child(format!("+{hidden}")),
301 )
302}
303
304fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
305 div()
306 .id(id)
307 .size(px(CONTROL_SIZE))
308 .flex()
309 .flex_none()
310 .items_center()
311 .justify_center()
312 .rounded_full()
313 .bg(background)
314 .cursor_pointer()
315 .hover(|button| button.opacity(0.85))
316}
317
318pub(super) fn round_control(id: &'static str, glyph: IconName, background: Hsla, foreground: Hsla) -> Stateful<Div> {
319 control_shell(id, background).child(icon(glyph, CONTROL_ICON, foreground))
320}
321
322pub fn mute_button(app: &Entity<AppState>, model: &CallModel, id: &'static str, size: f32) -> Stateful<Div> {
323 let (glyph, background, foreground) = if model.muted {
324 (IconName::MicOff, theme::red(), theme::white())
325 } else {
326 (IconName::Mic, theme::surface_raised(), theme::text())
327 };
328 let button = round_control(id, glyph, background, foreground).size(px(size));
329 if !model.can_unmute() {
330 return button
331 .opacity(DISABLED_OPACITY)
332 .cursor_default()
333 .tooltip(|window, cx| Tooltip::new(NO_MICROPHONE_HINT).build(window, cx));
334 }
335 let app = app.clone();
336 button.on_click(move |_, _, cx| {
337 cx.stop_propagation();
338 app.update(cx, |state, cx| state.toggle_call_mute(cx));
339 })
340}
341
342pub fn leave_button(app: &Entity<AppState>, model: &CallModel, id: &'static str, compact: bool) -> Stateful<Div> {
343 let label = if model.is_connecting() { "Cancel" } else { "Leave" };
344 let app = app.clone();
345 h_flex()
346 .id(id)
347 .h(px(if compact { 28. } else { CONTROL_SIZE }))
348 .px(px(if compact { 10. } else { 20. }))
349 .gap(px(8.))
350 .flex_none()
351 .items_center()
352 .justify_center()
353 .rounded_full()
354 .bg(theme::red())
355 .text_color(theme::white())
356 .text_size(px(if compact { 12. } else { 14. }))
357 .font_weight(FontWeight::SEMIBOLD)
358 .cursor_pointer()
359 .hover(|button| button.opacity(0.85))
360 .child(icon(IconName::PhoneOff, if compact { 14. } else { 18. }, theme::white()))
361 .child(label)
362 .on_click(move |_, _, cx| {
363 cx.stop_propagation();
364 app.update(cx, |state, cx| state.leave_call(cx));
365 })
366}
367
368pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
369 let (glyph, background, foreground) = if model.camera_on {
370 (IconName::Video, theme::accent(), theme::on_accent())
371 } else {
372 (IconName::VideoOff, theme::surface_raised(), theme::text())
373 };
374 let button = round_control("call-camera", glyph, background, foreground);
375 if !model.can_use_camera() {
376 return button
377 .opacity(DISABLED_OPACITY)
378 .cursor_default()
379 .tooltip(|window, cx| Tooltip::new(NO_CAMERA_HINT).build(window, cx));
380 }
381 let app = app.clone();
382 button.on_click(move |_, _, cx| {
383 cx.stop_propagation();
384 app.update(cx, |state, cx| state.toggle_call_camera(cx));
385 })
386}
387
388fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
389 let app = app.clone();
390 PopupMenuItem::element(move |_, _| {
391 h_flex()
392 .id("call-share-sound-row")
393 .w_full()
394 .gap(px(16.))
395 .items_center()
396 .justify_between()
397 .child(SHARE_SOUND_LABEL)
398 .child(Switch::new("call-share-sound").checked(sound))
399 })
400 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
401}
402
403fn share_items(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel, sound: bool) -> PopupMenu {
404 let screens = model.screens();
405 let single_screen = screens.len() == 1;
406 let mut popup = popup.min_w(px(MENU_WIDTH)).item(sound_switch_item(app, sound)).separator();
407 for (index, source) in screens.into_iter().enumerate() {
408 let label = if single_screen { "Share entire screen".to_owned() } else { format!("Share screen {}", index + 1) };
409 let source = source.clone();
410 let app = app.clone();
411 popup = popup.item(
412 PopupMenuItem::new(label)
413 .icon(IconName::Monitor)
414 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))),
415 );
416 }
417 popup = popup.separator().item(PopupMenuItem::label("Share a window..."));
418 let windows = model.windows();
419 if windows.is_empty() {
420 return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));
421 }
422 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
423 let label = source.label();
424 let source = source.clone();
425 let app = app.clone();
426 popup = popup.item(
427 PopupMenuItem::new(label)
428 .icon(IconName::AppWindow)
429 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))),
430 );
431 }
432 popup
433}
434
435fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyElement {
436 if model.local_share.is_some() {
437 let app = app.clone();
438 return round_control("call-share-stop", IconName::ScreenShareOff, theme::accent(), theme::on_accent())
439 .tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))
440 .on_click(move |_, _, cx| {
441 cx.stop_propagation();
442 app.update(cx, |state, cx| state.stop_call_share(cx));
443 })
444 .into_any_element();
445 }
446 let face = round_control("call-share-face", IconName::ScreenShare, theme::surface_raised(), theme::text());
447 if !model.can_share() {
448 return face
449 .opacity(DISABLED_OPACITY)
450 .cursor_default()
451 .tooltip(|window, cx| Tooltip::new(NO_SHARE_HINT).build(window, cx))
452 .into_any_element();
453 }
454 let app = app.clone();
455 let model = model.clone();
456 Button::new("call-share")
457 .ghost()
458 .p_0()
459 .size(px(CONTROL_SIZE))
460 .rounded_full()
461 .child(face)
462 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| share_items(popup, &app, &model, sound))
463 .into_any_element()
464}
465
466fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Option<AnyElement> {
467 let label = model.local_share.as_ref()?;
468 let sound_app = app.clone();
469 let app = app.clone();
470 Some(
471 h_flex()
472 .id("call-sharing-banner")
473 .w_full()
474 .h(px(BANNER_HEIGHT))
475 .flex_none()
476 .px(px(20.))
477 .gap(px(12.))
478 .items_center()
479 .justify_center()
480 .bg(theme::accent())
481 .text_color(theme::on_accent())
482 .text_size(px(13.))
483 .font_weight(FontWeight::SEMIBOLD)
484 .child(icon(IconName::ScreenShare, 16., theme::on_accent()))
485 .child(format!("You are sharing: {label}"))
486 .child(
487 div()
488 .id("call-sharing-sound")
489 .h(px(26.))
490 .px(px(12.))
491 .flex()
492 .items_center()
493 .rounded_full()
494 .border_1()
495 .border_color(theme::on_accent())
496 .cursor_pointer()
497 .hover(|button| button.opacity(0.9))
498 .child(if sound { "Computer sound on" } else { "Computer sound off" })
499 .on_click(move |_, _, cx| sound_app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))),
500 )
501 .child(
502 div()
503 .id("call-sharing-stop")
504 .h(px(26.))
505 .px(px(12.))
506 .flex()
507 .items_center()
508 .rounded_full()
509 .bg(theme::on_accent())
510 .text_color(theme::accent())
511 .cursor_pointer()
512 .hover(|button| button.opacity(0.9))
513 .child("Stop sharing")
514 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.stop_call_share(cx))),
515 )
516 .into_any_element(),
517 )
518}
519
520fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {
521 let app = app.clone();
522 let (background, foreground) = if open {
523 (theme::accent(), theme::on_accent())
524 } else {
525 (theme::surface_raised(), theme::text())
526 };
527 round_control("call-chat", IconName::MessageCircle, background, foreground)
528 .relative()
529 .tooltip(move |window, cx| Tooltip::new(if open { "Close the chat" } else { "Open the chat" }).build(window, cx))
530 .when(unread > 0, |button| {
531 button.child(div().absolute().top(px(-4.)).right(px(-4.)).child(count_badge(unread, false)))
532 })
533 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))
534}
535
536fn hand_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
537 let raised = model.own_hand.is_some();
538 let background = if raised { theme::accent() } else { theme::surface_raised() };
539 let button = control_shell("call-hand", background).child(div().text_size(px(CONTROL_ICON)).child(HAND_GLYPH));
540 let tooltip = if raised { "Lower hand" } else { "Raise hand" };
541 let button = button.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx));
542 if !model.can_react() {
543 return button.opacity(DISABLED_OPACITY).cursor_default();
544 }
545 let app = app.clone();
546 button.on_click(move |_, _, cx| {
547 cx.stop_propagation();
548 app.update(cx, |state, cx| state.toggle_call_hand(cx));
549 })
550}
551
552fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
553 let face = control_shell("call-reactions-face", theme::surface_raised())
554 .child(symbol("mood", CONTROL_ICON, theme::text()));
555 if !model.can_react() {
556 return face.opacity(DISABLED_OPACITY).cursor_default().into_any_element();
557 }
558 let app = app.clone();
559 Popover::new("call-reactions-popover")
560 .anchor(Anchor::BottomLeft)
561 .offset(px(10.))
562 .trigger(Button::new("call-reactions").ghost().p_0().size(px(CONTROL_SIZE)).rounded_full().child(face))
563 .content(move |_, _, cx| {
564 let popover = cx.entity().downgrade();
565 h_flex().id("call-reactions-row").gap(px(4.)).children(Reaction::ALL.into_iter().map(|reaction| {
566 let app = app.clone();
567 let popover = popover.clone();
568 div()
569 .id(reaction.name())
570 .size(px(REACTION_CELL))
571 .flex()
572 .items_center()
573 .justify_center()
574 .rounded(px(8.))
575 .text_size(px(24.))
576 .cursor_pointer()
577 .hover(|cell| cell.bg(theme::border_strong()))
578 .child(reaction_glyph(reaction))
579 .on_click(move |_, window, cx| {
580 app.update(cx, |state, cx| state.send_call_reaction(reaction, cx));
581 popover.update(cx, |state, cx| state.dismiss(window, cx)).ok();
582 })
583 }))
584 })
585 .into_any_element()
586}
587
588fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
589 let leave_app = app.clone();
590 let end_app = app.clone();
591 let can_end = model.can_end_meeting;
592 let lower_app = app.clone();
593 let can_lower_all = model.can_lower_hands() && model.any_hand_raised();
594 Button::new("call-leave-menu")
595 .ghost()
596 .p_0()
597 .size(px(CONTROL_SIZE))
598 .rounded_full()
599 .child(round_control(
600 "call-leave-menu-face",
601 IconName::ChevronUp,
602 theme::surface_raised(),
603 theme::text(),
604 ))
605 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
606 let leave_app = leave_app.clone();
607 let end_app = end_app.clone();
608 let lower_app = lower_app.clone();
609 let popup = popup.min_w(px(MENU_WIDTH)).item(
610 PopupMenuItem::new("Leave")
611 .icon(IconName::PhoneOff)
612 .on_click(move |_, _, cx| leave_app.update(cx, |state, cx| state.leave_call(cx))),
613 );
614 let popup = if can_lower_all {
615 popup.item(
616 PopupMenuItem::new("Lower all hands")
617 .on_click(move |_, _, cx| lower_app.update(cx, |state, cx| state.lower_all_call_hands(cx))),
618 )
619 } else {
620 popup
621 };
622 if can_end {
623 popup.item(
624 PopupMenuItem::new("End meeting for everyone")
625 .icon(IconName::PhoneOff)
626 .on_click(move |_, _, cx| end_app.update(cx, |state, cx| state.end_meeting_for_all(cx))),
627 )
628 } else {
629 popup
630 }
631 })
632}
633
634pub(super) fn device_items(
635 entries: Vec<DeviceEntry>,
636 selected: &calling::DeviceChoice,
637 pick: impl Fn(calling::DeviceChoice, &mut App) + Clone + 'static,
638) -> Vec<PopupMenuItem> {
639 entries
640 .into_iter()
641 .map(|entry| {
642 let pick = pick.clone();
643 let choice = entry.choice.clone();
644 PopupMenuItem::new(entry.label)
645 .checked(&entry.choice == selected)
646 .on_click(move |_, _, cx| pick(choice.clone(), cx))
647 })
648 .collect()
649}
650
651fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
652 let input_app = app.clone();
653 let output_app = app.clone();
654 let inputs = device_items(model.devices.input_entries(), &model.input, move |choice, cx| {
655 input_app.update(cx, |state, cx| state.select_call_input(choice, cx));
656 });
657 let outputs = device_items(model.devices.output_entries(), &model.output, move |choice, cx| {
658 output_app.update(cx, |state, cx| state.select_call_output(choice, cx));
659 });
660 let mut popup = popup
661 .min_w(px(MENU_WIDTH))
662 .item(PopupMenuItem::label("Microphone"));
663 if model.listen_only {
664 popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true));
665 } else {
666 for item in inputs {
667 popup = popup.item(item);
668 }
669 }
670 popup = popup.separator().item(PopupMenuItem::label("Speaker"));
671 for item in outputs {
672 popup = popup.item(item);
673 }
674 popup
675}
676
677fn devices_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
678 let app = app.clone();
679 let model = model.clone();
680 Button::new("call-devices")
681 .ghost()
682 .p_0()
683 .size(px(CONTROL_SIZE))
684 .rounded_full()
685 .child(round_control(
686 "call-devices-face",
687 IconName::Volume2,
688 theme::surface_raised(),
689 theme::text(),
690 ))
691 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
692 devices_menu(popup, &app, &model)
693 })
694}
695
696fn person_tile(app: &Entity<AppState>, state: &AppState, model: &CallModel, remote: &Tile, size: TileSize, now: Instant) -> AnyElement {
697 let extras = TileExtras {
698 hand: remote.hand.map(|rank| model.hand_position(rank)),
699 own: false,
700 reaction: model.chip_of(&remote.mri, now).map(|chip| (chip.reaction, chip.serial)),
701 spotlight: remote.spotlight.is_some(),
702 pinned: model.is_pinned(&remote.mri),
703 };
704 let element = person_tile_body(state, model, remote, size, now, &extras);
705 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
706}
707
708fn person_tile_body(state: &AppState, model: &CallModel, remote: &Tile, size: TileSize, now: Instant, extras: &TileExtras) -> AnyElement {
709 let video = state
710 .call
711 .as_ref()
712 .filter(|_| remote.has_video || model.is_one_to_one())
713 .and_then(|call| call.pictures.live(&VideoKey::Person(remote.mri.clone()), now));
714 if let Some(image) = video {
715 return video_tile(size, image, &remote.name, model.tile_speaking(remote), remote.muted, extras).into_any_element();
716 }
717 let waiting = remote.state == TileState::Invited;
718 let avatar = person_avatar(&state.directory, remote.user_id.as_deref(), &remote.name, size.avatar);
719 let avatar = if waiting { blinking(avatar) } else { avatar };
720 let caption = model.tile_caption(remote).map(|text| {
721 let label = div().text_size(px(12.)).text_color(theme::text_muted()).child(text);
722 if waiting { blinking(label) } else { label.into_any_element() }
723 });
724 tile(size, avatar, &remote.name, model.tile_speaking(remote), remote.muted, caption, extras).into_any_element()
725}
726
727fn own_tile(app: &Entity<AppState>, state: &AppState, model: &CallModel, size: TileSize, now: Instant) -> AnyElement {
728 let own_mri = model.own_mri.clone().unwrap_or_default();
729 let extras = TileExtras {
730 hand: model.own_hand.map(|rank| model.hand_position(rank)),
731 own: true,
732 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
733 spotlight: model.own_spotlight.is_some(),
734 pinned: model.is_pinned(&own_mri),
735 };
736 let element = own_tile_body(state, model, size, now, &extras);
737 if own_mri.is_empty() {
738 return element;
739 }
740 with_tile_menu(app, model, &own_mri, "You", true, element)
741}
742
743fn own_tile_body(state: &AppState, model: &CallModel, size: TileSize, now: Instant, extras: &TileExtras) -> AnyElement {
744 let me = state.directory.me.as_ref();
745 let self_view = state
746 .call
747 .as_ref()
748 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
749 if let Some(image) = self_view {
750 return video_tile(size, image, "You", model.local_speaking, model.muted, extras).into_any_element();
751 }
752 let avatar = person_avatar(
753 &state.directory,
754 me.map(|person| person.user_id.as_str()),
755 me.map_or("You", |person| person.display_name.as_str()),
756 size.avatar,
757 );
758 tile(size, avatar, "You", model.local_speaking, model.muted, None, extras).into_any_element()
759}
760
761fn remote_tiles(app: &Entity<AppState>, state: &AppState, model: &CallModel, size: TileSize, hidden_cap: GridLayout, now: Instant) -> Vec<AnyElement> {
762 let visible = model.visible_tiles();
763 let mut cells: Vec<AnyElement> = visible
764 .iter()
765 .take(hidden_cap.shown_others)
766 .map(|remote| person_tile(app, state, model, remote, size, now))
767 .collect();
768 if hidden_cap.hidden > 0 {
769 cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());
770 }
771 cells
772}
773
774fn people_strip(app: &Entity<AppState>, state: &AppState, model: &CallModel, now: Instant, focused: Option<&str>) -> Stateful<Div> {
775 let mut cells: Vec<AnyElement> = model
776 .strip_tiles()
777 .into_iter()
778 .filter(|remote| Some(remote.mri.as_str()) != focused)
779 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
780 .collect();
781 if focused.is_none() || focused != model.own_mri.as_deref() {
782 let own_index = model.own_cell_index(cells.len());
783 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
784 }
785 v_flex()
786 .id("call-strip")
787 .flex_none()
788 .w(px(STRIP_TILE.width))
789 .max_h(px(STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP))
790 .gap(px(STRIP_GAP))
791 .overflow_y_scroll()
792 .children(cells)
793}
794
795pub fn render_call_view(app: &Entity<AppState>, state: &AppState, chat: Option<Entity<ConversationView>>) -> Option<AnyElement> {
796 let call = state.call.as_ref()?;
797 let model = &call.model;
798 let now = Instant::now();
799 let (status, status_color) = status_line(model, now);
800 let header = h_flex()
801 .w_full()
802 .h(px(HEADER_HEIGHT))
803 .flex_none()
804 .px(px(20.))
805 .gap(px(12.))
806 .items_center()
807 .border_b_1()
808 .border_color(theme::border())
809 .child(icon(IconName::Phone, 18., theme::accent_text()))
810 .child(
811 div()
812 .min_w_0()
813 .truncate()
814 .text_size(px(16.))
815 .font_weight(FontWeight::SEMIBOLD)
816 .child(model.title.clone()),
817 )
818 .child(div().flex_none().text_size(px(13.)).text_color(status_color).child(status))
819 .children(recording_chip(model))
820 .children(room_chip(model))
821 .child(div().flex_1())
822 .children(return_button(app, model));
823
824 let max_tiles = if chat.is_some() { CHAT_OPEN_TILES } else { MAX_TILES };
825 let layout = grid_layout(model.visible_tiles().len(), max_tiles);
826 let cells_for_size = if chat.is_some() { MAX_TILES } else { layout.shown_others + usize::from(layout.hidden > 0) + 1 };
827 let size = tile_size(cells_for_size);
828 let mut cells = remote_tiles(app, state, model, size, layout, now);
829 let own_index = model.own_cell_index(cells.len());
830 cells.insert(own_index, own_tile(app, state, model, size, now));
831 let focus = model.focus().filter(|_| model.screen_sharer.is_none());
832 let stage = render_stage(app, state, false)
833 .or_else(|| whiteboard_stage(app, model))
834 .or_else(|| focus.as_ref().and_then(|focus| render_focus_stage(app, state, focus, now)));
835 let hold = hold_panel(app, model);
836 let focused = focus.as_ref().map(|focus| focus.mri.as_str());
837
838 let controls = h_flex()
839 .w_full()
840 .flex_none()
841 .py(px(18.))
842 .gap(px(12.))
843 .items_center()
844 .justify_center()
845 .border_t_1()
846 .border_color(theme::border())
847 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
848 .child(h_flex().gap(px(2.)).items_center().child(camera_button(app, model)).children(camera_menu_button(app, model, BackgroundMenu::of(state))))
849 .child(share_button(app, model, state.call_share_sound))
850 .when(model.has_reaction_controls(), |row| row.child(hand_button(app, model)).child(reactions_button(app, model)))
851 .child(devices_button(app, model))
852 .children(more_button(app, model))
853 .when(call.chat_thread().is_some(), |row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())))
854 .child(leave_button(app, model, "call-leave", false))
855 .when(model.kind == CallKind::Meeting, |row| row.child(leave_menu(app, model)));
856
857 let column = v_flex()
858 .relative()
859 .flex_1()
860 .min_w_0()
861 .h_full()
862 .bg(theme::background())
863 .child(header)
864 .children(lobby_banner(app, model))
865 .children(sharing_banner(app, model, state.call_share_sound))
866 .children(consult_banner(app, state))
867 .child(match stage {
868 _ if hold.is_some() => hold.expect("checked above"),
869 Some(stage) => h_flex()
870 .flex_1()
871 .min_h_0()
872 .p(px(GRID_PADDING))
873 .gap(px(TILE_GAP))
874 .items_center()
875 .child(stage)
876 .child(people_strip(app, state, model, now, focused))
877 .into_any_element(),
878 None => h_flex()
879 .id("call-grid")
880 .flex_1()
881 .min_h_0()
882 .overflow_y_scroll()
883 .flex_wrap()
884 .content_center()
885 .p(px(GRID_PADDING))
886 .gap(px(TILE_GAP))
887 .items_center()
888 .justify_center()
889 .children(cells)
890 .into_any_element(),
891 })
892 .child(controls)
893 .children(captions_overlay(model, now))
894 .children(captions_hint_chip(model))
895 .children(state.transfer_picker.clone())
896 .children(consent_overlay(app, model));
897 Some(
898 h_flex()
899 .flex_1()
900 .min_w_0()
901 .h_full()
902 .child(column)
903 .children(chat.map(|chat| chat_panel(app, chat)))
904 .into_any_element(),
905 )
906}
907
908fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
909 let app = app.clone();
910 v_flex()
911 .id("call-chat-panel")
912 .w(px(CHAT_PANEL_WIDTH))
913 .h_full()
914 .flex_none()
915 .border_l_1()
916 .border_color(theme::border())
917 .child(
918 h_flex()
919 .w_full()
920 .h(px(CHAT_HEADER_HEIGHT))
921 .flex_none()
922 .px(px(16.))
923 .items_center()
924 .justify_between()
925 .border_b_1()
926 .border_color(theme::border())
927 .child(div().text_size(px(15.)).font_weight(FontWeight::SEMIBOLD).child("Chat"))
928 .child(
929 div()
930 .id("call-chat-close")
931 .size(px(28.))
932 .flex()
933 .items_center()
934 .justify_center()
935 .rounded_full()
936 .cursor_pointer()
937 .hover(|button| button.bg(theme::row_hover()))
938 .tooltip(|window, cx| Tooltip::new("Close the chat").build(window, cx))
939 .child(icon(IconName::Close, 16., theme::text_muted()))
940 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx))),
941 ),
942 )
943 .child(chat)
944 .into_any_element()
945}