RTCPeerConnection.restartIce() - Web APIs 编辑

The WebRTC API's RTCPeerConnection interface offers the restartIce() method to allow a web application to easily request that ICE candidate gathering be redone on both ends of the connection. This simplifies the process by allowing the same method to be used by either the caller or the receiver to trigger an ICE restart.

After restartIce() returns, the offer returned by the next call to createOffer() is automatically configured to trigger ICE restart on both the local peer (once the local peer has been set) and on the remote peer, once the offer is sent across your signaling mechanism and the remote peer has set its description as well.

restartIce() causes the negotiationneeded event to be fired on the RTCPeerConnection to inform the application that it should perform negotiation using its signaling channel.

If negotiation fails to complete—either due to rollback or because incoming offers are in the process of being negotiated—the RTCPeerConnection will remember that you requested ICE restart. The next time the connection's signalingState changes to stable, the connection will fire the negotiationneeded event. This process continues until an ICE restart has been successfully completed.

Syntax

rtcPeerConnection.restartIce();

Parameters

None.

Return value

undefined.

Usage notes

After calling restartIce(), the next offer created using createOffer() will initiate ICE restart once sent to the remote peer over your signaling mechanism. Restarting ICE essentially resets ICE so that it creates all new candidates using new credentials. Existing media transmissions continue uninterrupted during this process.

For details about how ICE restart works, see ICE restart in Lifetime of a WebRTC session and RFC 5245, section 9.1.1.1: ICE specification.

Example

This example creates a handler for the iceconnectionstatechange event that handles a transition to the failed state by restarting ICE in order to try again.

pc.addEventListener("iceconnectionstatechange", event => {
  if (pc.iceConnectionState === "failed") {
    /* possibly reconfigure the connection in some way here */
    /* then request ICE restart */
    pc.restartIce();
  }
});

With this code in place, a transition to the failed state during ICE negotiation will cause a negotiationneeded event to be fired, in response to which your code should renegotiate as usual. However, because you have called restartIce(), your call to createOffer() which occurs in the handler for negotiationneeded will trigger an ICE restart rather than just a regular renegotiation.

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.restartIce()' in that specification.
Candidate RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:58 次

字数:5683

最后编辑:7年前

编辑次数:0 次

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