Cancel keep alive on join room
This commit is contained in:
parent
1d9581632f
commit
0ede41f8d5
1 changed files with 3 additions and 8 deletions
|
@ -56,9 +56,6 @@ class SnapdropServer {
|
||||||
if (!this._rooms[peer.ip]) {
|
if (!this._rooms[peer.ip]) {
|
||||||
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);
|
// console.log(peer.id, ' joined the room', peer.ip);
|
||||||
// notify all other peers
|
// notify all other peers
|
||||||
|
@ -87,7 +84,7 @@ class SnapdropServer {
|
||||||
|
|
||||||
_leaveRoom(peer) {
|
_leaveRoom(peer) {
|
||||||
if (!this._rooms[peer.ip] || !this._rooms[peer.ip][peer.id]) return;
|
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 the peer
|
||||||
delete this._rooms[peer.ip][peer.id];
|
delete this._rooms[peer.ip][peer.id];
|
||||||
|
@ -112,9 +109,7 @@ class SnapdropServer {
|
||||||
if (!peer) return console.error('undefined peer');
|
if (!peer) return console.error('undefined peer');
|
||||||
if (this._wss.readyState !== this._wss.OPEN) return console.error('Socket is closed');
|
if (this._wss.readyState !== this._wss.OPEN) return console.error('Socket is closed');
|
||||||
message = JSON.stringify(message);
|
message = JSON.stringify(message);
|
||||||
peer.socket.send(message, error => {
|
peer.socket.send(message, error => console.log(error));
|
||||||
if (error) this._leaveRoom(peer);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_keepAlive(peer) {
|
_keepAlive(peer) {
|
||||||
|
@ -134,7 +129,7 @@ class SnapdropServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
_cancelKeepAlive(peer) {
|
_cancelKeepAlive(peer) {
|
||||||
if (peer.timerId) {
|
if (peer && peer.timerId) {
|
||||||
clearTimeout(peer.timerId);
|
clearTimeout(peer.timerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue