The onsignalingstatechange event handler property of the RTCPeerConnection interface specifies a function to be called when the signalingstatechange event occurs on an RTCPeerConnection interface. The function receives as input the event object of type Event; this event is sent when the peer connection's signalingState changes, which may happen either because of a call to setLocalDescription() or to setRemoteDescription().
Syntax
rtcPeerConnection.onsignalingstatechange = errorHandler;
Value
Set this to a function which you provide that receives an Event object as input; this contains the signalingstatechange event. This event object doesn't provide details about what changed, but you can examine the signalingState property to determine what the new state is.
You may also, as always, set up a handler for the signalingstatechange event using addEventListener():
myRTCPeerConnection.addEventListener("signalingstatechange", mySignalingStateChangeHandler);
Or, using an anonymous (inline) handler:
myRTCPeerConnection.addEventListener("signalingstatechange", event => {
/* handle the event here */
});
Example
This snippet shows a handler for signalingstatechange that looks for the "have-local-pranswer" signaling state—indicating that a remote offer has been received and a local description of type "pranswer" has been applied in response.
pc.onsignalingstatechange = function(event) {
if (pc.signalingState === "have-local-pranswer") {
// setLocalDescription() has been called with an answer
}
};
Specifications
| Specification | Status | Comment |
|---|---|---|
| WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCPeerConnection.onsignalingstatechange' in that specification. |
Candidate Recommendation | Initial specification. |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
onsignalingstatechange | Chrome Full support 28 | Edge Full support 15 | Firefox Full support 22 | IE No support No | Opera
Full support
43
| Safari Full support 11 | WebView Android Full support Yes | Chrome Android Full support 28 | Firefox Android Full support 44 | Opera Android
Full support
43
| Safari iOS Full support Yes | Samsung Internet Android Full support 6.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.
See also
- Signaling and video calling: A WebRTC example
- The
signalingstatechangeevent and its type,Event.
