BlueGit

ict rusty-teams

Files

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

call_view.rs

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