这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

RTCPeerConnection.onicegatheringstatechange property is an EventHandler which specifies a function to be called when the icegatheringstatechange event is sent to an RTCPeerConnection instance. This happens when the ICE gathering state—that is, whether or not the ICE agent is actively gathering candidates—changes.

You don't need to watch for this event unless you have specific reasons to want to closely monitor the state of ICE gathering.

句法

RTCPeerConnection.onicegatheringstatechange = eventHandler;
					

A function you provide which is passed a single parameter: an 事件 object containing the icegatheringstatechange event. You can determine the new state of ICE gathering by looking at the value of the RTCPeerConnection.iceGatheringState 特性。

范例

This example updates status information presented to the user to let them know what's happening by examining the current value of the iceGatheringState property each time it changes and changing the contents of a status display based on the new information.

The status is simply presented as text in a <div> 元素:

<div id="iceStatus"></div>
					

The actual event handler looks like this:

pc.onicegatheringstatechange = function() {
  let label = "Unknown";
  switch(pc.iceGatheringState) {
    case "new":
    case "complete":
      label = "Idle";
      break;
    case "gathering":
      label = "Determining route";
      break;
  }
  document.getElementById("iceStatus").innerHTML = label;
}
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.onicegatheringstatechange' in that specification.
候选推荐 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onicegatheringstatechange Chrome 59 Edge 15 Firefox 22 IE No Opera 43
43
Promise-based version.
不支持 37 — 43
Safari 11 WebView Android 59 Chrome Android 59 Firefox Android 44 Opera Android 43
43
Promise-based version.
不支持 37 — 43
Safari iOS Yes Samsung Internet Android 7.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: