BlueGit

ict rusty-teams

Files

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

call_view.rs

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