@stoprocent/noble 1.17.2 → 1.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,9 @@ async function main () {
21
21
  }
22
22
 
23
23
  noble.on('discover', async (peripheral) => {
24
+ if (directConnect === '1') {
25
+ return;
26
+ }
24
27
  if ([peripheral.id, peripheral.address].includes(peripheralIdOrAddress)) {
25
28
  await noble.stopScanningAsync();
26
29
 
@@ -9,6 +9,7 @@ const Signaling = require('./signaling');
9
9
 
10
10
  const NobleBindings = function (options) {
11
11
  this._state = null;
12
+ this._isScanning = false;
12
13
 
13
14
  this._addresses = {};
14
15
  this._addresseTypes = {};
@@ -53,21 +54,27 @@ NobleBindings.prototype.stopScanning = function () {
53
54
 
54
55
  NobleBindings.prototype.connect = function (peripheralUuid, parameters = {}) {
55
56
  let address = this._addresses[peripheralUuid];
56
- let addressType = this._addresseTypes[peripheralUuid] || 'random'; // Default to 'random' if type is not defined
57
+ let addressType = this._addresseTypes[peripheralUuid] || 'random';
57
58
 
58
- // If address is not available, generate it from the UUID using the transformation logic inline
59
59
  if (!address) {
60
- address = peripheralUuid.match(/.{1,2}/g).join(':'); // Converts UUID back to MAC address format
61
- addressType = typeof(parameters) === 'object' && parameters.addressType ? parameters.addressType : 'random';
60
+ address = peripheralUuid.match(/.{1,2}/g).join(':');
61
+ addressType = parameters && parameters.addressType ? parameters.addressType : 'random';
62
62
  }
63
63
 
64
- // Manage connection attempts
65
- if (!this._pendingConnectionUuid) {
66
- this._pendingConnectionUuid = peripheralUuid;
67
- this._hci.createLeConn(address, addressType, parameters);
64
+ const createConnection = () => {
65
+ if (!this._pendingConnectionUuid) {
66
+ this._pendingConnectionUuid = peripheralUuid;
67
+ this._hci.createLeConn(address, addressType, parameters);
68
+ } else {
69
+ this._connectionQueue.push({ id: peripheralUuid, params: parameters });
70
+ }
71
+ };
72
+
73
+ if (this._isScanning) {
74
+ this.once('scanStop', createConnection);
75
+ this.stopScanning();
68
76
  } else {
69
- // If there is already a pending connection, queue this one
70
- this._connectionQueue.push({ id: peripheralUuid, params: parameters });
77
+ createConnection();
71
78
  }
72
79
  };
73
80
 
@@ -158,7 +165,7 @@ NobleBindings.prototype.onStateChange = function (state) {
158
165
  );
159
166
  console.log(' Try to run with environment variable:');
160
167
  console.log(' [sudo] NOBLE_HCI_DEVICE_ID=x node ...');
161
- }
168
+ }
162
169
 
163
170
  this.emit('stateChange', state);
164
171
  };
@@ -172,10 +179,12 @@ NobleBindings.prototype.onScanParametersSet = function () {
172
179
  };
173
180
 
174
181
  NobleBindings.prototype.onScanStart = function (filterDuplicates) {
182
+ this._isScanning = true;
175
183
  this.emit('scanStart', filterDuplicates);
176
184
  };
177
185
 
178
186
  NobleBindings.prototype.onScanStop = function () {
187
+ this._isScanning = false;
179
188
  this.emit('scanStop');
180
189
  };
181
190
 
@@ -276,13 +276,7 @@ Gap.prototype.parseServices = function (
276
276
  serviceUuids: [],
277
277
  solicitationServiceUuids: []
278
278
  };
279
-
280
- if (leMetaEventType !== LE_META_EVENT_TYPE_SCAN_RESPONSE) {
281
- // reset service data every non-scan response event
282
- advertisement.serviceUuids = [];
283
- advertisement.serviceSolicitationUuids = [];
284
- }
285
-
279
+
286
280
  while (i + 1 < eir.length) {
287
281
  const length = eir.readUInt8(i);
288
282
 
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "license": "MIT",
7
7
  "name": "@stoprocent/noble",
8
8
  "description": "A Node.js BLE (Bluetooth Low Energy) central library.",
9
- "version": "1.17.2",
9
+ "version": "1.17.4",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/stoprocent/noble.git"