Kevin
Kevin

Reputation: 3358

Create web_sys::RtcPeerConnection with customized configuration

I am trying to figure how to create a RtcPeerConnection with the web-sys crate. In JavaScript I can write the following:

const pc = new RTCPeerConnection({'iceServers': [{'urls': ['stun:stun.l.google.com:19302']}]});

How does this translate to rust? I have tried the following:

let mut rtc = RtcConfiguration::new();
let config = RtcConfiguration::ice_servers(&mut rtc, &JsValue::from_serde(&json!({"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})).unwrap());
let pc = RtcPeerConnection::new_with_configuration(&config).unwrap();

But it fails when creating pc. The json! macro is from serde_json::json.

Upvotes: 0

Views: 188

Answers (1)

Kevin
Kevin

Reputation: 3358

For anyone with the same issue, the following works:

let mut rtc = RtcConfiguration::new();
let config = rtc.ice_servers(&JsValue::from_serde(&json!([{"urls": "stun:stun.l.google.com:19302"}])).unwrap());
let pc = RtcPeerConnection::new_with_configuration(&config).unwrap();

Upvotes: 0

Related Questions