RTC Ice_servers configuration on web_sys

With javascript we pass into PeerConnection an Js Object that does the job of listing our servers and credentials as well... like this:
var configuration = { iceServers: [{ urls: "stun:stun.services.mozilla.com", username: "louis@mozilla.com", credential: "webrtcdemo" }, { urls: [ "stun:stun.example.com", "stun:stun-1.example.com" ] }] };

A online example for better understanding: RTCIceServer - Web APIs | MDN

But how we do it with web_sys::RtcConfiguration::ice_servers?

Link to function docs: RtcConfiguration in web_sys - Rust ?

I'm Trying this way:
`
let mut rtc = web_sys::RtcConfiguration::new();

let config = web_sys::RtcConfiguration::ice_servers(
    &mut rtc,
    &r#"{ iceServers: [{
        urls: "stun:stun.services.mozilla.com",
        username: "louis@mozilla.com", 
        credential: "webrtcdemo"
    }, {
        urls: [
                "stun:stun.example.com",
                "stun:stun-1.example.com"
        ]
    }]

};"#.into(),
);
let pc2 = RtcPeerConnection::new_with_configuration(&config)?;
`
It compiles but on my web-browser console it returns:

JsValue(TypeError: Failed to construct 'RTCPeerConnection': The provided value cannot be converted to a sequence. TypeError: Failed to construct 'RTCPeerConnection': The provided value cannot be converted to a sequence. at new WrappedRTCPeerConnection (<anonymous>:275:28) at Module.eval (webpack:///./pkg/index_bg.js?:381:15) at Module.eval (webpack:///./pkg/index_bg.js?:309:22) at __wbg_newwithconfiguration_049486145e56aba2 (http://localhost:8081/index.js:98:115) at web_sys::features::gen_RtcPeerConnection::RtcPeerConnection::new_with_configuration::hc078b64217307571 (http://localhost:8081/5ba58cfd45492289eaff.module.wasm:wasm-function[132]:0xf5a5)

I also tryed using js_sys::Object first to parse js_sys::JsString into a native JsObject but didn't work either.

up? :frowning:

I think "string".into() will give you just a JavaScript String, not an Object.

I haven't used that crate, but I see in the docs there's from_serde, which might allow you to construct a JsValue that is more complex than a primitive type.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.