(
channel: Arc<RTCDataChannel>,
source: AndroidWebRtcSource,
state: AppState,
udid: String,
stream_control_tx: mpsc::UnboundedSender<WebRtcStreamCommand>,
)
| 632 | } |
| 633 | |
| 634 | fn attach_android_data_channel( |
| 635 | channel: Arc<RTCDataChannel>, |
| 636 | source: AndroidWebRtcSource, |
| 637 | state: AppState, |
| 638 | udid: String, |
| 639 | stream_control_tx: mpsc::UnboundedSender<WebRtcStreamCommand>, |
| 640 | ) { |
| 641 | let (control_tx, control_rx) = mpsc::unbounded_channel::<ControlMessage>(); |
| 642 | task::spawn(run_android_webrtc_control_queue( |
| 643 | state.clone(), |
| 644 | udid.clone(), |
| 645 | control_rx, |
| 646 | )); |
| 647 | channel.on_message(Box::new(move |message: DataChannelMessage| { |
| 648 | let source = source.clone(); |
| 649 | let state = state.clone(); |
| 650 | let udid = udid.clone(); |
| 651 | let stream_control_tx = stream_control_tx.clone(); |
| 652 | let control_tx = control_tx.clone(); |
| 653 | Box::pin(async move { |
| 654 | let Ok(text) = std::str::from_utf8(&message.data) else { |
| 655 | warn!("Invalid Android WebRTC control message bytes for {udid}"); |
| 656 | return; |
| 657 | }; |
| 658 | if let Ok(message) = serde_json::from_str::<WebRtcDataChannelMessage>(text) { |
| 659 | match message { |
| 660 | WebRtcDataChannelMessage::ClientStats { stats } => { |
| 661 | if !stats.client_id.trim().is_empty() && !stats.kind.trim().is_empty() { |
| 662 | state.metrics.record_client_stream_stats(*stats); |
| 663 | } |
| 664 | } |
| 665 | WebRtcDataChannelMessage::StreamControl { |
| 666 | client_id: _, |
| 667 | force_keyframe, |
| 668 | foreground: _, |
| 669 | snapshot, |
| 670 | } => { |
| 671 | let command = WebRtcStreamCommand { |
| 672 | force_keyframe: force_keyframe.unwrap_or(false), |
| 673 | snapshot: snapshot.unwrap_or(false), |
| 674 | }; |
| 675 | if command.force_keyframe || command.snapshot { |
| 676 | source.request_keyframe(); |
| 677 | } |
| 678 | let _ = stream_control_tx.send(command); |
| 679 | } |
| 680 | WebRtcDataChannelMessage::StreamQuality { config } => { |
| 681 | match android_h264_quality_from_payload(Some(&config)) { |
| 682 | Ok(quality) => source.reconfigure_h264(quality), |
| 683 | Err(error) => { |
| 684 | warn!( |
| 685 | "Android WebRTC stream quality update failed for {udid}: {error}" |
| 686 | ); |
| 687 | source.request_keyframe(); |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | } |
no test coverage detected