A socket disconnection could occur due to various reasons (Eg: a network disconnection). To overcome this we would recommend reconnecting on a disconnection event.
You can refer to the below sample code to try to rejoin a room on a socket disconnect.
var isChannelOpen = true;
var interval;
function tryJoiningRoom() {
if (!isChannelOpen) {
SkylinkDemo.joinRoom({ // Replace with your preferred constraints
audio: true,
video: true
});
} else {
clearInterval(interval); // Channel is open. So we clear the interval
}
};
SkylinkDemo.on('sessionDisconnect', function(sid, peerInfo) { // This event is fired when the socket connection closes abruptly
isChannelOpen = false;
interval = setInterval(tryJoiningRoom, 2000); // We try to rejoin the room every 2 seconds until socket channel is opened.
});
SkylinkDemo.on('channelOpen', function() { // This event is fired when the socket connection is opened
isChannelOpen = true;
});