I just did a test.
Having all streams connected and closing the browser tab.
RTCPeerConnection Stream A: Sending Video LQ track
RTCPeerConnection Stream B: Sending Video HQ track + Audio track
RTCPeerConnection Stream C+: Receiving tracks only
Stream A: I received MediaStateChanged "newState":"DISCONNECTED","oldState":"CONNECTED"
Stream B: I did not receive a MediaStateChanged to disconnected. I would of expected it to be consistent with Stream A.
Stream A: I received 3x ElementDisconnected for all 3 tracks (Data, Audio, Video)
Stream B: I received 3x ElementDisconnected for all 3 tracks (Data, Audio, Video)
Stream C+: I only received
MediaFlowInStateChange NOT_FLOWING for stream which were connected to some track.
I do not have any information that the stream C+ have been destroyed.
If I use the ServerManager and request the list of WebRtcEndpoint which still exist using the getPipelines, I can see that they do not exist so kurento is in a valid state and there no leak.
But I did not managed to get an event informing me that these WebRtcEndpoint pipelines were destroyed for the Stream C+.
That being said, we can detect that a user disconnected via the signaling server instead of via kurento (with timeout to allow time for reconnection).
Alternatively, we could also detect a user disconnecting if all of it's receiving stream MediaFlowInStateChange are of type NOT_FLOWING and all of the sending stream have all of it's track to ElementDisconnected.
Let me know if this behavior it's not consistent for you or if there a better way to detect a disconnect.