Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ice trickle support on wasm #16

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions matchbox_socket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ wasm-bindgen = { version = "0.2", features = [ "serde-serialize" ], default-feat
js-sys = { version = "0.3", default-features = false }
web-sys = { version = "0.3.22", default-features = false, features = [
"MessageEvent",
"RtcPeerConnection",
"RtcPeerConnection", "RtcPeerConnectionIceEvent",
"RtcSdpType", "RtcSessionDescription", "RtcSessionDescriptionInit",
"RtcIceGatheringState",
"RtcConfiguration", "RtcDataChannel", "RtcDataChannelInit", "RtcDataChannelType",
"RtcIceCandidate", "RtcIceCandidateInit",
"RtcConfiguration",
"RtcDataChannel", "RtcDataChannelInit", "RtcDataChannelType", "RtcDataChannelEvent"
] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
20 changes: 19 additions & 1 deletion matchbox_socket/src/webrtc_socket/native/message_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,15 @@ impl CandidateTrickle {
peer_connection: &RTCPeerConnection,
candidate: RTCIceCandidate,
) {
let candidate = candidate.to_json().await.unwrap().candidate;
// Can't directly serialize/deserialize the candidate, as
// webrtc-rs' to_json uses snake_case and so isn't compatible
// with browsers
// let candidate = candidate.to_json().await.unwrap();
// let candidate = serde_json::to_string(&candidate).unwrap();

let candidate = candidate.to_json().await.unwrap();
assert_eq!(candidate.sdp_mline_index, 0); // we're assuming this on the other side
let candidate = candidate.candidate;

// Local candidates can only be sent after the remote description
if peer_connection.remote_description().await.is_some() {
Expand Down Expand Up @@ -185,9 +193,18 @@ impl CandidateTrickle {
match signal {
PeerSignal::IceCandidate(candidate) => {
debug!("got an IceCandidate signal! {}", candidate);
// Can't directly serialize/deserialize the candidate, as
// webrtc-rs' to_json uses snake_case and so isn't compatible
// with browsers
// let candidate = serde_json::from_str(&candidate).unwrap(); // todo: error handling
// peer_connection
// .add_ice_candidate(candidate)
// .await?;
// TODO: this looks like it's fixed in webrtc-rs 0.5
peer_connection
.add_ice_candidate(RTCIceCandidateInit {
candidate,
sdp_mline_index: 0,
..Default::default()
})
.await?;
Expand Down Expand Up @@ -410,6 +427,7 @@ async fn create_data_channel(
let config = RTCDataChannelInit {
ordered: Some(false),
max_retransmits: Some(0),
negotiated: Some(false),
id: Some(0),
..Default::default()
};
Expand Down
Loading