Только для чтения свойство  connectionState интерфейса RTCPeerConnection указывает на текущее состояние соединения, возвращая одно из строковых значений, определяемых в перечислении RTCPeerConnectionState.

Когда значение свойство изменяется, возникает событие   connectionstatechange на объекте интерфейса RTCPeerConnection .


var connectionState = RTCPeerConnection.connectionState;


Текущий статус соединения представлен одним из значений перечисления  RTCPeerConnectionState.

RTCPeerConnectionState enum

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

Constant Description
"new" At least one of the connection's ICE transports (RTCIceTransports or RTCDtlsTransports) are in the "new" state, and none of them are in one of the following states: "connecting", "checking", "failed", or "disconnected", or all of the connection's transports are in the "closed" state.
"connecting" One or more of the ICE transports are currently in the process of establishing a connection; that is, their RTCIceConnectionState is either "checking" or "connected", and no transports are in the "failed" state. <<< 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", or "checking".
"failed" One or more of the ICE transports on the connection is in the "failed" state.

The 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
Определение 'RTCPeerConnection.connectionState' в этой спецификации.
Кандидат в рекомендации Initial specification.

Совместимость с браузерами

BCD tables only load in the browser

Смотрите также