snapdrop

A Progressive Web App for local file sharing
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

commit 0731a21d685c35e45985a39e3df32549730953db
parent 61697d3abc5430ad58478b12a9b7fc36d8978881
Author: RobinLinus <robinlinus@users.noreply.github.com>
Date:   Fri, 21 Sep 2018 20:09:49 +0200

Cancel keep alive on join room

Diffstat:
Mserver/index.js | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/server/index.js b/server/index.js @@ -111,6 +111,7 @@ class SnapdropServer { _send(peer, message) { 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); @@ -119,17 +120,16 @@ class SnapdropServer { _keepAlive(peer) { var timeout = 10000; - // console.log(Date.now() - peer.lastBeat); + if (!peer.lastBeat) { + peer.lastBeat = Date.now(); + } if (Date.now() - peer.lastBeat > 2 * timeout) { this._leaveRoom(peer); return; } - if (this._wss.readyState == this._wss.OPEN) { - this._send(peer, { - type: 'ping' - }); - } + this._send(peer, { type: 'ping' }); + this._cancelKeepAlive(peer); peer.timerId = setTimeout(() => this._keepAlive(peer), timeout); } @@ -137,6 +137,7 @@ class SnapdropServer { _cancelKeepAlive(peer) { if (peer.timerId) { clearTimeout(peer.timerId); + peer.lastBeat = null; } } }