只读 connectionState 特性为 RTCPeerConnection interface indicates the current state of the peer connection by returning one of the string values specified by the enum RTCPeerConnectionState .

When this property's value changes, a connectionstatechange event is sent to the RTCPeerConnection 实例。

句法

var connectionState = RTCPeerConnection.connectionState;
					

The current state of the connection, as a value from the enum RTCPeerConnectionState .

RTCPeerConnectionState enum

RTCPeerConnectionState enum defines string constants which describe states in which the RTCPeerConnection may be. These values are returned by the connectionState property. This state essentially represents the aggregate state of all ICE transports (which are of type RTCIceTransport or RTCDtlsTransport ) being used by the connection.

常量 描述
"new" At least one of the connection's ICE transports ( RTCIceTransport s or RTCDtlsTransport s) are in the "new" state, and none of them are in one of the following states: "connecting" , "checking" , "failed" ,或 "disconnected" , or all of the connection's transports are in the "closed" 状态。
"connecting" One or more of the ICE transports are currently in the process of establishing a connection; that is, their RTCIceConnectionState "checking" or "connected" , and no transports are in the "failed" 状态。 <<< Make this a link once I know where that will be documented
"connected" Every ICE transport used by the connection is either in use (state "connected" or "completed" ) or is closed (state "closed" ); in addition, at least one transport is either "connected" or "completed" .
"disconnected" At least one of the ICE transports for the connection is in the "disconnected" state and none of the other transports are in the state "failed" , "connecting" ,或 "checking" .
"failed" One or more of the ICE transports on the connection is in the "failed" 状态。
"closed" RTCPeerConnection is closed.

This value was in the RTCSignalingState enum (and therefore found by reading the value of the signalingState ) property until the May 13, 2016 draft of the specification.

范例

var pc = new RTCPeerConnection(configuration);
/* ... */
var connectionState = pc.connectionState;
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.connectionState' 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
connectionState Chrome 72 Edge 79 Firefox No IE No Opera No Safari 11 WebView Android 72 Chrome Android 72 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 11.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: