ant-media / Ant-Media-Server

Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
https://antmedia.io
Other
4.16k stars 618 forks source link

Stream stuck in conference room after network disconnection #6143

Open yashtandon113 opened 4 months ago

yashtandon113 commented 4 months ago

Short description

In conference room, the stream gets stuck if the internet disconnects and reconnect.

Environment

Steps to reproduce

  1. Join the conference room using the AMS conference sample web page (conference.html) with v2.8.2
  2. Disconnect the network suddenly on device, like switch off the wifi, etc
  3. Close the browser and join the room again or connect the internet back

Expected behavior

old stream should be removed from the room or in case the Internet is back, the stream should reconnect using the same stream ID.

Actual behavior

old stream is not removed from the room and stuck in application

flameop commented 4 months ago

I’m getting this as well. I have 2 streams in conference-multitrack.html. One is an iPad. When the iPad is switched from 5G>Wifi the subtrack is removed as expected and I get a ‘Track is removed with id...' callback. When the iPad is switched from WiFi>5G the stream remains in the room & there is no callback that I can use to manage the event. The stream has to be manually deleted from the web panel.

mustafaboleken commented 4 months ago

Hi flameop,

You can add following check into info callbacks to be able to listen if network change.

else if (info == "ice_connection_state_changed") {
                    console.log("iceConnectionState Changed: ", JSON.stringify(obj))
                    var iceState = obj.state;
                    if (iceState === "failed" || iceState === "disconnected" || iceState === "closed") {

                        setTimeout(() => {
                        if (webRTCAdaptor.iceConnectionState(publishStreamId) !== "checking" &&
                            webRTCAdaptor.iceConnectionState(publishStreamId) !== "connected" &&
                            webRTCAdaptor.iceConnectionState(publishStreamId) !== "completed") {
                            // the code enters here, it means that we lost our connection or our network changed
                        }
                        }, 5000);

                    }
                }
sidpram commented 3 months ago

The original issue reported was

  1. Join the conference room using the AMS conference sample web page with v2.8.2
  2. Disconnect the network suddenly on the device, like switching off the wifi, (and not switching the networks)
  3. Close the browser.
  4. The other participants still see the disconnected user.

Expected behavior: old stream should be removed from the room.

Actual behavior: old stream is not removed from the room and is stuck in the application. The stream has to be manually deleted from the web panel (ANT portal).

How is this "ice_connection_state_changed" going to help to remove the user for other participants? The user who faces the network disconnection closes the browser. There is no way to report back to ANT that I am disconnected.

mustafaboleken commented 3 months ago

Hi @sidpram ,

When I checked the scenario with my iPhone 15 and also Safari on MacBook with the latest snapshot, I didn't face any problem and because of the question is I didn't get any callback, I suggest using ice connection change as a notification.

As far as I understand from your message, there are some undeleted stream on the server side after the network change. Let me test it with 2.8.2 and see if I can reproduced it or not.

flameop commented 3 months ago

My solution was to use the audio level change message as a ‘heartbeat’ mechanism. I store the timestamp for every participant’s audio level message on an array. If they are disconnected their audio messages stop sending. If that participants last audio message is over 5sec old I remove them from the room & delete their stream from the server with a curl message.