@stoprocent/noble 1.19.0 → 2.0.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 (97) hide show
  1. package/README.md +393 -650
  2. package/examples/advertisement-discovery.js +57 -48
  3. package/examples/connect-address.js +59 -34
  4. package/examples/echo.js +59 -69
  5. package/examples/enter-exit.js +55 -49
  6. package/examples/multiple-bindings.js +53 -0
  7. package/examples/peripheral-explorer-async.js +39 -21
  8. package/examples/peripheral-explorer.ts +52 -0
  9. package/index.d.ts +249 -209
  10. package/index.js +4 -1
  11. package/jest.config.js +4 -0
  12. package/lib/characteristic.js +153 -127
  13. package/lib/{win/src/callbacks.h → common/include/Emit.h} +17 -14
  14. package/lib/common/include/Peripheral.h +31 -0
  15. package/lib/common/include/ThreadSafeCallback.h +95 -0
  16. package/lib/{win/src/callbacks.cc → common/src/Emit.cc} +111 -68
  17. package/lib/descriptor.js +57 -54
  18. package/lib/hci-socket/acl-stream.js +2 -4
  19. package/lib/hci-socket/bindings.js +96 -73
  20. package/lib/hci-socket/gap.js +2 -3
  21. package/lib/hci-socket/gatt.js +2 -5
  22. package/lib/hci-socket/hci.js +19 -7
  23. package/lib/hci-socket/signaling.js +2 -3
  24. package/lib/hci-socket/smp.js +2 -3
  25. package/lib/hci-socket/vs.js +1 -0
  26. package/lib/mac/binding.gyp +5 -7
  27. package/lib/mac/bindings.js +1 -3
  28. package/lib/mac/src/ble_manager.h +1 -8
  29. package/lib/mac/src/ble_manager.mm +87 -44
  30. package/lib/mac/src/napi_objc.h +1 -0
  31. package/lib/mac/src/napi_objc.mm +0 -6
  32. package/lib/mac/src/noble_mac.h +5 -3
  33. package/lib/mac/src/noble_mac.mm +99 -57
  34. package/lib/mac/src/objc_cpp.h +3 -2
  35. package/lib/mac/src/objc_cpp.mm +0 -6
  36. package/lib/noble.js +579 -488
  37. package/lib/peripheral.js +171 -174
  38. package/lib/resolve-bindings.js +37 -30
  39. package/lib/service.js +58 -55
  40. package/lib/win/binding.gyp +4 -11
  41. package/lib/win/bindings.js +1 -3
  42. package/lib/win/src/ble_manager.cc +291 -166
  43. package/lib/win/src/ble_manager.h +11 -13
  44. package/lib/win/src/napi_winrt.cc +1 -7
  45. package/lib/win/src/napi_winrt.h +1 -1
  46. package/lib/win/src/noble_winrt.cc +88 -61
  47. package/lib/win/src/noble_winrt.h +5 -3
  48. package/lib/win/src/notify_map.cc +0 -7
  49. package/lib/win/src/notify_map.h +1 -8
  50. package/lib/win/src/peripheral_winrt.cc +29 -11
  51. package/lib/win/src/peripheral_winrt.h +1 -1
  52. package/lib/win/src/radio_watcher.cc +79 -69
  53. package/lib/win/src/radio_watcher.h +30 -11
  54. package/lib/win/src/winrt_cpp.cc +1 -1
  55. package/lib/win/src/winrt_cpp.h +3 -0
  56. package/package.json +14 -17
  57. package/prebuilds/darwin-x64+arm64/@stoprocent+noble.node +0 -0
  58. package/prebuilds/win32-ia32/@stoprocent+noble.node +0 -0
  59. package/prebuilds/win32-x64/@stoprocent+noble.node +0 -0
  60. package/test/lib/characteristic.test.js +202 -322
  61. package/test/lib/descriptor.test.js +62 -95
  62. package/test/lib/hci-socket/acl-stream.test.js +112 -108
  63. package/test/lib/hci-socket/bindings.test.js +576 -365
  64. package/test/lib/hci-socket/hci.test.js +442 -473
  65. package/test/lib/hci-socket/signaling.test.js +45 -48
  66. package/test/lib/hci-socket/smp.test.js +144 -142
  67. package/test/lib/hci-socket/vs.test.js +193 -18
  68. package/test/lib/peripheral.test.js +492 -322
  69. package/test/lib/resolve-bindings.test.js +207 -82
  70. package/test/lib/service.test.js +79 -88
  71. package/test/noble.test.js +381 -1085
  72. package/.editorconfig +0 -11
  73. package/.nycrc.json +0 -4
  74. package/codecov.yml +0 -5
  75. package/examples/cache-gatt-discovery.js +0 -198
  76. package/examples/cache-gatt-reconnect.js +0 -164
  77. package/examples/ext-advertisement-discovery.js +0 -65
  78. package/examples/peripheral-explorer.js +0 -225
  79. package/examples/pizza/central.js +0 -194
  80. package/examples/pizza/pizza.js +0 -60
  81. package/examples/test/test.custom.js +0 -131
  82. package/examples/uart-bind-params.js +0 -28
  83. package/lib/distributed/bindings.js +0 -326
  84. package/lib/mac/src/callbacks.cc +0 -222
  85. package/lib/mac/src/callbacks.h +0 -84
  86. package/lib/mac/src/peripheral.h +0 -23
  87. package/lib/resolve-bindings-web.js +0 -9
  88. package/lib/webbluetooth/bindings.js +0 -368
  89. package/lib/websocket/bindings.js +0 -321
  90. package/lib/win/src/peripheral.h +0 -23
  91. package/test/lib/distributed/bindings.test.js +0 -918
  92. package/test/lib/webbluetooth/bindings.test.js +0 -190
  93. package/test/lib/websocket/bindings.test.js +0 -456
  94. package/test/mocha.setup.js +0 -0
  95. package/with-bindings.js +0 -5
  96. package/with-custom-binding.js +0 -6
  97. package/ws-slave.js +0 -404
@@ -1,190 +0,0 @@
1
- const sinon = require('sinon');
2
- const should = require('should');
3
-
4
- const { assert } = sinon;
5
-
6
- const Bindings = require('../../../lib/webbluetooth/bindings');
7
-
8
- describe('webbluetooth bindings', () => {
9
- let bindings;
10
- let clock;
11
-
12
- beforeEach(() => {
13
- clock = sinon.useFakeTimers();
14
-
15
- bindings = new Bindings();
16
- });
17
-
18
- afterEach(() => {
19
- clock.restore();
20
- sinon.reset();
21
- });
22
-
23
- it('constructor', () => {
24
- should(bindings._ble).equal(null);
25
- should(bindings._startScanCommand).equal(null);
26
- should(bindings._peripherals).deepEqual({});
27
- });
28
-
29
- describe('init', () => {
30
- it('should use ble arg', () => {
31
- const errorCallback = sinon.spy();
32
-
33
- bindings.on('error', errorCallback);
34
- bindings.init({});
35
-
36
- clock.tick(1);
37
-
38
- assert.notCalled(errorCallback);
39
- });
40
- });
41
-
42
- it('onClose - should emit stateChange', () => {
43
- const callback = sinon.spy();
44
-
45
- bindings.on('stateChange', callback);
46
- bindings.onClose();
47
-
48
- assert.calledOnceWithExactly(callback, 'poweredOff');
49
- });
50
-
51
- describe('startScanning', () => {
52
- let scanStopCallback;
53
- let discoverCallback;
54
- let errorCallback;
55
- let scanStartCallback;
56
-
57
- let device;
58
-
59
- beforeEach(() => {
60
- device = {
61
- id: 'id',
62
- name: 'name',
63
- services: ['1234', 'service9']
64
- };
65
-
66
- scanStopCallback = sinon.spy();
67
- discoverCallback = sinon.spy();
68
- errorCallback = sinon.spy();
69
- scanStartCallback = sinon.spy();
70
-
71
- bindings._ble = {
72
- requestDevice: sinon.fake.resolves(device)
73
- };
74
-
75
- bindings.on('scanStop', scanStopCallback);
76
- bindings.on('discover', discoverCallback);
77
- bindings.on('error', errorCallback);
78
- bindings.on('scanStart', scanStartCallback);
79
- });
80
-
81
- it('should emit discover with object options', async () => {
82
- const options = { services: ['1234', '0x5678', 'service'] };
83
- const allowDuplicates = true;
84
-
85
- bindings.startScanning(options, allowDuplicates);
86
-
87
- await clock.tickAsync(210);
88
-
89
- assert.calledOnceWithExactly(bindings._ble.requestDevice, { filters: [{ services: [4660] }, { services: [22136] }, { services: ['service'] }] });
90
- assert.calledOnceWithExactly(scanStopCallback, {});
91
- assert.calledOnceWithExactly(discoverCallback, device.id, device.id, device.addressType, !device.paired, { localName: device.name }, undefined);
92
- assert.notCalled(errorCallback);
93
- assert.calledOnceWithExactly(scanStartCallback);
94
-
95
- should(bindings._peripherals).deepEqual({
96
- [device.id]: {
97
- uuid: device.id,
98
- address: device.id,
99
- advertisement: { localName: device.name }, // advertisement,
100
- device,
101
- cachedServices: {},
102
- localName: device.name,
103
- serviceUuids: options.services
104
- }
105
- });
106
- });
107
-
108
- it('should emit discover with array options', async () => {
109
- const options = ['1234', '0x5678', 'service'];
110
- const allowDuplicates = false;
111
-
112
- device.adData = {
113
- rssi: 33
114
- };
115
-
116
- bindings.startScanning(options, allowDuplicates);
117
-
118
- await clock.tickAsync(210);
119
-
120
- assert.calledOnceWithExactly(bindings._ble.requestDevice, { filters: [{ services: [4660] }, { services: [22136] }, { services: ['service'] }] });
121
- assert.calledOnceWithExactly(scanStopCallback, {});
122
- assert.calledOnceWithExactly(discoverCallback, device.id, device.id, device.addressType, !device.paired, { localName: device.name }, 33);
123
- assert.notCalled(errorCallback);
124
- assert.calledOnceWithExactly(scanStartCallback);
125
-
126
- should(bindings._peripherals).deepEqual({
127
- [device.id]: {
128
- uuid: device.id,
129
- address: device.id,
130
- advertisement: { localName: device.name }, // advertisement,
131
- device,
132
- cachedServices: {},
133
- localName: device.name,
134
- serviceUuids: [4660, 22136, 'service'],
135
- rssi: 33
136
- }
137
- });
138
- });
139
-
140
- it('should not emit discover on null device', async () => {
141
- const options = ['1234', '0x5678', 'service'];
142
- const allowDuplicates = false;
143
-
144
- bindings._ble.requestDevice = sinon.fake.resolves(null);
145
-
146
- bindings.startScanning(options, allowDuplicates);
147
-
148
- await clock.tickAsync(210);
149
-
150
- assert.calledOnceWithExactly(bindings._ble.requestDevice, { filters: [{ services: [4660] }, { services: [22136] }, { services: ['service'] }] });
151
- assert.calledOnceWithExactly(scanStopCallback, {});
152
- assert.notCalled(discoverCallback);
153
- assert.notCalled(errorCallback);
154
- assert.calledOnceWithExactly(scanStartCallback);
155
-
156
- should(bindings._peripherals).deepEqual({});
157
- });
158
-
159
- it('should emit error', async () => {
160
- const options = ['1234', '0x5678', 'service'];
161
- const allowDuplicates = false;
162
-
163
- bindings._ble.requestDevice = sinon.fake.rejects(new Error('err'));
164
-
165
- bindings.startScanning(options, allowDuplicates);
166
-
167
- await clock.tickAsync(210);
168
-
169
- assert.calledOnceWithExactly(bindings._ble.requestDevice, { filters: [{ services: [4660] }, { services: [22136] }, { services: ['service'] }] });
170
- assert.calledOnceWithExactly(scanStopCallback, {});
171
- assert.notCalled(discoverCallback);
172
- assert.calledOnceWithMatch(errorCallback, sinon.match({ message: 'err' }));
173
- assert.calledOnceWithExactly(scanStartCallback);
174
-
175
- should(bindings._peripherals).deepEqual({});
176
- });
177
- });
178
-
179
- it('stopScanning', () => {
180
- const callback = sinon.spy();
181
-
182
- bindings._startScanCommand = 'not_null';
183
- bindings.on('scanStop', callback);
184
-
185
- bindings.stopScanning();
186
-
187
- assert.calledOnceWithExactly(callback);
188
- should(bindings._startScanCommand).equal(null);
189
- });
190
- });
@@ -1,456 +0,0 @@
1
- const sinon = require('sinon');
2
- const should = require('should');
3
- const proxyquire = require('proxyquire').noCallThru();
4
-
5
- const { assert } = sinon;
6
-
7
- describe('webbluetooth bindings', () => {
8
- const FakeWebsocket = sinon.spy();
9
-
10
- const Bindings = proxyquire('../../../lib/websocket/bindings', {
11
- ws: FakeWebsocket
12
- });
13
-
14
- let bindings;
15
-
16
- beforeEach(() => {
17
- FakeWebsocket.prototype.on = sinon.spy();
18
-
19
- bindings = new Bindings();
20
- });
21
-
22
- afterEach(() => {
23
- sinon.reset();
24
- });
25
-
26
- it('constructor', () => {
27
- assert.calledOnceWithExactly(FakeWebsocket, 'ws://localhost:2846');
28
- assert.callCount(bindings._ws.on, 4);
29
- assert.calledWithMatch(bindings._ws.on, 'open', sinon.match.func);
30
- assert.calledWithMatch(bindings._ws.on, 'close', sinon.match.func);
31
- assert.calledWithMatch(bindings._ws.on, 'error', sinon.match.func);
32
- assert.calledWithMatch(bindings._ws.on, 'message', sinon.match.func);
33
- });
34
-
35
- it('onClose - should emit stateChange', () => {
36
- const callback = sinon.spy();
37
-
38
- bindings.on('stateChange', callback);
39
- bindings._onClose();
40
-
41
- assert.calledOnceWithExactly(callback, 'poweredOff');
42
- });
43
-
44
- describe('_onMessage', () => {
45
- const mainEvent = {
46
- peripheralUuid: 'peripheralUuid',
47
- address: 'address',
48
- addressType: 'addressType',
49
- connectable: 'connectable',
50
- advertisement: {
51
- localName: 'localName',
52
- txPowerLevel: 34,
53
- serviceUuids: 'ad.serviceUuids',
54
- manufacturerData: null,
55
- serviceData: null
56
- },
57
- rssi: 'rssi',
58
- serviceUuids: 'serviceUuids',
59
- serviceUuid: 'serviceUuid',
60
- includedServiceUuids: 'includedServiceUuids',
61
- characteristics: 'characteristics',
62
- characteristicUuid: 'characteristicUuid',
63
- isNotification: 'isNotification',
64
- state: 'state',
65
- descriptors: 'descriptors',
66
- descriptorUuid: 'descriptorUuid',
67
- handle: 'handle'
68
- };
69
-
70
- [
71
- { type: 'stateChange', event: ['stateChange', mainEvent.state] },
72
- { type: 'discover', event: ['discover', mainEvent.peripheralUuid, mainEvent.address, mainEvent.addressType, mainEvent.connectable, mainEvent.advertisement, mainEvent.rssi] },
73
- { type: 'connect', event: ['connect', mainEvent.peripheralUuid] },
74
- { type: 'disconnect', event: ['disconnect', mainEvent.peripheralUuid] },
75
- { type: 'rssiUpdate', event: ['rssiUpdate', mainEvent.peripheralUuid, mainEvent.rssi] },
76
- { type: 'servicesDiscover', event: ['servicesDiscover', mainEvent.peripheralUuid, mainEvent.serviceUuids] },
77
- { type: 'includedServicesDiscover', event: ['includedServicesDiscover', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.includedServiceUuids] },
78
- { type: 'characteristicsDiscover', event: ['characteristicsDiscover', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristics] },
79
- { type: 'read', event: ['read', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristicUuid, null, mainEvent.isNotification] },
80
- { type: 'write', event: ['write', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristicUuid] },
81
- { type: 'broadcast', event: ['broadcast', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristicUuid, mainEvent.state] },
82
- { type: 'notify', event: ['notify', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristicUuid, mainEvent.state] },
83
- { type: 'descriptorsDiscover', event: ['descriptorsDiscover', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristicUuid, mainEvent.descriptors] },
84
- { type: 'valueRead', event: ['valueRead', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristicUuid, mainEvent.descriptorUuid, null] },
85
- { type: 'valueWrite', event: ['valueWrite', mainEvent.peripheralUuid, mainEvent.serviceUuid, mainEvent.characteristicUuid, mainEvent.descriptorUuid] },
86
- { type: 'handleRead', event: ['handleRead', mainEvent.peripheralUuid, mainEvent.handle, null] },
87
- { type: 'handleWrite', event: ['handleWrite', mainEvent.peripheralUuid, mainEvent.handle] },
88
- { type: 'handleNotify', event: ['handleNotify', mainEvent.peripheralUuid, mainEvent.handle, null] }
89
- ].forEach(args => {
90
- const { type, event } = args;
91
- it(`should emit ${type}`, () => {
92
- bindings.emit = sinon.spy();
93
-
94
- const eventMsg = Object.assign({ type }, mainEvent);
95
- bindings._onMessage(eventMsg);
96
-
97
- assert.calledOnceWithExactly(bindings.emit, ...event);
98
- });
99
- });
100
- });
101
-
102
- describe('sendCommand', () => {
103
- it('should not callback without error', () => {
104
- const errorCallback = sinon.spy();
105
-
106
- bindings._ws.send = sinon.spy();
107
- bindings._sendCommand({ command: 3 }, errorCallback);
108
-
109
- bindings._ws.send.callArgWith(1, null);
110
-
111
- assert.calledOnceWithMatch(bindings._ws.send, '{"command":3}', sinon.match.func);
112
- assert.notCalled(errorCallback);
113
- });
114
-
115
- it('should callback error', () => {
116
- const errorCallback = sinon.spy();
117
-
118
- bindings._ws.send = sinon.spy();
119
- bindings._sendCommand({ command: 3 }, errorCallback);
120
-
121
- bindings._ws.send.callArgWith(1, 'error');
122
-
123
- assert.calledOnceWithMatch(bindings._ws.send, '{"command":3}', sinon.match.func);
124
- assert.calledOnceWithExactly(errorCallback, 'error');
125
- });
126
-
127
- it('should not callback error as it is missing', () => {
128
- bindings._ws.send = sinon.spy();
129
- bindings._sendCommand({ command: 3 });
130
-
131
- bindings._ws.send.callArgWith(1, 'error');
132
-
133
- assert.calledOnceWithMatch(bindings._ws.send, '{"command":3}', sinon.match.func);
134
- });
135
- });
136
-
137
- it('startScanning - should emit scanStart', () => {
138
- const callback = sinon.spy();
139
- const serviceUuids = ['service'];
140
- const allowDuplicates = true;
141
-
142
- bindings._sendCommand = sinon.spy();
143
- bindings.on('scanStart', callback);
144
- bindings.startScanning(serviceUuids, allowDuplicates);
145
-
146
- const startCommand = {
147
- action: 'startScanning',
148
- serviceUuids,
149
- allowDuplicates
150
- };
151
- assert.calledOnceWithExactly(callback);
152
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
153
- should(bindings._startScanCommand).deepEqual(startCommand);
154
- });
155
-
156
- it('stopScanning - should emit scanStop', () => {
157
- const callback = sinon.spy();
158
-
159
- bindings._startScanCommand = 'command';
160
- bindings._sendCommand = sinon.spy();
161
- bindings.on('scanStop', callback);
162
- bindings.stopScanning();
163
-
164
- const startCommand = {
165
- action: 'stopScanning'
166
- };
167
- assert.calledOnceWithExactly(callback);
168
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
169
- should(bindings._startScanCommand).equal(null);
170
- });
171
-
172
- it('connect - should send connect command', () => {
173
- const deviceUuid = 'deviceUuid';
174
-
175
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
176
- bindings._startScanCommand = 'command';
177
- bindings._sendCommand = sinon.spy();
178
- bindings.connect(deviceUuid);
179
-
180
- const startCommand = {
181
- action: 'connect',
182
- peripheralUuid: 'uuid'
183
- };
184
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
185
- });
186
-
187
- it('disconnect - should send disconnect command', () => {
188
- const deviceUuid = 'deviceUuid';
189
-
190
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
191
- bindings._startScanCommand = 'command';
192
- bindings._sendCommand = sinon.spy();
193
- bindings.disconnect(deviceUuid);
194
-
195
- const startCommand = {
196
- action: 'disconnect',
197
- peripheralUuid: 'uuid'
198
- };
199
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
200
- });
201
-
202
- it('updateRssi - should send updateRssi command', () => {
203
- const deviceUuid = 'deviceUuid';
204
-
205
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
206
- bindings._startScanCommand = 'command';
207
- bindings._sendCommand = sinon.spy();
208
- bindings.updateRssi(deviceUuid);
209
-
210
- const startCommand = {
211
- action: 'updateRssi',
212
- peripheralUuid: 'uuid'
213
- };
214
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
215
- });
216
-
217
- it('discoverServices - should send discoverServices command', () => {
218
- const deviceUuid = 'deviceUuid';
219
- const uuids = 'uuids';
220
-
221
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
222
- bindings._startScanCommand = 'command';
223
- bindings._sendCommand = sinon.spy();
224
- bindings.discoverServices(deviceUuid, uuids);
225
-
226
- const startCommand = {
227
- action: 'discoverServices',
228
- peripheralUuid: 'uuid',
229
- uuids
230
- };
231
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
232
- });
233
-
234
- it('discoverIncludedServices - should send discoverIncludedServices command', () => {
235
- const deviceUuid = 'deviceUuid';
236
- const serviceUuid = 'serviceUuid';
237
- const serviceUuids = 'serviceUuids';
238
-
239
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
240
- bindings._startScanCommand = 'command';
241
- bindings._sendCommand = sinon.spy();
242
- bindings.discoverIncludedServices(deviceUuid, serviceUuid, serviceUuids);
243
-
244
- const startCommand = {
245
- action: 'discoverIncludedServices',
246
- peripheralUuid: 'uuid',
247
- serviceUuid,
248
- serviceUuids
249
- };
250
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
251
- });
252
-
253
- it('discoverCharacteristics - should send discoverIncludedServices command', () => {
254
- const deviceUuid = 'deviceUuid';
255
- const serviceUuid = 'serviceUuid';
256
- const characteristicUuids = 'characteristicUuids';
257
-
258
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
259
- bindings._startScanCommand = 'command';
260
- bindings._sendCommand = sinon.spy();
261
- bindings.discoverCharacteristics(deviceUuid, serviceUuid, characteristicUuids);
262
-
263
- const startCommand = {
264
- action: 'discoverCharacteristics',
265
- peripheralUuid: 'uuid',
266
- serviceUuid,
267
- characteristicUuids
268
- };
269
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
270
- });
271
-
272
- it('read - should send read command', () => {
273
- const deviceUuid = 'deviceUuid';
274
- const serviceUuid = 'serviceUuid';
275
- const characteristicUuid = 'characteristicUuid';
276
-
277
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
278
- bindings._startScanCommand = 'command';
279
- bindings._sendCommand = sinon.spy();
280
- bindings.read(deviceUuid, serviceUuid, characteristicUuid);
281
-
282
- const startCommand = {
283
- action: 'read',
284
- peripheralUuid: 'uuid',
285
- serviceUuid,
286
- characteristicUuid
287
- };
288
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
289
- });
290
-
291
- it('write - should send write command', () => {
292
- const deviceUuid = 'deviceUuid';
293
- const serviceUuid = 'serviceUuid';
294
- const characteristicUuid = 'characteristicUuid';
295
- const data = Buffer.from([0x34, 0x12]);
296
- const withoutResponse = true;
297
-
298
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
299
- bindings._startScanCommand = 'command';
300
- bindings._sendCommand = sinon.spy();
301
- bindings.write(deviceUuid, serviceUuid, characteristicUuid, data, withoutResponse);
302
-
303
- const startCommand = {
304
- action: 'write',
305
- peripheralUuid: 'uuid',
306
- serviceUuid,
307
- characteristicUuid,
308
- data: '3412',
309
- withoutResponse
310
- };
311
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
312
- });
313
-
314
- it('broadcast - should send broadcast command', () => {
315
- const deviceUuid = 'deviceUuid';
316
- const serviceUuid = 'serviceUuid';
317
- const characteristicUuid = 'characteristicUuid';
318
- const broadcast = true;
319
-
320
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
321
- bindings._startScanCommand = 'command';
322
- bindings._sendCommand = sinon.spy();
323
- bindings.broadcast(deviceUuid, serviceUuid, characteristicUuid, broadcast);
324
-
325
- const startCommand = {
326
- action: 'broadcast',
327
- peripheralUuid: 'uuid',
328
- serviceUuid,
329
- characteristicUuid,
330
- broadcast
331
- };
332
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
333
- });
334
-
335
- it('notify - should send notify command', () => {
336
- const deviceUuid = 'deviceUuid';
337
- const serviceUuid = 'serviceUuid';
338
- const characteristicUuid = 'characteristicUuid';
339
- const notify = true;
340
-
341
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
342
- bindings._startScanCommand = 'command';
343
- bindings._sendCommand = sinon.spy();
344
- bindings.notify(deviceUuid, serviceUuid, characteristicUuid, notify);
345
-
346
- const startCommand = {
347
- action: 'notify',
348
- peripheralUuid: 'uuid',
349
- serviceUuid,
350
- characteristicUuid,
351
- notify
352
- };
353
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
354
- });
355
-
356
- it('discoverDescriptors - should send discoverDescriptors command', () => {
357
- const deviceUuid = 'deviceUuid';
358
- const serviceUuid = 'serviceUuid';
359
- const characteristicUuid = 'characteristicUuid';
360
-
361
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
362
- bindings._startScanCommand = 'command';
363
- bindings._sendCommand = sinon.spy();
364
- bindings.discoverDescriptors(deviceUuid, serviceUuid, characteristicUuid);
365
-
366
- const startCommand = {
367
- action: 'discoverDescriptors',
368
- peripheralUuid: 'uuid',
369
- serviceUuid,
370
- characteristicUuid
371
- };
372
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
373
- });
374
-
375
- it('readValue - should send readValue command', () => {
376
- const deviceUuid = 'deviceUuid';
377
- const serviceUuid = 'serviceUuid';
378
- const characteristicUuid = 'characteristicUuid';
379
- const descriptorUuid = 'descriptorUuid';
380
-
381
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
382
- bindings._startScanCommand = 'command';
383
- bindings._sendCommand = sinon.spy();
384
- bindings.readValue(deviceUuid, serviceUuid, characteristicUuid, descriptorUuid);
385
-
386
- const startCommand = {
387
- action: 'readValue',
388
- peripheralUuid: 'uuid',
389
- serviceUuid,
390
- characteristicUuid,
391
- descriptorUuid
392
- };
393
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
394
- });
395
-
396
- it('writeValue - should send writeValue command', () => {
397
- const deviceUuid = 'deviceUuid';
398
- const serviceUuid = 'serviceUuid';
399
- const characteristicUuid = 'characteristicUuid';
400
- const descriptorUuid = 'descriptorUuid';
401
- const data = Buffer.from([0x34, 0x12]);
402
-
403
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
404
- bindings._startScanCommand = 'command';
405
- bindings._sendCommand = sinon.spy();
406
- bindings.writeValue(deviceUuid, serviceUuid, characteristicUuid, descriptorUuid, data);
407
-
408
- const startCommand = {
409
- action: 'writeValue',
410
- peripheralUuid: 'uuid',
411
- serviceUuid,
412
- characteristicUuid,
413
- descriptorUuid,
414
- data: '3412'
415
- };
416
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
417
- });
418
-
419
- it('readHandle - should send readHandle command', () => {
420
- const deviceUuid = 'deviceUuid';
421
- const handle = 'handle';
422
-
423
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
424
- bindings._startScanCommand = 'command';
425
- bindings._sendCommand = sinon.spy();
426
- bindings.readHandle(deviceUuid, handle);
427
-
428
- const startCommand = {
429
- action: 'readHandle',
430
- peripheralUuid: 'uuid',
431
- handle
432
- };
433
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
434
- });
435
-
436
- it('writeHandle - should send writeHandle command', () => {
437
- const deviceUuid = 'deviceUuid';
438
- const handle = 'handle';
439
- const data = Buffer.from([0x34, 0x12]);
440
- const withoutResponse = true;
441
-
442
- bindings._peripherals[deviceUuid] = { uuid: 'uuid' };
443
- bindings._startScanCommand = 'command';
444
- bindings._sendCommand = sinon.spy();
445
- bindings.writeHandle(deviceUuid, handle, data, withoutResponse);
446
-
447
- const startCommand = {
448
- action: 'writeHandle',
449
- peripheralUuid: 'uuid',
450
- handle,
451
- data: '3412',
452
- withoutResponse
453
- };
454
- assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
455
- });
456
- });
File without changes
package/with-bindings.js DELETED
@@ -1,5 +0,0 @@
1
- const Noble = require('./lib/noble');
2
-
3
- module.exports = function (bindings) {
4
- return new Noble(bindings);
5
- };
@@ -1,6 +0,0 @@
1
- module.exports = function (options) {
2
- const Noble = require('./lib/noble');
3
- const bindings = require('./lib/resolve-bindings')(options);
4
-
5
- return new Noble(bindings);
6
- };