| 1 | use std::cell::Cell; |
| 2 | use std::rc::Rc; |
| 3 | use std::sync::Arc; |
| 4 | use std::time::{Duration, Instant}; |
| 5 | |
| 6 | use calling::{ |
| 7 | AttendeeLimits, CallCommand, CallState, CallUpdate, CameraDevice, CaptionEntry, CaptionState, ContentShare, |
| 8 | DeviceChoice, DeviceLists, EndKind, EndReason, HoldState, MeetingCapability, MeetingRole, |
| 9 | MeetingTarget, Progress, Reaction, Replacement, RosterEntry, ShareKind, ShareSource, SpeakingDetector, VideoHub, |
| 10 | VideoWant, |
| 11 | }; |
| 12 | use tokio::sync::mpsc::UnboundedSender; |
| 13 | |
| 14 | use super::background::BackgroundPick; |
| 15 | use super::health::{HealthBanner, HealthState}; |
| 16 | use super::bubbles::ChatBubble; |
| 17 | use super::fullscreen::FullscreenState; |
| 18 | use super::pictures::CallPictures; |
| 19 | use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, RECENT_SPEAKER, SPEAKER_HOLD, VisibleRotation, split_overflow}; |
| 20 | use super::transcript::{Transcript, TranscriptEntry}; |
| 21 | use super::view_settings::{CallLayout, ViewSettings}; |
| 22 | use super::options_dialog::OptionsDialog; |
| 23 | use super::push_to_talk::PushToTalk; |
| 24 | use super::report::SharedRecorder; |
| 25 | use super::share_view::ShareStage; |
| 26 | |
| 27 | pub const TEST_CALL_TITLE: &str = "Test call"; |
| 28 | pub const ECHO_NAME: &str = "Teams echo"; |
| 29 | pub const ECHO_MRI: &str = calling::signaling::ECHO_BOT_MRI; |
| 30 | const ORGID_PREFIX: &str = "8:orgid:"; |
| 31 | const BOT_PREFIX: &str = "28:"; |
| 32 | const AVATAR_SHARE: f32 = 0.42; |
| 33 | const MIN_AVATAR: f32 = 32.; |
| 34 | const MAX_AVATAR: f32 = 96.; |
| 35 | pub const REACTION_SHOWN: Duration = Duration::from_secs(3); |
| 36 | const OWN_ECHO_WINDOW: Duration = Duration::from_secs(2); |
| 37 | pub const CAPTION_SHOWN: Duration = Duration::from_secs(4); |
| 38 | const CAPTION_LINES: usize = 2; |
| 39 | |
| 40 | pub struct ActiveCall { |
| 41 | pub id: u64, |
| 42 | pub model: CallModel, |
| 43 | pub commands: UnboundedSender<CallCommand>, |
| 44 | pub viewing: bool, |
| 45 | pub conversation_id: Option<String>, |
| 46 | pub video: Arc<VideoHub>, |
| 47 | pub pictures: CallPictures, |
| 48 | pub stage_fullscreen: bool, |
| 49 | pub fullscreen: Option<FullscreenState>, |
| 50 | pub stage_size: Rc<Cell<(f32, f32)>>, |
| 51 | pub sent_wants: Vec<VideoWant>, |
| 52 | pub share_stage: ShareStage, |
| 53 | pub bubbles: Vec<ChatBubble>, |
| 54 | pub share_menu_open: bool, |
| 55 | pub lobby_list_open: bool, |
| 56 | pub chat_open: bool, |
| 57 | pub transcript_open: bool, |
| 58 | pub people_open: bool, |
| 59 | pub options_dialog: Option<OptionsDialog>, |
| 60 | pub meeting_target: Option<MeetingTarget>, |
| 61 | pub pending_move: Option<PendingMove>, |
| 62 | pub consult: Option<ConsultCall>, |
| 63 | pub push_to_talk: PushToTalk, |
| 64 | pub report: Option<SharedRecorder>, |
| 65 | } |
| 66 | |
| 67 | #[derive(Debug, Clone, PartialEq)] |
| 68 | pub struct PendingMove { |
| 69 | pub target: MeetingTarget, |
| 70 | pub title: String, |
| 71 | pub breakout: Option<BreakoutState>, |
| 72 | } |
| 73 | |
| 74 | pub struct ConsultCall { |
| 75 | pub target: (String, String), |
| 76 | pub held_name: String, |
| 77 | pub replacement: Option<Replacement>, |
| 78 | pub transfer: ConsultTransfer, |
| 79 | } |
| 80 | |
| 81 | #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 82 | pub enum ConsultTransfer { |
| 83 | #[default] |
| 84 | Idle, |
| 85 | Pending, |
| 86 | Done, |
| 87 | } |
| 88 | |
| 89 | impl ConsultCall { |
| 90 | pub fn new(target: (String, String), held_name: String) -> Self { |
| 91 | ConsultCall { |
| 92 | target, |
| 93 | held_name, |
| 94 | replacement: None, |
| 95 | transfer: ConsultTransfer::Idle, |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | pub fn ready_to_transfer(&self, model: &CallModel) -> bool { |
| 100 | model.is_live() && self.replacement.is_some() && self.transfer == ConsultTransfer::Idle |
| 101 | } |
| 102 | |
| 103 | pub fn banner_text(&self) -> String { |
| 104 | match self.transfer { |
| 105 | ConsultTransfer::Idle => format!("{} is on hold", self.held_name), |
| 106 | ConsultTransfer::Pending | ConsultTransfer::Done => { |
| 107 | format!("Transferring {} to {}...", self.held_name, self.target.1) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | impl ActiveCall { |
| 114 | pub fn new( |
| 115 | id: u64, |
| 116 | model: CallModel, |
| 117 | commands: UnboundedSender<CallCommand>, |
| 118 | conversation_id: Option<String>, |
| 119 | video: Arc<VideoHub>, |
| 120 | ) -> Self { |
| 121 | ActiveCall { |
| 122 | id, |
| 123 | model, |
| 124 | commands, |
| 125 | viewing: true, |
| 126 | conversation_id, |
| 127 | video, |
| 128 | pictures: CallPictures::default(), |
| 129 | stage_fullscreen: false, |
| 130 | fullscreen: None, |
| 131 | stage_size: Rc::default(), |
| 132 | sent_wants: Vec::new(), |
| 133 | share_stage: ShareStage::default(), |
| 134 | bubbles: Vec::new(), |
| 135 | share_menu_open: false, |
| 136 | lobby_list_open: false, |
| 137 | chat_open: false, |
| 138 | transcript_open: false, |
| 139 | people_open: false, |
| 140 | options_dialog: None, |
| 141 | meeting_target: None, |
| 142 | pending_move: None, |
| 143 | consult: None, |
| 144 | push_to_talk: PushToTalk::default(), |
| 145 | report: None, |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | pub fn chat_thread(&self) -> Option<&str> { |
| 150 | chat_thread( |
| 151 | self.model.kind, |
| 152 | self.model.meeting_chat.as_deref(), |
| 153 | self.conversation_id.as_deref(), |
| 154 | ) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | pub fn chat_thread<'a>( |
| 159 | kind: CallKind, |
| 160 | meeting_chat: Option<&'a str>, |
| 161 | conversation_id: Option<&'a str>, |
| 162 | ) -> Option<&'a str> { |
| 163 | match kind { |
| 164 | CallKind::Meeting => meeting_chat.or(conversation_id), |
| 165 | CallKind::Test | CallKind::Direct | CallKind::Group => conversation_id, |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 170 | pub enum CallKind { |
| 171 | Test, |
| 172 | Direct, |
| 173 | Group, |
| 174 | Meeting, |
| 175 | } |
| 176 | |
| 177 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 178 | pub enum TileState { |
| 179 | Invited, |
| 180 | Present, |
| 181 | InLobby, |
| 182 | Left, |
| 183 | } |
| 184 | |
| 185 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 186 | pub struct Tile { |
| 187 | pub mri: String, |
| 188 | pub user_id: Option<String>, |
| 189 | pub name: String, |
| 190 | pub muted: bool, |
| 191 | pub state: TileState, |
| 192 | pub invited: bool, |
| 193 | pub has_video: bool, |
| 194 | pub hand: Option<u64>, |
| 195 | pub spotlight: Option<u64>, |
| 196 | pub role: Option<MeetingRole>, |
| 197 | pub limits: AttendeeLimits, |
| 198 | } |
| 199 | |
| 200 | impl Tile { |
| 201 | pub fn invited(mri: &str, name: &str) -> Tile { |
| 202 | Tile { |
| 203 | mri: mri.to_owned(), |
| 204 | user_id: mri.strip_prefix(ORGID_PREFIX).map(str::to_owned), |
| 205 | name: name.to_owned(), |
| 206 | muted: false, |
| 207 | state: TileState::Invited, |
| 208 | invited: true, |
| 209 | has_video: false, |
| 210 | hand: None, |
| 211 | spotlight: None, |
| 212 | role: None, |
| 213 | limits: AttendeeLimits::default(), |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | #[derive(Debug, Clone, PartialEq)] |
| 219 | pub struct BreakoutState { |
| 220 | pub room_name: String, |
| 221 | pub main: Option<MeetingTarget>, |
| 222 | pub main_title: String, |
| 223 | } |
| 224 | |
| 225 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 226 | pub struct Focus { |
| 227 | pub mri: String, |
| 228 | pub own: bool, |
| 229 | pub spotlight: bool, |
| 230 | pub pinned: bool, |
| 231 | } |
| 232 | |
| 233 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 234 | pub struct CaptionLine { |
| 235 | pub id: String, |
| 236 | pub speaker: String, |
| 237 | pub text: String, |
| 238 | pub at: Instant, |
| 239 | } |
| 240 | |
| 241 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 242 | pub struct TileSize { |
| 243 | pub width: f32, |
| 244 | pub height: f32, |
| 245 | pub avatar: f32, |
| 246 | } |
| 247 | |
| 248 | impl TileSize { |
| 249 | pub fn sixteen_by_nine(width: f32) -> TileSize { |
| 250 | let height = width * 9. / 16.; |
| 251 | TileSize { |
| 252 | width, |
| 253 | height, |
| 254 | avatar: (height * AVATAR_SHARE).clamp(MIN_AVATAR, MAX_AVATAR), |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 260 | pub struct ReactionChip { |
| 261 | pub mri: String, |
| 262 | pub reaction: Reaction, |
| 263 | pub since: Instant, |
| 264 | pub serial: u64, |
| 265 | } |
| 266 | |
| 267 | #[derive(Debug, Clone)] |
| 268 | pub struct CallModel { |
| 269 | pub title: String, |
| 270 | pub kind: CallKind, |
| 271 | pub peer_name: String, |
| 272 | pub state: CallState, |
| 273 | pub progress: Option<Progress>, |
| 274 | pub muted: bool, |
| 275 | pub listen_only: bool, |
| 276 | pub audio_off: bool, |
| 277 | pub lobby: bool, |
| 278 | pub can_end_meeting: bool, |
| 279 | pub incoming: bool, |
| 280 | pub input: DeviceChoice, |
| 281 | pub output: DeviceChoice, |
| 282 | pub devices: DeviceLists, |
| 283 | pub local_speaking: bool, |
| 284 | pub remote_speaking: bool, |
| 285 | pub speaking_mris: Vec<String>, |
| 286 | pub connected_since: Option<Instant>, |
| 287 | pub own_mri: Option<String>, |
| 288 | pub tiles: Vec<Tile>, |
| 289 | pub screen_sharer: Option<String>, |
| 290 | pub camera_on: bool, |
| 291 | pub cameras: Vec<CameraDevice>, |
| 292 | pub camera: DeviceChoice, |
| 293 | pub local_share: Option<String>, |
| 294 | pub share_sources: Vec<ShareSource>, |
| 295 | pub share_sound: bool, |
| 296 | pub own_hand: Option<u64>, |
| 297 | pub own_spotlight: Option<u64>, |
| 298 | pub organizer: bool, |
| 299 | pub own_role: Option<MeetingRole>, |
| 300 | pub capability: MeetingCapability, |
| 301 | pub pinned: Option<String>, |
| 302 | pub captions: CaptionState, |
| 303 | pub caption_lines: Vec<CaptionLine>, |
| 304 | pub transcript: Transcript, |
| 305 | pub caption_language: Option<String>, |
| 306 | language_pending: bool, |
| 307 | pub background: BackgroundPick, |
| 308 | pub recording: bool, |
| 309 | pub recording_audio_only: bool, |
| 310 | pub transcribing: bool, |
| 311 | pub consent_required: bool, |
| 312 | pub hold: HoldState, |
| 313 | pub health: HealthState, |
| 314 | pub whiteboard: Option<ContentShare>, |
| 315 | pub breakout: Option<BreakoutState>, |
| 316 | pub main_meeting: Option<MeetingTarget>, |
| 317 | pub reactions: Vec<ReactionChip>, |
| 318 | reaction_serial: u64, |
| 319 | pub meeting_chat: Option<String>, |
| 320 | pub view: ViewSettings, |
| 321 | rotation: VisibleRotation, |
| 322 | stage_speaker: Option<String>, |
| 323 | recent_speakers: Vec<String>, |
| 324 | local_detector: SpeakingDetector, |
| 325 | remote_detector: SpeakingDetector, |
| 326 | } |
| 327 | |
| 328 | impl CallModel { |
| 329 | fn base(kind: CallKind, title: &str, peer_name: &str, tiles: Vec<Tile>) -> Self { |
| 330 | CallModel { |
| 331 | title: title.to_owned(), |
| 332 | kind, |
| 333 | peer_name: peer_name.to_owned(), |
| 334 | state: CallState::Connecting, |
| 335 | progress: None, |
| 336 | muted: false, |
| 337 | listen_only: false, |
| 338 | audio_off: false, |
| 339 | lobby: false, |
| 340 | can_end_meeting: false, |
| 341 | incoming: false, |
| 342 | input: DeviceChoice::SystemDefault, |
| 343 | output: DeviceChoice::SystemDefault, |
| 344 | devices: DeviceLists::default(), |
| 345 | local_speaking: false, |
| 346 | remote_speaking: false, |
| 347 | speaking_mris: Vec::new(), |
| 348 | connected_since: None, |
| 349 | own_mri: None, |
| 350 | tiles, |
| 351 | screen_sharer: None, |
| 352 | camera_on: false, |
| 353 | cameras: Vec::new(), |
| 354 | camera: DeviceChoice::SystemDefault, |
| 355 | local_share: None, |
| 356 | share_sources: Vec::new(), |
| 357 | share_sound: false, |
| 358 | own_hand: None, |
| 359 | own_spotlight: None, |
| 360 | organizer: false, |
| 361 | own_role: None, |
| 362 | capability: MeetingCapability::default(), |
| 363 | pinned: None, |
| 364 | captions: CaptionState::Off, |
| 365 | caption_lines: Vec::new(), |
| 366 | transcript: Transcript::default(), |
| 367 | caption_language: None, |
| 368 | language_pending: false, |
| 369 | background: BackgroundPick::None, |
| 370 | recording: false, |
| 371 | recording_audio_only: false, |
| 372 | transcribing: false, |
| 373 | consent_required: false, |
| 374 | hold: HoldState::Active, |
| 375 | health: HealthState::default(), |
| 376 | whiteboard: None, |
| 377 | breakout: None, |
| 378 | main_meeting: None, |
| 379 | reactions: Vec::new(), |
| 380 | reaction_serial: 0, |
| 381 | meeting_chat: None, |
| 382 | view: ViewSettings::default(), |
| 383 | rotation: VisibleRotation::default(), |
| 384 | stage_speaker: None, |
| 385 | recent_speakers: Vec::new(), |
| 386 | local_detector: SpeakingDetector::default(), |
| 387 | remote_detector: SpeakingDetector::default(), |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | pub fn test() -> Self { |
| 392 | Self::base( |
| 393 | CallKind::Test, |
| 394 | TEST_CALL_TITLE, |
| 395 | ECHO_NAME, |
| 396 | vec![Tile::invited(ECHO_MRI, ECHO_NAME)], |
| 397 | ) |
| 398 | } |
| 399 | |
| 400 | pub fn people(title: &str, callees: &[(String, String)]) -> Self { |
| 401 | let kind = if callees.len() == 1 { |
| 402 | CallKind::Direct |
| 403 | } else { |
| 404 | CallKind::Group |
| 405 | }; |
| 406 | let peer_name = match callees { |
| 407 | [(_, name)] => name.clone(), |
| 408 | _ => title.to_owned(), |
| 409 | }; |
| 410 | let tiles = callees |
| 411 | .iter() |
| 412 | .map(|(mri, name)| Tile::invited(mri, name)) |
| 413 | .collect(); |
| 414 | Self::base(kind, title, &peer_name, tiles) |
| 415 | } |
| 416 | |
| 417 | pub fn meeting(title: &str, can_end_meeting: bool) -> Self { |
| 418 | let mut model = Self::base(CallKind::Meeting, title, title, Vec::new()); |
| 419 | model.can_end_meeting = can_end_meeting; |
| 420 | model |
| 421 | } |
| 422 | |
| 423 | pub fn incoming(title: &str, caller_mri: &str, caller_name: &str) -> Self { |
| 424 | let mut model = Self::base( |
| 425 | CallKind::Direct, |
| 426 | title, |
| 427 | caller_name, |
| 428 | vec![Tile { |
| 429 | state: TileState::Present, |
| 430 | ..Tile::invited(caller_mri, caller_name) |
| 431 | }], |
| 432 | ); |
| 433 | model.incoming = true; |
| 434 | model |
| 435 | } |
| 436 | |
| 437 | pub fn apply(&mut self, update: CallUpdate) { |
| 438 | match update { |
| 439 | CallUpdate::State(state) => { |
| 440 | if let Some(since) = state.started_at() { |
| 441 | self.connected_since = Some(since); |
| 442 | } |
| 443 | if !matches!(state, CallState::Connected { .. }) { |
| 444 | self.silence(); |
| 445 | } |
| 446 | self.state = state; |
| 447 | } |
| 448 | CallUpdate::Muted(muted) => { |
| 449 | self.muted = muted; |
| 450 | if muted { |
| 451 | self.local_speaking = false; |
| 452 | self.local_detector.reset(); |
| 453 | } |
| 454 | } |
| 455 | CallUpdate::Levels { local, remote } => { |
| 456 | self.local_speaking = !self.muted && self.local_detector.update(local); |
| 457 | self.remote_speaking = self.remote_detector.update(remote); |
| 458 | } |
| 459 | CallUpdate::Devices(devices) => self.devices = devices, |
| 460 | CallUpdate::Selected { input, output } => { |
| 461 | self.input = input; |
| 462 | self.output = output; |
| 463 | } |
| 464 | CallUpdate::ListenOnly(listen_only) => self.listen_only = listen_only, |
| 465 | CallUpdate::Stats { .. } => {} |
| 466 | CallUpdate::Progress(progress) => self.progress = Some(progress), |
| 467 | CallUpdate::Roster(entries) => { |
| 468 | self.apply_roster(&entries); |
| 469 | self.refresh_layout(Instant::now()); |
| 470 | } |
| 471 | CallUpdate::Speakers(mris) => { |
| 472 | self.speaking_mris = mris; |
| 473 | self.refresh_layout(Instant::now()); |
| 474 | } |
| 475 | CallUpdate::Lobby(lobby) => self.lobby = lobby, |
| 476 | CallUpdate::OwnIdentity { mri } => self.own_mri = Some(mri), |
| 477 | CallUpdate::ScreenShare(sharer) => self.screen_sharer = sharer, |
| 478 | CallUpdate::VideoReady | CallUpdate::Notice(_) => {} |
| 479 | CallUpdate::Camera(on) => self.camera_on = on, |
| 480 | CallUpdate::Cameras(cameras) => self.cameras = cameras, |
| 481 | CallUpdate::LocalShare(label) => { |
| 482 | if label.is_none() { |
| 483 | self.share_sound = false; |
| 484 | } |
| 485 | self.local_share = label; |
| 486 | } |
| 487 | CallUpdate::ShareSources(sources) => self.share_sources = sources, |
| 488 | CallUpdate::ShareSound(active) => self.share_sound = active, |
| 489 | CallUpdate::OwnHand(rank) => self.own_hand = rank, |
| 490 | CallUpdate::Reaction { mri, reaction } => { |
| 491 | self.note_reaction(mri, reaction, Instant::now()) |
| 492 | } |
| 493 | CallUpdate::MeetingChat(thread) => self.meeting_chat = Some(thread), |
| 494 | CallUpdate::Captions(state) => { |
| 495 | if state != CaptionState::On { |
| 496 | self.caption_lines.clear(); |
| 497 | } |
| 498 | self.captions = state; |
| 499 | } |
| 500 | CallUpdate::Caption(entry) => self.note_caption(entry, Instant::now()), |
| 501 | CallUpdate::Recording(on) => self.recording = on, |
| 502 | CallUpdate::RecordingAudioOnly(audio_only) => self.recording_audio_only = audio_only, |
| 503 | CallUpdate::Transcribing(on) => self.transcribing = on, |
| 504 | CallUpdate::ConsentRequired(required) => self.consent_required = required, |
| 505 | CallUpdate::Hold(hold) => self.hold = hold, |
| 506 | CallUpdate::Health(health) => self.health.apply(health), |
| 507 | CallUpdate::IncomingVideo(enabled) => self.health.incoming_video = enabled, |
| 508 | CallUpdate::Whiteboard(share) => self.whiteboard = share, |
| 509 | CallUpdate::Capability(capability) => self.capability = capability, |
| 510 | CallUpdate::BreakoutRoom { main } => self.main_meeting = Some(main), |
| 511 | CallUpdate::BlurTiming(_) |
| 512 | | CallUpdate::Sample(_) |
| 513 | | CallUpdate::Diagnostics(_) |
| 514 | | CallUpdate::Organizer { .. } |
| 515 | | CallUpdate::MeetingOptions(_) |
| 516 | | CallUpdate::MeetingOptionsSaved(_) |
| 517 | | CallUpdate::WhiteboardUrl(_) |
| 518 | | CallUpdate::BreakoutMove(_) |
| 519 | | CallUpdate::ReplacementLink(_) |
| 520 | | CallUpdate::TransferResult { .. } => {} |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | pub fn note_caption(&mut self, entry: CaptionEntry, at: Instant) { |
| 525 | if self.captions == CaptionState::Off { |
| 526 | return; |
| 527 | } |
| 528 | let speaker = if entry.display_name.is_empty() { |
| 529 | "Someone".to_owned() |
| 530 | } else { |
| 531 | entry.display_name |
| 532 | }; |
| 533 | let offset = self |
| 534 | .connected_since |
| 535 | .map_or(Duration::ZERO, |since| at.saturating_duration_since(since)); |
| 536 | self.transcript.note(TranscriptEntry { |
| 537 | id: entry.id.clone(), |
| 538 | speaker: speaker.clone(), |
| 539 | text: entry.text.clone(), |
| 540 | offset, |
| 541 | }); |
| 542 | let line = CaptionLine { |
| 543 | id: entry.id, |
| 544 | speaker, |
| 545 | text: entry.text, |
| 546 | at, |
| 547 | }; |
| 548 | match self.caption_lines.last_mut() { |
| 549 | Some(last) if last.id == line.id => *last = line, |
| 550 | _ => self.caption_lines.push(line), |
| 551 | } |
| 552 | let surplus = self.caption_lines.len().saturating_sub(CAPTION_LINES); |
| 553 | self.caption_lines.drain(..surplus); |
| 554 | } |
| 555 | |
| 556 | pub fn visible_captions(&self, now: Instant) -> Vec<&CaptionLine> { |
| 557 | self.caption_lines |
| 558 | .iter() |
| 559 | .filter(|line| now.saturating_duration_since(line.at) < CAPTION_SHOWN) |
| 560 | .collect() |
| 561 | } |
| 562 | |
| 563 | pub fn choose_caption_language(&mut self, tag: &str) { |
| 564 | self.caption_language = Some(tag.to_owned()); |
| 565 | self.language_pending = true; |
| 566 | } |
| 567 | |
| 568 | pub fn take_ready_caption_language(&mut self) -> Option<String> { |
| 569 | if self.language_pending && self.captions == CaptionState::On { |
| 570 | self.language_pending = false; |
| 571 | return self.caption_language.clone(); |
| 572 | } |
| 573 | None |
| 574 | } |
| 575 | |
| 576 | pub fn captions_on(&self) -> bool { |
| 577 | matches!(self.captions, CaptionState::Starting | CaptionState::On) |
| 578 | } |
| 579 | |
| 580 | fn silence(&mut self) { |
| 581 | self.local_speaking = false; |
| 582 | self.remote_speaking = false; |
| 583 | self.speaking_mris.clear(); |
| 584 | self.local_detector.reset(); |
| 585 | self.remote_detector.reset(); |
| 586 | } |
| 587 | |
| 588 | pub fn note_reaction(&mut self, mri: String, reaction: Reaction, at: Instant) { |
| 589 | let own_echo = Some(&mri) == self.own_mri.as_ref() |
| 590 | && self.reactions.iter().any(|chip| { |
| 591 | chip.mri == mri |
| 592 | && chip.reaction == reaction |
| 593 | && at.saturating_duration_since(chip.since) < OWN_ECHO_WINDOW |
| 594 | }); |
| 595 | if own_echo { |
| 596 | return; |
| 597 | } |
| 598 | self.reactions.retain(|chip| { |
| 599 | chip.mri != mri && at.saturating_duration_since(chip.since) < REACTION_SHOWN |
| 600 | }); |
| 601 | self.reaction_serial += 1; |
| 602 | self.reactions.push(ReactionChip { |
| 603 | mri, |
| 604 | reaction, |
| 605 | since: at, |
| 606 | serial: self.reaction_serial, |
| 607 | }); |
| 608 | } |
| 609 | |
| 610 | pub fn chip_of(&self, mri: &str, now: Instant) -> Option<&ReactionChip> { |
| 611 | self.reactions.iter().find(|chip| { |
| 612 | chip.mri == mri && now.saturating_duration_since(chip.since) < REACTION_SHOWN |
| 613 | }) |
| 614 | } |
| 615 | |
| 616 | pub fn own_chip(&self, now: Instant) -> Option<&ReactionChip> { |
| 617 | self.chip_of(self.own_mri.as_deref()?, now) |
| 618 | } |
| 619 | |
| 620 | pub fn hand_position(&self, rank: u64) -> usize { |
| 621 | let raised = self |
| 622 | .tiles |
| 623 | .iter() |
| 624 | .filter_map(|tile| tile.hand) |
| 625 | .chain(self.own_hand); |
| 626 | 1 + raised.filter(|other| *other < rank).count() |
| 627 | } |
| 628 | |
| 629 | pub fn can_manage(&self) -> bool { |
| 630 | self.can_end_meeting || self.organizer |
| 631 | } |
| 632 | |
| 633 | pub fn organizes_meeting(&self) -> bool { |
| 634 | self.kind == CallKind::Meeting && self.can_manage() |
| 635 | } |
| 636 | |
| 637 | pub fn present_others(&self) -> usize { |
| 638 | self.tiles |
| 639 | .iter() |
| 640 | .filter(|tile| tile.state == TileState::Present) |
| 641 | .count() |
| 642 | } |
| 643 | |
| 644 | pub fn can_invite(&self) -> bool { |
| 645 | let open_to_everyone = matches!(self.kind, CallKind::Direct | CallKind::Group); |
| 646 | self.is_live() && !self.lobby && (open_to_everyone || self.organizes_meeting()) |
| 647 | } |
| 648 | |
| 649 | pub fn tile_role(&self, mri: &str) -> Option<MeetingRole> { |
| 650 | self.tiles |
| 651 | .iter() |
| 652 | .find(|tile| tile.mri == mri) |
| 653 | .and_then(|tile| tile.role) |
| 654 | } |
| 655 | |
| 656 | pub fn can_change_roles(&self, mri: &str) -> bool { |
| 657 | self.organizes_meeting() && self.tile_role(mri) != Some(MeetingRole::Organizer) |
| 658 | } |
| 659 | |
| 660 | pub fn attendee_allowed(&self, mri: &str, modality: calling::Modality) -> bool { |
| 661 | let limits = self |
| 662 | .tiles |
| 663 | .iter() |
| 664 | .find(|tile| tile.mri == mri) |
| 665 | .map(|tile| tile.limits.clone()) |
| 666 | .unwrap_or_default(); |
| 667 | calling::modality_allowed(modality, self.capability, &limits) |
| 668 | } |
| 669 | |
| 670 | pub fn can_lower_hands(&self) -> bool { |
| 671 | self.can_manage() |
| 672 | } |
| 673 | |
| 674 | pub fn lobby_guests(&self) -> Vec<&Tile> { |
| 675 | self.tiles |
| 676 | .iter() |
| 677 | .filter(|tile| tile.state == TileState::InLobby) |
| 678 | .collect() |
| 679 | } |
| 680 | |
| 681 | pub fn can_admit(&self) -> bool { |
| 682 | self.can_manage() && self.is_live() && !self.lobby |
| 683 | } |
| 684 | |
| 685 | pub fn is_pinned(&self, mri: &str) -> bool { |
| 686 | self.pinned.as_deref() == Some(mri) |
| 687 | } |
| 688 | |
| 689 | pub fn toggle_pin(&mut self, mri: &str) { |
| 690 | self.pinned = if self.is_pinned(mri) { |
| 691 | None |
| 692 | } else { |
| 693 | Some(mri.to_owned()) |
| 694 | }; |
| 695 | self.refresh_layout(Instant::now()); |
| 696 | } |
| 697 | |
| 698 | pub fn is_spotlighted(&self, mri: &str) -> bool { |
| 699 | self.own_mri.as_deref() == Some(mri) && self.own_spotlight.is_some() |
| 700 | || self |
| 701 | .tiles |
| 702 | .iter() |
| 703 | .any(|tile| tile.mri == mri && tile.spotlight.is_some()) |
| 704 | } |
| 705 | |
| 706 | pub fn focus(&self) -> Option<Focus> { |
| 707 | let own = |mri: &str| self.own_mri.as_deref() == Some(mri); |
| 708 | let on_stage = |mri: &str| { |
| 709 | own(mri) |
| 710 | || self |
| 711 | .visible_tiles() |
| 712 | .iter() |
| 713 | .any(|tile| tile.mri == mri && tile.state == TileState::Present) |
| 714 | }; |
| 715 | if let Some(pinned) = self.pinned.as_deref().filter(|mri| on_stage(mri)) { |
| 716 | return Some(Focus { |
| 717 | mri: pinned.to_owned(), |
| 718 | own: own(pinned), |
| 719 | spotlight: self.is_spotlighted(pinned), |
| 720 | pinned: true, |
| 721 | }); |
| 722 | } |
| 723 | let remote = self |
| 724 | .tiles |
| 725 | .iter() |
| 726 | .filter(|tile| tile.state == TileState::Present) |
| 727 | .filter_map(|tile| Some((tile.spotlight?, tile.mri.as_str()))); |
| 728 | let (_, mri) = remote |
| 729 | .chain(self.own_spotlight.zip(self.own_mri.as_deref())) |
| 730 | .min_by_key(|(rank, _)| *rank)?; |
| 731 | Some(Focus { |
| 732 | mri: mri.to_owned(), |
| 733 | own: own(mri), |
| 734 | spotlight: true, |
| 735 | pinned: false, |
| 736 | }) |
| 737 | } |
| 738 | |
| 739 | pub fn raised_hands(&self) -> usize { |
| 740 | self.tiles.iter().filter(|tile| tile.hand.is_some()).count() |
| 741 | + usize::from(self.own_hand.is_some()) |
| 742 | } |
| 743 | |
| 744 | pub fn any_hand_raised(&self) -> bool { |
| 745 | self.own_hand.is_some() || self.tiles.iter().any(|tile| tile.hand.is_some()) |
| 746 | } |
| 747 | |
| 748 | pub fn own_cell_index(&self, remote_cells: usize) -> usize { |
| 749 | let Some(own) = self.own_hand else { |
| 750 | return remote_cells; |
| 751 | }; |
| 752 | let ahead = self |
| 753 | .visible_tiles() |
| 754 | .iter() |
| 755 | .filter(|tile| tile.hand.is_some_and(|rank| rank < own)) |
| 756 | .count(); |
| 757 | ahead.min(remote_cells) |
| 758 | } |
| 759 | |
| 760 | fn apply_roster(&mut self, entries: &[RosterEntry]) { |
| 761 | let own_entry = entries |
| 762 | .iter() |
| 763 | .find(|entry| Some(&entry.mri) == self.own_mri.as_ref()); |
| 764 | if let Some(entry) = own_entry { |
| 765 | self.own_hand = entry.hand.as_ref().map(|hand| hand.rank); |
| 766 | } |
| 767 | self.own_spotlight = |
| 768 | own_entry.and_then(|entry| entry.spotlight.as_ref().map(|spotlight| spotlight.rank)); |
| 769 | if let Some(entry) = own_entry { |
| 770 | self.organizer = entry.organizer; |
| 771 | self.own_role = entry.role; |
| 772 | } |
| 773 | for entry in entries |
| 774 | .iter() |
| 775 | .filter(|entry| Some(&entry.mri) != self.own_mri.as_ref()) |
| 776 | { |
| 777 | let state = if entry.in_lobby { |
| 778 | TileState::InLobby |
| 779 | } else { |
| 780 | TileState::Present |
| 781 | }; |
| 782 | match self.tiles.iter_mut().find(|tile| tile.mri == entry.mri) { |
| 783 | Some(tile) => { |
| 784 | tile.state = state; |
| 785 | tile.muted = entry.muted; |
| 786 | tile.has_video = entry.has_video; |
| 787 | tile.hand = entry.hand.as_ref().map(|hand| hand.rank); |
| 788 | tile.spotlight = entry.spotlight.as_ref().map(|spotlight| spotlight.rank); |
| 789 | tile.role = entry.role; |
| 790 | tile.limits = entry.limits.clone(); |
| 791 | if tile.name.is_empty() { |
| 792 | tile.name = entry.display_name.clone(); |
| 793 | } |
| 794 | } |
| 795 | None if entry.mri.starts_with(BOT_PREFIX) => {} |
| 796 | None => self.tiles.push(Tile { |
| 797 | mri: entry.mri.clone(), |
| 798 | user_id: entry.mri.strip_prefix(ORGID_PREFIX).map(str::to_owned), |
| 799 | name: entry.display_name.clone(), |
| 800 | muted: entry.muted, |
| 801 | state, |
| 802 | invited: false, |
| 803 | has_video: entry.has_video, |
| 804 | hand: entry.hand.as_ref().map(|hand| hand.rank), |
| 805 | spotlight: entry.spotlight.as_ref().map(|spotlight| spotlight.rank), |
| 806 | role: entry.role, |
| 807 | limits: entry.limits.clone(), |
| 808 | }), |
| 809 | } |
| 810 | } |
| 811 | if self.kind == CallKind::Direct && self.present_others() > 1 { |
| 812 | self.kind = CallKind::Group; |
| 813 | } |
| 814 | let own_mri = self.own_mri.clone(); |
| 815 | let listed = |mri: &str| entries.iter().any(|entry| entry.mri == mri); |
| 816 | if self |
| 817 | .pinned |
| 818 | .as_deref() |
| 819 | .is_some_and(|mri| !listed(mri) && Some(mri) != own_mri.as_deref()) |
| 820 | { |
| 821 | self.pinned = None; |
| 822 | } |
| 823 | self.tiles.retain_mut(|tile| { |
| 824 | if listed(&tile.mri) || Some(&tile.mri) == own_mri.as_ref() { |
| 825 | return true; |
| 826 | } |
| 827 | match (tile.invited, tile.state) { |
| 828 | (true, TileState::Invited) => true, |
| 829 | (true, _) => { |
| 830 | tile.state = TileState::Left; |
| 831 | true |
| 832 | } |
| 833 | (false, _) => false, |
| 834 | } |
| 835 | }); |
| 836 | } |
| 837 | |
| 838 | pub fn visible_tiles(&self) -> Vec<&Tile> { |
| 839 | let mut tiles: Vec<&Tile> = self |
| 840 | .tiles |
| 841 | .iter() |
| 842 | .filter(|tile| tile.state != TileState::InLobby) |
| 843 | .collect(); |
| 844 | tiles.sort_by_key(|tile| { |
| 845 | let state = match tile.state { |
| 846 | TileState::Present => 0, |
| 847 | TileState::Invited => 1, |
| 848 | _ => 2, |
| 849 | }; |
| 850 | ( |
| 851 | !self.is_pinned(&tile.mri), |
| 852 | tile.hand.is_none(), |
| 853 | tile.hand.unwrap_or(0), |
| 854 | state, |
| 855 | ) |
| 856 | }); |
| 857 | tiles |
| 858 | } |
| 859 | |
| 860 | pub fn strip_tiles(&self) -> Vec<&Tile> { |
| 861 | let mut tiles = self.visible_tiles(); |
| 862 | tiles.sort_by_key(|tile| { |
| 863 | ( |
| 864 | !self.is_pinned(&tile.mri), |
| 865 | tile.hand.is_none(), |
| 866 | tile.hand.unwrap_or(0), |
| 867 | !self.tile_speaking(tile), |
| 868 | ) |
| 869 | }); |
| 870 | tiles |
| 871 | } |
| 872 | |
| 873 | pub fn has_content(&self) -> bool { |
| 874 | self.screen_sharer.is_some() || self.whiteboard.is_some() |
| 875 | } |
| 876 | |
| 877 | pub fn effective_layout(&self) -> CallLayout { |
| 878 | match self.view.layout { |
| 879 | CallLayout::Content if self.has_content() => CallLayout::Content, |
| 880 | CallLayout::Content => match self.view.layout_before_content { |
| 881 | CallLayout::Content => CallLayout::Gallery, |
| 882 | before => before, |
| 883 | }, |
| 884 | layout => layout, |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | fn is_prioritized(&self, tile: &Tile) -> bool { |
| 889 | self.is_pinned(&tile.mri) || tile.spotlight.is_some() || tile.hand.is_some() |
| 890 | } |
| 891 | |
| 892 | pub fn hidden_for_no_video(&self, tile: &Tile) -> bool { |
| 893 | self.view.hide_no_video |
| 894 | && matches!(self.kind, CallKind::Group | CallKind::Meeting) |
| 895 | && tile.state == TileState::Present |
| 896 | && !tile.has_video |
| 897 | && !self.is_pinned(&tile.mri) |
| 898 | && !self.tile_speaking(tile) |
| 899 | && !self.recent_speakers.contains(&tile.mri) |
| 900 | } |
| 901 | |
| 902 | pub fn hidden_without_video(&self) -> usize { |
| 903 | self.visible_tiles() |
| 904 | .into_iter() |
| 905 | .filter(|tile| self.hidden_for_no_video(tile)) |
| 906 | .count() |
| 907 | } |
| 908 | |
| 909 | fn layout_members(&self) -> Vec<&Tile> { |
| 910 | let mut tiles: Vec<&Tile> = self |
| 911 | .visible_tiles() |
| 912 | .into_iter() |
| 913 | .filter(|tile| !self.hidden_for_no_video(tile)) |
| 914 | .collect(); |
| 915 | tiles.sort_by_key(|tile| !self.is_prioritized(tile)); |
| 916 | tiles |
| 917 | } |
| 918 | |
| 919 | pub fn layout_tiles(&self) -> Vec<&Tile> { |
| 920 | let members = self.layout_members(); |
| 921 | let mut ordered: Vec<&Tile> = self |
| 922 | .rotation |
| 923 | .order() |
| 924 | .iter() |
| 925 | .filter_map(|mri| members.iter().find(|tile| &tile.mri == mri).copied()) |
| 926 | .collect(); |
| 927 | ordered.extend( |
| 928 | members |
| 929 | .into_iter() |
| 930 | .filter(|tile| !self.rotation.order().contains(&tile.mri)), |
| 931 | ); |
| 932 | ordered |
| 933 | } |
| 934 | |
| 935 | pub fn is_recent_speaker(&self, mri: &str) -> bool { |
| 936 | self.recent_speakers.iter().any(|recent| recent == mri) |
| 937 | } |
| 938 | |
| 939 | pub fn own_cells(&self) -> usize { |
| 940 | usize::from(!self.view.hide_me) |
| 941 | } |
| 942 | |
| 943 | fn rotation_capacity(&self, others: usize) -> usize { |
| 944 | let cells = match self.effective_layout() { |
| 945 | _ if self.has_content() => return others, |
| 946 | CallLayout::Speaker => FILMSTRIP_MAX, |
| 947 | CallLayout::Gallery | CallLayout::Content => GALLERY_MAX, |
| 948 | }; |
| 949 | split_overflow(others, self.own_cells(), cells).shown |
| 950 | } |
| 951 | |
| 952 | pub fn refresh_layout(&mut self, now: Instant) -> bool { |
| 953 | let members: Vec<String> = self |
| 954 | .layout_members() |
| 955 | .iter() |
| 956 | .map(|tile| tile.mri.clone()) |
| 957 | .collect(); |
| 958 | let priority: Vec<String> = self |
| 959 | .layout_members() |
| 960 | .iter() |
| 961 | .filter(|tile| self.is_prioritized(tile)) |
| 962 | .map(|tile| tile.mri.clone()) |
| 963 | .collect(); |
| 964 | let capacity = self.rotation_capacity(members.len()); |
| 965 | let speaking = self.speaking_mris.clone(); |
| 966 | let reordered = self |
| 967 | .rotation |
| 968 | .update(now, &members, &priority, &speaking, capacity); |
| 969 | let recent: Vec<String> = self |
| 970 | .tiles |
| 971 | .iter() |
| 972 | .filter(|tile| self.rotation.spoke_within(&tile.mri, now, RECENT_SPEAKER)) |
| 973 | .map(|tile| tile.mri.clone()) |
| 974 | .collect(); |
| 975 | let held = self.stage_speaker.as_deref().is_some_and(|mri| { |
| 976 | members.iter().any(|member| member == mri) && self.rotation.spoke_within(mri, now, SPEAKER_HOLD) |
| 977 | }); |
| 978 | let stage_speaker = if held { |
| 979 | self.stage_speaker.clone() |
| 980 | } else { |
| 981 | self.rotation |
| 982 | .steady_speaker(now, &members) |
| 983 | .map(str::to_owned) |
| 984 | .or_else(|| self.stage_speaker.clone().filter(|mri| members.contains(mri))) |
| 985 | }; |
| 986 | let changed = reordered || recent != self.recent_speakers || stage_speaker != self.stage_speaker; |
| 987 | self.recent_speakers = recent; |
| 988 | self.stage_speaker = stage_speaker; |
| 989 | changed |
| 990 | } |
| 991 | |
| 992 | pub fn speaker_focus(&self) -> Option<Focus> { |
| 993 | if let Some(focus) = self.focus() { |
| 994 | return Some(focus); |
| 995 | } |
| 996 | let tiles = self.layout_tiles(); |
| 997 | let spoken = self |
| 998 | .stage_speaker |
| 999 | .as_deref() |
| 1000 | .filter(|mri| tiles.iter().any(|tile| tile.mri == *mri)) |
| 1001 | .or_else(|| { |
| 1002 | self.rotation |
| 1003 | .last_speaker() |
| 1004 | .filter(|mri| tiles.iter().any(|tile| tile.mri == *mri)) |
| 1005 | }) |
| 1006 | .or_else(|| tiles.first().map(|tile| tile.mri.as_str())); |
| 1007 | let own_mri = self.own_mri.clone().filter(|_| self.own_cells() > 0); |
| 1008 | let (mri, own) = match (spoken, own_mri) { |
| 1009 | (Some(mri), _) => (mri.to_owned(), false), |
| 1010 | (None, Some(own_mri)) => (own_mri, true), |
| 1011 | (None, None) => return None, |
| 1012 | }; |
| 1013 | Some(Focus { |
| 1014 | mri, |
| 1015 | own, |
| 1016 | spotlight: false, |
| 1017 | pinned: false, |
| 1018 | }) |
| 1019 | } |
| 1020 | |
| 1021 | pub fn sharing_label(&self) -> Option<String> { |
| 1022 | let sharer = self.screen_sharer.as_ref()?; |
| 1023 | let name = self |
| 1024 | .tiles |
| 1025 | .iter() |
| 1026 | .find(|tile| &tile.mri == sharer) |
| 1027 | .map(|tile| tile.name.as_str()) |
| 1028 | .filter(|name| !name.is_empty()) |
| 1029 | .unwrap_or("Someone"); |
| 1030 | Some(format!("{name} is sharing")) |
| 1031 | } |
| 1032 | |
| 1033 | pub fn whiteboard_label(&self) -> Option<String> { |
| 1034 | let share = self.whiteboard.as_ref()?; |
| 1035 | let name = share |
| 1036 | .presenter |
| 1037 | .as_deref() |
| 1038 | .and_then(|presenter| self.tiles.iter().find(|tile| tile.mri == presenter)) |
| 1039 | .map(|tile| tile.name.as_str()) |
| 1040 | .filter(|name| !name.is_empty()) |
| 1041 | .unwrap_or("Someone"); |
| 1042 | Some(format!("{name} is sharing a whiteboard")) |
| 1043 | } |
| 1044 | |
| 1045 | pub fn whiteboard_url(&self) -> Option<&str> { |
| 1046 | self.whiteboard.as_ref()?.url.as_deref() |
| 1047 | } |
| 1048 | |
| 1049 | pub fn health_banner(&self) -> Option<HealthBanner> { |
| 1050 | self.health.banner(self.background != BackgroundPick::None) |
| 1051 | } |
| 1052 | |
| 1053 | pub fn is_one_to_one(&self) -> bool { |
| 1054 | self.kind == CallKind::Direct |
| 1055 | } |
| 1056 | |
| 1057 | pub fn can_hold(&self) -> bool { |
| 1058 | self.is_one_to_one() && self.is_live() && self.hold != HoldState::Remote |
| 1059 | } |
| 1060 | |
| 1061 | pub fn can_transfer(&self) -> bool { |
| 1062 | self.is_one_to_one() && self.is_live() && self.hold == HoldState::Active |
| 1063 | } |
| 1064 | |
| 1065 | pub fn can_record(&self) -> bool { |
| 1066 | self.organizes_meeting() && self.is_live() && !self.lobby |
| 1067 | } |
| 1068 | |
| 1069 | pub fn can_open_whiteboard(&self) -> bool { |
| 1070 | self.kind == CallKind::Meeting && self.is_live() && !self.lobby |
| 1071 | } |
| 1072 | |
| 1073 | pub fn tile_speaking(&self, tile: &Tile) -> bool { |
| 1074 | if self.speaking_mris.contains(&tile.mri) { |
| 1075 | return true; |
| 1076 | } |
| 1077 | let only_remote = self.tiles.len() == 1; |
| 1078 | only_remote && tile.state != TileState::Left && self.remote_speaking |
| 1079 | } |
| 1080 | |
| 1081 | pub fn tile_caption(&self, tile: &Tile) -> Option<&'static str> { |
| 1082 | match tile.state { |
| 1083 | TileState::Invited => Some(match self.progress { |
| 1084 | Some(Progress::Ringing) => "Ringing", |
| 1085 | _ => "Calling...", |
| 1086 | }), |
| 1087 | TileState::Left => Some("Left"), |
| 1088 | TileState::Present | TileState::InLobby => None, |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | pub fn elapsed(&self, now: Instant) -> Option<Duration> { |
| 1093 | self.connected_since |
| 1094 | .map(|since| now.saturating_duration_since(since)) |
| 1095 | } |
| 1096 | |
| 1097 | pub fn connecting_text(&self) -> &'static str { |
| 1098 | match (self.kind, self.progress) { |
| 1099 | (CallKind::Meeting, _) => "Joining...", |
| 1100 | (_, _) if self.incoming => "Connecting...", |
| 1101 | (_, Some(Progress::Ringing)) => "Ringing", |
| 1102 | _ => "Calling...", |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | pub fn is_active(&self) -> bool { |
| 1107 | matches!( |
| 1108 | self.state, |
| 1109 | CallState::Connecting | CallState::Connected { .. } | CallState::Reconnecting { .. } |
| 1110 | ) |
| 1111 | } |
| 1112 | |
| 1113 | pub fn is_connecting(&self) -> bool { |
| 1114 | matches!(self.state, CallState::Connecting) |
| 1115 | } |
| 1116 | |
| 1117 | pub fn is_reconnecting(&self) -> bool { |
| 1118 | matches!(self.state, CallState::Reconnecting { .. }) |
| 1119 | } |
| 1120 | |
| 1121 | pub fn ended_reason(&self) -> Option<&EndReason> { |
| 1122 | match &self.state { |
| 1123 | CallState::Ended { reason } => Some(reason), |
| 1124 | _ => None, |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | pub fn timer_text(&self, now: Instant) -> String { |
| 1129 | self.elapsed(now).map(format_elapsed).unwrap_or_default() |
| 1130 | } |
| 1131 | |
| 1132 | pub fn has_reaction_controls(&self) -> bool { |
| 1133 | matches!(self.kind, CallKind::Group | CallKind::Meeting) |
| 1134 | } |
| 1135 | |
| 1136 | pub fn can_react(&self) -> bool { |
| 1137 | self.is_live() && !self.lobby |
| 1138 | } |
| 1139 | |
| 1140 | pub fn can_use_camera(&self) -> bool { |
| 1141 | !self.cameras.is_empty() |
| 1142 | } |
| 1143 | |
| 1144 | pub fn can_share(&self) -> bool { |
| 1145 | !self.share_sources.is_empty() && self.is_live() |
| 1146 | } |
| 1147 | |
| 1148 | fn is_live(&self) -> bool { |
| 1149 | matches!( |
| 1150 | self.state, |
| 1151 | CallState::Connected { .. } | CallState::Reconnecting { .. } |
| 1152 | ) |
| 1153 | } |
| 1154 | |
| 1155 | pub fn screens(&self) -> Vec<&ShareSource> { |
| 1156 | self.share_sources |
| 1157 | .iter() |
| 1158 | .filter(|source| source.kind == ShareKind::Screen) |
| 1159 | .collect() |
| 1160 | } |
| 1161 | |
| 1162 | pub fn windows(&self) -> Vec<&ShareSource> { |
| 1163 | self.share_sources |
| 1164 | .iter() |
| 1165 | .filter(|source| source.kind == ShareKind::Window) |
| 1166 | .collect() |
| 1167 | } |
| 1168 | |
| 1169 | pub fn can_unmute(&self) -> bool { |
| 1170 | !self.listen_only && !self.audio_off |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | pub fn format_elapsed(elapsed: Duration) -> String { |
| 1175 | let seconds = elapsed.as_secs(); |
| 1176 | let (hours, minutes, seconds) = (seconds / 3600, seconds / 60 % 60, seconds % 60); |
| 1177 | if hours > 0 { |
| 1178 | format!("{hours}:{minutes:02}:{seconds:02}") |
| 1179 | } else { |
| 1180 | format!("{minutes:02}:{seconds:02}") |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | pub fn ended_notice(reason: &EndReason, elapsed: Option<Duration>, peer_name: &str) -> String { |
| 1185 | let ended = || match elapsed { |
| 1186 | Some(elapsed) => format!("Call ended {}", format_elapsed(elapsed)), |
| 1187 | None => "Call ended".to_owned(), |
| 1188 | }; |
| 1189 | match reason { |
| 1190 | EndReason::Cancelled => "Call cancelled".to_owned(), |
| 1191 | EndReason::Dropped => "Call dropped".to_owned(), |
| 1192 | EndReason::Failed(message) => format!("Call failed: {message}"), |
| 1193 | EndReason::LocalHangup => ended(), |
| 1194 | EndReason::Remote(EndKind::Declined) => format!("{peer_name} declined"), |
| 1195 | EndReason::Remote(EndKind::NoAnswer) => "No answer".to_owned(), |
| 1196 | EndReason::Remote(EndKind::Unavailable) => format!("{peer_name} is not available"), |
| 1197 | EndReason::Remote(_) => ended(), |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | #[cfg(test)] |
| 1202 | mod tests { |
| 1203 | use super::*; |
| 1204 | |
| 1205 | fn connected_model() -> CallModel { |
| 1206 | let mut model = CallModel::test(); |
| 1207 | model.apply(CallUpdate::State(CallState::Connected { |
| 1208 | since: Instant::now(), |
| 1209 | })); |
| 1210 | model |
| 1211 | } |
| 1212 | |
| 1213 | fn entry(mri: &str, name: &str, muted: bool, in_lobby: bool) -> RosterEntry { |
| 1214 | RosterEntry { |
| 1215 | mri: mri.into(), |
| 1216 | display_name: name.into(), |
| 1217 | muted, |
| 1218 | in_lobby, |
| 1219 | has_video: false, |
| 1220 | sharing: false, |
| 1221 | hand: None, |
| 1222 | spotlight: None, |
| 1223 | organizer: false, |
| 1224 | role: None, |
| 1225 | limits: AttendeeLimits::default(), |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | fn spotlit(mri: &str, name: &str, rank: u64) -> RosterEntry { |
| 1230 | RosterEntry { |
| 1231 | spotlight: Some(calling::Spotlight { |
| 1232 | state_id: format!("sp-{rank}"), |
| 1233 | rank, |
| 1234 | }), |
| 1235 | ..entry(mri, name, false, false) |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | fn organizer_entry(mri: &str) -> RosterEntry { |
| 1240 | RosterEntry { |
| 1241 | organizer: true, |
| 1242 | ..entry(mri, "Me", false, false) |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | fn raised(mri: &str, name: &str, rank: u64) -> RosterEntry { |
| 1247 | RosterEntry { |
| 1248 | hand: Some(calling::RaisedHand { |
| 1249 | state_id: format!("s-{rank}"), |
| 1250 | rank, |
| 1251 | }), |
| 1252 | ..entry(mri, name, false, false) |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | fn meeting_with_me() -> CallModel { |
| 1257 | let mut model = CallModel::meeting("Standup", false); |
| 1258 | model.apply(CallUpdate::OwnIdentity { |
| 1259 | mri: "8:orgid:me".into(), |
| 1260 | }); |
| 1261 | model |
| 1262 | } |
| 1263 | |
| 1264 | #[test] |
| 1265 | fn elapsed_text_is_minutes_and_seconds() { |
| 1266 | assert_eq!(format_elapsed(Duration::from_secs(42)), "00:42"); |
| 1267 | assert_eq!(format_elapsed(Duration::from_secs(61)), "01:01"); |
| 1268 | assert_eq!(format_elapsed(Duration::from_secs(3725)), "1:02:05"); |
| 1269 | } |
| 1270 | |
| 1271 | #[test] |
| 1272 | fn levels_drive_the_speaking_rings() { |
| 1273 | let mut model = connected_model(); |
| 1274 | model.apply(CallUpdate::Levels { |
| 1275 | local: 0.0, |
| 1276 | remote: 0.4, |
| 1277 | }); |
| 1278 | assert!(model.remote_speaking); |
| 1279 | assert!(!model.local_speaking); |
| 1280 | model.apply(CallUpdate::Levels { |
| 1281 | local: 0.4, |
| 1282 | remote: 0.0, |
| 1283 | }); |
| 1284 | assert!(model.local_speaking); |
| 1285 | } |
| 1286 | |
| 1287 | #[test] |
| 1288 | fn muting_switches_the_local_ring_off_at_once() { |
| 1289 | let mut model = connected_model(); |
| 1290 | model.apply(CallUpdate::Levels { |
| 1291 | local: 0.5, |
| 1292 | remote: 0.0, |
| 1293 | }); |
| 1294 | assert!(model.local_speaking); |
| 1295 | model.apply(CallUpdate::Muted(true)); |
| 1296 | assert!(!model.local_speaking); |
| 1297 | model.apply(CallUpdate::Levels { |
| 1298 | local: 0.5, |
| 1299 | remote: 0.0, |
| 1300 | }); |
| 1301 | assert!(!model.local_speaking); |
| 1302 | } |
| 1303 | |
| 1304 | #[test] |
| 1305 | fn reconnecting_keeps_the_timer_and_clears_the_rings() { |
| 1306 | let mut model = connected_model(); |
| 1307 | let since = model.connected_since.unwrap(); |
| 1308 | model.apply(CallUpdate::Levels { |
| 1309 | local: 0.5, |
| 1310 | remote: 0.5, |
| 1311 | }); |
| 1312 | model.apply(CallUpdate::State(CallState::Reconnecting { since })); |
| 1313 | assert!(model.is_reconnecting()); |
| 1314 | assert_eq!(model.connected_since, Some(since)); |
| 1315 | assert!(!model.remote_speaking && !model.local_speaking); |
| 1316 | } |
| 1317 | |
| 1318 | #[test] |
| 1319 | fn notices_for_every_end_reason() { |
| 1320 | let elapsed = Some(Duration::from_secs(42)); |
| 1321 | let notice = |reason: EndReason, elapsed| ended_notice(&reason, elapsed, "Bea"); |
| 1322 | assert_eq!(notice(EndReason::LocalHangup, elapsed), "Call ended 00:42"); |
| 1323 | assert_eq!( |
| 1324 | notice(EndReason::Remote(EndKind::Normal), elapsed), |
| 1325 | "Call ended 00:42" |
| 1326 | ); |
| 1327 | assert_eq!( |
| 1328 | notice(EndReason::Remote(EndKind::Normal), None), |
| 1329 | "Call ended" |
| 1330 | ); |
| 1331 | assert_eq!(notice(EndReason::Cancelled, None), "Call cancelled"); |
| 1332 | assert_eq!(notice(EndReason::Dropped, elapsed), "Call dropped"); |
| 1333 | assert_eq!( |
| 1334 | notice(EndReason::Failed("no route".into()), None), |
| 1335 | "Call failed: no route" |
| 1336 | ); |
| 1337 | assert_eq!( |
| 1338 | notice(EndReason::Remote(EndKind::Declined), None), |
| 1339 | "Bea declined" |
| 1340 | ); |
| 1341 | assert_eq!( |
| 1342 | notice(EndReason::Remote(EndKind::NoAnswer), None), |
| 1343 | "No answer" |
| 1344 | ); |
| 1345 | assert_eq!( |
| 1346 | notice(EndReason::Remote(EndKind::Unavailable), None), |
| 1347 | "Bea is not available" |
| 1348 | ); |
| 1349 | assert_eq!( |
| 1350 | notice(EndReason::Remote(EndKind::Cancelled), None), |
| 1351 | "Call ended" |
| 1352 | ); |
| 1353 | assert_eq!( |
| 1354 | notice(EndReason::Remote(EndKind::Other), None), |
| 1355 | "Call ended" |
| 1356 | ); |
| 1357 | assert_eq!( |
| 1358 | notice(EndReason::Remote(EndKind::AnsweredElsewhere), None), |
| 1359 | "Call ended" |
| 1360 | ); |
| 1361 | } |
| 1362 | |
| 1363 | #[test] |
| 1364 | fn the_connecting_text_follows_the_kind_of_call() { |
| 1365 | let mut direct = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]); |
| 1366 | assert_eq!(direct.connecting_text(), "Calling..."); |
| 1367 | direct.apply(CallUpdate::Progress(Progress::Ringing)); |
| 1368 | assert_eq!(direct.connecting_text(), "Ringing"); |
| 1369 | assert_eq!( |
| 1370 | CallModel::meeting("Standup", false).connecting_text(), |
| 1371 | "Joining..." |
| 1372 | ); |
| 1373 | assert_eq!( |
| 1374 | CallModel::incoming("Bea", "8:orgid:b", "Bea").connecting_text(), |
| 1375 | "Connecting..." |
| 1376 | ); |
| 1377 | assert_eq!(CallModel::test().connecting_text(), "Calling..."); |
| 1378 | } |
| 1379 | |
| 1380 | #[test] |
| 1381 | fn listen_only_blocks_unmuting() { |
| 1382 | let mut model = connected_model(); |
| 1383 | assert!(model.can_unmute()); |
| 1384 | model.apply(CallUpdate::ListenOnly(true)); |
| 1385 | assert!(!model.can_unmute()); |
| 1386 | } |
| 1387 | |
| 1388 | #[test] |
| 1389 | fn a_call_without_audio_blocks_unmuting() { |
| 1390 | let mut model = connected_model(); |
| 1391 | model.audio_off = true; |
| 1392 | assert!(!model.can_unmute()); |
| 1393 | } |
| 1394 | |
| 1395 | #[test] |
| 1396 | fn callees_start_invited_and_follow_the_progress() { |
| 1397 | let mut model = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]); |
| 1398 | assert_eq!(model.kind, CallKind::Direct); |
| 1399 | assert_eq!(model.peer_name, "Bea"); |
| 1400 | assert_eq!(model.tile_caption(&model.tiles[0]), Some("Calling...")); |
| 1401 | model.apply(CallUpdate::Progress(Progress::Ringing)); |
| 1402 | assert_eq!(model.tile_caption(&model.tiles[0]), Some("Ringing")); |
| 1403 | model.apply(CallUpdate::Roster(vec![entry( |
| 1404 | "8:orgid:b", |
| 1405 | "Bea", |
| 1406 | false, |
| 1407 | false, |
| 1408 | )])); |
| 1409 | assert_eq!(model.tiles[0].state, TileState::Present); |
| 1410 | assert_eq!(model.tile_caption(&model.tiles[0]), None); |
| 1411 | } |
| 1412 | |
| 1413 | #[test] |
| 1414 | fn several_callees_make_a_group_call_named_after_the_chat() { |
| 1415 | let model = CallModel::people( |
| 1416 | "Retro team", |
| 1417 | &[ |
| 1418 | ("8:orgid:b".into(), "Bea".into()), |
| 1419 | ("8:orgid:c".into(), "Cy".into()), |
| 1420 | ], |
| 1421 | ); |
| 1422 | assert_eq!(model.kind, CallKind::Group); |
| 1423 | assert_eq!(model.peer_name, "Retro team"); |
| 1424 | assert_eq!(model.tiles.len(), 2); |
| 1425 | } |
| 1426 | |
| 1427 | #[test] |
| 1428 | fn roster_adds_guests_updates_mute_and_drops_leavers() { |
| 1429 | let mut model = meeting_with_me(); |
| 1430 | model.apply(CallUpdate::Roster(vec![ |
| 1431 | entry("8:orgid:me", "Me", false, false), |
| 1432 | entry("8:orgid:a", "Ana", true, false), |
| 1433 | entry("8:orgid:b", "Bo", false, false), |
| 1434 | ])); |
| 1435 | assert_eq!(model.tiles.len(), 2); |
| 1436 | assert!( |
| 1437 | model |
| 1438 | .tiles |
| 1439 | .iter() |
| 1440 | .find(|tile| tile.name == "Ana") |
| 1441 | .unwrap() |
| 1442 | .muted |
| 1443 | ); |
| 1444 | model.apply(CallUpdate::Roster(vec![ |
| 1445 | entry("8:orgid:me", "Me", false, false), |
| 1446 | entry("8:orgid:b", "Bo", false, false), |
| 1447 | ])); |
| 1448 | assert_eq!(model.tiles.len(), 1); |
| 1449 | assert_eq!(model.tiles[0].name, "Bo"); |
| 1450 | } |
| 1451 | |
| 1452 | #[test] |
| 1453 | fn meeting_bots_get_no_tile_but_the_called_echo_bot_keeps_its_own() { |
| 1454 | let mut model = meeting_with_me(); |
| 1455 | model.apply(CallUpdate::Roster(vec![ |
| 1456 | entry("8:orgid:me", "Me", false, false), |
| 1457 | entry("8:orgid:a", "Ana", false, false), |
| 1458 | entry("28:bdd75849-e0a6-4cce-8fc1-d7c0d4da43e5", "", false, false), |
| 1459 | ])); |
| 1460 | let names: Vec<&str> = model.strip_tiles().iter().map(|tile| tile.name.as_str()).collect(); |
| 1461 | assert_eq!(names, vec!["Ana"]); |
| 1462 | assert_eq!(model.present_others(), 1); |
| 1463 | let mut echo = CallModel::people(ECHO_NAME, &[(ECHO_MRI.into(), ECHO_NAME.into())]); |
| 1464 | echo.apply(CallUpdate::Roster(vec![entry(ECHO_MRI, "", false, false)])); |
| 1465 | assert_eq!(echo.tiles.len(), 1); |
| 1466 | assert_eq!(echo.tiles[0].state, TileState::Present); |
| 1467 | } |
| 1468 | |
| 1469 | #[test] |
| 1470 | fn an_invited_callee_who_leaves_stays_as_left() { |
| 1471 | let mut model = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]); |
| 1472 | model.apply(CallUpdate::Roster(vec![entry( |
| 1473 | "8:orgid:b", |
| 1474 | "Bea", |
| 1475 | false, |
| 1476 | false, |
| 1477 | )])); |
| 1478 | model.apply(CallUpdate::Roster(Vec::new())); |
| 1479 | assert_eq!(model.tiles[0].state, TileState::Left); |
| 1480 | assert_eq!(model.tile_caption(&model.tiles[0]), Some("Left")); |
| 1481 | } |
| 1482 | |
| 1483 | #[test] |
| 1484 | fn lobby_guests_get_no_tile() { |
| 1485 | let mut model = meeting_with_me(); |
| 1486 | model.apply(CallUpdate::Roster(vec![ |
| 1487 | entry("8:orgid:a", "Ana", false, false), |
| 1488 | entry("8:orgid:g", "Guest", false, true), |
| 1489 | ])); |
| 1490 | let names: Vec<&str> = model |
| 1491 | .visible_tiles() |
| 1492 | .iter() |
| 1493 | .map(|tile| tile.name.as_str()) |
| 1494 | .collect(); |
| 1495 | assert_eq!(names, vec!["Ana"]); |
| 1496 | } |
| 1497 | |
| 1498 | #[test] |
| 1499 | fn the_lobby_flag_follows_the_call() { |
| 1500 | let mut model = meeting_with_me(); |
| 1501 | model.apply(CallUpdate::Lobby(true)); |
| 1502 | assert!(model.lobby); |
| 1503 | model.apply(CallUpdate::Lobby(false)); |
| 1504 | assert!(!model.lobby); |
| 1505 | } |
| 1506 | |
| 1507 | #[test] |
| 1508 | fn speakers_light_their_own_tile_and_a_lone_remote_follows_the_level() { |
| 1509 | let mut model = meeting_with_me(); |
| 1510 | model.apply(CallUpdate::Roster(vec![ |
| 1511 | entry("8:orgid:a", "Ana", false, false), |
| 1512 | entry("8:orgid:b", "Bo", false, false), |
| 1513 | ])); |
| 1514 | model.apply(CallUpdate::State(CallState::Connected { |
| 1515 | since: Instant::now(), |
| 1516 | })); |
| 1517 | model.apply(CallUpdate::Speakers(vec!["8:orgid:b".into()])); |
| 1518 | let tiles: Vec<Tile> = model.tiles.clone(); |
| 1519 | assert!(!model.tile_speaking(&tiles[0])); |
| 1520 | assert!(model.tile_speaking(&tiles[1])); |
| 1521 | let mut lone = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]); |
| 1522 | lone.apply(CallUpdate::State(CallState::Connected { |
| 1523 | since: Instant::now(), |
| 1524 | })); |
| 1525 | lone.apply(CallUpdate::Levels { |
| 1526 | local: 0.0, |
| 1527 | remote: 0.5, |
| 1528 | }); |
| 1529 | assert!(lone.tile_speaking(&lone.tiles[0].clone())); |
| 1530 | } |
| 1531 | |
| 1532 | fn crowd(count: usize) -> CallModel { |
| 1533 | let mut model = meeting_with_me(); |
| 1534 | model.apply(CallUpdate::Roster( |
| 1535 | (0..count) |
| 1536 | .map(|index| { |
| 1537 | entry( |
| 1538 | &format!("8:orgid:p{index}"), |
| 1539 | &format!("P{index}"), |
| 1540 | false, |
| 1541 | false, |
| 1542 | ) |
| 1543 | }) |
| 1544 | .collect(), |
| 1545 | )); |
| 1546 | model |
| 1547 | } |
| 1548 | |
| 1549 | fn shown_mris(model: &CallModel) -> Vec<String> { |
| 1550 | model |
| 1551 | .layout_tiles() |
| 1552 | .iter() |
| 1553 | .map(|tile| tile.mri.clone()) |
| 1554 | .collect() |
| 1555 | } |
| 1556 | |
| 1557 | #[test] |
| 1558 | fn hiding_people_without_video_keeps_speakers_and_the_pinned_person() { |
| 1559 | let mut model = meeting_with_me(); |
| 1560 | model.apply(CallUpdate::Roster(vec![ |
| 1561 | entry("8:orgid:a", "Ana", false, false), |
| 1562 | RosterEntry { |
| 1563 | has_video: true, |
| 1564 | ..entry("8:orgid:b", "Bo", false, false) |
| 1565 | }, |
| 1566 | entry("8:orgid:c", "Cy", false, false), |
| 1567 | ])); |
| 1568 | model.view.hide_no_video = true; |
| 1569 | assert_eq!(model.hidden_without_video(), 2); |
| 1570 | assert_eq!(shown_mris(&model), vec!["8:orgid:b"]); |
| 1571 | model.apply(CallUpdate::Speakers(vec!["8:orgid:a".into()])); |
| 1572 | assert_eq!(model.hidden_without_video(), 1); |
| 1573 | assert!(shown_mris(&model).contains(&"8:orgid:a".to_owned())); |
| 1574 | model.toggle_pin("8:orgid:c"); |
| 1575 | assert_eq!(model.hidden_without_video(), 0); |
| 1576 | } |
| 1577 | |
| 1578 | #[test] |
| 1579 | fn people_without_video_stay_in_one_to_one_calls() { |
| 1580 | let mut model = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]); |
| 1581 | model.view.hide_no_video = true; |
| 1582 | model.apply(CallUpdate::Roster(vec![entry( |
| 1583 | "8:orgid:b", |
| 1584 | "Bea", |
| 1585 | false, |
| 1586 | false, |
| 1587 | )])); |
| 1588 | assert_eq!(model.hidden_without_video(), 0); |
| 1589 | } |
| 1590 | |
| 1591 | #[test] |
| 1592 | fn focus_on_content_falls_back_to_the_previous_layout_when_the_share_ends() { |
| 1593 | let mut model = meeting_with_me(); |
| 1594 | model.view.choose(CallLayout::Speaker); |
| 1595 | model.view.choose(CallLayout::Content); |
| 1596 | assert_eq!(model.effective_layout(), CallLayout::Speaker); |
| 1597 | model.apply(CallUpdate::ScreenShare(Some("8:orgid:a".into()))); |
| 1598 | assert_eq!(model.effective_layout(), CallLayout::Content); |
| 1599 | model.apply(CallUpdate::ScreenShare(None)); |
| 1600 | assert_eq!(model.effective_layout(), CallLayout::Speaker); |
| 1601 | } |
| 1602 | |
| 1603 | #[test] |
| 1604 | fn the_speaker_stage_follows_the_active_speaker_and_keeps_the_last_one() { |
| 1605 | let mut model = crowd(3); |
| 1606 | model.apply(CallUpdate::Speakers(vec!["8:orgid:p1".into()])); |
| 1607 | assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1"); |
| 1608 | model.apply(CallUpdate::Speakers(Vec::new())); |
| 1609 | assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1"); |
| 1610 | model.toggle_pin("8:orgid:p2"); |
| 1611 | let focus = model.speaker_focus().unwrap(); |
| 1612 | assert_eq!((focus.mri.as_str(), focus.pinned), ("8:orgid:p2", true)); |
| 1613 | } |
| 1614 | |
| 1615 | #[test] |
| 1616 | fn a_pinned_person_outside_the_grid_moves_into_it() { |
| 1617 | let mut model = crowd(12); |
| 1618 | let grid = split_overflow(12, 1, GALLERY_MAX).shown; |
| 1619 | assert_eq!(grid, 7); |
| 1620 | assert!(!shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned())); |
| 1621 | model.toggle_pin("8:orgid:p11"); |
| 1622 | assert!(shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned())); |
| 1623 | assert_eq!(model.layout_tiles().len(), 12); |
| 1624 | } |
| 1625 | |
| 1626 | #[test] |
| 1627 | fn hiding_me_frees_a_grid_cell() { |
| 1628 | let mut model = crowd(12); |
| 1629 | assert_eq!(model.own_cells(), 1); |
| 1630 | model.view.hide_me = true; |
| 1631 | assert_eq!(model.own_cells(), 0); |
| 1632 | assert_eq!(split_overflow(12, model.own_cells(), GALLERY_MAX).shown, 8); |
| 1633 | } |
| 1634 | |
| 1635 | #[test] |
| 1636 | fn the_stage_label_names_the_sharer_and_the_strip_puts_the_speaker_first() { |
| 1637 | let mut model = meeting_with_me(); |
| 1638 | model.apply(CallUpdate::Roster(vec![ |
| 1639 | entry("8:orgid:a", "Ana", false, false), |
| 1640 | entry("8:orgid:b", "Bo", false, false), |
| 1641 | ])); |
| 1642 | assert_eq!(model.sharing_label(), None); |
| 1643 | model.apply(CallUpdate::ScreenShare(Some("8:orgid:b".into()))); |
| 1644 | assert_eq!(model.sharing_label().as_deref(), Some("Bo is sharing")); |
| 1645 | model.apply(CallUpdate::State(CallState::Connected { |
| 1646 | since: Instant::now(), |
| 1647 | })); |
| 1648 | model.apply(CallUpdate::Speakers(vec!["8:orgid:b".into()])); |
| 1649 | let names: Vec<&str> = model |
| 1650 | .strip_tiles() |
| 1651 | .iter() |
| 1652 | .map(|tile| tile.name.as_str()) |
| 1653 | .collect(); |
| 1654 | assert_eq!(names, vec!["Bo", "Ana"]); |
| 1655 | model.apply(CallUpdate::ScreenShare(None)); |
| 1656 | assert_eq!(model.sharing_label(), None); |
| 1657 | } |
| 1658 | |
| 1659 | #[test] |
| 1660 | fn roster_entries_carry_the_camera_flag_to_the_tile() { |
| 1661 | let mut model = meeting_with_me(); |
| 1662 | let mut with_camera = entry("8:orgid:a", "Ana", false, false); |
| 1663 | with_camera.has_video = true; |
| 1664 | model.apply(CallUpdate::Roster(vec![with_camera])); |
| 1665 | assert!(model.tiles[0].has_video); |
| 1666 | model.apply(CallUpdate::Roster(vec![entry( |
| 1667 | "8:orgid:a", |
| 1668 | "Ana", |
| 1669 | false, |
| 1670 | false, |
| 1671 | )])); |
| 1672 | assert!(!model.tiles[0].has_video); |
| 1673 | } |
| 1674 | |
| 1675 | #[test] |
| 1676 | fn present_guests_sort_before_waiting_ones() { |
| 1677 | let mut model = CallModel::people( |
| 1678 | "Group", |
| 1679 | &[ |
| 1680 | ("8:orgid:b".into(), "Bea".into()), |
| 1681 | ("8:orgid:c".into(), "Cy".into()), |
| 1682 | ], |
| 1683 | ); |
| 1684 | model.apply(CallUpdate::Roster(vec![entry( |
| 1685 | "8:orgid:c", |
| 1686 | "Cy", |
| 1687 | false, |
| 1688 | false, |
| 1689 | )])); |
| 1690 | let names: Vec<&str> = model |
| 1691 | .visible_tiles() |
| 1692 | .iter() |
| 1693 | .map(|tile| tile.name.as_str()) |
| 1694 | .collect(); |
| 1695 | assert_eq!(names, vec!["Cy", "Bea"]); |
| 1696 | } |
| 1697 | |
| 1698 | #[test] |
| 1699 | fn raised_hands_get_queue_positions_by_raise_time_and_sort_first() { |
| 1700 | let mut model = meeting_with_me(); |
| 1701 | model.apply(CallUpdate::Roster(vec![ |
| 1702 | entry("8:orgid:a", "Ana", false, false), |
| 1703 | raised("8:orgid:b", "Bo", 9), |
| 1704 | raised("8:orgid:c", "Cy", 4), |
| 1705 | raised("8:orgid:me", "Me", 6), |
| 1706 | ])); |
| 1707 | assert_eq!(model.own_hand, Some(6)); |
| 1708 | assert!(model.any_hand_raised()); |
| 1709 | let names: Vec<&str> = model |
| 1710 | .visible_tiles() |
| 1711 | .iter() |
| 1712 | .map(|tile| tile.name.as_str()) |
| 1713 | .collect(); |
| 1714 | assert_eq!(names, vec!["Cy", "Bo", "Ana"]); |
| 1715 | let positions: Vec<usize> = [4, 6, 9] |
| 1716 | .into_iter() |
| 1717 | .map(|rank| model.hand_position(rank)) |
| 1718 | .collect(); |
| 1719 | assert_eq!(positions, vec![1, 2, 3]); |
| 1720 | assert_eq!(model.own_cell_index(3), 1); |
| 1721 | let strip: Vec<&str> = model |
| 1722 | .strip_tiles() |
| 1723 | .iter() |
| 1724 | .map(|tile| tile.name.as_str()) |
| 1725 | .collect(); |
| 1726 | assert_eq!(strip, vec!["Cy", "Bo", "Ana"]); |
| 1727 | } |
| 1728 | |
| 1729 | #[test] |
| 1730 | fn a_roster_without_the_own_entry_keeps_the_own_hand() { |
| 1731 | let mut model = meeting_with_me(); |
| 1732 | model.apply(CallUpdate::OwnHand(Some(5))); |
| 1733 | model.apply(CallUpdate::Roster(vec![entry( |
| 1734 | "8:orgid:a", |
| 1735 | "Ana", |
| 1736 | false, |
| 1737 | false, |
| 1738 | )])); |
| 1739 | assert_eq!(model.own_hand, Some(5)); |
| 1740 | model.apply(CallUpdate::Roster(vec![entry( |
| 1741 | "8:orgid:me", |
| 1742 | "Me", |
| 1743 | false, |
| 1744 | false, |
| 1745 | )])); |
| 1746 | assert_eq!(model.own_hand, None); |
| 1747 | } |
| 1748 | |
| 1749 | #[test] |
| 1750 | fn reaction_controls_show_in_group_calls_and_meetings_only() { |
| 1751 | let mut model = CallModel::test(); |
| 1752 | for (kind, expected) in [ |
| 1753 | (CallKind::Test, false), |
| 1754 | (CallKind::Direct, false), |
| 1755 | (CallKind::Group, true), |
| 1756 | (CallKind::Meeting, true), |
| 1757 | ] { |
| 1758 | model.kind = kind; |
| 1759 | assert_eq!(model.has_reaction_controls(), expected); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | #[test] |
| 1764 | fn the_server_echo_of_an_own_reaction_does_not_restart_the_chip() { |
| 1765 | let mut model = meeting_with_me(); |
| 1766 | let start = Instant::now(); |
| 1767 | model.note_reaction("8:orgid:me".into(), Reaction::Like, start); |
| 1768 | let serial = model.reactions[0].serial; |
| 1769 | model.note_reaction( |
| 1770 | "8:orgid:me".into(), |
| 1771 | Reaction::Like, |
| 1772 | start + Duration::from_millis(1500), |
| 1773 | ); |
| 1774 | assert_eq!(model.reactions.len(), 1); |
| 1775 | assert_eq!(model.reactions[0].serial, serial); |
| 1776 | model.note_reaction( |
| 1777 | "8:orgid:me".into(), |
| 1778 | Reaction::Heart, |
| 1779 | start + Duration::from_millis(1600), |
| 1780 | ); |
| 1781 | assert_eq!(model.reactions[0].reaction, Reaction::Heart); |
| 1782 | model.note_reaction( |
| 1783 | "8:orgid:me".into(), |
| 1784 | Reaction::Heart, |
| 1785 | start + Duration::from_secs(4), |
| 1786 | ); |
| 1787 | assert_ne!(model.reactions[0].serial, serial); |
| 1788 | } |
| 1789 | |
| 1790 | #[test] |
| 1791 | fn another_persons_repeated_reaction_restarts_the_chip() { |
| 1792 | let mut model = meeting_with_me(); |
| 1793 | let start = Instant::now(); |
| 1794 | model.note_reaction("8:orgid:a".into(), Reaction::Like, start); |
| 1795 | let serial = model.reactions[0].serial; |
| 1796 | model.note_reaction( |
| 1797 | "8:orgid:a".into(), |
| 1798 | Reaction::Like, |
| 1799 | start + Duration::from_secs(1), |
| 1800 | ); |
| 1801 | assert_ne!(model.reactions[0].serial, serial); |
| 1802 | } |
| 1803 | |
| 1804 | #[test] |
| 1805 | fn lowering_clears_the_hand_everywhere() { |
| 1806 | let mut model = meeting_with_me(); |
| 1807 | model.apply(CallUpdate::Roster(vec![ |
| 1808 | raised("8:orgid:a", "Ana", 1), |
| 1809 | raised("8:orgid:me", "Me", 2), |
| 1810 | ])); |
| 1811 | model.apply(CallUpdate::Roster(vec![ |
| 1812 | entry("8:orgid:a", "Ana", false, false), |
| 1813 | entry("8:orgid:me", "Me", false, false), |
| 1814 | ])); |
| 1815 | assert!(!model.any_hand_raised()); |
| 1816 | assert_eq!(model.own_cell_index(1), 1); |
| 1817 | } |
| 1818 | |
| 1819 | #[test] |
| 1820 | fn only_organizers_may_lower_hands() { |
| 1821 | assert!(!CallModel::meeting("Standup", false).can_lower_hands()); |
| 1822 | assert!(CallModel::meeting("Standup", true).can_lower_hands()); |
| 1823 | } |
| 1824 | |
| 1825 | #[test] |
| 1826 | fn a_reaction_shows_for_three_seconds_on_its_sender_and_the_latest_wins() { |
| 1827 | let mut model = meeting_with_me(); |
| 1828 | let start = Instant::now(); |
| 1829 | model.note_reaction("8:orgid:a".into(), Reaction::Heart, start); |
| 1830 | model.note_reaction("8:orgid:me".into(), Reaction::Like, start); |
| 1831 | let reaction_at = |model: &CallModel, mri: &str, seconds: u64| { |
| 1832 | model |
| 1833 | .chip_of(mri, start + Duration::from_secs(seconds)) |
| 1834 | .map(|chip| chip.reaction) |
| 1835 | }; |
| 1836 | assert_eq!(reaction_at(&model, "8:orgid:a", 2), Some(Reaction::Heart)); |
| 1837 | assert_eq!( |
| 1838 | model |
| 1839 | .own_chip(start + Duration::from_secs(2)) |
| 1840 | .map(|chip| chip.reaction), |
| 1841 | Some(Reaction::Like) |
| 1842 | ); |
| 1843 | assert_eq!(reaction_at(&model, "8:orgid:a", 3), None); |
| 1844 | model.note_reaction( |
| 1845 | "8:orgid:a".into(), |
| 1846 | Reaction::Laugh, |
| 1847 | start + Duration::from_secs(1), |
| 1848 | ); |
| 1849 | assert_eq!(reaction_at(&model, "8:orgid:a", 2), Some(Reaction::Laugh)); |
| 1850 | assert_eq!(model.reactions.len(), 2); |
| 1851 | } |
| 1852 | |
| 1853 | #[test] |
| 1854 | fn the_chat_panel_picks_the_meeting_thread_or_the_call_chat() { |
| 1855 | assert_eq!( |
| 1856 | chat_thread(CallKind::Meeting, Some("19:meeting_x"), Some("19:list")), |
| 1857 | Some("19:meeting_x") |
| 1858 | ); |
| 1859 | assert_eq!( |
| 1860 | chat_thread(CallKind::Meeting, None, Some("19:list")), |
| 1861 | Some("19:list") |
| 1862 | ); |
| 1863 | assert_eq!( |
| 1864 | chat_thread(CallKind::Direct, Some("19:meeting_x"), Some("19:dm")), |
| 1865 | Some("19:dm") |
| 1866 | ); |
| 1867 | assert_eq!( |
| 1868 | chat_thread(CallKind::Group, None, Some("19:group")), |
| 1869 | Some("19:group") |
| 1870 | ); |
| 1871 | assert_eq!(chat_thread(CallKind::Test, None, None), None); |
| 1872 | } |
| 1873 | |
| 1874 | #[test] |
| 1875 | fn computer_sound_follows_the_share() { |
| 1876 | let mut model = connected_model(); |
| 1877 | model.apply(CallUpdate::LocalShare(Some("Screen".into()))); |
| 1878 | model.apply(CallUpdate::ShareSound(true)); |
| 1879 | assert!(model.share_sound); |
| 1880 | model.apply(CallUpdate::LocalShare(None)); |
| 1881 | assert!(!model.share_sound); |
| 1882 | } |
| 1883 | |
| 1884 | #[test] |
| 1885 | fn lobby_guests_are_listed_for_organizers_who_may_admit() { |
| 1886 | let mut model = meeting_with_me(); |
| 1887 | model.apply(CallUpdate::State(CallState::Connected { |
| 1888 | since: Instant::now(), |
| 1889 | })); |
| 1890 | model.apply(CallUpdate::Roster(vec![ |
| 1891 | entry("8:orgid:a", "Ana", false, false), |
| 1892 | entry("8:orgid:g1", "Gast Eins", false, true), |
| 1893 | entry("8:orgid:g2", "Gast Zwei", false, true), |
| 1894 | ])); |
| 1895 | let waiting: Vec<&str> = model |
| 1896 | .lobby_guests() |
| 1897 | .iter() |
| 1898 | .map(|tile| tile.name.as_str()) |
| 1899 | .collect(); |
| 1900 | assert_eq!(waiting, vec!["Gast Eins", "Gast Zwei"]); |
| 1901 | assert!(!model.can_admit()); |
| 1902 | model.apply(CallUpdate::Roster(vec![ |
| 1903 | organizer_entry("8:orgid:me"), |
| 1904 | entry("8:orgid:g1", "Gast Eins", false, true), |
| 1905 | ])); |
| 1906 | assert!(model.organizer && model.can_admit() && model.organizes_meeting()); |
| 1907 | let mut owner = CallModel::meeting("Standup", true); |
| 1908 | owner.apply(CallUpdate::State(CallState::Connected { |
| 1909 | since: Instant::now(), |
| 1910 | })); |
| 1911 | assert!(owner.can_admit()); |
| 1912 | owner.apply(CallUpdate::Lobby(true)); |
| 1913 | assert!(!owner.can_admit()); |
| 1914 | } |
| 1915 | |
| 1916 | #[test] |
| 1917 | fn a_spotlight_takes_the_stage_and_the_lowest_rank_wins() { |
| 1918 | let mut model = meeting_with_me(); |
| 1919 | model.apply(CallUpdate::Roster(vec![ |
| 1920 | entry("8:orgid:a", "Ana", false, false), |
| 1921 | spotlit("8:orgid:b", "Bo", 4), |
| 1922 | spotlit("8:orgid:c", "Cy", 2), |
| 1923 | ])); |
| 1924 | assert_eq!( |
| 1925 | model.focus(), |
| 1926 | Some(Focus { |
| 1927 | mri: "8:orgid:c".into(), |
| 1928 | own: false, |
| 1929 | spotlight: true, |
| 1930 | pinned: false |
| 1931 | }) |
| 1932 | ); |
| 1933 | assert!(model.is_spotlighted("8:orgid:b") && !model.is_spotlighted("8:orgid:a")); |
| 1934 | model.apply(CallUpdate::Roster(vec![ |
| 1935 | entry("8:orgid:a", "Ana", false, false), |
| 1936 | spotlit("8:orgid:b", "Bo", 4), |
| 1937 | entry("8:orgid:c", "Cy", false, false), |
| 1938 | ])); |
| 1939 | assert_eq!( |
| 1940 | model.focus().map(|focus| focus.mri), |
| 1941 | Some("8:orgid:b".to_owned()) |
| 1942 | ); |
| 1943 | model.apply(CallUpdate::Roster(vec![entry( |
| 1944 | "8:orgid:a", |
| 1945 | "Ana", |
| 1946 | false, |
| 1947 | false, |
| 1948 | )])); |
| 1949 | assert_eq!(model.focus(), None); |
| 1950 | } |
| 1951 | |
| 1952 | #[test] |
| 1953 | fn spotlighting_yourself_puts_your_own_tile_on_the_stage() { |
| 1954 | let mut model = meeting_with_me(); |
| 1955 | model.apply(CallUpdate::Roster(vec![ |
| 1956 | entry("8:orgid:a", "Ana", false, false), |
| 1957 | spotlit("8:orgid:me", "Me", 1), |
| 1958 | ])); |
| 1959 | assert_eq!( |
| 1960 | model.focus(), |
| 1961 | Some(Focus { |
| 1962 | mri: "8:orgid:me".into(), |
| 1963 | own: true, |
| 1964 | spotlight: true, |
| 1965 | pinned: false |
| 1966 | }) |
| 1967 | ); |
| 1968 | } |
| 1969 | |
| 1970 | #[test] |
| 1971 | fn a_pin_is_local_beats_the_spotlight_and_ends_when_the_person_leaves() { |
| 1972 | let mut model = meeting_with_me(); |
| 1973 | model.apply(CallUpdate::State(CallState::Connected { |
| 1974 | since: Instant::now(), |
| 1975 | })); |
| 1976 | model.apply(CallUpdate::Roster(vec![ |
| 1977 | entry("8:orgid:a", "Ana", false, false), |
| 1978 | spotlit("8:orgid:b", "Bo", 1), |
| 1979 | ])); |
| 1980 | model.toggle_pin("8:orgid:a"); |
| 1981 | assert_eq!( |
| 1982 | model.focus(), |
| 1983 | Some(Focus { |
| 1984 | mri: "8:orgid:a".into(), |
| 1985 | own: false, |
| 1986 | spotlight: false, |
| 1987 | pinned: true |
| 1988 | }) |
| 1989 | ); |
| 1990 | let names: Vec<&str> = model |
| 1991 | .strip_tiles() |
| 1992 | .iter() |
| 1993 | .map(|tile| tile.name.as_str()) |
| 1994 | .collect(); |
| 1995 | assert_eq!(names[0], "Ana"); |
| 1996 | model.toggle_pin("8:orgid:b"); |
| 1997 | assert_eq!( |
| 1998 | model |
| 1999 | .focus() |
| 2000 | .map(|focus| (focus.mri, focus.spotlight, focus.pinned)), |
| 2001 | Some(("8:orgid:b".to_owned(), true, true)) |
| 2002 | ); |
| 2003 | model.toggle_pin("8:orgid:b"); |
| 2004 | assert_eq!(model.pinned, None); |
| 2005 | model.toggle_pin("8:orgid:a"); |
| 2006 | model.apply(CallUpdate::Roster(vec![spotlit("8:orgid:b", "Bo", 1)])); |
| 2007 | assert_eq!(model.pinned, None); |
| 2008 | } |
| 2009 | |
| 2010 | fn caption(id: &str, speaker: &str, text: &str, is_final: bool) -> CaptionEntry { |
| 2011 | CaptionEntry { |
| 2012 | id: id.into(), |
| 2013 | user_id: "u".into(), |
| 2014 | display_name: speaker.into(), |
| 2015 | text: text.into(), |
| 2016 | is_final, |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | #[test] |
| 2021 | fn captions_keep_two_lines_update_partials_and_fade_after_four_seconds() { |
| 2022 | let mut model = meeting_with_me(); |
| 2023 | let start = Instant::now(); |
| 2024 | model.note_caption(caption("1", "Ana", "ignored while off", false), start); |
| 2025 | assert!(model.caption_lines.is_empty()); |
| 2026 | model.apply(CallUpdate::Captions(CaptionState::On)); |
| 2027 | model.note_caption(caption("1", "Ana", "Hello", false), start); |
| 2028 | model.note_caption(caption("1", "Ana", "Hello there", true), start); |
| 2029 | assert_eq!(model.caption_lines.len(), 1); |
| 2030 | assert_eq!(model.caption_lines[0].text, "Hello there"); |
| 2031 | model.note_caption( |
| 2032 | caption("2", "", "Next", false), |
| 2033 | start + Duration::from_secs(1), |
| 2034 | ); |
| 2035 | model.note_caption( |
| 2036 | caption("3", "Bo", "Third", false), |
| 2037 | start + Duration::from_secs(2), |
| 2038 | ); |
| 2039 | let texts: Vec<&str> = model |
| 2040 | .caption_lines |
| 2041 | .iter() |
| 2042 | .map(|line| line.text.as_str()) |
| 2043 | .collect(); |
| 2044 | assert_eq!(texts, vec!["Next", "Third"]); |
| 2045 | assert_eq!(model.caption_lines[0].speaker, "Someone"); |
| 2046 | assert_eq!( |
| 2047 | model.visible_captions(start + Duration::from_secs(3)).len(), |
| 2048 | 2 |
| 2049 | ); |
| 2050 | assert_eq!( |
| 2051 | model |
| 2052 | .visible_captions(start + Duration::from_millis(5500)) |
| 2053 | .len(), |
| 2054 | 1 |
| 2055 | ); |
| 2056 | assert!( |
| 2057 | model |
| 2058 | .visible_captions(start + Duration::from_secs(7)) |
| 2059 | .is_empty() |
| 2060 | ); |
| 2061 | model.apply(CallUpdate::Captions(CaptionState::Off)); |
| 2062 | assert!(model.caption_lines.is_empty() && !model.captions_on()); |
| 2063 | } |
| 2064 | |
| 2065 | fn one_to_one() -> CallModel { |
| 2066 | let mut model = CallModel::people("Bea", &[("8:orgid:bea".into(), "Bea".into())]); |
| 2067 | model.apply(CallUpdate::State(CallState::Connected { |
| 2068 | since: Instant::now(), |
| 2069 | })); |
| 2070 | model |
| 2071 | } |
| 2072 | |
| 2073 | #[test] |
| 2074 | fn hold_and_transfer_belong_to_one_to_one_calls_and_follow_the_hold_state() { |
| 2075 | let mut model = one_to_one(); |
| 2076 | assert!(model.can_hold() && model.can_transfer()); |
| 2077 | model.apply(CallUpdate::Hold(HoldState::Local)); |
| 2078 | assert!(model.can_hold() && !model.can_transfer()); |
| 2079 | model.apply(CallUpdate::Hold(HoldState::Remote)); |
| 2080 | assert!(!model.can_hold() && !model.can_transfer()); |
| 2081 | let meeting = meeting_with_me(); |
| 2082 | assert!(!meeting.can_hold() && !meeting.can_transfer()); |
| 2083 | assert!( |
| 2084 | !CallModel::people( |
| 2085 | "Group", |
| 2086 | &[ |
| 2087 | ("8:orgid:a".into(), "A".into()), |
| 2088 | ("8:orgid:b".into(), "B".into()) |
| 2089 | ] |
| 2090 | ) |
| 2091 | .can_hold() |
| 2092 | ); |
| 2093 | } |
| 2094 | |
| 2095 | #[test] |
| 2096 | fn the_transcript_keeps_every_caption_with_its_offset_while_the_overlay_keeps_two() { |
| 2097 | let mut model = meeting_with_me(); |
| 2098 | let start = Instant::now(); |
| 2099 | model.apply(CallUpdate::State(CallState::Connected { since: start })); |
| 2100 | model.apply(CallUpdate::Captions(CaptionState::On)); |
| 2101 | model.note_caption(caption("1", "Ana Example", "One", true), start + Duration::from_secs(5)); |
| 2102 | model.note_caption(caption("2", "Bo Sample", "Two", true), start + Duration::from_secs(65)); |
| 2103 | model.note_caption(caption("3", "Ana Example", "Three", true), start + Duration::from_secs(70)); |
| 2104 | assert_eq!(model.caption_lines.len(), 2); |
| 2105 | assert_eq!(model.transcript.filtered("").len(), 3); |
| 2106 | assert_eq!(model.transcript.filtered("")[1].offset, Duration::from_secs(65)); |
| 2107 | model.apply(CallUpdate::Captions(CaptionState::Off)); |
| 2108 | model.note_caption(caption("4", "Bo Sample", "Ignored", true), start + Duration::from_secs(80)); |
| 2109 | assert!(model.caption_lines.is_empty()); |
| 2110 | assert_eq!(model.transcript.filtered("").len(), 3); |
| 2111 | } |
| 2112 | |
| 2113 | #[test] |
| 2114 | fn a_chosen_spoken_language_is_handed_out_once_the_captions_are_on() { |
| 2115 | let mut model = meeting_with_me(); |
| 2116 | model.choose_caption_language("de-DE"); |
| 2117 | model.apply(CallUpdate::Captions(CaptionState::Starting)); |
| 2118 | assert_eq!(model.take_ready_caption_language(), None); |
| 2119 | model.apply(CallUpdate::Captions(CaptionState::On)); |
| 2120 | assert_eq!(model.take_ready_caption_language().as_deref(), Some("de-DE")); |
| 2121 | assert_eq!(model.take_ready_caption_language(), None); |
| 2122 | assert_eq!(model.caption_language.as_deref(), Some("de-DE")); |
| 2123 | } |
| 2124 | |
| 2125 | #[test] |
| 2126 | fn audio_only_and_transcription_follow_their_own_updates() { |
| 2127 | let mut model = meeting_with_me(); |
| 2128 | model.apply(CallUpdate::Transcribing(true)); |
| 2129 | assert!(model.transcribing && !model.recording); |
| 2130 | model.apply(CallUpdate::Recording(true)); |
| 2131 | model.apply(CallUpdate::RecordingAudioOnly(true)); |
| 2132 | assert!(model.recording && model.recording_audio_only); |
| 2133 | model.apply(CallUpdate::Transcribing(false)); |
| 2134 | assert!(!model.transcribing && model.recording); |
| 2135 | } |
| 2136 | |
| 2137 | #[test] |
| 2138 | fn recording_and_consent_follow_the_call_updates_and_only_organizers_may_record() { |
| 2139 | let mut model = meeting_with_me(); |
| 2140 | model.apply(CallUpdate::State(CallState::Connected { |
| 2141 | since: Instant::now(), |
| 2142 | })); |
| 2143 | assert!(!model.can_record()); |
| 2144 | model.apply(CallUpdate::Roster(vec![organizer_entry("8:orgid:me")])); |
| 2145 | assert!(model.can_record()); |
| 2146 | model.apply(CallUpdate::Recording(true)); |
| 2147 | model.apply(CallUpdate::ConsentRequired(true)); |
| 2148 | assert!(model.recording && model.consent_required); |
| 2149 | model.apply(CallUpdate::ConsentRequired(false)); |
| 2150 | assert!(model.recording && !model.consent_required); |
| 2151 | model.apply(CallUpdate::Recording(false)); |
| 2152 | assert!(!model.recording); |
| 2153 | } |
| 2154 | |
| 2155 | #[test] |
| 2156 | fn a_whiteboard_share_names_the_presenter_and_offers_the_browser_only_with_a_link() { |
| 2157 | let mut model = meeting_with_me(); |
| 2158 | model.apply(CallUpdate::Roster(vec![entry( |
| 2159 | "8:orgid:ana", |
| 2160 | "Ana", |
| 2161 | false, |
| 2162 | false, |
| 2163 | )])); |
| 2164 | assert_eq!(model.whiteboard_label(), None); |
| 2165 | let share = |presenter: &str, url: Option<&str>| calling::ContentShare { |
| 2166 | session_id: "s".into(), |
| 2167 | presenter: Some(presenter.into()), |
| 2168 | subject: "Whiteboard".into(), |
| 2169 | url: url.map(str::to_owned), |
| 2170 | whiteboard: true, |
| 2171 | }; |
| 2172 | model.apply(CallUpdate::Whiteboard(Some(share( |
| 2173 | "8:orgid:ana", |
| 2174 | Some("https://app.whiteboard.microsoft.com/x"), |
| 2175 | )))); |
| 2176 | assert_eq!( |
| 2177 | model.whiteboard_label().as_deref(), |
| 2178 | Some("Ana is sharing a whiteboard") |
| 2179 | ); |
| 2180 | assert_eq!( |
| 2181 | model.whiteboard_url(), |
| 2182 | Some("https://app.whiteboard.microsoft.com/x") |
| 2183 | ); |
| 2184 | model.apply(CallUpdate::Whiteboard(Some(share( |
| 2185 | "8:orgid:stranger", |
| 2186 | None, |
| 2187 | )))); |
| 2188 | assert_eq!( |
| 2189 | model.whiteboard_label().as_deref(), |
| 2190 | Some("Someone is sharing a whiteboard") |
| 2191 | ); |
| 2192 | assert_eq!(model.whiteboard_url(), None); |
| 2193 | model.apply(CallUpdate::Whiteboard(None)); |
| 2194 | assert_eq!(model.whiteboard_label(), None); |
| 2195 | } |
| 2196 | |
| 2197 | #[test] |
| 2198 | fn a_consultation_can_transfer_once_connected_with_a_replacement_link() { |
| 2199 | let mut model = CallModel::people("Ana", &[("8:orgid:ana".into(), "Ana".into())]); |
| 2200 | let mut consult = ConsultCall::new(("8:orgid:ana".into(), "Ana".into()), "Chris".into()); |
| 2201 | assert_eq!(consult.banner_text(), "Chris is on hold"); |
| 2202 | consult.replacement = Some(Replacement::of_call("https://cc/replacement")); |
| 2203 | assert!(!consult.ready_to_transfer(&model)); |
| 2204 | model.apply(CallUpdate::State(CallState::Connected { |
| 2205 | since: Instant::now(), |
| 2206 | })); |
| 2207 | assert!(consult.ready_to_transfer(&model)); |
| 2208 | consult.transfer = ConsultTransfer::Pending; |
| 2209 | assert!(!consult.ready_to_transfer(&model)); |
| 2210 | assert_eq!(consult.banner_text(), "Transferring Chris to Ana..."); |
| 2211 | } |
| 2212 | } |