Transport `connectionstatechange` event mismatch
See original GitHub issueBug Report
Hi,
From the documentation, transport.on(“connectionstatechange”, fn(connectionState)
, emits RTCPeerConnectionState
. However, mediasoup-client internally listens and emits RTCIceConnectionState
.
Your environment
- Operating system: MacOS
- Browser version: Chrome 108
- npm version: 7.24
- mediasoup version: 3.11.3
- mediasoup-client version: 3.6.57
Issue description
The issue with this comes during disconnection. Suppose, you turn off the internet, connectionstatechange
goes from connected
-> disconnect
and there’s still a chance that the connection can go connected
again (there’s a 10-second window for the next retry). If the retry is unsuccessful, RTCPeerConnectionState
emits failed
event whereas RTCIceConnectionState
is still in disconnect
state so transport never emits the failed
event.
For ice restarts, I’m waiting for this failed
state, rather than disconnect
state because of the auto retry.
Now, since mediasoup-client only emits RTCIceConnectionState
on transport, I have to internally listen to this private state via transport.handler._pc.connectionState
to find out if the actual connection state and then do an ice restart.
This is mediasoup-client code related to this:
// Listens to RTCIceConnectionState and not RTCPeerConnectionState
this._pc.addEventListener('iceconnectionstatechange', () => {
switch (this._pc.iceConnectionState) {
case 'checking':
this.emit('@connectionstatechange', 'connecting');
break;
case 'connected':
case 'completed':
this.emit('@connectionstatechange', 'connected');
break;
case 'failed':
this.emit('@connectionstatechange', 'failed');
break;
case 'disconnected':
this.emit('@connectionstatechange', 'disconnected');
break;
case 'closed':
this.emit('@connectionstatechange', 'closed');
break;
}
});
Wanted to know if this is intentional. If so, then the documentation should reflect the actually used state. Having the transport emit the RTCPeerConnectionState
would be useful for the above case mentioned instead of listening on the RTCPeerConnection
object itself.
Issue Analytics
- State:
- Created 9 months ago
- Comments:12 (7 by maintainers)
Done in https://github.com/versatica/mediasoup-client/commit/3134822a5f314a315db977e4e834425bfae7698f and released in 3.6.67. Thanks.
I’ll think about this in next days. Thanks a lot.