RTCIceServers.urls - Web APIs 编辑

Draft

This page is not complete.

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

Experimental

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The 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.

Syntax

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.

Examples

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.

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceServer.urls' in that specification.
Candidate RecommendationInitial specification.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:97 次

字数:6095

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文