MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / attach_android_data_channel

Function attach_android_data_channel

packages/server/src/transport/webrtc.rs:634–707  ·  view source on GitHub ↗
(
    channel: Arc<RTCDataChannel>,
    source: AndroidWebRtcSource,
    state: AppState,
    udid: String,
    stream_control_tx: mpsc::UnboundedSender<WebRtcStreamCommand>,
)

Source from the content-addressed store, hash-verified

632}
633
634fn 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 }

Callers 1

Calls 8

is_emptyMethod · 0.80
reconfigure_h264Method · 0.80
cloneMethod · 0.65
sendMethod · 0.65
request_keyframeMethod · 0.45

Tested by

no test coverage detected