Monitoring events like icestatechange, connectionstatechange, and dtlsstatechange upon force quitting an application

I am building a project in React Native, where two users communicate via mediasoup. I am using socket.io to make a room to allow two people in the same room can talk to each other. If a user leaves the room by clicking a end-call button, the mediasoup server recognizes the dtlsstatechange. However, if a user leaves the room by forcefully quitting the app, the server does not recognize any change in the events.

Do you have any ideas why that is? And would there be a way for me to check if someone has “destroyed” the connection built using mediasoup?None of the events like icestatechange, connectionstatechange, and dtlsstatechange in the mediasoup server fire if someone force-quits the app.

You should detect a participant leaves via your signalling events (i.e. socket.io “close” or “disconnect” or however they are).

but shouldn’t a transport detect whether a participant has left or not since the connection would be lost? I even tried to use transport.observer events, but it still did not work.

No, mediasoup is ICE Lite server so it does not send ICE connectivity checks to endpoints. As a feature request we may fire ICE “disconnected” event if we stop receiving ICE connectivity checks from endpoints for X seconds, but that would not give you an instant “peer left” notification at all.

You must rely on your signalling, that’s what really tells you whether the user is “connected” or not. A different storey is its media connectivity status, which may even fail or disconnect while your peer is “connected” to your server app.

I waited about 2-3 minutes to see if any of those events fire, but did not see anything. Would that be because the connection to socket had already been disconnected once a user left?

Sorry, which events do you mean? I don’t know socket.io, I “just” assume it provides you with events when a WS disconnects. Not related to mediasoup anyway.

I meant events like icestatechange, connectionstatechange, dtlsstatechange. I feel like mediasoup should capture those events once socket connection is lost because losing a socket connection would result in change in icestate, connectionstate, and dtlsstate

No, you are wrong. If the client does not send any new packet (for example, a DTLS Close alert) mediasoup has no way to detect “connection closure”). Hope it’s clear now.

but it actually does detect dtlsstatechange sometimes, which is somewhat inconsistent. If mediasoup did not or could not detect the change all the time, I wouldn’t be asking this question.

Depending on how the device loses its connection to the socket server, sometimes mediasoup detects the changes, but sometimes it does not

I already explained it. If you abruptly close the client, it may happen (randomly) that the PeerConnection in the browser sends a DTLS Close alert (in that case the mediasoup transport will detect it and fire “dtlsstatechange” => “closed”) or it may happen that the PeerConnection has no time to send anything (in that case mediasoup will not receive any DTLS Close alert). And all this depends on client’s behaviour, not on mediasoup. So there is nothing inconsistent here. It’s just that you want to imagine a WebRTC over UDP connection as if it was a TCP connection in which both peers are sending keep alives, and it’s not like that.

1 Like