From 61650273c7587f528478650ebf87393a3ca54695 Mon Sep 17 00:00:00 2001 From: majo-icutech Date: Tue, 26 Oct 2021 09:49:42 +0000 Subject: [PATCH] Handled disconnect reason to higher level --- lib/hci-socket/bindings.js | 2 +- lib/noble.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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!`); }