The RTCPeerConnection.onconnectionstatechange
property specifies an event handler 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 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; } }
Specification |
---|
WebRTC 1.0: Real-Time Communication Between Browsers (WebRTC 1.0) # dom-rtcpeerconnection-onconnectionstatechange |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onconnectionstatechange |
72 |
79 |
No |
No |
No |
11 |
72 |
72 |
No |
No |
11 |
11.0 |
connectionstatechange
event and its type, Event
.
© 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/onconnectionstatechange