From 0ede41f8d5397e8b7beb62ba6abe2571296f4690 Mon Sep 17 00:00:00 2001 From: RobinLinus Date: Fri, 21 Sep 2018 20:34:49 +0200 Subject: [PATCH] Cancel keep alive on join room --- server/index.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/index.js b/server/index.js index 17e6b07..f231651 100644 --- a/server/index.js +++ b/server/index.js @@ -56,9 +56,6 @@ class SnapdropServer { if (!this._rooms[peer.ip]) { this._rooms[peer.ip] = {}; } - if (this._rooms[peer.ip][peer.id]) { - this._cancelKeepAlive(this._rooms[peer.ip][peer.id]); - } // console.log(peer.id, ' joined the room', peer.ip); // notify all other peers @@ -87,7 +84,7 @@ class SnapdropServer { _leaveRoom(peer) { if (!this._rooms[peer.ip] || !this._rooms[peer.ip][peer.id]) return; - this._cancelKeepAlive(peer); + this._cancelKeepAlive(this._rooms[peer.ip][peer.id]); // delete the peer delete this._rooms[peer.ip][peer.id]; @@ -112,9 +109,7 @@ class SnapdropServer { if (!peer) return console.error('undefined peer'); if (this._wss.readyState !== this._wss.OPEN) return console.error('Socket is closed'); message = JSON.stringify(message); - peer.socket.send(message, error => { - if (error) this._leaveRoom(peer); - }); + peer.socket.send(message, error => console.log(error)); } _keepAlive(peer) { @@ -134,7 +129,7 @@ class SnapdropServer { } _cancelKeepAlive(peer) { - if (peer.timerId) { + if (peer && peer.timerId) { clearTimeout(peer.timerId); } }