RTCPeerConnection.iceGatheringState

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

只读属性 RTCPeerConnection.iceGatheringState 返回一个描述连接的 ICE 收集状态的字符串。比如当 ICE 候选收集完成的时候,你可以通过该属性的变化侦测到。

通过监听 icegatheringstatechange 类型的事件,你可以侦测到该属性的变化。

可能的值是:

new

对等连接刚刚创建,尚未进行任何网络连接。

gathering

ICE 代理正在收集候选的连接。

complete

ICE 代理完成了候选的收集。如果发生了需要收集的新候选,例如一个新接口的增加或者一个新的 ICE 服务器的增加,状态将恢复到 gathering,并去收集这些候选。

示例

js
const pc = new RTCPeerConnection();
const state = pc.iceGatheringState;

规范

Specification
WebRTC: Real-Time Communication in Browsers
# dom-peerconnection-ice-gathering-state

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
iceGatheringState

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见