How to detect disconnected WebRTCEndPoint ?

674 views
Skip to first unread message

piwpiw

unread,
Apr 30, 2021, 12:04:38 PM4/30/21
to kurento
Hello Community,

I'm trying to listen to the events when a WebRTCEndPoint is disconnected from the client side. For example when internet connection is lost or the user closes the browser tab.

So far on the WebRTCEndPoint, I have been listening to the following events : 

  • ElementDisconnected
  • DataChannelClose
  • IceComponentStateChange
When testing, my WebRTCEndPoint is created the Candidates are sent to Kurento, then either I refresh the page or I cut internet connection.

ElementDisconnected and DataChannelClose are never triggered. IceComponentStateChange is triggered but with only the following states : GATHERING, CONNECTING, CONNECTED, READY. No DISCONNECTED state.

Does anyone know how to detect a user disconnection ? 

Thanks
Cheers,

Israel Robotnick

unread,
Apr 30, 2021, 1:27:13 PM4/30/21
to kur...@googlegroups.com
You are listening to webrtc events, but webrtc extends media, and that's what u are looking for.

Check mediaflowin/out:


--
You received this message because you are subscribed to the Google Groups "kurento" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kurento+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kurento/ccfd2aeb-d349-4d83-a046-3948f5e093d3n%40googlegroups.com.

Youssef Mellouki

unread,
Apr 30, 2021, 7:01:00 PM4/30/21
to kur...@googlegroups.com
Thanks Man. Working perfect. 

You received this message because you are subscribed to a topic in the Google Groups "kurento" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kurento/aFFN1n6DtUA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kurento+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kurento/CACfXCSc2swf3s2H%2Be8midtRntkz5DraK7Vdn%2B4z5H%2BXA8_Lz2w%40mail.gmail.com.

Israel Robotnick

unread,
May 1, 2021, 4:01:12 PM5/1/21
to kur...@googlegroups.com

piwpiw

unread,
May 2, 2021, 3:30:06 PM5/2/21
to kurento
Hi Israel,

I implemented MediaFlowInStateChange and MediaFlowOutStateChange events on the WebRTCEndPoints. This works properly when internet connection stops. The events are fired correctly.

However if the end user destroys the WebRTCEndPoints after like closing his navigator or quitting the page, no event is fired. I'm handling also the event Error which is not fired neither in such scenario.

Do you know please how to detect the case the user has closed his navigator tab ?

Thanks.

Regards,

Pascal Tozzi

unread,
May 2, 2021, 4:42:33 PM5/2/21
to kurento
Have you tried https://doc-kurento.readthedocs.io/en/latest/features/events.html#mediastatechanged
I use it to detect when the rtcpeerconnection state switch to connected.
I do not use it to detect disconnected though, so I can't guarantee anything.

webRtcEndpoint.on('MediaStateChanged', event => {
    console.info(event.newState);
}

I am planning on investigating a similar issue also on our side, thus might have more information within the next few days.

Pascal Tozzi

unread,
May 2, 2021, 6:59:55 PM5/2/21
to kurento
I just did a test.
I've implemented all endpoint events from https://doc-kurento.readthedocs.io/en/latest/features/events.html#endpoint-events 

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.

Youssef Mellouki

unread,
May 2, 2021, 11:35:53 PM5/2/21
to kur...@googlegroups.com
Thanks Pascal for taking the time to look at that.

I have double checked and found out there was a problem with my implementation.

So conclusion : MediaStateChanged (Connected/Disconnected), MediaFlowOut/InStateChange (Flowing/Not_Flowing) all work like charm.

Thank you very much.

Regards,

Garanti sans virus. www.avg.com

Israel Robotnick

unread,
May 3, 2021, 12:09:45 PM5/3/21
to kur...@googlegroups.com
Im pretty sure im using only flowIN of webRTC Endpoint and it works.
Are you sure you listen correctly?
You probably also have a webSocket connection to the browser, you can use it as well to know when it's closed.



Reply all
Reply to author
Forward
0 new messages