RTCPeerConnection.connectionState
Baseline 2023Newly available
Since May 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
connectionState
只读属性表示了当前所有被使用的 ICE 连接的状态,其返回值为以下字符串之一:new
、connecting
、connected
、disconnected
、failed
或 closed
。
该状态本质上表示所有使用的 ICE 连接(类型为 RTCIceTransport
或 RTCDtlsTransport
)的聚合状态。
当属性值变化时,一个 connectionstatechange
事件将被发送给 RTCPeerConnection
对象实例。
语法
var connectionState = RTCPeerConnection.connectionState;
返回值
一个用于表示当前连接状态的字符串,为以下列出的值之一:
new
-
表示至少有一个 ICE 连接(
RTCIceTransport
或RTCDtlsTransport
对象)处于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
已关闭。
示例
var pc = new RTCPeerConnection(configuration);
/* ... */
var connectionState = pc.connectionState;
规范
Specification |
---|
WebRTC: Real-Time Communication in Browsers # dom-peerconnection-connection-state |