大网数据广告活动
Web 标准与前端开发

RTCPeerConnection: restartIce() method

· 52CE 我爱测

The **`restartIce()`** method of the RTCPeerConnection interface allows a web application to 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 t

WebRTC

The restartIce() method of the RTCPeerConnection interface allows a web application to 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 RTCPeerConnection.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 RTCPeerConnection.negotiationneeded_event 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 RTCPeerConnection.signalingState changes to stable, the connection will fire the RTCPeerConnection.negotiationneeded_event event. This process continues until an ICE restart has been successfully completed.

Syntax

restartIce()

Parameters

None.

Return value

None (undefined).

Usage notes

After calling restartIce(), the next offer created using RTCPeerConnection.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 and .

Examples

This example creates a handler for the RTCPeerConnection.iceconnectionstatechange_event 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 RTCPeerConnection.negotiationneeded_event event to be fired, in response to which your code should renegotiate as usual. However, because you have called restartIce(), your call to RTCPeerConnection.createOffer which occurs in the handler for negotiationneeded will trigger an ICE restart rather than just a regular renegotiation.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。