RTCPeerConnection.connectionState
The read-only connectionState 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.
Syntax
var connectionState = RTCPeerConnection.connectionState;
Value
A string representing the current state of the connection, that is one of the following litterals:
new-
At least one of the connection's ICE transports (
RTCIceTransportorRTCDtlsTransportobjects) is in thenewstate, 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
iceConnectionStateis eithercheckingorconnected, 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 statefailed,connecting, orchecking. failed-
One or more of the ICE transports on the connection is in the
failedstate. closed-
The
RTCPeerConnectionis closed.
Example
var pc = new RTCPeerConnection(configuration); /* ... */ var connectionState = pc.connectionState;
Specifications
| Specification |
|---|
| WebRTC 1.0: Real-Time Communication Between Browsers (WebRTC 1.0) # dom-peerconnection-connection-state |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
connectionState |
72 |
79 |
No |
No |
60 |
11 |
72 |
72 |
No |
51 |
11 |
11.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState