@stoprocent/noble 1.9.2-16
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/.editorconfig +11 -0
- package/.eslintrc.js +25 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/fediverse-action.yml +16 -0
- package/.github/workflows/nodepackage.yml +77 -0
- package/.github/workflows/npm-publish.yml +26 -0
- package/.github/workflows/prebuild.yml +65 -0
- package/.nycrc.json +4 -0
- package/CHANGELOG.md +119 -0
- package/LICENSE +20 -0
- package/MAINTAINERS.md +1 -0
- package/README.md +833 -0
- package/assets/noble-logo.png +0 -0
- package/assets/noble-logo.svg +13 -0
- package/binding.gyp +19 -0
- package/codecov.yml +5 -0
- package/examples/advertisement-discovery.js +65 -0
- package/examples/cache-gatt-discovery.js +198 -0
- package/examples/cache-gatt-reconnect.js +164 -0
- package/examples/echo.js +104 -0
- package/examples/enter-exit.js +78 -0
- package/examples/peripheral-explorer-async.js +133 -0
- package/examples/peripheral-explorer.js +225 -0
- package/examples/pizza/README.md +15 -0
- package/examples/pizza/central.js +194 -0
- package/examples/pizza/pizza.js +60 -0
- package/index.d.ts +203 -0
- package/index.js +6 -0
- package/lib/characteristic.js +161 -0
- package/lib/characteristics.json +449 -0
- package/lib/descriptor.js +72 -0
- package/lib/descriptors.json +47 -0
- package/lib/distributed/bindings.js +326 -0
- package/lib/hci-socket/acl-stream.js +60 -0
- package/lib/hci-socket/bindings.js +788 -0
- package/lib/hci-socket/crypto.js +74 -0
- package/lib/hci-socket/gap.js +432 -0
- package/lib/hci-socket/gatt.js +809 -0
- package/lib/hci-socket/hci-status.json +71 -0
- package/lib/hci-socket/hci.js +1264 -0
- package/lib/hci-socket/signaling.js +76 -0
- package/lib/hci-socket/smp.js +140 -0
- package/lib/hci-uart/bindings.js +569 -0
- package/lib/hci-uart/hci-serial-parser.js +70 -0
- package/lib/hci-uart/hci.js +1336 -0
- package/lib/mac/binding.gyp +26 -0
- package/lib/mac/bindings.js +11 -0
- package/lib/mac/src/ble_manager.h +41 -0
- package/lib/mac/src/ble_manager.mm +435 -0
- package/lib/mac/src/callbacks.cc +222 -0
- package/lib/mac/src/callbacks.h +84 -0
- package/lib/mac/src/napi_objc.h +12 -0
- package/lib/mac/src/napi_objc.mm +50 -0
- package/lib/mac/src/noble_mac.h +34 -0
- package/lib/mac/src/noble_mac.mm +264 -0
- package/lib/mac/src/objc_cpp.h +26 -0
- package/lib/mac/src/objc_cpp.mm +126 -0
- package/lib/mac/src/peripheral.h +23 -0
- package/lib/manufacture.js +48 -0
- package/lib/noble.js +593 -0
- package/lib/peripheral.js +219 -0
- package/lib/resolve-bindings-web.js +9 -0
- package/lib/resolve-bindings.js +44 -0
- package/lib/service.js +72 -0
- package/lib/services.json +92 -0
- package/lib/webbluetooth/bindings.js +368 -0
- package/lib/websocket/bindings.js +321 -0
- package/lib/win/binding.gyp +23 -0
- package/lib/win/bindings.js +11 -0
- package/lib/win/src/ble_manager.cc +802 -0
- package/lib/win/src/ble_manager.h +77 -0
- package/lib/win/src/callbacks.cc +274 -0
- package/lib/win/src/callbacks.h +33 -0
- package/lib/win/src/napi_winrt.cc +76 -0
- package/lib/win/src/napi_winrt.h +12 -0
- package/lib/win/src/noble_winrt.cc +308 -0
- package/lib/win/src/noble_winrt.h +34 -0
- package/lib/win/src/notify_map.cc +62 -0
- package/lib/win/src/notify_map.h +50 -0
- package/lib/win/src/peripheral.h +23 -0
- package/lib/win/src/peripheral_winrt.cc +296 -0
- package/lib/win/src/peripheral_winrt.h +82 -0
- package/lib/win/src/radio_watcher.cc +125 -0
- package/lib/win/src/radio_watcher.h +61 -0
- package/lib/win/src/winrt_cpp.cc +82 -0
- package/lib/win/src/winrt_cpp.h +11 -0
- package/lib/win/src/winrt_guid.cc +12 -0
- package/lib/win/src/winrt_guid.h +13 -0
- package/misc/nrf52840dk.hex +6921 -0
- package/misc/prj.conf +43 -0
- package/package.json +96 -0
- package/test/lib/characteristic.test.js +791 -0
- package/test/lib/descriptor.test.js +249 -0
- package/test/lib/distributed/bindings.test.js +918 -0
- package/test/lib/hci-socket/acl-stream.test.js +188 -0
- package/test/lib/hci-socket/bindings.test.js +1756 -0
- package/test/lib/hci-socket/crypto.test.js +55 -0
- package/test/lib/hci-socket/gap.test.js +1089 -0
- package/test/lib/hci-socket/gatt.test.js +2392 -0
- package/test/lib/hci-socket/hci.test.js +1891 -0
- package/test/lib/hci-socket/signaling.test.js +94 -0
- package/test/lib/hci-socket/smp.test.js +268 -0
- package/test/lib/manufacture.test.js +77 -0
- package/test/lib/peripheral.test.js +623 -0
- package/test/lib/resolve-bindings.test.js +102 -0
- package/test/lib/service.test.js +195 -0
- package/test/lib/webbluetooth/bindings.test.js +190 -0
- package/test/lib/websocket/bindings.test.js +456 -0
- package/test/noble.test.js +1565 -0
- package/test.js +131 -0
- package/with-bindings.js +5 -0
- package/ws-slave.js +404 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
const sinon = require('sinon');
|
|
2
|
+
const should = require('should');
|
|
3
|
+
|
|
4
|
+
const { assert } = sinon;
|
|
5
|
+
|
|
6
|
+
const Descriptor = require('../../lib/descriptor');
|
|
7
|
+
|
|
8
|
+
describe('descriptor', () => {
|
|
9
|
+
let mockNoble = null;
|
|
10
|
+
const mockPeripheralId = 'mock-peripheral-id';
|
|
11
|
+
const mockServiceUuid = 'mock-service-uuid';
|
|
12
|
+
const mockCharacteristicUuid = 'mock-characteristic-uuid';
|
|
13
|
+
const mockUuid = 'mock-uuid';
|
|
14
|
+
|
|
15
|
+
let descriptor = null;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockNoble = {};
|
|
19
|
+
|
|
20
|
+
descriptor = new Descriptor(
|
|
21
|
+
mockNoble,
|
|
22
|
+
mockPeripheralId,
|
|
23
|
+
mockServiceUuid,
|
|
24
|
+
mockCharacteristicUuid,
|
|
25
|
+
mockUuid
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should have a uuid', () => {
|
|
30
|
+
should(descriptor.uuid).equal(mockUuid);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should lookup name and type by uuid', () => {
|
|
34
|
+
descriptor = new Descriptor(
|
|
35
|
+
mockNoble,
|
|
36
|
+
mockPeripheralId,
|
|
37
|
+
mockServiceUuid,
|
|
38
|
+
mockCharacteristicUuid,
|
|
39
|
+
'2900'
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
should(descriptor.name).equal('Characteristic Extended Properties');
|
|
43
|
+
should(descriptor.type).equal(
|
|
44
|
+
'org.bluetooth.descriptor.gatt.characteristic_extended_properties'
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('toString', () => {
|
|
49
|
+
it('should be uuid, name, type', () => {
|
|
50
|
+
should(descriptor.toString()).equal(
|
|
51
|
+
'{"uuid":"mock-uuid","name":null,"type":null}'
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('readValue', () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
mockNoble.readValue = sinon.spy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
sinon.reset();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should delegate to noble', () => {
|
|
66
|
+
descriptor.readValue();
|
|
67
|
+
|
|
68
|
+
assert.calledOnceWithExactly(
|
|
69
|
+
mockNoble.readValue,
|
|
70
|
+
mockPeripheralId,
|
|
71
|
+
mockServiceUuid,
|
|
72
|
+
mockCharacteristicUuid,
|
|
73
|
+
mockUuid
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should callback', () => {
|
|
78
|
+
const callback = sinon.spy();
|
|
79
|
+
|
|
80
|
+
descriptor.readValue(callback);
|
|
81
|
+
descriptor.emit('valueRead');
|
|
82
|
+
// Check for single callback
|
|
83
|
+
descriptor.emit('valueRead');
|
|
84
|
+
|
|
85
|
+
assert.calledOnceWithExactly(callback, null, undefined);
|
|
86
|
+
assert.calledOnceWithExactly(
|
|
87
|
+
mockNoble.readValue,
|
|
88
|
+
mockPeripheralId,
|
|
89
|
+
mockServiceUuid,
|
|
90
|
+
mockCharacteristicUuid,
|
|
91
|
+
mockUuid
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should callback with error, data', () => {
|
|
96
|
+
const mockData = Buffer.alloc(0);
|
|
97
|
+
const callback = sinon.spy();
|
|
98
|
+
|
|
99
|
+
descriptor.readValue(callback);
|
|
100
|
+
descriptor.emit('valueRead', mockData);
|
|
101
|
+
// Check for single callback
|
|
102
|
+
descriptor.emit('valueRead', mockData);
|
|
103
|
+
|
|
104
|
+
assert.calledOnceWithExactly(callback, null, mockData);
|
|
105
|
+
assert.calledOnceWithExactly(
|
|
106
|
+
mockNoble.readValue,
|
|
107
|
+
mockPeripheralId,
|
|
108
|
+
mockServiceUuid,
|
|
109
|
+
mockCharacteristicUuid,
|
|
110
|
+
mockUuid
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('readValueAsync', () => {
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
mockNoble.readValue = sinon.spy();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
afterEach(() => {
|
|
121
|
+
sinon.reset();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should delegate to noble', async () => {
|
|
125
|
+
const promise = descriptor.readValueAsync();
|
|
126
|
+
descriptor.emit('valueRead');
|
|
127
|
+
// Check for single callback
|
|
128
|
+
descriptor.emit('valueRead');
|
|
129
|
+
|
|
130
|
+
should(promise).resolvedWith(undefined);
|
|
131
|
+
assert.calledOnceWithExactly(
|
|
132
|
+
mockNoble.readValue,
|
|
133
|
+
mockPeripheralId,
|
|
134
|
+
mockServiceUuid,
|
|
135
|
+
mockCharacteristicUuid,
|
|
136
|
+
mockUuid
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should resolve with data', async () => {
|
|
141
|
+
const mockData = Buffer.alloc(0);
|
|
142
|
+
|
|
143
|
+
const promise = descriptor.readValueAsync();
|
|
144
|
+
descriptor.emit('valueRead', mockData);
|
|
145
|
+
// Check for single callback
|
|
146
|
+
descriptor.emit('valueRead', mockData);
|
|
147
|
+
|
|
148
|
+
should(promise).resolvedWith(mockData);
|
|
149
|
+
assert.calledOnceWithExactly(
|
|
150
|
+
mockNoble.readValue,
|
|
151
|
+
mockPeripheralId,
|
|
152
|
+
mockServiceUuid,
|
|
153
|
+
mockCharacteristicUuid,
|
|
154
|
+
mockUuid
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('writeValue', () => {
|
|
160
|
+
beforeEach(() => {
|
|
161
|
+
mockNoble.writeValue = sinon.spy();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
afterEach(() => {
|
|
165
|
+
sinon.reset();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should only accept data as a buffer', () => {
|
|
169
|
+
const mockData = {};
|
|
170
|
+
|
|
171
|
+
should(() => descriptor.writeValue(mockData)).throw(
|
|
172
|
+
'data must be a Buffer'
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
assert.notCalled(mockNoble.writeValue);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should delegate to noble', () => {
|
|
179
|
+
const mockData = Buffer.alloc(0);
|
|
180
|
+
descriptor.writeValue(mockData);
|
|
181
|
+
|
|
182
|
+
assert.calledOnceWithExactly(
|
|
183
|
+
mockNoble.writeValue,
|
|
184
|
+
mockPeripheralId,
|
|
185
|
+
mockServiceUuid,
|
|
186
|
+
mockCharacteristicUuid,
|
|
187
|
+
mockUuid,
|
|
188
|
+
mockData
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should callback', () => {
|
|
193
|
+
const mockData = Buffer.alloc(0);
|
|
194
|
+
const callback = sinon.spy();
|
|
195
|
+
|
|
196
|
+
descriptor.writeValue(mockData, callback);
|
|
197
|
+
descriptor.emit('valueWrite');
|
|
198
|
+
// Check for single callback
|
|
199
|
+
descriptor.emit('valueWrite');
|
|
200
|
+
|
|
201
|
+
assert.calledOnceWithExactly(callback, null);
|
|
202
|
+
assert.calledOnceWithExactly(
|
|
203
|
+
mockNoble.writeValue,
|
|
204
|
+
mockPeripheralId,
|
|
205
|
+
mockServiceUuid,
|
|
206
|
+
mockCharacteristicUuid,
|
|
207
|
+
mockUuid,
|
|
208
|
+
mockData
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe('writeValueAsync', () => {
|
|
214
|
+
beforeEach(() => {
|
|
215
|
+
mockNoble.writeValue = sinon.spy();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
afterEach(() => {
|
|
219
|
+
sinon.reset();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('should only accept data as a buffer', async () => {
|
|
223
|
+
const mockData = {};
|
|
224
|
+
|
|
225
|
+
const promise = descriptor.writeValueAsync(mockData);
|
|
226
|
+
|
|
227
|
+
should(promise).rejectedWith('data must be a Buffer');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('should delegate to noble', async () => {
|
|
231
|
+
const mockData = Buffer.alloc(0);
|
|
232
|
+
|
|
233
|
+
const promise = descriptor.writeValueAsync(mockData);
|
|
234
|
+
descriptor.emit('valueWrite');
|
|
235
|
+
// Check for single callback
|
|
236
|
+
descriptor.emit('valueWrite');
|
|
237
|
+
|
|
238
|
+
should(promise).resolvedWith(undefined);
|
|
239
|
+
assert.calledOnceWithExactly(
|
|
240
|
+
mockNoble.writeValue,
|
|
241
|
+
mockPeripheralId,
|
|
242
|
+
mockServiceUuid,
|
|
243
|
+
mockCharacteristicUuid,
|
|
244
|
+
mockUuid,
|
|
245
|
+
mockData
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|