Reputation: 3358
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
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