RTCPeerConnection.onconnectionstatechange

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

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.

Syntax

RTCPeerConnection.onconnectionstatechange = eventHandler;

Value

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.

Example

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

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browser
The definition of 'RTCPeerConnection.onconnectionstatechange' in that specification.
Working Draft Initial specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) No support [1] No support (Yes) ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? No support [1] No support ? ?

[1] See bug 1265827 to track the status of implementing this event and the RTCPeerConnection.connectionState property.

See also

Document Tags and Contributors

 Contributors to this page: Sheppy
 Last updated by: Sheppy,