question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transport `connectionstatechange` event mismatch

See original GitHub issue

Bug 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:closed
  • Created 9 months ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ibccommented, Dec 10, 2022
1reaction
ibccommented, Dec 7, 2022

I’ll think about this in next days. Thanks a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transport connection state changed to failed - Google Groups
mediasoup-client:Transport Transport connection state changed to failed +15s. The application gets the local media. Status top left shows 'Connected'.
Read more >
RTCPeerConnection: connectionstatechange event - Web APIs
The connectionstatechange event is sent to the onconnectionstatechange event handler on an RTCPeerConnection object after a new track has ...
Read more >
Aditya ezioda004 - GitHub
Transport connectionstatechange event mismatch. Bug Report Hi, From the documentation, transport.on(“connectionstatechange”, fn(connectionState) , emits ...
Read more >
19816 - Communication Agent Connection State Changed
Use Main Menu, and then Alarms & Events and examine the alarm log. This Event is a log of connection state change. ·...
Read more >
Transport connectionstate changes do disconnected
Hi Team, The client transport connectionstate goes to disconnected after few minutes randomly. It works perfectly for like 30 minutes then disconnects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found