diff --git a/lib/hci-socket/bindings.js b/lib/hci-socket/bindings.js index 40359623c..137a184a0 100644 --- a/lib/hci-socket/bindings.js +++ b/lib/hci-socket/bindings.js @@ -277,7 +277,7 @@ NobleBindings.prototype.onDisconnComplete = function (handle, reason) { delete this._handles[uuid]; delete this._handles[handle]; - this.emit('disconnect', uuid); // TODO: handle reason? + this.emit('disconnect', uuid, reason); } else { console.warn(`noble warning: unknown handle ${handle} disconnected!`); } diff --git a/lib/noble.js b/lib/noble.js index 436408dcc..5ea8171e9 100644 --- a/lib/noble.js +++ b/lib/noble.js @@ -237,12 +237,12 @@ Noble.prototype.disconnect = function (peripheralUuid) { this._bindings.disconnect(peripheralUuid); }; -Noble.prototype.onDisconnect = function (peripheralUuid) { +Noble.prototype.onDisconnect = function (peripheralUuid, reason) { const peripheral = this._peripherals[peripheralUuid]; if (peripheral) { peripheral.state = 'disconnected'; - peripheral.emit('disconnect'); + peripheral.emit('disconnect', reason); } else { this.emit('warning', `unknown peripheral ${peripheralUuid} disconnected!`); }