From 9e06faa5814c851bb93413bcb3faaa1ef600f0c4 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 21 Aug 2018 03:12:53 +0000 Subject: [PATCH] fix closing of device --- lib/device-tracker.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/device-tracker.js b/lib/device-tracker.js index 47e08fc..2958a49 100644 --- a/lib/device-tracker.js +++ b/lib/device-tracker.js @@ -18,6 +18,9 @@ Devices.add = function (store, servername, newDevice, isPort) { // add device // TODO only use a device id var devId = newDevice.id || servername; + if (!newDevice.__servername) { + newDevice.__servername = servername; + } if (!store._devices) { store._devices = {}; } if (!store._devices[devId]) { store._devices[devId] = newDevice; @@ -63,21 +66,17 @@ Devices.remove = function (store, servername, device) { return devices.splice(index, 1)[0]; }; Devices.close = function (store, device) { - var dev = store._devices[device.id]; - var id = device.id; + var dev = store._devices[device.id || device.__servername]; // because we're actually using names rather than don't have reliable deviceIds yet if (!dev) { - Object.keys(store._devices[device.id]).some(function (key) { + Object.keys(store._devices).some(function (key) { if (store._devices[key].socketId === device.socketId) { - id = key; + // TODO double check that all domains are removed delete store._devices[key]; return true; } }); } - - // TODO double check that all domains are removed - if (id) { delete store._devices[id]; } }; Devices.bySocket = function (store, socketId) { var dev;