Skip to content

Commit

Permalink
fix: error is not valid if ice candidate is null (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau authored Sep 19, 2023
1 parent 6db5f5a commit b23e825
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion matchbox_socket/src/webrtc_socket/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,15 @@ impl CandidateTrickle {
debug!("received ice candidate: {candidate_json:?}");
match serde_json::from_str::<RTCIceCandidateInit>(&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:?}");
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions matchbox_socket/src/webrtc_socket/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
};
Expand All @@ -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(
Expand Down

0 comments on commit b23e825

Please sign in to comment.