Merge branch 'master' into commercial-next

This commit is contained in:
AJ ONeal 2018-08-21 03:13:05 +00:00
commit 2fc1ac7536
1 changed files with 6 additions and 7 deletions

View File

@ -18,6 +18,9 @@ Devices.add = function (store, servername, newDevice, isPort) {
// add device // add device
// TODO only use a device id // TODO only use a device id
var devId = newDevice.id || servername; var devId = newDevice.id || servername;
if (!newDevice.__servername) {
newDevice.__servername = servername;
}
if (!store._devices) { store._devices = {}; } if (!store._devices) { store._devices = {}; }
if (!store._devices[devId]) { if (!store._devices[devId]) {
store._devices[devId] = newDevice; store._devices[devId] = newDevice;
@ -63,21 +66,17 @@ Devices.remove = function (store, servername, device) {
return devices.splice(index, 1)[0]; return devices.splice(index, 1)[0];
}; };
Devices.close = function (store, device) { Devices.close = function (store, device) {
var dev = store._devices[device.id]; var dev = store._devices[device.id || device.__servername];
var id = device.id;
// because we're actually using names rather than don't have reliable deviceIds yet // because we're actually using names rather than don't have reliable deviceIds yet
if (!dev) { 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) { if (store._devices[key].socketId === device.socketId) {
id = key; // TODO double check that all domains are removed
delete store._devices[key]; delete store._devices[key];
return true; return true;
} }
}); });
} }
// TODO double check that all domains are removed
if (id) { delete store._devices[id]; }
}; };
Devices.bySocket = function (store, socketId) { Devices.bySocket = function (store, socketId) {
var dev; var dev;