| 1 | use std::sync::Arc; |
| 2 | use std::time::Instant; |
| 3 | |
| 4 | use calling::{CaptionState, HoldState, MeetingRole, Modality, VideoKey}; |
| 5 | use gpui_kit::assets::IconName; |
| 6 | use gpui_kit::component::button::{Button, ButtonVariants as _}; |
| 7 | use gpui_kit::component::dialog::DialogFooter; |
| 8 | use gpui_kit::component::menu::{ContextMenuExt as _, DropdownMenu as _, PopupMenu, PopupMenuItem}; |
| 9 | use gpui_kit::component::popover::Popover; |
| 10 | use gpui_kit::component::{Sizable as _, WindowExt as _, h_flex, v_flex}; |
| 11 | use gpui_kit::prelude::FluentBuilder as _; |
| 12 | use gpui_kit::*; |
| 13 | |
| 14 | use super::avatar::person_avatar; |
| 15 | use super::call_control_fold::{Foldable, FoldedControls, folded_items}; |
| 16 | use super::call_extras::{CameraMenu, background_items, effect_items, open_transfer_picker}; |
| 17 | use super::call_record::{record_items, transcript_and_settings_items}; |
| 18 | use super::call_toolbar::{split_chevron, tool_face, tool_trigger}; |
| 19 | use super::call_view::{BANNER_HEIGHT, MENU_WIDTH}; |
| 20 | use super::widgets::{Corner, corner_badge, count_badge, icon}; |
| 21 | use crate::app_state::AppState; |
| 22 | use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus, contain_size}; |
| 23 | use crate::i18n::tr; |
| 24 | use crate::notice::truncated; |
| 25 | use crate::theme; |
| 26 | |
| 27 | const BANNER_TEXT: f32 = 13.; |
| 28 | const PILL_HEIGHT: f32 = 26.; |
| 29 | const LOBBY_LIST_WIDTH: f32 = 340.; |
| 30 | const LOBBY_NAME_LIMIT: usize = 28; |
| 31 | const CAPTION_WIDTH: f32 = 720.; |
| 32 | const CAPTION_BOTTOM: f32 = 16.; |
| 33 | const CAPTION_TOP: f32 = 72.; |
| 34 | const CAPTION_FADE_SECONDS: f32 = 1.; |
| 35 | const CAPTION_BACKGROUND: f32 = 0.72; |
| 36 | const FOCUS_RADIUS: f32 = 12.; |
| 37 | const FOCUS_BORDER: f32 = 2.; |
| 38 | const FOCUS_AVATAR: f32 = 140.; |
| 39 | const CHIP_HEIGHT: f32 = 24.; |
| 40 | const MORE_SIZE: f32 = 28.; |
| 41 | const NAME_LIMIT: usize = 32; |
| 42 | |
| 43 | fn dark_text() -> Hsla { |
| 44 | hsla(0., 0., 0.08, 1.) |
| 45 | } |
| 46 | |
| 47 | pub(super) fn pill( |
| 48 | id: impl Into<ElementId>, |
| 49 | label: impl Into<SharedString>, |
| 50 | filled: bool, |
| 51 | ) -> Stateful<Div> { |
| 52 | let (background, foreground) = if filled { |
| 53 | (dark_text(), theme::white()) |
| 54 | } else { |
| 55 | (dark_text().opacity(0.12), dark_text()) |
| 56 | }; |
| 57 | div() |
| 58 | .id(id) |
| 59 | .h(px(PILL_HEIGHT)) |
| 60 | .px(px(12.)) |
| 61 | .flex() |
| 62 | .flex_none() |
| 63 | .items_center() |
| 64 | .rounded_full() |
| 65 | .bg(background) |
| 66 | .text_color(foreground) |
| 67 | .text_size(px(BANNER_TEXT)) |
| 68 | .font_weight(FontWeight::SEMIBOLD) |
| 69 | .cursor_pointer() |
| 70 | .hover(|button| button.opacity(0.85)) |
| 71 | .child(label.into()) |
| 72 | } |
| 73 | |
| 74 | pub fn lobby_text(waiting: usize) -> String { |
| 75 | match waiting { |
| 76 | 1 => "1 person is waiting in the lobby".to_owned(), |
| 77 | count => format!("{count} people are waiting in the lobby"), |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | fn lobby_list(app: &Entity<AppState>, guests: &[(String, String)]) -> Div { |
| 82 | v_flex() |
| 83 | .w(px(LOBBY_LIST_WIDTH)) |
| 84 | .gap(px(6.)) |
| 85 | .children(guests.iter().map(|(mri, name)| { |
| 86 | let (admit_app, deny_app) = (app.clone(), app.clone()); |
| 87 | let (admit_mri, deny_mri) = (mri.clone(), mri.clone()); |
| 88 | h_flex() |
| 89 | .w_full() |
| 90 | .gap(px(8.)) |
| 91 | .items_center() |
| 92 | .child( |
| 93 | div() |
| 94 | .flex_1() |
| 95 | .min_w_0() |
| 96 | .truncate() |
| 97 | .text_size(px(14.)) |
| 98 | .child(truncated(name, LOBBY_NAME_LIMIT)), |
| 99 | ) |
| 100 | .child( |
| 101 | Button::new(SharedString::from(format!("lobby-admit-{mri}"))) |
| 102 | .label(tr("common.admit")) |
| 103 | .on_click(move |_, _, cx| { |
| 104 | admit_app.update(cx, |state, cx| { |
| 105 | state.admit_call_guest(admit_mri.clone(), cx) |
| 106 | }) |
| 107 | }), |
| 108 | ) |
| 109 | .child( |
| 110 | Button::new(SharedString::from(format!("lobby-deny-{mri}"))) |
| 111 | .label(tr("common.deny")) |
| 112 | .ghost() |
| 113 | .on_click(move |_, _, cx| { |
| 114 | deny_app |
| 115 | .update(cx, |state, cx| state.deny_call_guest(deny_mri.clone(), cx)) |
| 116 | }), |
| 117 | ) |
| 118 | })) |
| 119 | } |
| 120 | |
| 121 | pub fn lobby_banner( |
| 122 | app: &Entity<AppState>, |
| 123 | model: &CallModel, |
| 124 | list_open: bool, |
| 125 | ) -> Option<AnyElement> { |
| 126 | if !model.can_admit() { |
| 127 | return None; |
| 128 | } |
| 129 | let guests: Vec<(String, String)> = model |
| 130 | .lobby_guests() |
| 131 | .into_iter() |
| 132 | .map(|tile| (tile.mri.clone(), tile.name.clone())) |
| 133 | .collect(); |
| 134 | if guests.is_empty() { |
| 135 | return None; |
| 136 | } |
| 137 | let list_app = app.clone(); |
| 138 | let open_app = app.clone(); |
| 139 | let admit_app = app.clone(); |
| 140 | Some( |
| 141 | h_flex() |
| 142 | .id("call-lobby-banner") |
| 143 | .w_full() |
| 144 | .h(px(BANNER_HEIGHT)) |
| 145 | .flex_none() |
| 146 | .px(px(20.)) |
| 147 | .gap(px(12.)) |
| 148 | .items_center() |
| 149 | .justify_center() |
| 150 | .bg(theme::amber()) |
| 151 | .text_color(dark_text()) |
| 152 | .text_size(px(BANNER_TEXT)) |
| 153 | .font_weight(FontWeight::SEMIBOLD) |
| 154 | .child(lobby_text(guests.len())) |
| 155 | .child( |
| 156 | Popover::new("call-lobby-popover") |
| 157 | .anchor(Anchor::TopLeft) |
| 158 | .offset(px(8.)) |
| 159 | .open(list_open) |
| 160 | .on_open_change(move |open, _, cx| { |
| 161 | open_app.update(cx, |state, cx| state.set_call_lobby_list(*open, cx)) |
| 162 | }) |
| 163 | .trigger( |
| 164 | Button::new("call-lobby-view") |
| 165 | .ghost() |
| 166 | .p_0() |
| 167 | .h(px(PILL_HEIGHT)) |
| 168 | .rounded_full() |
| 169 | .child(pill("call-lobby-view-face", "View", false)), |
| 170 | ) |
| 171 | .content(move |_, _, _| lobby_list(&list_app, &guests)), |
| 172 | ) |
| 173 | .child( |
| 174 | pill("call-lobby-admit-all", "Admit all", true).on_click(move |_, _, cx| { |
| 175 | admit_app.update(cx, |state, cx| state.admit_all_call_guests(cx)) |
| 176 | }), |
| 177 | ) |
| 178 | .into_any_element(), |
| 179 | ) |
| 180 | } |
| 181 | |
| 182 | fn confirm_remove( |
| 183 | app: &Entity<AppState>, |
| 184 | mri: &str, |
| 185 | name: &str, |
| 186 | window: &mut Window, |
| 187 | cx: &mut App, |
| 188 | ) { |
| 189 | let app = app.clone(); |
| 190 | let mri = mri.to_owned(); |
| 191 | let heading = format!("Remove {} from the meeting?", truncated(name, NAME_LIMIT)); |
| 192 | window.open_alert_dialog(cx, move |alert, _, _| { |
| 193 | let app = app.clone(); |
| 194 | let mri = mri.clone(); |
| 195 | let cancel = Button::new("remove-cancel") |
| 196 | .label(tr("common.cancel")) |
| 197 | .on_click(|_, window, cx| window.close_dialog(cx)); |
| 198 | let remove = Button::new("remove-confirm") |
| 199 | .label(tr("common.remove")) |
| 200 | .danger() |
| 201 | .on_click(move |_, window, cx| { |
| 202 | app.update(cx, |state, cx| { |
| 203 | state.remove_call_participant(mri.clone(), cx) |
| 204 | }); |
| 205 | window.close_dialog(cx); |
| 206 | }); |
| 207 | alert |
| 208 | .title(heading.clone()) |
| 209 | .description("They leave the call and can only come back if they join again.") |
| 210 | .footer(DialogFooter::new().child(cancel).child(remove)) |
| 211 | .on_ok(|_, _, _| false) |
| 212 | }); |
| 213 | } |
| 214 | |
| 215 | fn own_tile_items(popup: PopupMenu, app: &Entity<AppState>) -> PopupMenu { |
| 216 | let hide_app = app.clone(); |
| 217 | popup.min_w(px(MENU_WIDTH)).item( |
| 218 | PopupMenuItem::new("Hide for me") |
| 219 | .icon(IconName::EyeOff) |
| 220 | .on_click(move |_, _, cx| { |
| 221 | hide_app.update(cx, |state, cx| state.set_call_hide_me(true, cx)) |
| 222 | }), |
| 223 | ) |
| 224 | } |
| 225 | |
| 226 | pub fn tile_menu( |
| 227 | popup: PopupMenu, |
| 228 | app: &Entity<AppState>, |
| 229 | model: &CallModel, |
| 230 | mri: &str, |
| 231 | name: &str, |
| 232 | own: bool, |
| 233 | ) -> PopupMenu { |
| 234 | if own { |
| 235 | return own_tile_items(popup, app); |
| 236 | } |
| 237 | let pinned = model.is_pinned(mri); |
| 238 | let spotlighted = model.is_spotlighted(mri); |
| 239 | let organizes = model.organizes_meeting(); |
| 240 | let raised = model |
| 241 | .tiles |
| 242 | .iter() |
| 243 | .any(|tile| tile.mri == mri && tile.hand.is_some()); |
| 244 | let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted); |
| 245 | let mut popup = popup.min_w(px(MENU_WIDTH)); |
| 246 | let pin_app = app.clone(); |
| 247 | let pin_mri = mri.to_owned(); |
| 248 | popup = popup.item( |
| 249 | PopupMenuItem::new(if pinned { "Unpin" } else { "Pin for me" }) |
| 250 | .icon(IconName::Frame) |
| 251 | .on_click(move |_, _, cx| { |
| 252 | pin_app.update(cx, |state, cx| state.toggle_call_pin(&pin_mri, cx)) |
| 253 | }), |
| 254 | ); |
| 255 | if model.is_one_to_one() |
| 256 | || model |
| 257 | .tiles |
| 258 | .iter() |
| 259 | .any(|tile| tile.mri == mri && tile.has_video) |
| 260 | { |
| 261 | let (fit_app, fit_mri) = (app.clone(), mri.to_owned()); |
| 262 | let fitted = model.is_fitted(mri); |
| 263 | popup = popup.item( |
| 264 | PopupMenuItem::new(if fitted { "Fill frame" } else { "Fit to frame" }) |
| 265 | .icon(if fitted { |
| 266 | IconName::Expand |
| 267 | } else { |
| 268 | IconName::Shrink |
| 269 | }) |
| 270 | .on_click(move |_, _, cx| { |
| 271 | fit_app.update(cx, |state, cx| state.toggle_call_fit(&fit_mri, cx)) |
| 272 | }), |
| 273 | ); |
| 274 | } |
| 275 | if organizes { |
| 276 | let (spotlight_app, spotlight_mri) = (app.clone(), mri.to_owned()); |
| 277 | popup = popup.item( |
| 278 | PopupMenuItem::new(if spotlighted { |
| 279 | "Stop spotlight" |
| 280 | } else { |
| 281 | "Spotlight for everyone" |
| 282 | }) |
| 283 | .icon(IconName::Star) |
| 284 | .on_click(move |_, _, cx| { |
| 285 | spotlight_app.update(cx, |state, cx| { |
| 286 | state.toggle_call_spotlight(spotlight_mri.clone(), cx) |
| 287 | }) |
| 288 | }), |
| 289 | ); |
| 290 | } |
| 291 | if organizes { |
| 292 | let (mute_app, mute_mri) = (app.clone(), mri.to_owned()); |
| 293 | popup = popup.item( |
| 294 | PopupMenuItem::new("Mute") |
| 295 | .icon(IconName::MicOff) |
| 296 | .disabled(muted) |
| 297 | .on_click(move |_, _, cx| { |
| 298 | mute_app.update(cx, |state, cx| { |
| 299 | state.mute_call_participant(mute_mri.clone(), cx) |
| 300 | }) |
| 301 | }), |
| 302 | ); |
| 303 | } |
| 304 | if model.can_change_roles(mri) { |
| 305 | popup = restriction_items(popup, app, model, mri); |
| 306 | } |
| 307 | if organizes && raised { |
| 308 | let (hand_app, hand_mri) = (app.clone(), mri.to_owned()); |
| 309 | popup = popup.item(PopupMenuItem::new("Lower hand").on_click(move |_, _, cx| { |
| 310 | hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx)) |
| 311 | })); |
| 312 | } |
| 313 | if organizes { |
| 314 | let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned()); |
| 315 | popup = popup.separator().item( |
| 316 | PopupMenuItem::new("Remove from meeting...") |
| 317 | .icon(IconName::Close) |
| 318 | .on_click(move |_, window, cx| { |
| 319 | confirm_remove(&remove_app, &remove_mri, &remove_name, window, cx) |
| 320 | }), |
| 321 | ); |
| 322 | } |
| 323 | popup |
| 324 | } |
| 325 | |
| 326 | fn modality_item( |
| 327 | app: &Entity<AppState>, |
| 328 | mri: &str, |
| 329 | modality: Modality, |
| 330 | allowed: bool, |
| 331 | ) -> PopupMenuItem { |
| 332 | let (app, mri) = (app.clone(), mri.to_owned()); |
| 333 | let (label, glyph) = match (modality, allowed) { |
| 334 | (Modality::Mic, true) => ("Disable mic", IconName::MicOff), |
| 335 | (Modality::Mic, false) => ("Allow mic", IconName::Mic), |
| 336 | (Modality::Camera, true) => ("Disable camera", IconName::VideoOff), |
| 337 | (Modality::Camera, false) => ("Allow camera", IconName::Video), |
| 338 | }; |
| 339 | PopupMenuItem::new(label) |
| 340 | .icon(glyph) |
| 341 | .on_click(move |_, _, cx| { |
| 342 | app.update(cx, |state, cx| { |
| 343 | state.set_call_attendee_modality(mri.clone(), modality, !allowed, cx) |
| 344 | }) |
| 345 | }) |
| 346 | } |
| 347 | |
| 348 | fn restriction_items( |
| 349 | popup: PopupMenu, |
| 350 | app: &Entity<AppState>, |
| 351 | model: &CallModel, |
| 352 | mri: &str, |
| 353 | ) -> PopupMenu { |
| 354 | let presenter = model.tile_role(mri) == Some(MeetingRole::Presenter); |
| 355 | let (role_app, role_mri) = (app.clone(), mri.to_owned()); |
| 356 | popup |
| 357 | .item(modality_item( |
| 358 | app, |
| 359 | mri, |
| 360 | Modality::Mic, |
| 361 | model.attendee_allowed(mri, Modality::Mic), |
| 362 | )) |
| 363 | .item(modality_item( |
| 364 | app, |
| 365 | mri, |
| 366 | Modality::Camera, |
| 367 | model.attendee_allowed(mri, Modality::Camera), |
| 368 | )) |
| 369 | .item( |
| 370 | PopupMenuItem::new(if presenter { |
| 371 | "Make attendee" |
| 372 | } else { |
| 373 | "Make presenter" |
| 374 | }) |
| 375 | .icon(IconName::Users) |
| 376 | .on_click(move |_, _, cx| { |
| 377 | let role = if presenter { |
| 378 | MeetingRole::Attendee |
| 379 | } else { |
| 380 | MeetingRole::Presenter |
| 381 | }; |
| 382 | role_app.update(cx, |state, cx| { |
| 383 | state.set_call_role(role_mri.clone(), role, cx) |
| 384 | }) |
| 385 | }), |
| 386 | ) |
| 387 | } |
| 388 | |
| 389 | fn more_overlay( |
| 390 | app: &Entity<AppState>, |
| 391 | model: &CallModel, |
| 392 | mri: &str, |
| 393 | name: &str, |
| 394 | own: bool, |
| 395 | group: SharedString, |
| 396 | ) -> Div { |
| 397 | let (app, model, mri_owned, name) = |
| 398 | (app.clone(), model.clone(), mri.to_owned(), name.to_owned()); |
| 399 | div() |
| 400 | .absolute() |
| 401 | .top(px(8.)) |
| 402 | .right(px(8.)) |
| 403 | .opacity(0.) |
| 404 | .group_hover(group, |more| more.opacity(1.)) |
| 405 | .child( |
| 406 | Button::new(SharedString::from(format!("call-tile-more-{mri}"))) |
| 407 | .icon(IconName::Ellipsis) |
| 408 | .ghost() |
| 409 | .xsmall() |
| 410 | .size(px(MORE_SIZE)) |
| 411 | .rounded_full() |
| 412 | .bg(black().opacity(0.55)) |
| 413 | .text_color(theme::white()) |
| 414 | .tooltip("More") |
| 415 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 416 | tile_menu(popup, &app, &model, &mri_owned, &name, own) |
| 417 | }), |
| 418 | ) |
| 419 | } |
| 420 | |
| 421 | /// Adds the right-click menu and a "..." button that shows while the pointer is over the tile. |
| 422 | pub fn attach_tile_menu( |
| 423 | tile: Stateful<Div>, |
| 424 | app: &Entity<AppState>, |
| 425 | model: &CallModel, |
| 426 | mri: &str, |
| 427 | name: &str, |
| 428 | own: bool, |
| 429 | ) -> AnyElement { |
| 430 | let group = SharedString::from(format!("call-tile-group-{mri}")); |
| 431 | let (context_app, context_model, context_mri, context_name) = |
| 432 | (app.clone(), model.clone(), mri.to_owned(), name.to_owned()); |
| 433 | tile.group(group.clone()) |
| 434 | .relative() |
| 435 | .child(more_overlay(app, model, mri, name, own, group)) |
| 436 | .context_menu(move |popup, _, _| { |
| 437 | tile_menu( |
| 438 | popup, |
| 439 | &context_app, |
| 440 | &context_model, |
| 441 | &context_mri, |
| 442 | &context_name, |
| 443 | own, |
| 444 | ) |
| 445 | }) |
| 446 | .into_any_element() |
| 447 | } |
| 448 | |
| 449 | pub fn with_tile_menu( |
| 450 | app: &Entity<AppState>, |
| 451 | model: &CallModel, |
| 452 | mri: &str, |
| 453 | name: &str, |
| 454 | own: bool, |
| 455 | tile: AnyElement, |
| 456 | ) -> AnyElement { |
| 457 | let wrapper = div() |
| 458 | .id(SharedString::from(format!("call-tile-{mri}"))) |
| 459 | .flex_none() |
| 460 | .child(tile); |
| 461 | attach_tile_menu(wrapper, app, model, mri, name, own) |
| 462 | } |
| 463 | |
| 464 | pub fn more_button( |
| 465 | app: &Entity<AppState>, |
| 466 | model: &CallModel, |
| 467 | folded: &FoldedControls, |
| 468 | ) -> Option<AnyElement> { |
| 469 | if !matches!( |
| 470 | model.kind, |
| 471 | crate::call::CallKind::Meeting |
| 472 | | crate::call::CallKind::Direct |
| 473 | | crate::call::CallKind::Group |
| 474 | ) { |
| 475 | return None; |
| 476 | } |
| 477 | let app = app.clone(); |
| 478 | let model = model.clone(); |
| 479 | let folded = folded.clone(); |
| 480 | let unread = folded.chat_unread; |
| 481 | let chat_folded = folded.folds(Foldable::Chat); |
| 482 | Some( |
| 483 | tool_trigger( |
| 484 | "call-more", |
| 485 | tool_face("call-more-face", IconName::Ellipsis, "More", false) |
| 486 | .relative() |
| 487 | .when(chat_folded && unread > 0, |face| { |
| 488 | face.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false))) |
| 489 | }), |
| 490 | ) |
| 491 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, window, cx| { |
| 492 | more_menu(popup, window, cx, &app, &model, &folded) |
| 493 | }) |
| 494 | .into_any_element(), |
| 495 | ) |
| 496 | } |
| 497 | |
| 498 | fn more_menu( |
| 499 | popup: PopupMenu, |
| 500 | window: &mut Window, |
| 501 | cx: &mut Context<PopupMenu>, |
| 502 | app: &Entity<AppState>, |
| 503 | model: &CallModel, |
| 504 | folded: &FoldedControls, |
| 505 | ) -> PopupMenu { |
| 506 | let popup = folded_items(popup.min_w(px(MENU_WIDTH)), window, cx, app, model, folded); |
| 507 | let popup = match model.kind { |
| 508 | crate::call::CallKind::Meeting => meeting_items(popup, window, cx, app, model), |
| 509 | crate::call::CallKind::Direct => one_to_one_items(popup, window, cx, app, model), |
| 510 | _ => record_items(popup, window, cx, app, model), |
| 511 | }; |
| 512 | incoming_video_item(popup, app, model) |
| 513 | } |
| 514 | |
| 515 | fn incoming_video_item(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu { |
| 516 | if model.health.incoming_video { |
| 517 | return popup; |
| 518 | } |
| 519 | let app = app.clone(); |
| 520 | popup.item( |
| 521 | PopupMenuItem::new("Turn on incoming video") |
| 522 | .icon(IconName::Video) |
| 523 | .on_click(move |_, _, cx| { |
| 524 | app.update(cx, |state, cx| state.set_call_incoming_video(true, cx)) |
| 525 | }), |
| 526 | ) |
| 527 | } |
| 528 | |
| 529 | fn one_to_one_items( |
| 530 | mut popup: PopupMenu, |
| 531 | window: &mut Window, |
| 532 | cx: &mut Context<PopupMenu>, |
| 533 | app: &Entity<AppState>, |
| 534 | model: &CallModel, |
| 535 | ) -> PopupMenu { |
| 536 | let (hold_app, transfer_app) = (app.clone(), app.clone()); |
| 537 | let held = model.hold == HoldState::Local; |
| 538 | popup = popup.item( |
| 539 | PopupMenuItem::new(if held { "Resume" } else { "Hold" }) |
| 540 | .icon(IconName::Timer) |
| 541 | .disabled(!held && !model.can_hold()) |
| 542 | .on_click(move |_, _, cx| hold_app.update(cx, |state, cx| state.toggle_call_hold(cx))), |
| 543 | ); |
| 544 | popup = record_items(popup, window, cx, app, model); |
| 545 | let can_transfer = model.can_transfer(); |
| 546 | popup.item( |
| 547 | PopupMenuItem::new("Transfer...") |
| 548 | .icon(IconName::Forward) |
| 549 | .disabled(!can_transfer) |
| 550 | .on_click(move |_, window, cx| open_transfer_picker(&transfer_app, window, cx)), |
| 551 | ) |
| 552 | } |
| 553 | |
| 554 | fn meeting_items( |
| 555 | mut popup: PopupMenu, |
| 556 | window: &mut Window, |
| 557 | cx: &mut Context<PopupMenu>, |
| 558 | app: &Entity<AppState>, |
| 559 | model: &CallModel, |
| 560 | ) -> PopupMenu { |
| 561 | let (mute_app, captions_app, board_app) = (app.clone(), app.clone(), app.clone()); |
| 562 | let captions_on = model.captions_on(); |
| 563 | if model.organizes_meeting() { |
| 564 | popup = popup.item( |
| 565 | PopupMenuItem::new("Mute all") |
| 566 | .icon(IconName::MicOff) |
| 567 | .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))), |
| 568 | ); |
| 569 | } |
| 570 | popup = record_items(popup, window, cx, app, model); |
| 571 | if model.can_open_whiteboard() { |
| 572 | popup = popup.item( |
| 573 | PopupMenuItem::new("Whiteboard") |
| 574 | .icon(IconName::Frame) |
| 575 | .on_click(move |_, _, cx| { |
| 576 | board_app.update(cx, |state, cx| state.open_call_whiteboard(cx)) |
| 577 | }), |
| 578 | ); |
| 579 | } |
| 580 | let popup = popup.item( |
| 581 | PopupMenuItem::new(if captions_on { |
| 582 | "Turn off live captions" |
| 583 | } else { |
| 584 | "Turn on live captions" |
| 585 | }) |
| 586 | .icon(if captions_on { |
| 587 | IconName::CaptionsOff |
| 588 | } else { |
| 589 | IconName::Captions |
| 590 | }) |
| 591 | .on_click(move |_, _, cx| { |
| 592 | captions_app.update(cx, |state, cx| state.toggle_call_captions(cx)) |
| 593 | }), |
| 594 | ); |
| 595 | transcript_and_settings_items(popup, app) |
| 596 | } |
| 597 | |
| 598 | pub fn camera_menu_button( |
| 599 | app: &Entity<AppState>, |
| 600 | model: &CallModel, |
| 601 | backgrounds: CameraMenu, |
| 602 | ) -> Option<AnyElement> { |
| 603 | if !model.can_use_camera() { |
| 604 | return None; |
| 605 | } |
| 606 | let app = app.clone(); |
| 607 | let model = model.clone(); |
| 608 | Some( |
| 609 | split_chevron("call-camera-menu", "call-camera-menu-face") |
| 610 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 611 | camera_menu(popup, &app, &model, &backgrounds) |
| 612 | }) |
| 613 | .into_any_element(), |
| 614 | ) |
| 615 | } |
| 616 | |
| 617 | fn camera_menu( |
| 618 | popup: PopupMenu, |
| 619 | app: &Entity<AppState>, |
| 620 | model: &CallModel, |
| 621 | backgrounds: &CameraMenu, |
| 622 | ) -> PopupMenu { |
| 623 | let camera_app = app.clone(); |
| 624 | let cameras = super::call_view::device_items( |
| 625 | calling::camera_entries(&model.cameras), |
| 626 | &model.camera, |
| 627 | move |choice, cx| { |
| 628 | camera_app.update(cx, |state, cx| state.select_call_camera(choice, cx)); |
| 629 | }, |
| 630 | ); |
| 631 | let mut popup = popup |
| 632 | .min_w(px(MENU_WIDTH)) |
| 633 | .item(PopupMenuItem::label("Camera")); |
| 634 | for item in cameras { |
| 635 | popup = popup.item(item); |
| 636 | } |
| 637 | background_items( |
| 638 | effect_items( |
| 639 | super::call_extras::quality_items(popup, app, backgrounds.quality), |
| 640 | app, |
| 641 | backgrounds.effects, |
| 642 | ), |
| 643 | app, |
| 644 | backgrounds, |
| 645 | ) |
| 646 | } |
| 647 | |
| 648 | pub fn captions_overlay(model: &CallModel, now: Instant) -> Option<AnyElement> { |
| 649 | let lines = model.visible_captions(now); |
| 650 | if lines.is_empty() { |
| 651 | return None; |
| 652 | } |
| 653 | let shown = CAPTION_SHOWN.as_secs_f32(); |
| 654 | Some( |
| 655 | div() |
| 656 | .id("call-captions") |
| 657 | .absolute() |
| 658 | .left_0() |
| 659 | .right_0() |
| 660 | .map(|overlay| match model.view.caption_position { |
| 661 | CaptionPosition::Bottom => overlay.bottom(px(CAPTION_BOTTOM)), |
| 662 | CaptionPosition::Top => overlay.top(px(CAPTION_TOP)), |
| 663 | }) |
| 664 | .flex() |
| 665 | .justify_center() |
| 666 | .px(px(24.)) |
| 667 | .child( |
| 668 | v_flex() |
| 669 | .w(px(CAPTION_WIDTH)) |
| 670 | .max_w_full() |
| 671 | .gap(px(4.)) |
| 672 | .px(px(16.)) |
| 673 | .py(px(8.)) |
| 674 | .rounded(px(10.)) |
| 675 | .bg(hsla(0., 0., 0., CAPTION_BACKGROUND)) |
| 676 | .text_color(theme::white()) |
| 677 | .text_size(px(model.view.caption_size.text_size())) |
| 678 | .children(lines.into_iter().map(|line| { |
| 679 | let age = now.saturating_duration_since(line.at).as_secs_f32(); |
| 680 | let fade = ((shown - age) / CAPTION_FADE_SECONDS).clamp(0., 1.); |
| 681 | h_flex() |
| 682 | .opacity(fade) |
| 683 | .gap(px(8.)) |
| 684 | .items_start() |
| 685 | .child( |
| 686 | div() |
| 687 | .flex_none() |
| 688 | .font_weight(FontWeight::BOLD) |
| 689 | .child(format!("{}:", line.speaker)), |
| 690 | ) |
| 691 | .child(div().flex_1().min_w_0().child(line.text.clone())) |
| 692 | })), |
| 693 | ) |
| 694 | .into_any_element(), |
| 695 | ) |
| 696 | } |
| 697 | |
| 698 | fn focus_chip(label: &'static str, glyph: IconName, background: Hsla, foreground: Hsla) -> Div { |
| 699 | h_flex() |
| 700 | .h(px(CHIP_HEIGHT)) |
| 701 | .px(px(8.)) |
| 702 | .gap(px(4.)) |
| 703 | .items_center() |
| 704 | .rounded_full() |
| 705 | .bg(background) |
| 706 | .text_color(foreground) |
| 707 | .text_size(px(12.)) |
| 708 | .font_weight(FontWeight::SEMIBOLD) |
| 709 | .child(icon(glyph, 13., foreground)) |
| 710 | .child(label) |
| 711 | } |
| 712 | |
| 713 | pub fn spotlight_chip() -> Div { |
| 714 | focus_chip("Spotlight", IconName::Star, theme::amber(), dark_text()) |
| 715 | } |
| 716 | |
| 717 | pub fn pin_chip() -> Div { |
| 718 | focus_chip( |
| 719 | "Pinned", |
| 720 | IconName::Frame, |
| 721 | hsla(0., 0., 0., 0.6), |
| 722 | theme::white(), |
| 723 | ) |
| 724 | } |
| 725 | |
| 726 | pub fn render_focus_stage( |
| 727 | app: &Entity<AppState>, |
| 728 | state: &AppState, |
| 729 | focus: &Focus, |
| 730 | size: (f32, f32), |
| 731 | now: Instant, |
| 732 | ) -> Option<AnyElement> { |
| 733 | let call = state.call.as_ref()?; |
| 734 | let model = &call.model; |
| 735 | let me = state.directory.me.as_ref(); |
| 736 | let (name, user_id, speaking, muted, key) = if focus.own { |
| 737 | ( |
| 738 | "You".to_owned(), |
| 739 | me.map(|person| person.user_id.clone()), |
| 740 | model.local_speaking, |
| 741 | model.muted, |
| 742 | VideoKey::LocalCamera, |
| 743 | ) |
| 744 | } else { |
| 745 | let tile = model.tiles.iter().find(|tile| tile.mri == focus.mri)?; |
| 746 | ( |
| 747 | tile.name.clone(), |
| 748 | tile.user_id.clone(), |
| 749 | model.tile_speaking(tile), |
| 750 | tile.muted, |
| 751 | VideoKey::Person(tile.mri.clone()), |
| 752 | ) |
| 753 | }; |
| 754 | let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now); |
| 755 | let avatar_only = image.is_none(); |
| 756 | let (picture_size, picture) = match image { |
| 757 | Some(image) => { |
| 758 | let pixels = image.size(0); |
| 759 | let (width, height) = |
| 760 | contain_size(size, (pixels.width.0 as f32, pixels.height.0 as f32)); |
| 761 | let picture = img(ImageSource::Render(image)) |
| 762 | .size_full() |
| 763 | .object_fit(ObjectFit::Fill) |
| 764 | .rounded(px(FOCUS_RADIUS)) |
| 765 | .into_any_element(); |
| 766 | ((width, height), picture) |
| 767 | } |
| 768 | None => ( |
| 769 | contain_size(size, (16., 9.)), |
| 770 | div() |
| 771 | .size_full() |
| 772 | .flex() |
| 773 | .items_center() |
| 774 | .justify_center() |
| 775 | .child(person_avatar( |
| 776 | &state.directory, |
| 777 | user_id.as_deref(), |
| 778 | &name, |
| 779 | FOCUS_AVATAR, |
| 780 | )) |
| 781 | .into_any_element(), |
| 782 | ), |
| 783 | }; |
| 784 | let stage = div() |
| 785 | .id("call-focus-stage") |
| 786 | .relative() |
| 787 | .w(px(picture_size.0)) |
| 788 | .h(px(picture_size.1)) |
| 789 | .flex_none() |
| 790 | .overflow_hidden() |
| 791 | .rounded(px(FOCUS_RADIUS)) |
| 792 | .when(avatar_only, |stage| stage.bg(hsla(0., 0., 0.04, 1.))) |
| 793 | .border(px(FOCUS_BORDER)) |
| 794 | .border_color(if speaking { |
| 795 | theme::green() |
| 796 | } else { |
| 797 | transparent_black() |
| 798 | }) |
| 799 | .child(picture) |
| 800 | .child( |
| 801 | h_flex() |
| 802 | .absolute() |
| 803 | .top(px(12.)) |
| 804 | .left(px(12.)) |
| 805 | .gap(px(6.)) |
| 806 | .when(focus.spotlight, |chips| chips.child(spotlight_chip())) |
| 807 | .when(focus.pinned, |chips| chips.child(pin_chip())), |
| 808 | ) |
| 809 | .child( |
| 810 | h_flex() |
| 811 | .absolute() |
| 812 | .left(px(8.)) |
| 813 | .bottom(px(8.)) |
| 814 | .gap(px(8.)) |
| 815 | .px(px(8.)) |
| 816 | .py(px(4.)) |
| 817 | .rounded(px(6.)) |
| 818 | .bg(hsla(0., 0., 0., 0.6)) |
| 819 | .text_color(theme::white()) |
| 820 | .text_size(px(13.)) |
| 821 | .font_weight(FontWeight::SEMIBOLD) |
| 822 | .child(name.clone()) |
| 823 | .when(muted, |plate| { |
| 824 | plate.child(icon(IconName::MicOff, 14., theme::red())) |
| 825 | }), |
| 826 | ); |
| 827 | let stage = attach_tile_menu(stage, app, model, &focus.mri, &name, focus.own); |
| 828 | Some( |
| 829 | div() |
| 830 | .w(px(size.0)) |
| 831 | .h(px(size.1)) |
| 832 | .flex_none() |
| 833 | .flex() |
| 834 | .items_center() |
| 835 | .justify_center() |
| 836 | .child(stage) |
| 837 | .into_any_element(), |
| 838 | ) |
| 839 | } |
| 840 | |
| 841 | pub fn captions_state_hint(model: &CallModel) -> Option<&'static str> { |
| 842 | match model.captions { |
| 843 | CaptionState::Starting => Some("Starting live captions..."), |
| 844 | CaptionState::Failed(_) => Some("Live captions could not start"), |
| 845 | CaptionState::On | CaptionState::Off => None, |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | pub fn captions_hint_chip(model: &CallModel) -> Option<AnyElement> { |
| 850 | let text = captions_state_hint(model)?; |
| 851 | Some( |
| 852 | div() |
| 853 | .id("call-captions-hint") |
| 854 | .absolute() |
| 855 | .left_0() |
| 856 | .right_0() |
| 857 | .bottom(px(CAPTION_BOTTOM)) |
| 858 | .flex() |
| 859 | .justify_center() |
| 860 | .child( |
| 861 | div() |
| 862 | .px(px(12.)) |
| 863 | .py(px(6.)) |
| 864 | .rounded_full() |
| 865 | .bg(hsla(0., 0., 0., CAPTION_BACKGROUND)) |
| 866 | .text_color(theme::white()) |
| 867 | .text_size(px(13.)) |
| 868 | .child(text), |
| 869 | ) |
| 870 | .into_any_element(), |
| 871 | ) |
| 872 | } |