@stoprocent/noble 1.10.2 → 1.11.0

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.
Files changed (45) hide show
  1. package/.github/workflows/fediverse-action.yml +16 -0
  2. package/.github/workflows/nodepackage.yml +6 -15
  3. package/.github/workflows/npm-publish.yml +2 -2
  4. package/.github/workflows/prebuild.yml +65 -0
  5. package/README.md +11 -3
  6. package/examples/advertisement-discovery.js +1 -1
  7. package/examples/cache-gatt-discovery.js +1 -1
  8. package/examples/cache-gatt-reconnect.js +1 -1
  9. package/examples/echo.js +1 -1
  10. package/examples/enter-exit.js +2 -2
  11. package/examples/ext-advertisement-discovery.js +65 -0
  12. package/examples/peripheral-explorer-async.js +1 -1
  13. package/examples/peripheral-explorer.js +1 -1
  14. package/examples/pizza/central.js +1 -1
  15. package/index.d.ts +187 -194
  16. package/index.js +1 -6
  17. package/lib/distributed/bindings.js +33 -33
  18. package/lib/hci-socket/bindings.js +1 -3
  19. package/lib/hci-socket/crypto.js +4 -4
  20. package/lib/hci-socket/gap.js +22 -18
  21. package/lib/hci-socket/gatt.js +4 -4
  22. package/lib/hci-socket/hci.js +2 -2
  23. package/lib/noble.js +10 -6
  24. package/lib/peripheral.js +0 -7
  25. package/lib/resolve-bindings.js +39 -3
  26. package/lib/webbluetooth/bindings.js +2 -2
  27. package/lib/websocket/bindings.js +32 -32
  28. package/lib/win/src/ble_manager.cc +4 -1
  29. package/lib/win/src/ble_manager.h +1 -1
  30. package/lib/win/src/peripheral_winrt.cc +2 -0
  31. package/lib/win/src/radio_watcher.cc +1 -0
  32. package/lib/win/src/winrt_cpp.cc +1 -0
  33. package/package.json +28 -24
  34. package/test/lib/distributed/bindings.test.js +15 -15
  35. package/test/lib/hci-socket/gap.test.js +39 -0
  36. package/test/lib/webbluetooth/bindings.test.js +2 -2
  37. package/test/lib/websocket/bindings.test.js +2 -2
  38. package/test/mocha.setup.js +0 -0
  39. package/test/noble.test.js +12 -11
  40. package/test.custom.js +131 -0
  41. package/test.js +1 -1
  42. package/with-custom-binding.js +6 -0
  43. package/ws-slave.js +10 -10
  44. package/lib/manufacture.js +0 -48
  45. package/test/lib/manufacture.test.js +0 -77
@@ -199,9 +199,9 @@ Gatt.prototype.errorResponse = function (opcode, handle, status) {
199
199
 
200
200
  Gatt.prototype._queueCommand = function (buffer, callback, writeCallback) {
201
201
  this._commandQueue.push({
202
- buffer: buffer,
203
- callback: callback,
204
- writeCallback: writeCallback
202
+ buffer,
203
+ callback,
204
+ writeCallback
205
205
  });
206
206
 
207
207
  if (this._currentCommand === null) {
@@ -375,7 +375,7 @@ Gatt.prototype.discoverServices = function (uuids) {
375
375
  }
376
376
  }
377
377
 
378
- if ((opcode !== ATT_OP_READ_BY_GROUP_RESP && opcode !== ATT_OP_ERROR) || services[services.length - 1].endHandle === 0xffff) {
378
+ if (opcode !== ATT_OP_READ_BY_GROUP_RESP || services[services.length - 1].endHandle === 0xffff) {
379
379
  const serviceUuids = [];
380
380
  for (i = 0; i < services.length; i++) {
381
381
  const uuid = services[i].uuid.trim();
@@ -845,8 +845,8 @@ Hci.prototype.onSocketData = function (data) {
845
845
  this.emit('aclDataPkt', handle, cid, pktData);
846
846
  } else {
847
847
  this._handleBuffers[handle] = {
848
- length: length,
849
- cid: cid,
848
+ length,
849
+ cid,
850
850
  data: pktData
851
851
  };
852
852
  }
package/lib/noble.js CHANGED
@@ -18,7 +18,7 @@ function Noble (bindings) {
18
18
  this._services = {};
19
19
  this._characteristics = {};
20
20
  this._descriptors = {};
21
- this._discoveredPeripheralUUids = [];
21
+ this._discoveredPeripheralUUids = {};
22
22
 
23
23
  this._bindings.on('stateChange', this.onStateChange.bind(this));
24
24
  this._bindings.on('addressChange', this.onAddressChange.bind(this));
@@ -58,7 +58,11 @@ function Noble (bindings) {
58
58
  this.initialized = true;
59
59
 
60
60
  process.nextTick(() => {
61
- this._bindings.init();
61
+ try {
62
+ this._bindings.init();
63
+ } catch (error) {
64
+ this.emit('warning', 'Initialization of USB device failed: ' + error.message);
65
+ }
62
66
  });
63
67
  }
64
68
  });
@@ -131,7 +135,7 @@ const startScanning = function (serviceUuids, allowDuplicates, callback) {
131
135
  });
132
136
  }
133
137
 
134
- this._discoveredPeripheralUUids = [];
138
+ this._discoveredPeripheralUUids = {};
135
139
  this._allowDuplicates = allowDuplicates;
136
140
 
137
141
  this._bindings.startScanning(serviceUuids, allowDuplicates);
@@ -204,10 +208,10 @@ Noble.prototype.onDiscover = function (uuid, address, addressType, connectable,
204
208
  peripheral.rssi = rssi;
205
209
  }
206
210
 
207
- const previouslyDiscoverd = (this._discoveredPeripheralUUids.indexOf(uuid) !== -1);
211
+ const previouslyDiscoverd = this._discoveredPeripheralUUids[uuid] === true;
208
212
 
209
213
  if (!previouslyDiscoverd) {
210
- this._discoveredPeripheralUUids.push(uuid);
214
+ this._discoveredPeripheralUUids[uuid] = true;
211
215
  }
212
216
 
213
217
  if (this._allowDuplicates || !previouslyDiscoverd || (!scannable && !connectable)) {
@@ -587,7 +591,7 @@ Noble.prototype.onHandleNotify = function (peripheralUuid, handle, data) {
587
591
 
588
592
  Noble.prototype.onMtu = function (peripheralUuid, mtu) {
589
593
  const peripheral = this._peripherals[peripheralUuid];
590
- if (peripheral && 'mtu' in peripheral && mtu) peripheral.mtu = mtu;
594
+ if (peripheral && mtu) peripheral.mtu = mtu;
591
595
  };
592
596
 
593
597
  module.exports = Noble;
package/lib/peripheral.js CHANGED
@@ -1,8 +1,6 @@
1
1
  const events = require('events');
2
2
  const util = require('util');
3
3
 
4
- const Manufacturer = require('./manufacture');
5
-
6
4
  function Peripheral (noble, id, address, addressType, connectable, advertisement, rssi, scannable) {
7
5
  this._noble = noble;
8
6
 
@@ -17,11 +15,6 @@ function Peripheral (noble, id, address, addressType, connectable, advertisement
17
15
  this.services = null;
18
16
  this.mtu = null;
19
17
  this.state = 'disconnected';
20
- this.manufacturer = null;
21
-
22
- if (typeof this.advertisement !== 'undefined' && typeof this.advertisement.manufacturerData !== 'undefined') {
23
- this.manufacturer = new Manufacturer(noble, this.advertisement.manufacturerData);
24
- }
25
18
  }
26
19
 
27
20
  util.inherits(Peripheral, events.EventEmitter);
@@ -1,7 +1,43 @@
1
+ const os = require('os');
1
2
 
2
- module.exports = function (options) {
3
- if (process.env.NOBLE_HCI_UART_PORT) {
4
- return new (require('./hci-uart/bindings'))(options);
3
+ function getWindowsBindings () {
4
+ const ver = os
5
+ .release()
6
+ .split('.')
7
+ .map((str) => parseInt(str, 10));
8
+ if (
9
+ !(
10
+ ver[0] > 10 ||
11
+ (ver[0] === 10 && ver[1] > 0) ||
12
+ (ver[0] === 10 && ver[1] === 0 && ver[2] >= 15063)
13
+ )
14
+ ) {
15
+ return require('./hci-socket/bindings');
16
+ } else {
17
+ return require('./win/bindings');
18
+ }
19
+ }
20
+
21
+ module.exports = function (options = {}) {
22
+ const platform = os.platform();
23
+
24
+ if (process.env.NOBLE_WEBSOCKET) {
25
+ return new (require('./websocket/bindings'))(options);
26
+ } else if (process.env.NOBLE_DISTRIBUTED) {
27
+ return new (require('./distributed/bindings'))(options);
28
+ } else if (
29
+ platform === 'linux' ||
30
+ platform === 'freebsd' ||
31
+ (process.env.BLUETOOTH_HCI_SOCKET_UART_PORT ||
32
+ process.env.BLUETOOTH_HCI_SOCKET_FORCE_UART) ||
33
+ (process.env.BLUETOOTH_HCI_SOCKET_USB_VID &&
34
+ process.env.BLUETOOTH_HCI_SOCKET_USB_PID)
35
+ ) {
36
+ return new (require('./hci-socket/bindings'))(options);
37
+ } else if (platform === 'darwin') {
38
+ return new (require('./mac/bindings'))(options);
39
+ } else if (platform === 'win32') {
40
+ return new (getWindowsBindings())(options);
5
41
  } else {
6
42
  throw new Error('Unsupported platform');
7
43
  }
@@ -109,9 +109,9 @@ NobleBindings.prototype.startScanning = function (options, allowDuplicates) {
109
109
 
110
110
  self._peripherals[address] = {
111
111
  uuid: address,
112
- address: address,
112
+ address,
113
113
  advertisement: { localName: device.name }, // advertisement,
114
- device: device,
114
+ device,
115
115
  cachedServices: {},
116
116
  localName: device.name,
117
117
  serviceUuids: options.services
@@ -79,9 +79,9 @@ NobleBindings.prototype._onMessage = function (event) {
79
79
 
80
80
  this._peripherals[peripheralUuid] = {
81
81
  uuid: peripheralUuid,
82
- address: address,
83
- advertisement: advertisement,
84
- rssi: rssi
82
+ address,
83
+ advertisement,
84
+ rssi
85
85
  };
86
86
 
87
87
  this.emit('discover', peripheralUuid, address, addressType, connectable, advertisement, rssi);
@@ -135,8 +135,8 @@ NobleBindings.prototype._sendCommand = function (command, errorCallback) {
135
135
  NobleBindings.prototype.startScanning = function (serviceUuids, allowDuplicates) {
136
136
  this._startScanCommand = {
137
137
  action: 'startScanning',
138
- serviceUuids: serviceUuids,
139
- allowDuplicates: allowDuplicates
138
+ serviceUuids,
139
+ allowDuplicates
140
140
  };
141
141
  this._sendCommand(this._startScanCommand);
142
142
 
@@ -186,7 +186,7 @@ NobleBindings.prototype.discoverServices = function (deviceUuid, uuids) {
186
186
  this._sendCommand({
187
187
  action: 'discoverServices',
188
188
  peripheralUuid: peripheral.uuid,
189
- uuids: uuids
189
+ uuids
190
190
  });
191
191
  };
192
192
 
@@ -196,8 +196,8 @@ NobleBindings.prototype.discoverIncludedServices = function (deviceUuid, service
196
196
  this._sendCommand({
197
197
  action: 'discoverIncludedServices',
198
198
  peripheralUuid: peripheral.uuid,
199
- serviceUuid: serviceUuid,
200
- serviceUuids: serviceUuids
199
+ serviceUuid,
200
+ serviceUuids
201
201
  });
202
202
  };
203
203
 
@@ -207,8 +207,8 @@ NobleBindings.prototype.discoverCharacteristics = function (deviceUuid, serviceU
207
207
  this._sendCommand({
208
208
  action: 'discoverCharacteristics',
209
209
  peripheralUuid: peripheral.uuid,
210
- serviceUuid: serviceUuid,
211
- characteristicUuids: characteristicUuids
210
+ serviceUuid,
211
+ characteristicUuids
212
212
  });
213
213
  };
214
214
 
@@ -218,8 +218,8 @@ NobleBindings.prototype.read = function (deviceUuid, serviceUuid, characteristic
218
218
  this._sendCommand({
219
219
  action: 'read',
220
220
  peripheralUuid: peripheral.uuid,
221
- serviceUuid: serviceUuid,
222
- characteristicUuid: characteristicUuid
221
+ serviceUuid,
222
+ characteristicUuid
223
223
  });
224
224
  };
225
225
 
@@ -229,10 +229,10 @@ NobleBindings.prototype.write = function (deviceUuid, serviceUuid, characteristi
229
229
  this._sendCommand({
230
230
  action: 'write',
231
231
  peripheralUuid: peripheral.uuid,
232
- serviceUuid: serviceUuid,
233
- characteristicUuid: characteristicUuid,
232
+ serviceUuid,
233
+ characteristicUuid,
234
234
  data: data.toString('hex'),
235
- withoutResponse: withoutResponse
235
+ withoutResponse
236
236
  });
237
237
  };
238
238
 
@@ -242,9 +242,9 @@ NobleBindings.prototype.broadcast = function (deviceUuid, serviceUuid, character
242
242
  this._sendCommand({
243
243
  action: 'broadcast',
244
244
  peripheralUuid: peripheral.uuid,
245
- serviceUuid: serviceUuid,
246
- characteristicUuid: characteristicUuid,
247
- broadcast: broadcast
245
+ serviceUuid,
246
+ characteristicUuid,
247
+ broadcast
248
248
  });
249
249
  };
250
250
 
@@ -254,9 +254,9 @@ NobleBindings.prototype.notify = function (deviceUuid, serviceUuid, characterist
254
254
  this._sendCommand({
255
255
  action: 'notify',
256
256
  peripheralUuid: peripheral.uuid,
257
- serviceUuid: serviceUuid,
258
- characteristicUuid: characteristicUuid,
259
- notify: notify
257
+ serviceUuid,
258
+ characteristicUuid,
259
+ notify
260
260
  });
261
261
  };
262
262
 
@@ -266,8 +266,8 @@ NobleBindings.prototype.discoverDescriptors = function (deviceUuid, serviceUuid,
266
266
  this._sendCommand({
267
267
  action: 'discoverDescriptors',
268
268
  peripheralUuid: peripheral.uuid,
269
- serviceUuid: serviceUuid,
270
- characteristicUuid: characteristicUuid
269
+ serviceUuid,
270
+ characteristicUuid
271
271
  });
272
272
  };
273
273
 
@@ -277,9 +277,9 @@ NobleBindings.prototype.readValue = function (deviceUuid, serviceUuid, character
277
277
  this._sendCommand({
278
278
  action: 'readValue',
279
279
  peripheralUuid: peripheral.uuid,
280
- serviceUuid: serviceUuid,
281
- characteristicUuid: characteristicUuid,
282
- descriptorUuid: descriptorUuid
280
+ serviceUuid,
281
+ characteristicUuid,
282
+ descriptorUuid
283
283
  });
284
284
  };
285
285
 
@@ -289,9 +289,9 @@ NobleBindings.prototype.writeValue = function (deviceUuid, serviceUuid, characte
289
289
  this._sendCommand({
290
290
  action: 'writeValue',
291
291
  peripheralUuid: peripheral.uuid,
292
- serviceUuid: serviceUuid,
293
- characteristicUuid: characteristicUuid,
294
- descriptorUuid: descriptorUuid,
292
+ serviceUuid,
293
+ characteristicUuid,
294
+ descriptorUuid,
295
295
  data: data.toString('hex')
296
296
  });
297
297
  };
@@ -302,7 +302,7 @@ NobleBindings.prototype.readHandle = function (deviceUuid, handle) {
302
302
  this._sendCommand({
303
303
  action: 'readHandle',
304
304
  peripheralUuid: peripheral.uuid,
305
- handle: handle
305
+ handle
306
306
  });
307
307
  };
308
308
 
@@ -312,9 +312,9 @@ NobleBindings.prototype.writeHandle = function (deviceUuid, handle, data, withou
312
312
  this._sendCommand({
313
313
  action: 'writeHandle',
314
314
  peripheralUuid: peripheral.uuid,
315
- handle: handle,
315
+ handle,
316
316
  data: data.toString('hex'),
317
- withoutResponse: withoutResponse
317
+ withoutResponse
318
318
  });
319
319
  };
320
320
 
@@ -12,8 +12,10 @@
12
12
  #include <winrt/Windows.Storage.Streams.h>
13
13
  using winrt::Windows::Devices::Bluetooth::BluetoothCacheMode;
14
14
  using winrt::Windows::Devices::Bluetooth::BluetoothConnectionStatus;
15
+ using winrt::Windows::Devices::Bluetooth::BluetoothLEDevice;
15
16
  using winrt::Windows::Storage::Streams::DataReader;
16
17
  using winrt::Windows::Storage::Streams::DataWriter;
18
+ using winrt::Windows::Storage::Streams::IBuffer;
17
19
 
18
20
  template <typename T> auto inFilter(std::vector<T> filter, T object)
19
21
  {
@@ -190,7 +192,7 @@ bool BLEManager::Connect(const std::string& uuid)
190
192
  return true;
191
193
  }
192
194
 
193
- void BLEManager::OnConnected(IAsyncOperation<BluetoothLEDevice> asyncOp, AsyncStatus& status,
195
+ void BLEManager::OnConnected(IAsyncOperation<BluetoothLEDevice> asyncOp, AsyncStatus status,
194
196
  const std::string uuid)
195
197
  {
196
198
  if (status == AsyncStatus::Completed)
@@ -375,6 +377,7 @@ void BLEManager::OnCharacteristicsDiscovered(IAsyncOperation<GattCharacteristics
375
377
  auto result = asyncOp.GetResults();
376
378
  CHECK_RESULT(result);
377
379
  std::vector<std::pair<std::string, std::vector<std::string>>> characteristicsUuids;
380
+
378
381
  FOR(characteristic, result.Characteristics())
379
382
  {
380
383
  auto id = characteristic.Uuid();
@@ -47,7 +47,7 @@ private:
47
47
  void OnRadio(Radio& radio);
48
48
  void OnScanResult(BluetoothLEAdvertisementWatcher watcher, const BluetoothLEAdvertisementReceivedEventArgs& args);
49
49
  void OnScanStopped(BluetoothLEAdvertisementWatcher watcher, const BluetoothLEAdvertisementWatcherStoppedEventArgs& args);
50
- void OnConnected(IAsyncOperation<BluetoothLEDevice> asyncOp, AsyncStatus& status, std::string uuid);
50
+ void OnConnected(IAsyncOperation<BluetoothLEDevice> asyncOp, AsyncStatus status, std::string uuid);
51
51
  void OnConnectionStatusChanged(BluetoothLEDevice device, winrt::Windows::Foundation::IInspectable inspectable);
52
52
  void OnServicesDiscovered(IAsyncOperation<GattDeviceServicesResult> asyncOp, AsyncStatus status, std::string uuid, std::vector<winrt::guid> serviceUUIDs);
53
53
  void OnIncludedServicesDiscovered(IAsyncOperation<GattDeviceServicesResult> asyncOp, AsyncStatus status, std::string uuid, std::string serviceId, std::vector<winrt::guid> serviceUUIDs);
@@ -2,6 +2,7 @@
2
2
  #include "winrt_cpp.h"
3
3
 
4
4
  #include <winrt/Windows.Storage.Streams.h>
5
+ #include <winrt/Windows.Foundation.Collections.h>
5
6
  using namespace winrt::Windows::Storage::Streams;
6
7
 
7
8
  using winrt::Windows::Devices::Bluetooth::BluetoothCacheMode;
@@ -43,6 +44,7 @@ void PeripheralWinrt::Update(const int rssiValue, const BluetoothLEAdvertisement
43
44
  advertismentType == BluetoothLEAdvertisementType::ConnectableDirected;
44
45
 
45
46
  manufacturerData.clear();
47
+
46
48
  for (auto ds : advertisment.DataSections())
47
49
  {
48
50
  if (ds.DataType() == BluetoothLEAdvertisementDataTypes::TxPowerLevel())
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "radio_watcher.h"
11
11
  #include "winrt_cpp.h"
12
+ #include <winrt/Windows.Foundation.Collections.h>
12
13
 
13
14
  using winrt::Windows::Devices::Radios::RadioKind;
14
15
  using winrt::Windows::Foundation::AsyncStatus;
@@ -4,6 +4,7 @@
4
4
  #include <iomanip>
5
5
 
6
6
  #include <winrt\Windows.Devices.Bluetooth.h>
7
+ #include <winrt/Windows.Foundation.Collections.h>
7
8
 
8
9
  std::string ws2s(const wchar_t* wstr)
9
10
  {
package/package.json CHANGED
@@ -7,10 +7,10 @@
7
7
  "license": "MIT",
8
8
  "name": "@stoprocent/noble",
9
9
  "description": "A Node.js BLE (Bluetooth Low Energy) central library.",
10
- "version": "1.10.2",
10
+ "version": "1.11.0",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/stoprocent/noble.git"
13
+ "url": "https://github.com/stoprocent/noble.git"
14
14
  },
15
15
  "bugs": {
16
16
  "url": "https://github.com/stoprocent/noble/issues"
@@ -35,35 +35,45 @@
35
35
  "win32"
36
36
  ],
37
37
  "dependencies": {
38
- "debug": "^4.3.1"
38
+ "debug": "^4.3.4",
39
+ "napi-thread-safe-callback": "^0.0.6",
40
+ "node-addon-api": "^4.3.0",
41
+ "node-gyp-build": "^4.5.0"
39
42
  },
40
43
  "optionalDependencies": {
41
- "async": "^3.2.4",
42
- "serialport": "^10.4.0"
44
+ "@stoprocent/bluetooth-hci-socket": "^0.6.1"
43
45
  },
44
46
  "devDependencies": {
45
- "async": "^3.2.0",
47
+ "async": "^3.2.4",
46
48
  "cross-env": "^7.0.3",
47
- "eslint": "^7.32.0",
48
- "eslint-config-semistandard": "^16.0.0",
49
- "eslint-config-standard": "^16.0.3",
50
- "eslint-plugin-import": "^2.25.3",
51
- "eslint-plugin-node": "^11.1.0",
52
- "eslint-plugin-promise": "^5.2.0",
53
- "mocha": "^9.2.2",
54
- "node-gyp": "^8.4.1",
49
+ "eslint": "^8.31.0",
50
+ "eslint-config-semistandard": "^17.0.0",
51
+ "eslint-config-standard": "^17.0.0",
52
+ "eslint-plugin-import": "^2.26.0",
53
+ "eslint-plugin-n": "^15.6.0",
54
+ "eslint-plugin-promise": "^6.1.1",
55
+ "mocha": "^10.2.0",
56
+ "node-gyp": "^9.3.1",
55
57
  "nyc": "^15.1.0",
56
- "prebuildify": "^5.0.0",
58
+ "prebuildify": "^5.0.1",
57
59
  "prebuildify-ci": "^1.0.5",
58
- "prettier": "^2.3.0",
60
+ "prettier": "^2.8.1",
59
61
  "proxyquire": "^2.1.3",
60
62
  "should": "~13.2.3",
61
- "sinon": "^12.0.1",
62
- "ws": "^8.3.0"
63
+ "sinon": "^15.0.1",
64
+ "ws": "^8.11.0"
63
65
  },
64
66
  "scripts": {
67
+ "install": "node-gyp-build",
65
68
  "lint": "eslint \"**/*.js\"",
66
69
  "lint-fix": "eslint \"**/*.js\" --fix",
70
+ "prebuild": "prebuildify --napi --strip",
71
+ "prebuild-darwin": "prebuildify --napi --strip --arch x64+arm64",
72
+ "prebuild-win32": "prebuildify --napi --strip",
73
+ "prebuild-linux": "prebuildify --napi --strip",
74
+ "prebuild-download": "prebuildify-ci download",
75
+ "pretest": "npm run rebuild",
76
+ "rebuild": "node-gyp rebuild",
67
77
  "coverage": "nyc npm test && nyc report --reporter=text-lcov > .nyc_output/lcov.info",
68
78
  "test": "cross-env NODE_ENV=test mocha --recursive \"test/*.test.js\" \"test/**/*.test.js\" --exit"
69
79
  },
@@ -74,11 +84,5 @@
74
84
  "napi_versions": [
75
85
  4
76
86
  ]
77
- },
78
- "homepage": "https://github.com/stoprocent/noble#readme",
79
- "directories": {
80
- "example": "examples",
81
- "lib": "lib",
82
- "test": "test"
83
87
  }
84
88
  }
@@ -428,7 +428,7 @@ describe('distributed bindings', () => {
428
428
  assert.fail('Should throw an error');
429
429
  } catch (e) {
430
430
  should(e).instanceOf(Error);
431
- should(e.message).eql('Cannot read property \'ws\' of undefined');
431
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
432
432
  }
433
433
  });
434
434
 
@@ -459,7 +459,7 @@ describe('distributed bindings', () => {
459
459
  assert.fail('Should throw an error');
460
460
  } catch (e) {
461
461
  should(e).instanceOf(Error);
462
- should(e.message).eql('Cannot read property \'ws\' of undefined');
462
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
463
463
  }
464
464
  });
465
465
 
@@ -490,7 +490,7 @@ describe('distributed bindings', () => {
490
490
  assert.fail('Should throw an error');
491
491
  } catch (e) {
492
492
  should(e).instanceOf(Error);
493
- should(e.message).eql('Cannot read property \'ws\' of undefined');
493
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
494
494
  }
495
495
  });
496
496
 
@@ -521,7 +521,7 @@ describe('distributed bindings', () => {
521
521
  assert.fail('Should throw an error');
522
522
  } catch (e) {
523
523
  should(e).instanceOf(Error);
524
- should(e.message).eql('Cannot read property \'ws\' of undefined');
524
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
525
525
  }
526
526
  });
527
527
 
@@ -553,7 +553,7 @@ describe('distributed bindings', () => {
553
553
  assert.fail('Should throw an error');
554
554
  } catch (e) {
555
555
  should(e).instanceOf(Error);
556
- should(e.message).eql('Cannot read property \'ws\' of undefined');
556
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
557
557
  }
558
558
  });
559
559
 
@@ -586,7 +586,7 @@ describe('distributed bindings', () => {
586
586
  assert.fail('Should throw an error');
587
587
  } catch (e) {
588
588
  should(e).instanceOf(Error);
589
- should(e.message).eql('Cannot read property \'ws\' of undefined');
589
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
590
590
  }
591
591
  });
592
592
 
@@ -619,7 +619,7 @@ describe('distributed bindings', () => {
619
619
  assert.fail('Should throw an error');
620
620
  } catch (e) {
621
621
  should(e).instanceOf(Error);
622
- should(e.message).eql('Cannot read property \'ws\' of undefined');
622
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
623
623
  }
624
624
  });
625
625
 
@@ -652,7 +652,7 @@ describe('distributed bindings', () => {
652
652
  assert.fail('Should throw an error');
653
653
  } catch (e) {
654
654
  should(e).instanceOf(Error);
655
- should(e.message).eql('Cannot read property \'ws\' of undefined');
655
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
656
656
  }
657
657
  });
658
658
 
@@ -687,7 +687,7 @@ describe('distributed bindings', () => {
687
687
  assert.fail('Should throw an error');
688
688
  } catch (e) {
689
689
  should(e).instanceOf(Error);
690
- should(e.message).eql('Cannot read property \'ws\' of undefined');
690
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
691
691
  }
692
692
  });
693
693
 
@@ -721,7 +721,7 @@ describe('distributed bindings', () => {
721
721
  assert.fail('Should throw an error');
722
722
  } catch (e) {
723
723
  should(e).instanceOf(Error);
724
- should(e.message).eql('Cannot read property \'ws\' of undefined');
724
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
725
725
  }
726
726
  });
727
727
 
@@ -755,7 +755,7 @@ describe('distributed bindings', () => {
755
755
  assert.fail('Should throw an error');
756
756
  } catch (e) {
757
757
  should(e).instanceOf(Error);
758
- should(e.message).eql('Cannot read property \'ws\' of undefined');
758
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
759
759
  }
760
760
  });
761
761
 
@@ -788,7 +788,7 @@ describe('distributed bindings', () => {
788
788
  assert.fail('Should throw an error');
789
789
  } catch (e) {
790
790
  should(e).instanceOf(Error);
791
- should(e.message).eql('Cannot read property \'ws\' of undefined');
791
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
792
792
  }
793
793
  });
794
794
 
@@ -822,7 +822,7 @@ describe('distributed bindings', () => {
822
822
  assert.fail('Should throw an error');
823
823
  } catch (e) {
824
824
  should(e).instanceOf(Error);
825
- should(e.message).eql('Cannot read property \'ws\' of undefined');
825
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
826
826
  }
827
827
  });
828
828
 
@@ -857,7 +857,7 @@ describe('distributed bindings', () => {
857
857
  assert.fail('Should throw an error');
858
858
  } catch (e) {
859
859
  should(e).instanceOf(Error);
860
- should(e.message).eql('Cannot read property \'ws\' of undefined');
860
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
861
861
  }
862
862
  });
863
863
 
@@ -889,7 +889,7 @@ describe('distributed bindings', () => {
889
889
  assert.fail('Should throw an error');
890
890
  } catch (e) {
891
891
  should(e).instanceOf(Error);
892
- should(e.message).eql('Cannot read property \'ws\' of undefined');
892
+ should(e.message.startsWith('Cannot read') && e.message.includes('\'ws\'') && e.message.includes('undefined')).eql(true);
893
893
  }
894
894
  });
895
895
 
@@ -1086,4 +1086,43 @@ describe('hci-socket gap', () => {
1086
1086
  assert.notCalled(discoverCallback);
1087
1087
  });
1088
1088
  });
1089
+
1090
+ it('should reset the service data on non scan responses', () => {
1091
+ const hci = {
1092
+ on: sinon.spy()
1093
+ };
1094
+
1095
+ const status = 'status';
1096
+ const address = 'a:d:d:r:e:s:s';
1097
+ const addressType = 'addressType';
1098
+ const rssi = 'rssi';
1099
+
1100
+ const eirType = 0x21;
1101
+ const serviceUuid = Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]);
1102
+ const serviceData = Buffer.from([0x05, 0x06]);
1103
+ const eirLength = serviceUuid.length + serviceData.length + 1;
1104
+ const eirLengthAndType = Buffer.from([eirLength, eirType]);
1105
+ const eir = Buffer.concat([eirLengthAndType, serviceUuid, serviceData]);
1106
+
1107
+ const discoverCallback = sinon.spy();
1108
+
1109
+ const gap = new Gap(hci);
1110
+ gap.on('discover', discoverCallback);
1111
+ gap.onHciLeAdvertisingReport(status, 0x04, address, addressType, eir, rssi);
1112
+
1113
+ const expectedServiceData = [
1114
+ {
1115
+ uuid: '0f0e0d0c0b0a09080706050403020100',
1116
+ data: serviceData
1117
+ }
1118
+ ];
1119
+
1120
+ should(gap._discoveries[address].advertisement.serviceData).deepEqual(expectedServiceData);
1121
+
1122
+ gap.onHciLeAdvertisingReport(status, 0x01, address, addressType, eir, rssi);
1123
+
1124
+ should(gap._discoveries[address].advertisement.serviceData).deepEqual(expectedServiceData);
1125
+
1126
+ assert.calledOnce(discoverCallback);
1127
+ });
1089
1128
  });