草案
此页面不完整。

I'm experimenting with structure for pages documenting members of dictionaries. Please contact sheppy with any feedback.

这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

RTCIceServer dictionary's urls property specifies the URL or URLs of the servers to be used for ICE negotiations. These are typically STUN and/or TURN servers.

句法

var iceServer = {
                  urls = iceServerUrl | [ url1, ..., urlN ],
                  username: "webrtc", // optional
                  credential: "turnpassword" // optional
                };
iceServers.push(iceServer);
					

The value of this property may be specified as a single URL or as an array of multiple URLs.

范例

Let's look a few examples of varying complexity.

A single ICE server

This example creates a new RTCPeerConnection which will use a STUN server at stunserver.example.org to negotiate connections.

myPeerConnection = new RTCPeerConnection({
  iceServers: [
    {
      urls: "stun:stunserver.example.org"
    }
  ]
});
					

Notice that only the urls property is provided; the STUN server doesn't require authentication, so this is all that's needed.

A single ICE server with authentication

The second example creates a new RTCPeerConnection which will use a TURN server at turnserver.example.org to negotiate connections. Logging into the TURN server will use the username "webrtc" and the creative password "turnpassword".

myPeerConnection = new RTCPeerConnection({
  iceServers: [
    {
      urls: "turn:turnserver.example.org",
      username: "webrtc",
      credential: "turnpassword"
    }
  ]
});
					

A single ICE server with multiple URLs

The next example creates a new RTCPeerConnection which will use a single TURN server which has multiple URLs. This is useful if the server is, for example, available both on "turn" and "turns" schemes, or if there's a fallback address available for the server.

Keep in mind that ICE will try all the URLs you list here, so the more you include, the longer connections will take to establish.

myPeerConnection = new RTCPeerConnection({
  iceServers: [
    {
      urls: ["turns:turnserver.example.org", "turn:turnserver.example.org"],
      username: "webrtc",
      credential: "turnpassword"
    }
  ]
});
					

Multiple ICE servers

Finally, this example creates a new RTCPeerConnection which will use one of two servers for ICE negotiation. Each server can have one or more URLs, as demonstrated above.

myPeerConnection = new RTCPeerConnection({
  iceServers: [
    {
      urls: ["turns:turnserver.example.org", "turn:turnserver.example.org"],
      username: "webrtc",
      credential: "turnpassword"
    },
    {
      urls: "stun: stunserver.example.org"
    }
  ]
});
					

Two ICE servers are provided. One is a TURN server which can be accessed both over TURN and TURNS. The other is a STUN server. Any number of servers could be listed of any combination of types.

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceServer.urls' in that specification.
候选推荐 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
urls Chrome Yes Edge ≤79 Firefox 37 IE No Opera ? Safari ? WebView Android No Chrome Android Yes Firefox Android 37 Opera Android ? Safari iOS ? Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: