From 26bf4d6dc30d5314603cb45ab09894f43d48ac8e Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Thu, 1 Jun 2023 01:47:28 +0200 Subject: [PATCH] ensure that otherPeers never receive `peer-left` after `peer-joined` on reconnect by leaving room before rejoining it --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 2e5bdcb..029a955 100644 --- a/index.js +++ b/index.js @@ -362,6 +362,11 @@ class PairDropServer { _joinRoom(peer, roomType = 'ip', roomSecret = '') { const room = roomType === 'ip' ? peer.ip : roomSecret; + if (this._rooms[room] && this._rooms[room][peer.id]) { + // ensures that otherPeers never receive `peer-left` after `peer-joined` on reconnect. + this._leaveRoom(peer, roomType, roomSecret); + } + // if room doesn't exist, create it if (!this._rooms[room]) { this._rooms[room] = {};