stabilize connection on reconnect by terminating websocket only on timeout and not always when peer leaves its ip room

This commit is contained in:
schlagmichdoch 2023-06-01 01:26:53 +02:00
parent d36cd3524c
commit 3e2368c0c9

View file

@ -219,10 +219,15 @@ class PairDropServer {
} }
_onDisconnect(sender) { _onDisconnect(sender) {
this._disconnect(sender);
}
_disconnect(sender) {
this._leaveRoom(sender, 'ip', '', true); this._leaveRoom(sender, 'ip', '', true);
this._leaveAllSecretRooms(sender, true); this._leaveAllSecretRooms(sender, true);
this._removeRoomKey(sender.roomKey); this._removeRoomKey(sender.roomKey);
sender.roomKey = null; sender.roomKey = null;
sender.socket.terminate();
} }
_onRoomSecrets(sender, message) { _onRoomSecrets(sender, message) {
@ -357,10 +362,6 @@ class PairDropServer {
_joinRoom(peer, roomType = 'ip', roomSecret = '') { _joinRoom(peer, roomType = 'ip', roomSecret = '') {
const room = roomType === 'ip' ? peer.ip : roomSecret; const room = roomType === 'ip' ? peer.ip : roomSecret;
if (this._rooms[room] && this._rooms[room][peer.id]) {
this._leaveRoom(peer, roomType, roomSecret);
}
// if room doesn't exist, create it // if room doesn't exist, create it
if (!this._rooms[room]) { if (!this._rooms[room]) {
this._rooms[room] = {}; this._rooms[room] = {};
@ -385,10 +386,6 @@ class PairDropServer {
// delete the peer // delete the peer
delete this._rooms[room][peer.id]; delete this._rooms[room][peer.id];
if (roomType === 'ip') {
peer.socket.terminate();
}
//if room is empty, delete the room //if room is empty, delete the room
if (!Object.keys(this._rooms[room]).length) { if (!Object.keys(this._rooms[room]).length) {
delete this._rooms[room]; delete this._rooms[room];
@ -468,8 +465,7 @@ class PairDropServer {
peer.lastBeat = Date.now(); peer.lastBeat = Date.now();
} }
if (Date.now() - peer.lastBeat > 2 * timeout) { if (Date.now() - peer.lastBeat > 2 * timeout) {
this._leaveRoom(peer); this._disconnect(peer);
this._leaveAllSecretRooms(peer);
return; return;
} }