BlueGit

ict rusty-teams

Files

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

call_view.rs

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