diff --git a/README.md b/README.md index 96fd65c..759cff4 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,10 @@ $ npm run build will generate ES5 js files. # Revision History +* 4.0.1 + - Fix an issue where BLE termination cannot be performed while 'close' event + - Fix an issue where localName cannot be resumed + * 4.0.0 - Remove Node.js v0.12 support - Remove [BLECAST_TM](http://www.robotsfx.com/robot/BLECAST_TM.html) node and [BLECAST_BL](http://www.robotsfx.com/robot/BLECAST_BL.html) node diff --git a/lib/asakusa_giken.html b/lib/asakusa_giken.html index 0e1fefe..fa81d6f 100644 --- a/lib/asakusa_giken.html +++ b/lib/asakusa_giken.html @@ -85,14 +85,13 @@ localNames.splice(localNames.indexOf(c.localName), 1); } }); - $('#node-config-input-localName').append(option); - $('#node-config-input-localName').val(this.localName); for (i = 0; i < localNames.length; i++) { var localName = localNames[i]; var option = $('').attr('value', localName) .text(localName); $('#node-config-input-localName').append(option); } + $('#node-config-input-localName').val(this.localName); $('#node-config-input-address').blur(function() { var text = $(this).val(); if (text && typeof(text) === 'string') { diff --git a/package.json b/package.json index ff5d78f..88626a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-asakusa_giken", - "version": "4.0.0", + "version": "4.0.1", "description": "Node-RED nodes for Asakusa Giken Devices", "license": "MIT", "repository": { diff --git a/src/asakusa_giken.es6.js b/src/asakusa_giken.es6.js index 25115a2..31f4b91 100644 --- a/src/asakusa_giken.es6.js +++ b/src/asakusa_giken.es6.js @@ -29,9 +29,9 @@ export default function(RED) { } this.name = n.name; - this.on('close', () => { + this.on('close', (done) => { if (this.bleenvNode) { - bleenv.remove(this, RED); + bleenv.remove(this, done, RED); } }); bleenv.clear(RED); @@ -77,9 +77,9 @@ export default function(RED) { } this.name = n.name; - this.on('close', () => { + this.on('close', (done) => { if (this.bleioNode) { - bleio.remove(this, RED); + bleio.remove(this, done, RED); } }); bleio.clear(RED); @@ -103,9 +103,9 @@ export default function(RED) { } this.name = n.name; - this.on('close', () => { + this.on('close', (done) => { if (this.bleioNode) { - bleio.remove(this, RED); + bleio.remove(this, done, RED); } }); bleio.clear(RED); diff --git a/src/bleio.es6.js b/src/bleio.es6.js index 88f82a0..400fabc 100644 --- a/src/bleio.es6.js +++ b/src/bleio.es6.js @@ -491,20 +491,30 @@ function setupPeripheral(peripheral, RED) { peripheral.connect(); } }; + if (peripheral.removeHandler) { + peripheral.removeHandler(); + } peripheral.on('connect', connectHandler); peripheral.on('disconnect', disconnectHandler); - peripheral.terminate = () => { + peripheral.removeHandler = () => { + peripheral.removeListener('connect', connectHandler); + peripheral.removeListener('disconnect', disconnectHandler); + }; + peripheral.terminate = (done) => { if (CONN_DEBUG) { RED.log.info(`${TAG}[CONN_DEBUG] (terminate) start terminate!!`); } peripheral.instrumented = false; peripheral.terminated = true; - peripheral.removeListener('connect', connectHandler); - peripheral.removeListener('disconnect', disconnectHandler); + peripheral.removeHandler(); if (peripheral.state !== 'disconnected') { if (CONN_DEBUG) { RED.log.info(`${TAG}[CONN_DEBUG] (terminate) disconnect()`); } peripheral.disconnect((err) => { disconnectHandler(err); ble.stop(RED); + if (CONN_DEBUG) { RED.log.info(`${TAG}[CONN_DEBUG] (terminate) disconnect() done!`); } ble.start(RED); + if (done) { + done(); + } }); } }; @@ -617,7 +627,7 @@ export function register(node, RED) { if (CONN_DEBUG) { RED.log.info(`${TAG}[CONN_DEBUG] (register) end`); } } -export function remove(node, RED) { +export function remove(node, done, RED) { if (!node || !node.bleioNode) { throw new Error('invalid node'); } @@ -644,7 +654,7 @@ export function remove(node, RED) { delete periphNodes[address][node.id]; if (Object.keys(periphNodes[address]).length === 0) { if (CONN_DEBUG) { RED.log.info(`${TAG}[CONN_DEBUG] (remove) terminate()`); } - peripheral.terminate(); + peripheral.terminate(done); } else { if (CONN_DEBUG) { RED.log.info(`${TAG}[CONN_DEBUG] (remove) disconnect()`); } peripheral.disconnect(); // will re-connect