Closed ing-fabian closed 4 years ago
Hi @ing-fabian ,
Thanks for writing in with your issue. I apologize for the delayed response. There shouldn't be any difference in how you handle connection disruptions between 2.0.0 and the latest 2.x version. Can you share with me exactly how you were managing reconnections in 2.0.0 and how you are managing them in 2.5.1? Code snippets would be greatly helpful.
Thanks,
Manjesh Malavalli JSDK Team
Hi Manjesh,
We are doing the reconnecting process in the same way we were doing it, the only difference is that now when we try to reconnect we got a SignalingServerBusyError and the user is not able to reconnect.
Things we see have changed:
Before when the user was disconnected, Twilio triggered the event participantDisconnected. Now, instead of receiving this event, we receive a signalling server error. This happens when we try to emulated a disconnection which we are doing by stopping the normal execution of our application within DevTools in the browser.
Before after receiving the participantDisconnected event, we just clean all the resources and connect again. Now, if we do this, as I already mentioned, the connect function from Twilio returns a SignalingServerBusyError and it's not possible to reconnect from our site, the only way we found possible was refreshing the page.
Before during the retry we did not have any problem retrying the connection, now if we catch the signalling error and retry the connection we got into an infinite loop because the connect method return a signallingServerBusyError and the cycle never stop.
Below you can see a snippet, the snippet might be wrong as I just write it to show a basic example of what we are doing. I might had forget a comma or something :).
const sdkEvents = new EventEmitter();
sdkEvents.on('event', event => {
const { level, name } = event;
if (name === 'closed') {
reconnect();
}
});
function reconnect() {
const retries = 0;
const connectWithRetry = () => {
try{
connect(token, { ..., eventListener: sdkEvents }).then( room => {
room.on('participantDisconnected', (participant) => reconnect());
).catch(error){
retries++;
if(retries < 3) {
connectWithRetry();
}
}
} catch(e) {
retries++;
if(retries < 3) {
connectWithRetry();
} else {
console.log('Stop reconnecting');
}
}
};
connectWithRetry();
}
I hope this is more clear now.
Hi @ing-fabian ,
You should not be reconnecting on the participantDisconnected
event because this event means that somebody else left the Room. not you. Instead you should reconnect only on the disconnected
event like so:
room.on('disconnected', (room, error) => {
if (error) {
reconnect();
}
});
Getting a "closed" event on the EventListener does not necessarily mean that you got inadvertently disconnected. It may also be due to the user voluntarily leaving the Room. So I wouldn't recommend reconnecting there.
If you are getting the SignalingServerBusyError
, then you are creating too many connection requests too fast. So, I recommend that you add an exponential backoff mechanism to your retries. Also, with all 2.x SDKs, we will internally try to reconnect when there is a network disruption or handoff.
So, to sum up, reconnecting with an exponential backoff and reconnecting on disconnected
instead of participantDisconnected
should fix your issues.
Please let me know if this helps.
Thanks,
Manjesh Malavalli JSDK Team
Hi Manjesh,
Indeed, you are right the event that we are listen to do the reconnection is room.on('disconnected'), I just wrote the code from my main and made a mistake. Anyway, if I understood well, I just need to wait some time till I can actually create a new connection. I'll give it a try and come back to you. Thanks!
Hi Manjesh,
Thank you for your help, I'm closing this issue now. Applying a 500ms delay after getting a signalling error, now the reconnection process works as expected.
Code to reproduce the issue:
**Logs
Expected behavior:
We need a way of resetting the state and try to connect again the user, even if the signalling has failed. With the old version 2.0.0 we were catching the disconnected event and after that we basically clean the whole state of our app and retry the connection, for some of our users this is working. How can we do this with the new version?
Actual behavior:
With the version 2.0.0 we were able to get this events trigger when the user was disconnected or his signalling has any problem. Now, with the new version we are able to catch the error on the signalling using the eventListener but after that error is reported we can not connect again. Basically if this problem happens to our users, we are not able to reconnecting the user without refreshing the page.
Software versions: