@stoprocent/noble
Advanced tools
@@ -12,2 +12,3 @@ const events = require('events'); | ||
this._state = null; | ||
this._isScanning = false; | ||
@@ -57,17 +58,23 @@ this._addresses = {}; | ||
let address = this._addresses[peripheralUuid]; | ||
let addressType = this._addresseTypes[peripheralUuid] || 'random'; // Default to 'random' if type is not defined | ||
let addressType = this._addresseTypes[peripheralUuid] || 'random'; | ||
// If address is not available, generate it from the UUID using the transformation logic inline | ||
if (!address) { | ||
address = peripheralUuid.match(/.{1,2}/g).join(':'); // Converts UUID back to MAC address format | ||
addressType = typeof(parameters) === 'object' && parameters.addressType ? parameters.addressType : 'random'; | ||
address = peripheralUuid.match(/.{1,2}/g).join(':'); | ||
addressType = parameters && parameters.addressType ? parameters.addressType : 'random'; | ||
} | ||
// Manage connection attempts | ||
if (!this._pendingConnectionUuid) { | ||
this._pendingConnectionUuid = peripheralUuid; | ||
this._hci.createLeConn(address, addressType, parameters); | ||
const createConnection = () => { | ||
if (!this._pendingConnectionUuid) { | ||
this._pendingConnectionUuid = peripheralUuid; | ||
this._hci.createLeConn(address, addressType, parameters); | ||
} else { | ||
this._connectionQueue.push({ id: peripheralUuid, params: parameters }); | ||
} | ||
}; | ||
if (this._isScanning) { | ||
this.once('scanStop', createConnection); | ||
this.stopScanning(); | ||
} else { | ||
// If there is already a pending connection, queue this one | ||
this._connectionQueue.push({ id: peripheralUuid, params: parameters }); | ||
createConnection(); | ||
} | ||
@@ -163,3 +170,3 @@ }; | ||
console.log(' [sudo] NOBLE_HCI_DEVICE_ID=x node ...'); | ||
} | ||
} | ||
@@ -178,2 +185,3 @@ this.emit('stateChange', state); | ||
NobleBindings.prototype.onScanStart = function (filterDuplicates) { | ||
this._isScanning = true; | ||
this.emit('scanStart', filterDuplicates); | ||
@@ -183,2 +191,3 @@ }; | ||
NobleBindings.prototype.onScanStop = function () { | ||
this._isScanning = false; | ||
this.emit('scanStop'); | ||
@@ -185,0 +194,0 @@ }; |
@@ -279,9 +279,3 @@ const debug = require('debug')('gap'); | ||
}; | ||
if (leMetaEventType !== LE_META_EVENT_TYPE_SCAN_RESPONSE) { | ||
// reset service data every non-scan response event | ||
advertisement.serviceUuids = []; | ||
advertisement.serviceSolicitationUuids = []; | ||
} | ||
while (i + 1 < eir.length) { | ||
@@ -288,0 +282,0 @@ const length = eir.readUInt8(i); |
@@ -9,3 +9,3 @@ { | ||
"description": "A Node.js BLE (Bluetooth Low Energy) central library.", | ||
"version": "1.17.3", | ||
"version": "1.17.4", | ||
"repository": { | ||
@@ -12,0 +12,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18061
0.02%2328265
-0.01%