RTCIceServer - Web APIs 编辑

The RTCIceServer dictionary defines how to connect to a single ICE server (such as a STUN or TURN server). Objects of this type are provided in the configuration of an RTCPeerConnection, in the iceServers array.

Properties

credential Optional
The credential to use when logging into the server. This is only used if the RTCIceServer represents a TURN server.
credentialType Optional
If the RTCIceServer represents a TURN server, this attribute specifies what kind of credential is to be used when connecting. This must be one of the values defined by the RTCIceCredentialType enum. The default is password.
urls
This required property is either a single DOMString or an array of DOMStrings, each specifying a URL which can be used to connect to the server.
username Optional
If the RTCIceServer is a TURN server, then this is the username to use during the authentication process.

Avoid specifying an unnecessarily large number of URLs in the urls property; the startup time for your connection will go up substantially. Every server in the list will be contacted and tried out before one is selected to be used for negotiation.

Older versions of the WebRTC specification included an url property instead of urls; this was changed in order to let you specify multiple addresses for each server in the list, as shown in the example below.

Obsolete properties

The following properties have been removed from the specification and should not be used.

url This is an obsolete API and is no longer guaranteed to work.
This obsolete property is a string specifies a single ICE server's URL. Do not use this property; use urls instead. Because many older books and examples still use this, we include it to help developers update their code or make sense of older examples.

Example

The configuration below establishes two ICE servers. 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);

Once the configuration object has been created, it is passed into the RTCPeerConnection() constructor to use it as the configuration for the new peer connection.

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:79 次

字数:5995

最后编辑:7 年前

编辑次数:0 次

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