Web/API/RTCConfiguration/iceServers

From Get docs

The RTCConfiguration dictionary's iceServers property is an array of RTCIceServer objects, each of which describes a single STUN or TURN server to use for negotiation purposes.

Syntax

let rtcConfiguration = {
  iceServers: [ iceServer1... ]
};

let rtcConfiguration.iceServers = [ iceServer1... ];

Value

An array of zero or more RTCIceServer objects, each of which describes one STUN or TURN server for the ICE agent to use during the connection's negotiation. Each object must at least have an urls property, which is an array of one or more strings, each providing one server's URL.

If the array is empty, or if the iceServers option isn't specified, the ICE agent will negotiate without the use of any servers, which will limit the connection to local peers.

Description

How the list of servers you provide is used is up to the implementation of the user agent. While it can be useful to provide a second server as a fallback in case the first is offline, listing too many servers can delay the user's connection being established, depending on the network's performance and how many servers get used for negotiation before a connection is established.

If the list of servers is changed while a connection is already active by calling the the RTCPeerConnection method setConfiguration(), no immediate effect occurs. However, the new list of servers is used for any future renegotiation, such as while handling an ICE restart.

Examples

The configuration below opens a new peer connection, specifying two servers for the ICE agent to use for negotiation. The first one, stun:stun.services.mozilla.com, requires authentication, so the username and password are provided. The second server has two URLs: stun:stun.example.com and stun:stun-1.example.com.

var configuration = { iceServers: [{
                          urls: "stun:stun.services.mozilla.com",
                          username: "[email protected]", 
                          credential: "webrtcdemo"
                      }, {
                          urls: ["stun:stun.example.com", "stun:stun-1.example.com"]
                      }]
};

var pc = new RTCPeerConnection(configuration);

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between BrowsersThe definition of 'RTCConfiguration.iceServers' in that specification. Candidate Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
iceServers Chrome

Full support 23

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support Yes

Safari

?

WebView Android

Full support Yes

Chrome Android

Full support 57

Firefox Android

?

Opera Android

Full support Yes

Safari iOS

?

Samsung Internet Android

Full support 7.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown


See also