From 537add3fd826858c8688d41ba147f1a9c3654cbb Mon Sep 17 00:00:00 2001 From: Matt Hemmings Date: Thu, 13 Sep 2018 17:52:07 +0000 Subject: [PATCH] Add socket ID to unregisterClient and cleanup --- tracker.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tracker.js b/tracker.js index 1b8da55..925df90 100644 --- a/tracker.js +++ b/tracker.js @@ -82,11 +82,17 @@ export default class L2LTracker extends L2LConnection { } removeDisconnectedClients() { - var ids = Array.from(this.clients.keys()), - toRemove = ids.filter(id => !this.getSocketForClientId(id)); - toRemove.forEach(id => this.clients.delete(id)); - if (toRemove.length) - console.log(`[l2l] ${this} removing disconnected clients ${ids.join(",")}`) + let ids = Array.from(this.clients.keys()); + let toRemove = ids.filter(id => !this.getSocketForClientId(id)); + toRemove = toRemove.map(id => { + let client = this.clients.get(id); + this.clients.delete(id); + return `${id} (${client ? client.socketId : ''})`; + }); + + if (toRemove.length) { + console.log(`[l2l] ${this} removing disconnected clients ${toRemove.join(',')}`); + } } open() { @@ -163,8 +169,9 @@ export default class L2LTracker extends L2LConnection { } unregisterClient(_, answerFn, socket) { - var clientId = this.getClientIdForSocketId(socket.id); - this.debug && console.log(`[l2l] ${this} got unregister request ${clientId}`); + let clientId = this.getClientIdForSocketId(socket.id); + let client = this.clients.get(clientId); + console.log(`[l2l] ${this} got unregister request ${clientId} (${client ? client.socketId : ''})`); this.clients.delete(clientId); typeof answerFn === "function" && answerFn(); }