@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.
- package/README.md +393 -650
- package/examples/advertisement-discovery.js +57 -48
- package/examples/connect-address.js +59 -34
- package/examples/echo.js +59 -69
- package/examples/enter-exit.js +55 -49
- package/examples/multiple-bindings.js +53 -0
- package/examples/peripheral-explorer-async.js +39 -21
- package/examples/peripheral-explorer.ts +52 -0
- package/index.d.ts +249 -209
- package/index.js +4 -1
- package/jest.config.js +4 -0
- package/lib/characteristic.js +153 -127
- package/lib/{win/src/callbacks.h → common/include/Emit.h} +17 -14
- package/lib/common/include/Peripheral.h +31 -0
- package/lib/common/include/ThreadSafeCallback.h +95 -0
- package/lib/{win/src/callbacks.cc → common/src/Emit.cc} +111 -68
- package/lib/descriptor.js +57 -54
- package/lib/hci-socket/acl-stream.js +2 -4
- package/lib/hci-socket/bindings.js +96 -73
- package/lib/hci-socket/gap.js +2 -3
- package/lib/hci-socket/gatt.js +2 -5
- package/lib/hci-socket/hci.js +19 -7
- package/lib/hci-socket/signaling.js +2 -3
- package/lib/hci-socket/smp.js +2 -3
- package/lib/hci-socket/vs.js +1 -0
- package/lib/mac/binding.gyp +5 -7
- package/lib/mac/bindings.js +1 -3
- package/lib/mac/src/ble_manager.h +1 -8
- package/lib/mac/src/ble_manager.mm +87 -44
- package/lib/mac/src/napi_objc.h +1 -0
- package/lib/mac/src/napi_objc.mm +0 -6
- package/lib/mac/src/noble_mac.h +5 -3
- package/lib/mac/src/noble_mac.mm +99 -57
- package/lib/mac/src/objc_cpp.h +3 -2
- package/lib/mac/src/objc_cpp.mm +0 -6
- package/lib/noble.js +579 -488
- package/lib/peripheral.js +171 -174
- package/lib/resolve-bindings.js +37 -30
- package/lib/service.js +58 -55
- package/lib/win/binding.gyp +4 -11
- package/lib/win/bindings.js +1 -3
- package/lib/win/src/ble_manager.cc +291 -166
- package/lib/win/src/ble_manager.h +11 -13
- package/lib/win/src/napi_winrt.cc +1 -7
- package/lib/win/src/napi_winrt.h +1 -1
- package/lib/win/src/noble_winrt.cc +88 -61
- package/lib/win/src/noble_winrt.h +5 -3
- package/lib/win/src/notify_map.cc +0 -7
- package/lib/win/src/notify_map.h +1 -8
- package/lib/win/src/peripheral_winrt.cc +29 -11
- package/lib/win/src/peripheral_winrt.h +1 -1
- package/lib/win/src/radio_watcher.cc +79 -69
- package/lib/win/src/radio_watcher.h +30 -11
- package/lib/win/src/winrt_cpp.cc +1 -1
- package/lib/win/src/winrt_cpp.h +3 -0
- package/package.json +14 -17
- package/prebuilds/darwin-x64+arm64/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-ia32/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-x64/@stoprocent+noble.node +0 -0
- package/test/lib/characteristic.test.js +202 -322
- package/test/lib/descriptor.test.js +62 -95
- package/test/lib/hci-socket/acl-stream.test.js +112 -108
- package/test/lib/hci-socket/bindings.test.js +576 -365
- package/test/lib/hci-socket/hci.test.js +442 -473
- package/test/lib/hci-socket/signaling.test.js +45 -48
- package/test/lib/hci-socket/smp.test.js +144 -142
- package/test/lib/hci-socket/vs.test.js +193 -18
- package/test/lib/peripheral.test.js +492 -322
- package/test/lib/resolve-bindings.test.js +207 -82
- package/test/lib/service.test.js +79 -88
- package/test/noble.test.js +381 -1085
- package/.editorconfig +0 -11
- package/.nycrc.json +0 -4
- package/codecov.yml +0 -5
- package/examples/cache-gatt-discovery.js +0 -198
- package/examples/cache-gatt-reconnect.js +0 -164
- package/examples/ext-advertisement-discovery.js +0 -65
- package/examples/peripheral-explorer.js +0 -225
- package/examples/pizza/central.js +0 -194
- package/examples/pizza/pizza.js +0 -60
- package/examples/test/test.custom.js +0 -131
- package/examples/uart-bind-params.js +0 -28
- package/lib/distributed/bindings.js +0 -326
- package/lib/mac/src/callbacks.cc +0 -222
- package/lib/mac/src/callbacks.h +0 -84
- package/lib/mac/src/peripheral.h +0 -23
- package/lib/resolve-bindings-web.js +0 -9
- package/lib/webbluetooth/bindings.js +0 -368
- package/lib/websocket/bindings.js +0 -321
- package/lib/win/src/peripheral.h +0 -23
- package/test/lib/distributed/bindings.test.js +0 -918
- package/test/lib/webbluetooth/bindings.test.js +0 -190
- package/test/lib/websocket/bindings.test.js +0 -456
- package/test/mocha.setup.js +0 -0
- package/with-bindings.js +0 -5
- package/with-custom-binding.js +0 -6
- package/ws-slave.js +0 -404
package/ws-slave.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/* jshint loopfunc: true */
|
|
2
|
-
const WebSocket = require('ws');
|
|
3
|
-
|
|
4
|
-
const noble = require('./index');
|
|
5
|
-
|
|
6
|
-
const serverMode = !process.argv[2];
|
|
7
|
-
const port = 0xB1e;
|
|
8
|
-
const host = process.argv[2];
|
|
9
|
-
|
|
10
|
-
let ws;
|
|
11
|
-
let wss;
|
|
12
|
-
|
|
13
|
-
if (serverMode) {
|
|
14
|
-
console.log('noble - ws slave - server mode');
|
|
15
|
-
wss = new WebSocket.Server({
|
|
16
|
-
port: 0xB1e
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
wss.on('connection', function (ws_) {
|
|
20
|
-
console.log('ws -> connection');
|
|
21
|
-
|
|
22
|
-
ws = ws_;
|
|
23
|
-
|
|
24
|
-
ws.on('message', onMessage);
|
|
25
|
-
|
|
26
|
-
ws.on('close', function () {
|
|
27
|
-
console.log('ws -> close');
|
|
28
|
-
noble.stopScanning();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
noble.on('stateChange', function (state) {
|
|
32
|
-
sendEvent({
|
|
33
|
-
type: 'stateChange',
|
|
34
|
-
state
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Send poweredOn if already in this state.
|
|
39
|
-
if (noble.state === 'poweredOn') {
|
|
40
|
-
sendEvent({
|
|
41
|
-
type: 'stateChange',
|
|
42
|
-
state: 'poweredOn'
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
} else {
|
|
47
|
-
ws = new WebSocket('ws://' + host + ':' + port);
|
|
48
|
-
|
|
49
|
-
ws.on('open', function () {
|
|
50
|
-
console.log('ws -> open');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
ws.on('message', function (message) {
|
|
54
|
-
onMessage(message);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
ws.on('close', function () {
|
|
58
|
-
console.log('ws -> close');
|
|
59
|
-
|
|
60
|
-
noble.stopScanning();
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const peripherals = {};
|
|
65
|
-
|
|
66
|
-
// TODO: open/close ws on state change
|
|
67
|
-
|
|
68
|
-
function sendEvent (event) {
|
|
69
|
-
const message = JSON.stringify(event);
|
|
70
|
-
|
|
71
|
-
console.log('ws -> send: ' + message);
|
|
72
|
-
|
|
73
|
-
const clients = serverMode ? wss.clients : [ws];
|
|
74
|
-
|
|
75
|
-
for (let i = 0; i < clients.length; i++) {
|
|
76
|
-
clients[i].send(message);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const onMessage = function (message) {
|
|
81
|
-
console.log('ws -> message: ' + message);
|
|
82
|
-
|
|
83
|
-
const command = JSON.parse(message);
|
|
84
|
-
|
|
85
|
-
const action = command.action;
|
|
86
|
-
const peripheralUuid = command.peripheralUuid;
|
|
87
|
-
const serviceUuids = command.serviceUuids;
|
|
88
|
-
const serviceUuid = command.serviceUuid;
|
|
89
|
-
const characteristicUuids = command.characteristicUuids;
|
|
90
|
-
const characteristicUuid = command.characteristicUuid;
|
|
91
|
-
const data = command.data ? Buffer.from(command.data, 'hex') : null;
|
|
92
|
-
const withoutResponse = command.withoutResponse;
|
|
93
|
-
const broadcast = command.broadcast;
|
|
94
|
-
const notify = command.notify;
|
|
95
|
-
const descriptorUuid = command.descriptorUuid;
|
|
96
|
-
let handle;
|
|
97
|
-
|
|
98
|
-
const peripheral = peripherals[peripheralUuid];
|
|
99
|
-
let service = null;
|
|
100
|
-
let characteristic = null;
|
|
101
|
-
let descriptor = null;
|
|
102
|
-
|
|
103
|
-
if (peripheral && serviceUuid) {
|
|
104
|
-
const services = peripheral.services;
|
|
105
|
-
|
|
106
|
-
for (const i in services) {
|
|
107
|
-
if (services[i].uuid === serviceUuid) {
|
|
108
|
-
service = services[i];
|
|
109
|
-
|
|
110
|
-
if (characteristicUuid) {
|
|
111
|
-
const characteristics = service.characteristics;
|
|
112
|
-
|
|
113
|
-
for (const j in characteristics) {
|
|
114
|
-
if (characteristics[j].uuid === characteristicUuid) {
|
|
115
|
-
characteristic = characteristics[j];
|
|
116
|
-
|
|
117
|
-
if (descriptorUuid) {
|
|
118
|
-
const descriptors = characteristic.descriptors;
|
|
119
|
-
|
|
120
|
-
for (const k in descriptors) {
|
|
121
|
-
if (descriptors[k].uuid === descriptorUuid) {
|
|
122
|
-
descriptor = descriptors[k];
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (action === 'startScanning') {
|
|
137
|
-
noble.startScanning(serviceUuids, command.allowDuplicates);
|
|
138
|
-
} else if (action === 'stopScanning') {
|
|
139
|
-
noble.stopScanning();
|
|
140
|
-
} else if (action === 'connect') {
|
|
141
|
-
peripheral.connect();
|
|
142
|
-
} else if (action === 'disconnect') {
|
|
143
|
-
peripheral.disconnect();
|
|
144
|
-
} else if (action === 'updateRssi') {
|
|
145
|
-
peripheral.updateRssi();
|
|
146
|
-
} else if (action === 'discoverServices') {
|
|
147
|
-
peripheral.discoverServices(command.uuids);
|
|
148
|
-
} else if (action === 'discoverIncludedServices') {
|
|
149
|
-
service.discoverIncludedServices(serviceUuids);
|
|
150
|
-
} else if (action === 'discoverCharacteristics') {
|
|
151
|
-
service.discoverCharacteristics(characteristicUuids);
|
|
152
|
-
} else if (action === 'read') {
|
|
153
|
-
characteristic.read();
|
|
154
|
-
} else if (action === 'write') {
|
|
155
|
-
characteristic.write(data, withoutResponse);
|
|
156
|
-
} else if (action === 'broadcast') {
|
|
157
|
-
characteristic.broadcast(broadcast);
|
|
158
|
-
} else if (action === 'notify') {
|
|
159
|
-
characteristic.notify(notify);
|
|
160
|
-
} else if (action === 'discoverDescriptors') {
|
|
161
|
-
characteristic.discoverDescriptors();
|
|
162
|
-
} else if (action === 'readValue') {
|
|
163
|
-
descriptor.readValue();
|
|
164
|
-
} else if (action === 'writeValue') {
|
|
165
|
-
descriptor.writeValue(data);
|
|
166
|
-
} else if (action === 'readHandle') {
|
|
167
|
-
peripheral.readHandle(handle);
|
|
168
|
-
} else if (action === 'writeHandle') {
|
|
169
|
-
peripheral.writeHandle(handle, data, withoutResponse);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
noble.on('discover', function (peripheral) {
|
|
174
|
-
peripherals[peripheral.uuid] = peripheral;
|
|
175
|
-
|
|
176
|
-
peripheral.on('connect', function () {
|
|
177
|
-
sendEvent({
|
|
178
|
-
type: 'connect',
|
|
179
|
-
peripheralUuid: this.uuid
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
peripheral.on('disconnect', function () {
|
|
184
|
-
sendEvent({
|
|
185
|
-
type: 'disconnect',
|
|
186
|
-
peripheralUuid: this.uuid
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
for (const i in this.services) {
|
|
190
|
-
for (const j in this.services[i].characteristics) {
|
|
191
|
-
for (const k in this.services[i].characteristics[j].descriptors) {
|
|
192
|
-
this.services[i].characteristics[j].descriptors[k].removeAllListeners();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
this.services[i].characteristics[j].removeAllListeners();
|
|
196
|
-
}
|
|
197
|
-
this.services[i].removeAllListeners();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
this.removeAllListeners();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
peripheral.on('rssiUpdate', function (rssi) {
|
|
204
|
-
sendEvent({
|
|
205
|
-
type: 'rssiUpdate',
|
|
206
|
-
peripheralUuid: this.uuid,
|
|
207
|
-
rssi
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
peripheral.on('servicesDiscover', function (services) {
|
|
212
|
-
const peripheral = this;
|
|
213
|
-
const serviceUuids = [];
|
|
214
|
-
|
|
215
|
-
const includedServicesDiscover = function (includedServiceUuids) {
|
|
216
|
-
sendEvent({
|
|
217
|
-
type: 'includedServicesDiscover',
|
|
218
|
-
peripheralUuid: peripheral.uuid,
|
|
219
|
-
serviceUuid: this.uuid,
|
|
220
|
-
includedServiceUuids
|
|
221
|
-
});
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
const characteristicsDiscover = function (characteristics) {
|
|
225
|
-
const service = this;
|
|
226
|
-
const discoveredCharacteristics = [];
|
|
227
|
-
|
|
228
|
-
const read = function (data, isNotification) {
|
|
229
|
-
const characteristic = this;
|
|
230
|
-
|
|
231
|
-
sendEvent({
|
|
232
|
-
type: 'read',
|
|
233
|
-
peripheralUuid: peripheral.uuid,
|
|
234
|
-
serviceUuid: service.uuid,
|
|
235
|
-
characteristicUuid: characteristic.uuid,
|
|
236
|
-
data: data.toString('hex'),
|
|
237
|
-
isNotification
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const write = function () {
|
|
242
|
-
const characteristic = this;
|
|
243
|
-
|
|
244
|
-
sendEvent({
|
|
245
|
-
type: 'write',
|
|
246
|
-
peripheralUuid: peripheral.uuid,
|
|
247
|
-
serviceUuid: service.uuid,
|
|
248
|
-
characteristicUuid: characteristic.uuid
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
const broadcast = function (state) {
|
|
253
|
-
const characteristic = this;
|
|
254
|
-
|
|
255
|
-
sendEvent({
|
|
256
|
-
type: 'broadcast',
|
|
257
|
-
peripheralUuid: peripheral.uuid,
|
|
258
|
-
serviceUuid: service.uuid,
|
|
259
|
-
characteristicUuid: characteristic.uuid,
|
|
260
|
-
state
|
|
261
|
-
});
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
const notify = function (state) {
|
|
265
|
-
const characteristic = this;
|
|
266
|
-
|
|
267
|
-
sendEvent({
|
|
268
|
-
type: 'notify',
|
|
269
|
-
peripheralUuid: peripheral.uuid,
|
|
270
|
-
serviceUuid: service.uuid,
|
|
271
|
-
characteristicUuid: characteristic.uuid,
|
|
272
|
-
state
|
|
273
|
-
});
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
const descriptorsDiscover = function (descriptors) {
|
|
277
|
-
const characteristic = this;
|
|
278
|
-
|
|
279
|
-
const discoveredDescriptors = [];
|
|
280
|
-
|
|
281
|
-
const valueRead = function (data) {
|
|
282
|
-
const descriptor = this;
|
|
283
|
-
|
|
284
|
-
sendEvent({
|
|
285
|
-
type: 'valueRead',
|
|
286
|
-
peripheralUuid: peripheral.uuid,
|
|
287
|
-
serviceUuid: service.uuid,
|
|
288
|
-
characteristicUuid: characteristic.uuid,
|
|
289
|
-
descriptorUuid: descriptor.uuid,
|
|
290
|
-
data: data.toString('hex')
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
const valueWrite = function (data) {
|
|
295
|
-
const descriptor = this;
|
|
296
|
-
|
|
297
|
-
sendEvent({
|
|
298
|
-
type: 'valueWrite',
|
|
299
|
-
peripheralUuid: peripheral.uuid,
|
|
300
|
-
serviceUuid: service.uuid,
|
|
301
|
-
characteristicUuid: characteristic.uuid,
|
|
302
|
-
descriptorUuid: descriptor.uuid
|
|
303
|
-
});
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
for (const k in descriptors) {
|
|
307
|
-
descriptors[k].on('valueRead', valueRead);
|
|
308
|
-
|
|
309
|
-
descriptors[k].on('valueWrite', valueWrite);
|
|
310
|
-
|
|
311
|
-
discoveredDescriptors.push(descriptors[k].uuid);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
sendEvent({
|
|
315
|
-
type: 'descriptorsDiscover',
|
|
316
|
-
peripheralUuid: peripheral.uuid,
|
|
317
|
-
serviceUuid: service.uuid,
|
|
318
|
-
characteristicUuid: this.uuid,
|
|
319
|
-
descriptors: discoveredDescriptors
|
|
320
|
-
});
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
for (let j = 0; j < characteristics.length; j++) {
|
|
324
|
-
characteristics[j].on('read', read);
|
|
325
|
-
|
|
326
|
-
characteristics[j].on('write', write);
|
|
327
|
-
|
|
328
|
-
characteristics[j].on('broadcast', broadcast);
|
|
329
|
-
|
|
330
|
-
characteristics[j].on('notify', notify);
|
|
331
|
-
|
|
332
|
-
characteristics[j].on('descriptorsDiscover', descriptorsDiscover);
|
|
333
|
-
|
|
334
|
-
discoveredCharacteristics.push({
|
|
335
|
-
uuid: characteristics[j].uuid,
|
|
336
|
-
properties: characteristics[j].properties
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
sendEvent({
|
|
341
|
-
type: 'characteristicsDiscover',
|
|
342
|
-
peripheralUuid: peripheral.uuid,
|
|
343
|
-
serviceUuid: this.uuid,
|
|
344
|
-
characteristics: discoveredCharacteristics
|
|
345
|
-
});
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
for (const i in services) {
|
|
349
|
-
services[i].on('includedServicesDiscover', includedServicesDiscover);
|
|
350
|
-
|
|
351
|
-
services[i].on('characteristicsDiscover', characteristicsDiscover);
|
|
352
|
-
|
|
353
|
-
serviceUuids.push(services[i].uuid);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
sendEvent({
|
|
357
|
-
type: 'servicesDiscover',
|
|
358
|
-
peripheralUuid: this.uuid,
|
|
359
|
-
serviceUuids
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
peripheral.on('handleRead', function (handle, data) {
|
|
364
|
-
sendEvent({
|
|
365
|
-
type: 'handleRead',
|
|
366
|
-
peripheralUuid: this.uuid,
|
|
367
|
-
handle,
|
|
368
|
-
data: data.toString('hex')
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
peripheral.on('handleWrite', function (handle) {
|
|
373
|
-
sendEvent({
|
|
374
|
-
type: 'handleWrite',
|
|
375
|
-
peripheralUuid: this.uuid,
|
|
376
|
-
handle
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
peripheral.on('handleNotify', function (handle, data) {
|
|
381
|
-
sendEvent({
|
|
382
|
-
type: 'handleNotify',
|
|
383
|
-
peripheralUuid: this.uuid,
|
|
384
|
-
handle,
|
|
385
|
-
data: data.toString('hex')
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
sendEvent({
|
|
390
|
-
type: 'discover',
|
|
391
|
-
peripheralUuid: peripheral.uuid,
|
|
392
|
-
address: peripheral.address,
|
|
393
|
-
addressType: peripheral.addressType,
|
|
394
|
-
connectable: peripheral.connectable,
|
|
395
|
-
advertisement: {
|
|
396
|
-
localName: peripheral.advertisement.localName,
|
|
397
|
-
txPowerLevel: peripheral.advertisement.txPowerLevel,
|
|
398
|
-
serviceUuids: peripheral.advertisement.serviceUuids,
|
|
399
|
-
manufacturerData: (peripheral.advertisement.manufacturerData ? peripheral.advertisement.manufacturerData.toString('hex') : null),
|
|
400
|
-
serviceData: (peripheral.advertisement.serviceData ? peripheral.advertisement.serviceData.toString('hex') : null)
|
|
401
|
-
},
|
|
402
|
-
rssi: peripheral.rssi
|
|
403
|
-
});
|
|
404
|
-
});
|