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 用户代理 . 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
方法
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);
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCConfiguration.iceServers' in that specification. |
候选推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
iceServers
|
Chrome 23 | Edge ≤79 | Firefox ? | IE 不支持 No | Opera Yes | Safari ? | WebView Android Yes | Chrome Android 57 | Firefox Android ? | Opera Android Yes | Safari iOS ? | Samsung Internet Android 7.0 |
完整支持
不支持
兼容性未知