RTCConfiguration.iceServers - Web APIs 编辑

Value

BCD tables only load in the browser

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.

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

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

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.

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

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: "louis@mozilla.com",
                          credential: "webrtcdemo"
                      }, {
                          urls: ["stun:stun.example.com", "stun:stun-1.example.com"]
                      }]
};

var pc = new RTCPeerConnection(configuration);
SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCConfiguration.iceServers' in that specification.
Candidate RecommendationInitial definition.

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

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

发布评论

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

词条统计

浏览:127 次

字数:4232

最后编辑:7年前

编辑次数:0 次

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