Transport connectionstate never changes to 'failed', stuck on 'disconnected'

Here’s an example:

            transport.appData.idletimer = setTimeout(async (wss, room, handle) => {
                console.log("User had disconnected before transport connected. Alert them to request again.");
                if (Transports.has(room)) {
                    Transports.get(room).delete(handle);
                    if (Transports.get(room).size == 0) Transports.delete(room);
                }
                await transport.close();
                wss.send(JSON.stringify({
                    "chat": "publish",
                    "type": "closed",
                    "room": room,
                    "handle": handle
                }));
            }, 10000, WSS, transport.appData.room, transport.appData.handle);
        
            transport.on("dtlsstatechange", (dtlsState) => {
                if (dtlsState == "connected") {
                    clearTimeout(transport.appData.idletimer);  
                    WSS.send(JSON.stringify({
                        "chat": "publish",
                        "type": "connected",
                        "room": transport.appData.room,
                        "handle": transport.appData.handle
                    }));
                }
            });      
            Transports.get(Received.room).set(Received.handle, {
                "transport": transport
            });

Media server does not need to monitor for anything more than connected on the transports to ensure no issues, if the timeout goes off we throw an error to have user decide what to do from there (or code automatic handling).

With state reaching connected we can tell the user they’re connected and start monitoring the transport for disconnected/connected states on the client side. Something like this.

           Transport.on("connectionstatechange", async (connectionState) => {
                    switch (connectionState) {
                        case "connected":
                            // Break that delayed mechanism we're connected again woo!
                            break;
                        case "disconnected":
                           // Create a delayed mechanism to repeatedly send Ice if no connection was made
                            break;
                    }
                });

When we reach disconnected and there wasn’t a request to close transport (publish/subscribe). We can schedule to send ice out momentarily if self-recovery does not work. I generally repeat request every 10 seconds and when we hit connected I stop destroy any timeouts/etc.


With that all said, you need to be careful with states. A bit confusing but imagine you listened for disconnected at media server level on the transport. What if user left room, or closed broadcast, what if they didn’t do any of those two things and are just lagging really hard. In these cases chat server would have gotten prompt of an action or the user is lagging they’ll be with us in a moment unless they get kicked out the chat server then completely destroy their session.