RTCPeerConnection.onicegatheringstatechange - Web APIs 编辑

Experimental

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The 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.

Syntax

RTCPeerConnection.onicegatheringstatechange = eventHandler;

Value

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

Example

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 presented as text in a <div> element:

<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;
}

Specifications

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

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:70 次

字数:4453

最后编辑:8年前

编辑次数:0 次

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