| 1 | use super::*; |
| 2 | |
| 3 | pub(super) struct NextPeer { |
| 4 | pub(super) session: PeerSession, |
| 5 | pub(super) offered: Option<OfferedMedia>, |
| 6 | pub(super) answered: Option<AnsweredMedia>, |
| 7 | pub(super) leg_links: BTreeMap<String, String>, |
| 8 | pub(super) remote_audio: Option<RtcAudioTrack>, |
| 9 | pub(super) reply_tags: Vec<String>, |
| 10 | pub(super) deadline: Option<Instant>, |
| 11 | pub(super) connected: bool, |
| 12 | pub(super) retargeted: bool, |
| 13 | } |
| 14 | |
| 15 | pub(super) async fn next_peer_event(next: &mut Option<NextPeer>) -> Option<PeerEvent> { |
| 16 | match next { |
| 17 | Some(next) => next.session.events.recv().await, |
| 18 | None => std::future::pending().await, |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | pub(super) fn video_possible(remote_set: bool, layout: Layout, path: MediaPath) -> bool { |
| 23 | remote_set && !(layout == Layout::OneToOne && path == MediaPath::Mixer) |
| 24 | } |
| 25 | |
| 26 | /// Re-queuing while `next` is set spins the call task (defer -> pending -> defer...). |
| 27 | pub(super) fn camera_may_start(pending: bool, next_is_some: bool, possible: bool) -> bool { |
| 28 | pending && !next_is_some && possible |
| 29 | } |
| 30 | |
| 31 | #[allow(clippy::too_many_arguments)] |
| 32 | pub(super) async fn start_escalation( |
| 33 | factory: &PeerConnectionFactory, |
| 34 | grant: &RelayGrant, |
| 35 | options: &CallOptions, |
| 36 | track: &RtcAudioTrack, |
| 37 | remote: &RemoteCall, |
| 38 | links: &CallbackLinks, |
| 39 | media_leg_id: &str, |
| 40 | acceptance_links: &BTreeMap<String, String>, |
| 41 | ) -> Result<NextPeer> { |
| 42 | let url = acceptance_links |
| 43 | .get("mediaRenegotiation") |
| 44 | .ok_or_else(|| Error::Signaling("acceptance without a mediaRenegotiation link".into()))?; |
| 45 | let session = open_peer(factory, grant, &options.relay_host, false)?; |
| 46 | let media = create_offer(&session.peer, factory, track, Layout::Conference, None).await?; |
| 47 | let body = renegotiation_body( |
| 48 | &remote.participant, |
| 49 | links, |
| 50 | &media.signaled.sdp, |
| 51 | media_leg_id, |
| 52 | &media.modalities, |
| 53 | true, |
| 54 | false, |
| 55 | ); |
| 56 | let reply_tags = offer_reply_tags(&body); |
| 57 | remote |
| 58 | .signaling |
| 59 | .post_json("POST mediaRenegotiation", url, body) |
| 60 | .await?; |
| 61 | Ok(NextPeer { |
| 62 | session, |
| 63 | offered: Some(media), |
| 64 | answered: None, |
| 65 | leg_links: acceptance_links.clone(), |
| 66 | remote_audio: None, |
| 67 | reply_tags, |
| 68 | deadline: Some(Instant::now() + NEXT_PEER_LIMIT), |
| 69 | connected: false, |
| 70 | retargeted: false, |
| 71 | }) |
| 72 | } |
| 73 | |
| 74 | #[allow(clippy::too_many_arguments)] |
| 75 | pub(super) async fn escalate( |
| 76 | factory: &PeerConnectionFactory, |
| 77 | grant: &RelayGrant, |
| 78 | options: &CallOptions, |
| 79 | track: &RtcAudioTrack, |
| 80 | remote: &RemoteCall, |
| 81 | links: &CallbackLinks, |
| 82 | media_leg_id: &str, |
| 83 | acceptance_links: &BTreeMap<String, String>, |
| 84 | negotiator: &mut MediaNegotiator, |
| 85 | live: &mut Live, |
| 86 | timeline: &Timeline, |
| 87 | ) -> Option<NextPeer> { |
| 88 | match start_escalation( |
| 89 | factory, |
| 90 | grant, |
| 91 | options, |
| 92 | track, |
| 93 | remote, |
| 94 | links, |
| 95 | media_leg_id, |
| 96 | acceptance_links, |
| 97 | ) |
| 98 | .await |
| 99 | { |
| 100 | Ok(pending) => { |
| 101 | timeline.record("escalation", "new peer connection, new offer sent"); |
| 102 | if let Some(media) = &pending.offered { |
| 103 | timeline.record_sdp("local offer", &media.signaled.sdp); |
| 104 | } |
| 105 | live.peers.push(pending.session.peer.clone()); |
| 106 | Some(pending) |
| 107 | } |
| 108 | Err(error) => { |
| 109 | negotiator.escalation_failed(); |
| 110 | timeline.record("escalation failed", error.to_string()); |
| 111 | None |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | #[allow(clippy::too_many_arguments)] |
| 117 | pub(super) async fn answer_on_new_peer( |
| 118 | factory: &PeerConnectionFactory, |
| 119 | grant: &RelayGrant, |
| 120 | options: &CallOptions, |
| 121 | track: &RtcAudioTrack, |
| 122 | teams_offer: &str, |
| 123 | camera_on: bool, |
| 124 | camera: Option<&RtcVideoTrack>, |
| 125 | share: Option<&RtcVideoTrack>, |
| 126 | ) -> Result<(PeerSession, AnsweredMedia)> { |
| 127 | let session = open_peer(factory, grant, &options.relay_host, false)?; |
| 128 | // Keep every video mid from the mixer offer (camera, gallery, share). |
| 129 | // Reject would stop them and leave set_track InvalidState after the new |
| 130 | // peer replaces the old one. When the camera is already on, answer sendrecv |
| 131 | // so the remote keeps receiving across the escalation. |
| 132 | let video = match (camera_on, camera) { |
| 133 | (true, Some(camera)) => AnswerVideo::Send(camera), |
| 134 | _ => AnswerVideo::Receive, |
| 135 | }; |
| 136 | let answered = answer_offer_with( |
| 137 | &session.peer, |
| 138 | Some(track), |
| 139 | teams_offer, |
| 140 | video, |
| 141 | None, |
| 142 | share, |
| 143 | camera_on, |
| 144 | None, |
| 145 | true, |
| 146 | true, |
| 147 | ) |
| 148 | .await?; |
| 149 | Ok((session, answered)) |
| 150 | } |
| 151 | |
| 152 | pub(super) fn video_lines_from_answer( |
| 153 | peer: &PeerConnection, |
| 154 | answered: &AnsweredMedia, |
| 155 | ) -> Option<VideoLines> { |
| 156 | let camera_mid = answered.camera_mid.as_deref()?; |
| 157 | let camera = peer_transceiver(peer, camera_mid)?; |
| 158 | let share = share_carrier_mid(&answered.remote).and_then(|mid| peer_transceiver(peer, &mid)); |
| 159 | Some(VideoLines { camera, share }) |
| 160 | } |
| 161 | |
| 162 | pub(super) async fn send_media_answer( |
| 163 | remote: &RemoteCall, |
| 164 | links: &CallbackLinks, |
| 165 | reply_links: &BTreeMap<String, String>, |
| 166 | answered: &AnsweredMedia, |
| 167 | media_leg_id: &str, |
| 168 | ) -> Result<(BTreeMap<String, String>, String)> { |
| 169 | let url = reply_links |
| 170 | .get("mediaAnswer") |
| 171 | .ok_or_else(|| Error::Signaling("renegotiation without a mediaAnswer link".into()))?; |
| 172 | let body = escalation_answer_body( |
| 173 | &remote.participant, |
| 174 | links, |
| 175 | &answered.answer_sdp, |
| 176 | media_leg_id, |
| 177 | ); |
| 178 | let response = remote |
| 179 | .signaling |
| 180 | .post_json_body("POST mediaAnswer", url, body) |
| 181 | .await?; |
| 182 | Ok((nested_links(&response), object_keys(&response))) |
| 183 | } |
| 184 | |
| 185 | pub(super) fn absorb_answered_links( |
| 186 | into: &mut BTreeMap<String, String>, |
| 187 | extra: &BTreeMap<String, String>, |
| 188 | timeline: &Timeline, |
| 189 | response_keys: &str, |
| 190 | ) { |
| 191 | if extra.is_empty() { |
| 192 | if !response_keys.is_empty() { |
| 193 | timeline.record( |
| 194 | "media answer links", |
| 195 | format!("none, body keys {response_keys}"), |
| 196 | ); |
| 197 | } |
| 198 | return; |
| 199 | } |
| 200 | let names = extra.keys().cloned().collect::<Vec<_>>().join(","); |
| 201 | timeline.record("media answer links", names); |
| 202 | into.extend(extra.clone()); |
| 203 | } |
| 204 | |
| 205 | #[allow(clippy::too_many_arguments)] |
| 206 | pub(super) fn negotiate_video( |
| 207 | video: &mut VideoReceive, |
| 208 | signaling: &Arc<Signaling>, |
| 209 | control: &CallControl, |
| 210 | timeline: &Timeline, |
| 211 | answer_sdp: &str, |
| 212 | media: &OfferedMedia, |
| 213 | from_mixer: bool, |
| 214 | links: &BTreeMap<String, String>, |
| 215 | roster: &Roster, |
| 216 | ) { |
| 217 | negotiate_video_lines( |
| 218 | video, |
| 219 | signaling, |
| 220 | control, |
| 221 | timeline, |
| 222 | answer_sdp, |
| 223 | &media.signaled.lines, |
| 224 | from_mixer, |
| 225 | links, |
| 226 | roster, |
| 227 | ); |
| 228 | } |
| 229 | |
| 230 | #[allow(clippy::too_many_arguments)] |
| 231 | pub(super) fn negotiate_video_lines( |
| 232 | video: &mut VideoReceive, |
| 233 | signaling: &Arc<Signaling>, |
| 234 | control: &CallControl, |
| 235 | timeline: &Timeline, |
| 236 | teams_sdp: &str, |
| 237 | lines: &[crate::sdp::SignaledLine], |
| 238 | from_mixer: bool, |
| 239 | links: &BTreeMap<String, String>, |
| 240 | roster: &Roster, |
| 241 | ) { |
| 242 | let streams = match stream_lines(teams_sdp, lines) { |
| 243 | Ok(streams) => streams, |
| 244 | Err(error) => { |
| 245 | timeline.record("video slots unknown", error.to_string()); |
| 246 | return; |
| 247 | } |
| 248 | }; |
| 249 | let table = SlotTable::from_streams(&streams); |
| 250 | let link = links |
| 251 | .get("applyChannelParameters") |
| 252 | .or_else(|| links.get("controlVideoStreaming")); |
| 253 | timeline.record( |
| 254 | "video slots", |
| 255 | format!( |
| 256 | "{} receive slot(s), screen {}, fromMixer={from_mixer}, request link {}", |
| 257 | table.people.len(), |
| 258 | table.screen.is_some(), |
| 259 | link.is_some() |
| 260 | ), |
| 261 | ); |
| 262 | let requester = link.filter(|_| from_mixer).map(|url| { |
| 263 | SourceRequester::start( |
| 264 | signaling.clone(), |
| 265 | url.clone(), |
| 266 | video.router().clone(), |
| 267 | control.video.clone(), |
| 268 | timeline.clone(), |
| 269 | ) |
| 270 | }); |
| 271 | video.negotiated(table, requester); |
| 272 | send_receive_change(control, video.reselect(roster)); |
| 273 | } |
| 274 | |
| 275 | pub(super) fn tell_bound_camera( |
| 276 | remote: &RemoteCall, |
| 277 | links: &BTreeMap<String, String>, |
| 278 | local_video: &LocalVideo, |
| 279 | request_id: &mut u32, |
| 280 | timeline: &Timeline, |
| 281 | ) { |
| 282 | let mid = local_video |
| 283 | .camera_mid() |
| 284 | .unwrap_or_else(|| CAMERA_MID.to_owned()); |
| 285 | tell_media_descriptions( |
| 286 | remote, |
| 287 | links, |
| 288 | MediaDescription::camera_line(mid, local_video.camera_on()), |
| 289 | request_id, |
| 290 | timeline, |
| 291 | ); |
| 292 | } |
| 293 | |
| 294 | pub(super) fn tell_bound_share( |
| 295 | remote: &RemoteCall, |
| 296 | links: &BTreeMap<String, String>, |
| 297 | local_video: &LocalVideo, |
| 298 | request_id: &mut u32, |
| 299 | timeline: &Timeline, |
| 300 | ) { |
| 301 | if !local_video.sharing() { |
| 302 | return; |
| 303 | } |
| 304 | let mid = local_video |
| 305 | .share_mid() |
| 306 | .unwrap_or_else(|| SHARE_MID.to_owned()); |
| 307 | tell_media_descriptions( |
| 308 | remote, |
| 309 | links, |
| 310 | MediaDescription::share_line(mid, true), |
| 311 | request_id, |
| 312 | timeline, |
| 313 | ); |
| 314 | } |
| 315 | |
| 316 | pub(super) async fn camera_devices(mode: VideoMode) -> Vec<CameraDevice> { |
| 317 | match mode { |
| 318 | VideoMode::Pattern => vec![CameraDevice { |
| 319 | key: "pattern".into(), |
| 320 | name: "Test pattern".into(), |
| 321 | }], |
| 322 | VideoMode::Off => Vec::new(), |
| 323 | VideoMode::Platform => tokio::task::spawn_blocking(list_cameras) |
| 324 | .await |
| 325 | .unwrap_or_default(), |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | pub(super) fn refresh_cameras( |
| 330 | updates: mpsc::UnboundedSender<CallUpdate>, |
| 331 | mode: VideoMode, |
| 332 | timeline: Timeline, |
| 333 | ) { |
| 334 | tokio::spawn(async move { |
| 335 | let started = Instant::now(); |
| 336 | let cameras = camera_devices(mode).await; |
| 337 | timeline.record( |
| 338 | "camera list", |
| 339 | format!( |
| 340 | "{} camera(s) in {} ms", |
| 341 | cameras.len(), |
| 342 | started.elapsed().as_millis() |
| 343 | ), |
| 344 | ); |
| 345 | let _ = updates.send(CallUpdate::Cameras(cameras)); |
| 346 | }); |
| 347 | } |
| 348 | |
| 349 | pub(super) const SHARE_THUMBNAIL_WINDOWS: usize = 12; |
| 350 | |
| 351 | pub(super) const SHARE_THUMBNAIL_WIDTH: u32 = 320; |
| 352 | |
| 353 | pub(super) const SHARE_THUMBNAIL_HEIGHT: u32 = 180; |
| 354 | |
| 355 | pub(super) fn announce_share(control: &CallControl, source: &ShareSource) { |
| 356 | control.send(CallUpdate::ShareKind(Some(source.kind))); |
| 357 | control.send(CallUpdate::LocalShare(Some(source.label()))); |
| 358 | } |
| 359 | |
| 360 | pub(super) fn clear_share(control: &CallControl) { |
| 361 | control.send(CallUpdate::ShareKind(None)); |
| 362 | control.send(CallUpdate::LocalShare(None)); |
| 363 | } |
| 364 | |
| 365 | pub(super) fn refresh_share_sources( |
| 366 | updates: mpsc::UnboundedSender<CallUpdate>, |
| 367 | mode: VideoMode, |
| 368 | with_thumbnails: bool, |
| 369 | ) { |
| 370 | tokio::spawn(async move { |
| 371 | let picker = current_share_picker(); |
| 372 | let sources = match mode { |
| 373 | VideoMode::Pattern => vec![ |
| 374 | ShareSource { |
| 375 | id: 1, |
| 376 | kind: ShareKind::Screen, |
| 377 | title: "Test screen".into(), |
| 378 | }, |
| 379 | ShareSource { |
| 380 | id: 2, |
| 381 | kind: ShareKind::Window, |
| 382 | title: "Test window".into(), |
| 383 | }, |
| 384 | ], |
| 385 | VideoMode::Off => Vec::new(), |
| 386 | VideoMode::Platform if picker == SharePicker::Portal => Vec::new(), |
| 387 | VideoMode::Platform => tokio::task::spawn_blocking(list_share_sources) |
| 388 | .await |
| 389 | .unwrap_or_default(), |
| 390 | }; |
| 391 | let sources = share_sources_for_menu(picker, sources); |
| 392 | let _ = updates.send(CallUpdate::ShareSources(sources.clone())); |
| 393 | if picker == SharePicker::Portal || !with_thumbnails { |
| 394 | return; |
| 395 | } |
| 396 | let wanted: Vec<ShareSource> = sources |
| 397 | .iter() |
| 398 | .filter(|source| source.kind == ShareKind::Screen) |
| 399 | .chain( |
| 400 | sources |
| 401 | .iter() |
| 402 | .filter(|source| source.kind == ShareKind::Window) |
| 403 | .take(SHARE_THUMBNAIL_WINDOWS), |
| 404 | ) |
| 405 | .cloned() |
| 406 | .collect(); |
| 407 | for source in wanted { |
| 408 | let picture = match mode { |
| 409 | VideoMode::Platform => { |
| 410 | let wanted = source.clone(); |
| 411 | tokio::task::spawn_blocking(move || { |
| 412 | share_thumbnail(&wanted, SHARE_THUMBNAIL_WIDTH, SHARE_THUMBNAIL_HEIGHT) |
| 413 | }) |
| 414 | .await |
| 415 | .ok() |
| 416 | .flatten() |
| 417 | } |
| 418 | VideoMode::Pattern => Some(VideoPicture::solid( |
| 419 | SHARE_THUMBNAIL_WIDTH, |
| 420 | SHARE_THUMBNAIL_HEIGHT, |
| 421 | 120, |
| 422 | 80, |
| 423 | 40, |
| 424 | )), |
| 425 | VideoMode::Off => None, |
| 426 | }; |
| 427 | if let Some(picture) = picture |
| 428 | && updates |
| 429 | .send(CallUpdate::ShareThumbnail { |
| 430 | source, |
| 431 | picture: Arc::new(picture), |
| 432 | }) |
| 433 | .is_err() |
| 434 | { |
| 435 | return; |
| 436 | } |
| 437 | } |
| 438 | }); |
| 439 | } |
| 440 | |
| 441 | pub(super) fn tell_media_descriptions( |
| 442 | remote: &RemoteCall, |
| 443 | links: &BTreeMap<String, String>, |
| 444 | description: MediaDescription, |
| 445 | request_id: &mut u32, |
| 446 | timeline: &Timeline, |
| 447 | ) { |
| 448 | let Some(url) = links.get("updateMediaDescriptions").cloned() else { |
| 449 | timeline.record("updateMediaDescriptions skipped", "no link from the mixer"); |
| 450 | return; |
| 451 | }; |
| 452 | *request_id += 1; |
| 453 | let request_id = *request_id; |
| 454 | let signaling = remote.signaling.clone(); |
| 455 | let timeline = timeline.clone(); |
| 456 | tokio::spawn(async move { |
| 457 | let sent = format!( |
| 458 | "{} {} request {request_id}", |
| 459 | description.mid, description.direction |
| 460 | ); |
| 461 | if let Err(error) = signaling |
| 462 | .update_media_descriptions(&url, &[description], request_id) |
| 463 | .await |
| 464 | { |
| 465 | timeline.record("updateMediaDescriptions failed", format!("{sent}: {error}")); |
| 466 | } |
| 467 | }); |
| 468 | } |
| 469 | |
| 470 | pub(super) fn attach_share_line( |
| 471 | peer: &PeerConnection, |
| 472 | factory: &PeerConnectionFactory, |
| 473 | local_video: &mut LocalVideo, |
| 474 | camera_mid: Option<&str>, |
| 475 | ) -> Result<()> { |
| 476 | let camera = camera_mid.and_then(|mid| peer_transceiver(peer, mid)); |
| 477 | if !local_video.has_lines() && camera.is_none() { |
| 478 | return Err(Error::Webrtc("no video line negotiated".into())); |
| 479 | } |
| 480 | let share = add_share_line(peer, factory)?; |
| 481 | local_video |
| 482 | .add_share_line(share.clone(), camera) |
| 483 | .inspect_err(|_| { |
| 484 | let _ = share.stop(); |
| 485 | }) |
| 486 | } |
| 487 | |
| 488 | pub(super) fn start_camera_line( |
| 489 | local_video: &mut LocalVideo, |
| 490 | peer: &PeerConnection, |
| 491 | direct_mid: Option<&str>, |
| 492 | choice: &DeviceChoice, |
| 493 | ) -> Result<()> { |
| 494 | if !local_video.has_lines() { |
| 495 | let mid = direct_mid.ok_or_else(|| Error::Webrtc("no video line negotiated".into()))?; |
| 496 | let camera = peer_transceiver(peer, mid) |
| 497 | .ok_or_else(|| Error::Webrtc("no transceiver for the camera line".into()))?; |
| 498 | if !matches!( |
| 499 | camera.direction(), |
| 500 | RtpTransceiverDirection::SendRecv | RtpTransceiverDirection::SendOnly |
| 501 | ) { |
| 502 | peer.add_track( |
| 503 | MediaStreamTrack::Video(local_video.camera_track()), |
| 504 | &[CAMERA_STREAM], |
| 505 | ) |
| 506 | .map_err(|error| Error::Webrtc(error.to_string()))?; |
| 507 | } |
| 508 | local_video.set_lines(VideoLines { |
| 509 | camera, |
| 510 | share: None, |
| 511 | })?; |
| 512 | } |
| 513 | local_video.start_camera(choice) |
| 514 | } |
| 515 | |
| 516 | pub(super) fn defer_to_new_peer( |
| 517 | change: Change, |
| 518 | deferred: &mut Vec<Change>, |
| 519 | local_video: &mut LocalVideo, |
| 520 | control: &CallControl, |
| 521 | ) { |
| 522 | match change { |
| 523 | Change::Camera(true) => { |
| 524 | control.send(CallUpdate::Camera(true)); |
| 525 | deferred.push(change); |
| 526 | } |
| 527 | Change::Share(true) => deferred.push(change), |
| 528 | change => undo_change(change, local_video, control), |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | /// A server escalation that fails leaves the call direct, so only what waited for the new peer is undone. |
| 533 | pub(super) fn settle_failed_escalation( |
| 534 | server: bool, |
| 535 | layout: Layout, |
| 536 | negotiator: &mut MediaNegotiator, |
| 537 | deferred: &mut Vec<Change>, |
| 538 | local_video: &mut LocalVideo, |
| 539 | control: &CallControl, |
| 540 | ) { |
| 541 | if server { |
| 542 | negotiator.server_escalation_failed(); |
| 543 | for change in deferred.drain(..) { |
| 544 | undo_change(change, local_video, control); |
| 545 | } |
| 546 | } else if layout == Layout::OneToOne { |
| 547 | drop_local_media(local_video, control); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | pub(super) fn drop_local_media(local_video: &mut LocalVideo, control: &CallControl) { |
| 552 | if local_video.sharing() { |
| 553 | local_video.stop_share(); |
| 554 | clear_share(control); |
| 555 | } |
| 556 | if local_video.camera_on() { |
| 557 | local_video.stop_camera(); |
| 558 | control.send(CallUpdate::Camera(false)); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | pub(super) fn undo_change(change: Change, local_video: &mut LocalVideo, control: &CallControl) { |
| 563 | match change { |
| 564 | Change::Camera(true) => { |
| 565 | local_video.stop_camera(); |
| 566 | control.send(CallUpdate::Camera(false)); |
| 567 | } |
| 568 | Change::Camera(false) => control.send(CallUpdate::Camera(false)), |
| 569 | Change::Share(true) => { |
| 570 | local_video.stop_share(); |
| 571 | clear_share(control); |
| 572 | control.send(CallUpdate::Notice(notice_with_detail( |
| 573 | SHARING_START_NOTICE, |
| 574 | "", |
| 575 | ))); |
| 576 | } |
| 577 | Change::Share(false) => {} |
| 578 | Change::Hold(_) => control.send(CallUpdate::Notice(HOLD_CHANGE_FAILED_NOTICE.into())), |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | pub(super) async fn apply_background( |
| 583 | choice: BackgroundChoice, |
| 584 | local_video: &LocalVideo, |
| 585 | control: &CallControl, |
| 586 | timeline: &Timeline, |
| 587 | ) { |
| 588 | match choice { |
| 589 | BackgroundChoice::None => local_video.set_background(false, None), |
| 590 | BackgroundChoice::Blur => local_video.set_background(true, None), |
| 591 | BackgroundChoice::Image(path) => { |
| 592 | match tokio::task::spawn_blocking(move || BackgroundPicture::load(&path)).await { |
| 593 | Ok(Ok(picture)) => local_video.set_background(true, Some(Arc::new(picture))), |
| 594 | Ok(Err(error)) => { |
| 595 | timeline.record("background image failed", error.to_string()); |
| 596 | control.send(CallUpdate::Notice(BACKGROUND_IMAGE_FAILED_NOTICE.into())); |
| 597 | } |
| 598 | Err(_) => {} |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | pub(super) fn send_receive_change(control: &CallControl, change: ReceiveChange) { |
| 605 | if let Some(sharer) = change.screen_sharer { |
| 606 | control.send(CallUpdate::ScreenShare(sharer)); |
| 607 | } |
| 608 | } |