opentok / opentok-react

React components for OpenTok.js
https://www.npmjs.com/package/opentok-react
MIT License
107 stars 105 forks source link

sessionDisconnected, sessionReconnected, sessionReconnecting events not triggered on internet connection change #236

Closed vineus closed 1 year ago

vineus commented 1 year ago

Version used: "opentok-react": "0.11.0"

When I turn my internet connection off, I expect the sessionDisconnected to be triggered with a reason networkDisconnected according the doc

"networkDisconnected" — The network connection terminated abruptly (for example, the client lost its internet connection). Prior to dispatching a sessionDisconnected event for this reason, the Session object dispatches a reconnecting event, and the client attempts to reconnect to the OpenTok session. If the reconnection fails, the Session object dispatches a sessionDisconnected event with the reason property set to "networkDisconnected".

When I listen to the event from a session created with createSession:

const session = createSession({
        apiKey: apiKey,
        sessionId: sessionId,
        token: token
});
session.session.on("sessionDisconnected", (event) => console.log("disconnected!", event));

I can never see this event triggered when I change my wifi state from on to off (with a publisher stream created):

The opentok lib triggers lots of ERR_INTERNET_DISCONNECTED errors so it knows the connection is lost 😉

image

Is this something I'm doing wrong here ?

vineus commented 1 year ago

Answering my own question: sessionDisconnected is triggered after 40s. Before that, sessionReconnecting is triggered (and you can treat both as "disconnected", the main difference being that you need to reconnect the session manually when disconnected)

enricop89 commented 1 year ago

@vineus yes, the documentation is here: https://tokbox.com/developer/guides/connect-session/js/#automatic_reconnection