@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.
- package/.github/workflows/fediverse-action.yml +16 -0
- package/.github/workflows/nodepackage.yml +6 -15
- package/.github/workflows/npm-publish.yml +2 -2
- package/.github/workflows/prebuild.yml +65 -0
- package/README.md +11 -3
- package/examples/advertisement-discovery.js +1 -1
- package/examples/cache-gatt-discovery.js +1 -1
- package/examples/cache-gatt-reconnect.js +1 -1
- package/examples/echo.js +1 -1
- package/examples/enter-exit.js +2 -2
- package/examples/ext-advertisement-discovery.js +65 -0
- package/examples/peripheral-explorer-async.js +1 -1
- package/examples/peripheral-explorer.js +1 -1
- package/examples/pizza/central.js +1 -1
- package/index.d.ts +187 -194
- package/index.js +1 -6
- package/lib/distributed/bindings.js +33 -33
- package/lib/hci-socket/bindings.js +1 -3
- package/lib/hci-socket/crypto.js +4 -4
- package/lib/hci-socket/gap.js +22 -18
- package/lib/hci-socket/gatt.js +4 -4
- package/lib/hci-socket/hci.js +2 -2
- package/lib/noble.js +10 -6
- package/lib/peripheral.js +0 -7
- package/lib/resolve-bindings.js +39 -3
- package/lib/webbluetooth/bindings.js +2 -2
- package/lib/websocket/bindings.js +32 -32
- package/lib/win/src/ble_manager.cc +4 -1
- package/lib/win/src/ble_manager.h +1 -1
- package/lib/win/src/peripheral_winrt.cc +2 -0
- package/lib/win/src/radio_watcher.cc +1 -0
- package/lib/win/src/winrt_cpp.cc +1 -0
- package/package.json +28 -24
- package/test/lib/distributed/bindings.test.js +15 -15
- package/test/lib/hci-socket/gap.test.js +39 -0
- package/test/lib/webbluetooth/bindings.test.js +2 -2
- package/test/lib/websocket/bindings.test.js +2 -2
- package/test/mocha.setup.js +0 -0
- package/test/noble.test.js +12 -11
- package/test.custom.js +131 -0
- package/test.js +1 -1
- package/with-custom-binding.js +6 -0
- package/ws-slave.js +10 -10
- package/lib/manufacture.js +0 -48
- package/test/lib/manufacture.test.js +0 -77
|
@@ -97,7 +97,7 @@ describe('webbluetooth bindings', () => {
|
|
|
97
97
|
uuid: device.id,
|
|
98
98
|
address: device.id,
|
|
99
99
|
advertisement: { localName: device.name }, // advertisement,
|
|
100
|
-
device
|
|
100
|
+
device,
|
|
101
101
|
cachedServices: {},
|
|
102
102
|
localName: device.name,
|
|
103
103
|
serviceUuids: options.services
|
|
@@ -128,7 +128,7 @@ describe('webbluetooth bindings', () => {
|
|
|
128
128
|
uuid: device.id,
|
|
129
129
|
address: device.id,
|
|
130
130
|
advertisement: { localName: device.name }, // advertisement,
|
|
131
|
-
device
|
|
131
|
+
device,
|
|
132
132
|
cachedServices: {},
|
|
133
133
|
localName: device.name,
|
|
134
134
|
serviceUuids: [4660, 22136, 'service'],
|
|
@@ -145,8 +145,8 @@ describe('webbluetooth bindings', () => {
|
|
|
145
145
|
|
|
146
146
|
const startCommand = {
|
|
147
147
|
action: 'startScanning',
|
|
148
|
-
serviceUuids
|
|
149
|
-
allowDuplicates
|
|
148
|
+
serviceUuids,
|
|
149
|
+
allowDuplicates
|
|
150
150
|
};
|
|
151
151
|
assert.calledOnceWithExactly(callback);
|
|
152
152
|
assert.calledOnceWithExactly(bindings._sendCommand, startCommand);
|
|
File without changes
|
package/test/noble.test.js
CHANGED
|
@@ -563,7 +563,7 @@ describe('noble', () => {
|
|
|
563
563
|
should(noble._services).have.keys(uuid);
|
|
564
564
|
should(noble._characteristics).have.keys(uuid);
|
|
565
565
|
should(noble._descriptors).have.keys(uuid);
|
|
566
|
-
should(noble._discoveredPeripheralUUids).deepEqual(
|
|
566
|
+
should(noble._discoveredPeripheralUUids).deepEqual({ uuid: true });
|
|
567
567
|
|
|
568
568
|
assert.calledOnceWithExactly(eventCallback, peripheral);
|
|
569
569
|
});
|
|
@@ -613,7 +613,7 @@ describe('noble', () => {
|
|
|
613
613
|
should(noble._services).be.empty();
|
|
614
614
|
should(noble._characteristics).be.empty();
|
|
615
615
|
should(noble._descriptors).be.empty();
|
|
616
|
-
should(noble._discoveredPeripheralUUids).deepEqual(
|
|
616
|
+
should(noble._discoveredPeripheralUUids).deepEqual({ uuid: true });
|
|
617
617
|
|
|
618
618
|
assert.calledOnceWithExactly(eventCallback, peripheral);
|
|
619
619
|
});
|
|
@@ -627,7 +627,7 @@ describe('noble', () => {
|
|
|
627
627
|
const rssi = 'rssi';
|
|
628
628
|
|
|
629
629
|
// register peripheral
|
|
630
|
-
noble._discoveredPeripheralUUids =
|
|
630
|
+
noble._discoveredPeripheralUUids = { uuid: true };
|
|
631
631
|
noble._allowDuplicates = true;
|
|
632
632
|
|
|
633
633
|
const eventCallback = sinon.spy();
|
|
@@ -654,7 +654,7 @@ describe('noble', () => {
|
|
|
654
654
|
const rssi = 'rssi';
|
|
655
655
|
|
|
656
656
|
// register peripheral
|
|
657
|
-
noble._discoveredPeripheralUUids =
|
|
657
|
+
noble._discoveredPeripheralUUids = { uuid: true };
|
|
658
658
|
|
|
659
659
|
const eventCallback = sinon.spy();
|
|
660
660
|
noble.on('discover', eventCallback);
|
|
@@ -1508,25 +1508,26 @@ describe('noble', () => {
|
|
|
1508
1508
|
});
|
|
1509
1509
|
});
|
|
1510
1510
|
|
|
1511
|
-
it('onMtu - should update peripheral mtu', () => {
|
|
1511
|
+
it('onMtu - should update peripheral mtu when set before already', () => {
|
|
1512
1512
|
const peripheral = {
|
|
1513
|
-
mtu:
|
|
1513
|
+
mtu: 234
|
|
1514
1514
|
};
|
|
1515
1515
|
|
|
1516
1516
|
noble._peripherals = { uuid: peripheral };
|
|
1517
|
-
noble.onMtu('uuid',
|
|
1517
|
+
noble.onMtu('uuid', 123);
|
|
1518
1518
|
|
|
1519
|
-
should(peripheral).deepEqual({ mtu:
|
|
1519
|
+
should(peripheral).deepEqual({ mtu: 123 });
|
|
1520
1520
|
});
|
|
1521
1521
|
|
|
1522
|
-
it('onMtu - should
|
|
1522
|
+
it('onMtu - should update peripheral mtu too when empty', () => {
|
|
1523
1523
|
const peripheral = {
|
|
1524
|
+
mtu: null
|
|
1524
1525
|
};
|
|
1525
1526
|
|
|
1526
1527
|
noble._peripherals = { uuid: peripheral };
|
|
1527
|
-
noble.onMtu('uuid',
|
|
1528
|
+
noble.onMtu('uuid', 123);
|
|
1528
1529
|
|
|
1529
|
-
should(peripheral).deepEqual({ });
|
|
1530
|
+
should(peripheral).deepEqual({ mtu: 123 });
|
|
1530
1531
|
});
|
|
1531
1532
|
|
|
1532
1533
|
describe('onIncludedServicesDiscover', () => {
|
package/test.custom.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const noble = require('./with-custom-binding')({ extended: true });
|
|
2
|
+
|
|
3
|
+
console.log('noble');
|
|
4
|
+
|
|
5
|
+
noble.on('stateChange', function (state) {
|
|
6
|
+
console.log('on -> stateChange: ' + state);
|
|
7
|
+
|
|
8
|
+
if (state === 'poweredOn') {
|
|
9
|
+
noble.startScanning([], true);
|
|
10
|
+
} else {
|
|
11
|
+
noble.stopScanning();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
noble.on('scanStart', function () {
|
|
16
|
+
console.log('on -> scanStart');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
noble.on('scanStop', function () {
|
|
20
|
+
console.log('on -> scanStop');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
noble.on('discover', function (peripheral) {
|
|
24
|
+
console.log('on -> discover: ' + peripheral);
|
|
25
|
+
|
|
26
|
+
noble.stopScanning();
|
|
27
|
+
|
|
28
|
+
peripheral.on('connect', function () {
|
|
29
|
+
console.log('on -> connect');
|
|
30
|
+
this.updateRssi();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
peripheral.on('disconnect', function () {
|
|
34
|
+
console.log('on -> disconnect');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
peripheral.on('rssiUpdate', function (rssi) {
|
|
38
|
+
console.log('on -> RSSI update ' + rssi);
|
|
39
|
+
this.discoverServices();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
peripheral.on('servicesDiscover', function (services) {
|
|
43
|
+
console.log('on -> peripheral services discovered ' + services);
|
|
44
|
+
|
|
45
|
+
const serviceIndex = 0;
|
|
46
|
+
|
|
47
|
+
services[serviceIndex].on(
|
|
48
|
+
'includedServicesDiscover',
|
|
49
|
+
function (includedServiceUuids) {
|
|
50
|
+
console.log(
|
|
51
|
+
'on -> service included services discovered ' + includedServiceUuids
|
|
52
|
+
);
|
|
53
|
+
this.discoverCharacteristics();
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
services[serviceIndex].on(
|
|
58
|
+
'characteristicsDiscover',
|
|
59
|
+
function (characteristics) {
|
|
60
|
+
console.log(
|
|
61
|
+
'on -> service characteristics discovered ' + characteristics
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const characteristicIndex = 0;
|
|
65
|
+
|
|
66
|
+
characteristics[characteristicIndex].on(
|
|
67
|
+
'read',
|
|
68
|
+
function (data, isNotification) {
|
|
69
|
+
console.log(
|
|
70
|
+
'on -> characteristic read ' + data + ' ' + isNotification
|
|
71
|
+
);
|
|
72
|
+
console.log(data);
|
|
73
|
+
|
|
74
|
+
peripheral.disconnect();
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
characteristics[characteristicIndex].on('write', function () {
|
|
79
|
+
console.log('on -> characteristic write ');
|
|
80
|
+
|
|
81
|
+
peripheral.disconnect();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
characteristics[characteristicIndex].on('broadcast', function (state) {
|
|
85
|
+
console.log('on -> characteristic broadcast ' + state);
|
|
86
|
+
|
|
87
|
+
peripheral.disconnect();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
characteristics[characteristicIndex].on('notify', function (state) {
|
|
91
|
+
console.log('on -> characteristic notify ' + state);
|
|
92
|
+
|
|
93
|
+
peripheral.disconnect();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
characteristics[characteristicIndex].on(
|
|
97
|
+
'descriptorsDiscover',
|
|
98
|
+
function (descriptors) {
|
|
99
|
+
console.log('on -> descriptors discover ' + descriptors);
|
|
100
|
+
|
|
101
|
+
const descriptorIndex = 0;
|
|
102
|
+
|
|
103
|
+
descriptors[descriptorIndex].on('valueRead', function (data) {
|
|
104
|
+
console.log('on -> descriptor value read ' + data);
|
|
105
|
+
console.log(data);
|
|
106
|
+
peripheral.disconnect();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
descriptors[descriptorIndex].on('valueWrite', function () {
|
|
110
|
+
console.log('on -> descriptor value write ');
|
|
111
|
+
peripheral.disconnect();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
descriptors[descriptorIndex].readValue();
|
|
115
|
+
// descriptors[descriptorIndex].writeValue(new Buffer([0]));
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
characteristics[characteristicIndex].read();
|
|
120
|
+
// characteristics[characteristicIndex].write(new Buffer('hello'));
|
|
121
|
+
// characteristics[characteristicIndex].broadcast(true);
|
|
122
|
+
// characteristics[characteristicIndex].notify(true);
|
|
123
|
+
// characteristics[characteristicIndex].discoverDescriptors();
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
services[serviceIndex].discoverIncludedServices();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
peripheral.connect();
|
|
131
|
+
});
|
package/test.js
CHANGED
package/ws-slave.js
CHANGED
|
@@ -31,7 +31,7 @@ if (serverMode) {
|
|
|
31
31
|
noble.on('stateChange', function (state) {
|
|
32
32
|
sendEvent({
|
|
33
33
|
type: 'stateChange',
|
|
34
|
-
state
|
|
34
|
+
state
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
|
|
@@ -204,7 +204,7 @@ noble.on('discover', function (peripheral) {
|
|
|
204
204
|
sendEvent({
|
|
205
205
|
type: 'rssiUpdate',
|
|
206
206
|
peripheralUuid: this.uuid,
|
|
207
|
-
rssi
|
|
207
|
+
rssi
|
|
208
208
|
});
|
|
209
209
|
});
|
|
210
210
|
|
|
@@ -217,7 +217,7 @@ noble.on('discover', function (peripheral) {
|
|
|
217
217
|
type: 'includedServicesDiscover',
|
|
218
218
|
peripheralUuid: peripheral.uuid,
|
|
219
219
|
serviceUuid: this.uuid,
|
|
220
|
-
includedServiceUuids
|
|
220
|
+
includedServiceUuids
|
|
221
221
|
});
|
|
222
222
|
};
|
|
223
223
|
|
|
@@ -234,7 +234,7 @@ noble.on('discover', function (peripheral) {
|
|
|
234
234
|
serviceUuid: service.uuid,
|
|
235
235
|
characteristicUuid: characteristic.uuid,
|
|
236
236
|
data: data.toString('hex'),
|
|
237
|
-
isNotification
|
|
237
|
+
isNotification
|
|
238
238
|
});
|
|
239
239
|
};
|
|
240
240
|
|
|
@@ -257,7 +257,7 @@ noble.on('discover', function (peripheral) {
|
|
|
257
257
|
peripheralUuid: peripheral.uuid,
|
|
258
258
|
serviceUuid: service.uuid,
|
|
259
259
|
characteristicUuid: characteristic.uuid,
|
|
260
|
-
state
|
|
260
|
+
state
|
|
261
261
|
});
|
|
262
262
|
};
|
|
263
263
|
|
|
@@ -269,7 +269,7 @@ noble.on('discover', function (peripheral) {
|
|
|
269
269
|
peripheralUuid: peripheral.uuid,
|
|
270
270
|
serviceUuid: service.uuid,
|
|
271
271
|
characteristicUuid: characteristic.uuid,
|
|
272
|
-
state
|
|
272
|
+
state
|
|
273
273
|
});
|
|
274
274
|
};
|
|
275
275
|
|
|
@@ -356,7 +356,7 @@ noble.on('discover', function (peripheral) {
|
|
|
356
356
|
sendEvent({
|
|
357
357
|
type: 'servicesDiscover',
|
|
358
358
|
peripheralUuid: this.uuid,
|
|
359
|
-
serviceUuids
|
|
359
|
+
serviceUuids
|
|
360
360
|
});
|
|
361
361
|
});
|
|
362
362
|
|
|
@@ -364,7 +364,7 @@ noble.on('discover', function (peripheral) {
|
|
|
364
364
|
sendEvent({
|
|
365
365
|
type: 'handleRead',
|
|
366
366
|
peripheralUuid: this.uuid,
|
|
367
|
-
handle
|
|
367
|
+
handle,
|
|
368
368
|
data: data.toString('hex')
|
|
369
369
|
});
|
|
370
370
|
});
|
|
@@ -373,7 +373,7 @@ noble.on('discover', function (peripheral) {
|
|
|
373
373
|
sendEvent({
|
|
374
374
|
type: 'handleWrite',
|
|
375
375
|
peripheralUuid: this.uuid,
|
|
376
|
-
handle
|
|
376
|
+
handle
|
|
377
377
|
});
|
|
378
378
|
});
|
|
379
379
|
|
|
@@ -381,7 +381,7 @@ noble.on('discover', function (peripheral) {
|
|
|
381
381
|
sendEvent({
|
|
382
382
|
type: 'handleNotify',
|
|
383
383
|
peripheralUuid: this.uuid,
|
|
384
|
-
handle
|
|
384
|
+
handle,
|
|
385
385
|
data: data.toString('hex')
|
|
386
386
|
});
|
|
387
387
|
});
|
package/lib/manufacture.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
const tryRequire = modulePath => {
|
|
4
|
-
try {
|
|
5
|
-
return require(modulePath);
|
|
6
|
-
} catch (e) {
|
|
7
|
-
console.error(`ERROR:\tCould not load manufacturer list from "${modulePath}".`);
|
|
8
|
-
console.error(`\tPlease see "${path.join(__dirname, '..', 'scripts', 'manufactures', 'README.md')}" for instructions.`);
|
|
9
|
-
return {};
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const hexValues = tryRequire('./manufactures-hex.json');
|
|
14
|
-
const decValues = tryRequire('./manufactures-dec.json');
|
|
15
|
-
|
|
16
|
-
function Manufacture (noble, data) {
|
|
17
|
-
this._noble = noble;
|
|
18
|
-
|
|
19
|
-
this.name = null;
|
|
20
|
-
this.data = data;
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const tmp = JSON.parse(JSON.stringify(data)).data;
|
|
24
|
-
|
|
25
|
-
if (Array.isArray(tmp)) {
|
|
26
|
-
this.name = decValues[tmp[0]];
|
|
27
|
-
}
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.error(e);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
Manufacture.prototype.toString = function () {
|
|
34
|
-
return JSON.stringify({
|
|
35
|
-
name: this.name,
|
|
36
|
-
data: JSON.parse(JSON.stringify(this.data))
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
Manufacture.nameFromHex = function (hexValue) {
|
|
41
|
-
return hexValues[hexValue] || undefined;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
Manufacture.nameFromDec = function (decValue) {
|
|
45
|
-
return decValues[decValue] || undefined;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
module.exports = Manufacture;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const should = require('should');
|
|
2
|
-
const proxyquire = require('proxyquire').noCallThru();
|
|
3
|
-
|
|
4
|
-
const decValues = {
|
|
5
|
-
135: 'DEC name'
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const hexValues = {
|
|
9
|
-
135: 'HEX name'
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const Manufacture = proxyquire('../../lib/manufacture', {
|
|
13
|
-
'./manufactures-dec.json': decValues,
|
|
14
|
-
'./manufactures-hex.json': hexValues
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('manufacture', () => {
|
|
18
|
-
it('should have only data, no name', () => {
|
|
19
|
-
const noble = 'fake_noble';
|
|
20
|
-
const data = 'not_a_json';
|
|
21
|
-
const manufacture = new Manufacture(noble, data);
|
|
22
|
-
|
|
23
|
-
should(manufacture._noble).eql(noble);
|
|
24
|
-
should(manufacture.data).eql(data);
|
|
25
|
-
should(manufacture.name).eql(null);
|
|
26
|
-
|
|
27
|
-
should(manufacture.toString()).eql('{"name":null,"data":"not_a_json"}');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should have data and name', () => {
|
|
31
|
-
const noble = 'fake_noble';
|
|
32
|
-
const data = Buffer.from([0x87, 0x00, 0x0d, 0x9c], 'hex');
|
|
33
|
-
const manufacture = new Manufacture(noble, data);
|
|
34
|
-
|
|
35
|
-
should(manufacture._noble).eql(noble);
|
|
36
|
-
should(manufacture.data).eql(data);
|
|
37
|
-
should(manufacture.name).eql('DEC name');
|
|
38
|
-
|
|
39
|
-
should(manufacture.toString()).eql(
|
|
40
|
-
'{"name":"DEC name","data":{"type":"Buffer","data":[135,0,13,156]}}'
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should have no array data', () => {
|
|
45
|
-
const noble = 'fake_noble';
|
|
46
|
-
const data = '{type: "not an array"}';
|
|
47
|
-
const manufacture = new Manufacture(noble, data);
|
|
48
|
-
|
|
49
|
-
should(manufacture._noble).eql(noble);
|
|
50
|
-
should(manufacture.data).eql(data);
|
|
51
|
-
should(manufacture.name).eql(null);
|
|
52
|
-
|
|
53
|
-
should(manufacture.toString()).eql(
|
|
54
|
-
'{"name":null,"data":"{type: \\"not an array\\"}"}'
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('get existing name from HEX', () => {
|
|
59
|
-
const name = Manufacture.nameFromHex(135);
|
|
60
|
-
should(name).eql('HEX name');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('get unknown name from HEX', () => {
|
|
64
|
-
const name = Manufacture.nameFromHex(1);
|
|
65
|
-
should(name).eql(undefined);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('get existing name from DEC', () => {
|
|
69
|
-
const name = Manufacture.nameFromDec(135);
|
|
70
|
-
should(name).eql('DEC name');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('get unknown name from DEC', () => {
|
|
74
|
-
const name = Manufacture.nameFromDec(1);
|
|
75
|
-
should(name).eql(undefined);
|
|
76
|
-
});
|
|
77
|
-
});
|