The RTCPeerConnection.onconnectionstatechange property specifies an EventHandler which is called to handle the connectionstatechange event when it occurs on an instance of RTCPeerConnection. This happens whenever the aggregate state of the connection changes. The aggregate state is a combination of the states of all of the individual network transports being used by the connection.


RTCPeerConnection.onconnectionstatechange = eventHandler;


A function which is called by the browser when the connectionstatechange event occurs on the RTCPeerConnection. The function receives as input a single parameter, which is an object of type Event. The event object contains no special information of note; you can look at the value of the peer connection's connectionState property to determine what the new state is.


pc.onconnectionstatechange = function(event) {
  switch(pc.connectionState) {
    case "connected":
      // The connection has become fully connected
    case "disconnected":
    case "failed":
      // One or more transports has terminated unexpectedly or in an error
    case "closed":
      // The connection has been closed


Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCPeerConnection.onconnectionstatechange' in that specification.
Candidate Recommendation Initial specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onconnectionstatechangeChrome Full support 72Edge Full support 79Firefox No support NoIE No support NoOpera No support NoSafari Full support 11WebView Android Full support 72Chrome Android Full support 72Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 11.0


Full support  
Full support
No support  
No support

See also