RTCPeerConnection.connectionState
connectionState 只读属性表示了当前所有被使用的 ICE 连接的状态,其返回值为以下字符串之一:new、connecting、connected、disconnected、failed 或 closed。
该状态本质上表示所有使用的 ICE 连接(类型为 RTCIceTransport (en-US) 或 RTCDtlsTransport (en-US))的聚合状态。
当属性值变化时,一个 connectionstatechange (en-US) 事件将被发送给 RTCPeerConnection 对象实例。
语法
js
var connectionState = RTCPeerConnection.connectionState;
返回值
一个用于表示当前连接状态的字符串,为以下列出的值之一:
new-
表示至少有一个 ICE 连接(
RTCIceTransport(en-US) 或RTCDtlsTransport(en-US) 对象)处于new状态,并且没有连接处于以下状态:connecting、checking、failed、disconnected,或者这些连接都处于closed状态。 connecting-
表示至少有一个 ICE 连接处于正在建立连接的状态;也就是说,它们的
iceConnectionState值为checking或connected,并且没有连接处于failed状态。 connected-
表示每一个 ICE 连接要么正在使用(
connected或completed状态),要么已被关闭(closed状态);并且,至少有一个连接处于connected或completed状态。 disconnected-
表示至少有一个 ICE 连接处于
disconnected状态,并且没有连接处于failed、connecting或checking状态。 failed-
表示至少有一个 ICE 连接处于
failed的状态。 closed-
表示
RTCPeerConnection已关闭。
示例
js
var pc = new RTCPeerConnection(configuration);
/* ... */
var connectionState = pc.connectionState;
规范
| Specification |
|---|
| WebRTC: Real-Time Communication in Browsers # dom-peerconnection-connection-state |
浏览器兼容性
BCD tables only load in the browser