RTCPeerConnection: connectionState property
WebRTC
WebRTC
The connectionState read-only property of the RTCPeerConnection interface indicates the current state of the peer connection by returning one of the following string values: new, connecting, connected, disconnected, failed, or closed.
This state essentially represents the aggregate state of all ICE transports (which are of type RTCIceTransport or RTCDtlsTransport) being used by the connection.
When this property's value changes, a connectionstatechange event is sent to the RTCPeerConnection instance.
Value
A string representing the current state of the connection. This can take on of the following values:
new- : At least one of the connection's ICE transports (RTCIceTransport or RTCDtlsTransport objects) is in the
newstate, and none of them are in one of the following states:connecting,checking,failed,disconnected, or all of the connection's transports are in theclosedstate. connecting- : One or more of the ICE transports are currently in the process of establishing a connection;
that is, their iceConnectionState is either
checkingorconnected, and no transports are in thefailedstate. connected- : Every ICE transport used by the connection is either in use (state
connectedorcompleted) or is closed (stateclosed); in addition, at least one transport is eitherconnectedorcompleted. disconnected- : At least one of the ICE transports for the connection is in the
disconnectedstate and none of the other transports are in the states:failed,connecting, orchecking. failed- : One or more of the ICE transports on the connection is in the
failedstate. closed- : The RTCPeerConnection is closed.
Example
const peerConnection = new RTCPeerConnection(configuration);
// …
const connectionState = peerConnection.connectionState;
Specifications
Browser compatibility
See also
- Lifetime of a WebRTC session
- RTCPeerConnection
- connectionstatechange
- RTCIceTransport.state
- WebRTC