From b23e8250ee5deca02ba446f469546b11947d2201 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau, M.Sc. (he/him)" Date: Tue, 19 Sep 2023 13:24:53 -0400 Subject: [PATCH] fix: error is not valid if ice candidate is null (#327) --- matchbox_socket/src/webrtc_socket/native.rs | 7 ++++++- matchbox_socket/src/webrtc_socket/wasm.rs | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/matchbox_socket/src/webrtc_socket/native.rs b/matchbox_socket/src/webrtc_socket/native.rs index 66bb1c2f..03ef604f 100644 --- a/matchbox_socket/src/webrtc_socket/native.rs +++ b/matchbox_socket/src/webrtc_socket/native.rs @@ -396,10 +396,15 @@ impl CandidateTrickle { debug!("received ice candidate: {candidate_json:?}"); match serde_json::from_str::(&candidate_json) { Ok(candidate_init) => { + debug!("ice candidate received: {}", candidate_init.candidate); peer_connection.add_ice_candidate(candidate_init).await?; } Err(err) => { - error!("failed to parse ice candidate json, ignoring: {err:?}"); + if *candidate_json == *"null" { + debug!("Received null ice candidate, this means there are no further ice candidates"); + } else { + warn!("failed to parse ice candidate json, ignoring: {err:?}"); + } } } } diff --git a/matchbox_socket/src/webrtc_socket/wasm.rs b/matchbox_socket/src/webrtc_socket/wasm.rs index d4f865a3..3d13722e 100644 --- a/matchbox_socket/src/webrtc_socket/wasm.rs +++ b/matchbox_socket/src/webrtc_socket/wasm.rs @@ -346,7 +346,6 @@ async fn complete_handshake( } msg = peer_signal_rx.next() => { if let Some(PeerSignal::IceCandidate(candidate)) = msg { - debug!("received ice candidate: {candidate:?}"); try_add_rtc_ice_candidate(&conn, &candidate).await; } } @@ -375,7 +374,7 @@ async fn try_add_rtc_ice_candidate(connection: &RtcPeerConnection, candidate_str let parsed_candidate = match js_sys::JSON::parse(candidate_string) { Ok(c) => c, Err(err) => { - error!("failed to parse candidate json: {err:?}"); + warn!("failed to parse ice candidate json, ignoring: {err:?}"); return; } }; @@ -384,7 +383,9 @@ async fn try_add_rtc_ice_candidate(connection: &RtcPeerConnection, candidate_str debug!("Received null ice candidate, this means there are no further ice candidates"); None } else { - Some(RtcIceCandidateInit::from(parsed_candidate)) + let candidate = RtcIceCandidateInit::from(parsed_candidate); + debug!("ice candidate received: {candidate:?}"); + Some(candidate) }; JsFuture::from(