From 91e0989c317b2427762d4d2e4c420cebf8270b5e Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Mon, 24 Jul 2023 23:28:04 +0200 Subject: [PATCH 1/2] Fix MTU for peripheral --- index.d.ts | 1 + lib/noble.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 2d447f513..11c7fda01 100644 --- a/index.d.ts +++ b/index.d.ts @@ -65,6 +65,7 @@ export declare class Peripheral extends events.EventEmitter { connectable: boolean; advertisement: Advertisement; rssi: number; + mtu: number | null; services: Service[]; state: 'error' | 'connecting' | 'connected' | 'disconnecting' | 'disconnected'; diff --git a/lib/noble.js b/lib/noble.js index b396e01f0..e4bb51335 100644 --- a/lib/noble.js +++ b/lib/noble.js @@ -587,7 +587,7 @@ Noble.prototype.onHandleNotify = function (peripheralUuid, handle, data) { Noble.prototype.onMtu = function (peripheralUuid, mtu) { const peripheral = this._peripherals[peripheralUuid]; - if (peripheral && peripheral.mtu && mtu) peripheral.mtu = mtu; + if (peripheral && mtu) peripheral.mtu = mtu; }; module.exports = Noble; From 8c535700fd0a9c28cd218dabf26ef65758be9f1c Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Wed, 26 Jul 2023 12:55:29 +0200 Subject: [PATCH 2/2] Adjusted test --- test/noble.test.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/noble.test.js b/test/noble.test.js index 239f5b23d..7de9261ce 100644 --- a/test/noble.test.js +++ b/test/noble.test.js @@ -1508,25 +1508,26 @@ describe('noble', () => { }); }); - it('onMtu - should update peripheral mtu', () => { + it('onMtu - should update peripheral mtu when set before already', () => { const peripheral = { - mtu: 'nan' + mtu: 234 }; noble._peripherals = { uuid: peripheral }; - noble.onMtu('uuid', 'mtu'); + noble.onMtu('uuid', 123); - should(peripheral).deepEqual({ mtu: 'mtu' }); + should(peripheral).deepEqual({ mtu: 123 }); }); - it('onMtu - should not update peripheral mtu', () => { + it('onMtu - should update peripheral mtu too when empty', () => { const peripheral = { + mtu: null }; noble._peripherals = { uuid: peripheral }; - noble.onMtu('uuid', 'mtu'); + noble.onMtu('uuid', 123); - should(peripheral).deepEqual({ }); + should(peripheral).deepEqual({ mtu: 123 }); }); describe('onIncludedServicesDiscover', () => {