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);
Specification | Status | Comment |
---|---|---|
WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCConfiguration.iceServers' in that specification. | Candidate Recommendation | Initial definition. |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论