I'm using WebRTC and realize it is not supported in all browsers. However, Chrome and Firefox do support it (in newer versions; I have the newest versions installed) as long as you have the correct prefix for certain variables. For instance, I have the following for PeerConnection for cross-browser support:
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
Now that it should be supported cross-browser, I have the following code:
var servers = {
iceservers: [
{url: "stun:23.21.150.121"},
{url: "stun:stun.1.google.com:19302"}
]
};
var pc = PeerConnection(servers);
But in Chrome it gets an error on the last line (var pc = PeerConnection(servers);
). The error is:
Failed to construct 'RTCPeerConnection': Malformed RTCConfiguration"}
Obviously, Chrome does not like my configuration parameter in the PeerConnection declaration. But my question is: why am I getting this error and how come only in Chrome? (FireFox works fine)
Well, the solution is actually quiet simple. The servers
object must be created with iceServers
in camel case. Also, you forgot your new
keyword when creating the connection but that is probably a typo in the question.
Like this:
var servers = {
iceServers: [
{url: "stun:23.21.150.121"},
{url: "stun:stun.1.google.com:19302"}
]
};
var pc = new PeerConnection(servers);
Both all lower case and camel case work just fine in FireFox. So, changing it should not change how it works there but it must be camel case for it to work in Chrome.
See Ben's answer. JavaScript is case-sensitive and 'iceServers' is the correct spelling from the mediacapture spec.
I wanted to clarify that all lower case 'iceservers' doesn't actually work in Firefox either, in that your STUN servers are being ignored. Firefox uses its default STUN server when it doesn't see one provided, so that's why it appears to work, but not using the STUN servers you think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With