diff --git a/index.d.ts b/index.d.ts index 2d447f51..11c7fda0 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 b396e01f..e4bb5133 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; diff --git a/test/noble.test.js b/test/noble.test.js index 239f5b23..7de9261c 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', () => {