Commit 3ea93e43 authored by Donald Chen's avatar Donald Chen
Browse files

fix disconnectAll command

parent d5d3a4b3
......@@ -17,6 +17,7 @@ module.exports = function(RED) {
function NobleConnectNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.log("Created node "+node.id);
// Store local copies of the node configuration
......@@ -75,26 +76,38 @@ module.exports = function(RED) {
node.log("create peripheral "+p.uuid);
node.peripherals[p.uuid] = {};
}
node.peripherals[p.uuid].lastUpdated = new Date().getTime();
if (p.hasOwnProperty("once")) node.peripherals[p.uuid].once = p.once;
if (p.hasOwnProperty("rssi")) node.peripherals[p.uuid].rssi = p.rssi;
node.peripherals[p.uuid].peripheralObj = p;
if (p.hasOwnProperty("rssi")) {
node.peripherals[p.uuid].rssi = p.rssi;
}
if (p.hasOwnProperty("advertisement") && p.advertisement.hasOwnProperty("localName")) {
node.peripherals[p.uuid].name = p.advertisement.localName;
}
if (p.hasOwnProperty("connected")) node.peripherals[p.uuid].connected = p.connected;
if (p.hasOwnProperty("connected")) {
node.peripherals[p.uuid].connected = p.connected;
}
}
function disconnectAll() {
node.log("disconnect all");
var uuids = [];
for (var i=0; i<Object.keys(node.peripherals).length; i++) {
uuids.push(Object.keys(node.peripherals)[i]);
}
for (var j=0; j<uuids.length; j++) {
// try to be safe about this...
if (node.peripherals.hasOwnProperty(uuids[j]) && node.peripherals[uuids[j]].hasOwnProperty("once")) {
node.peripherals[uuids[j]].once('disconnect', () => { peripheralDisconnected(node.peripherals[uuids[j]]); });
}
var p = node.peripherals[uuids[j]].peripheralObj;
if(p && p.connected) {
p.disconnect();
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment