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