Determining Peer-Connection States
The RTCPeerConnection interface provides two features that simplify working with peer-connection states: an onconnectionstatechange property for attaching a callback function, and a connectionState property for determining what state the connection is in. (Note the WebRTC connectionState differs from the signalingState that appeared as part of the the perfect-negotiation code in the last chapter).
You can define a handleRtcConnectionStateChange() callback function, right alongside the other peer-connection callbacks you’ve already written. To start, write a call to console.log to get a sense of how the connection state changes as a call is established. A local connection_state variable will make it easier ...
Get Programming WebRTC now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.