@stoprocent/bleno 0.8.6 → 0.10.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 +197 -30
- package/examples/echo/async.js +47 -0
- package/examples/echo/characteristic.js +15 -17
- package/examples/echo/main.js +19 -1
- package/examples/uart/main.js +3 -2
- package/examples/with-bindings/main.js +35 -0
- package/index.d.ts +166 -121
- package/index.js +5 -1
- package/lib/bleno.js +108 -17
- package/lib/characteristic.js +27 -10
- package/lib/common/include/ThreadSafeCallback.h +95 -0
- package/lib/hci-socket/acl-stream.js +3 -3
- package/lib/hci-socket/bindings.js +36 -29
- package/lib/hci-socket/gatt.js +177 -105
- package/lib/hci-socket/hci.js +5 -3
- package/lib/hci-socket/mgmt.js +1 -1
- package/lib/hci-socket/smp.js +5 -4
- package/lib/mac/binding.gyp +2 -6
- package/lib/mac/bindings.js +2 -3
- package/lib/mac/src/ble_peripheral_manager.h +3 -7
- package/lib/mac/src/ble_peripheral_manager.mm +101 -171
- package/lib/mac/src/bleno_mac.h +0 -1
- package/lib/mac/src/bleno_mac.mm +21 -33
- package/lib/mac/src/callbacks.h +12 -48
- package/lib/mac/src/callbacks.mm +35 -45
- package/lib/mac/src/napi_objc.mm +9 -30
- package/lib/mac/src/objc_cpp.h +2 -2
- package/lib/mac/src/objc_cpp.mm +3 -37
- package/lib/resolve-bindings.js +27 -6
- package/package.json +7 -10
- package/prebuilds/darwin-x64+arm64/@stoprocent+bleno.node +0 -0
- package/prebuilds/win32-ia32/@stoprocent+bleno.node +0 -0
- package/prebuilds/win32-x64/@stoprocent+bleno.node +0 -0
- package/test/characteristic.test.js +158 -11
- package/examples/battery-service/README.md +0 -14
- package/examples/blink1/README.md +0 -44
- package/examples/pizza/README.md +0 -16
- package/lib/mac/src/noble_mac.h +0 -34
- package/lib/mac/src/noble_mac.mm +0 -267
- package/lib/mac/src/peripheral.h +0 -23
- package/with-bindings.js +0 -5
- package/with-custom-binding.js +0 -6
|
@@ -15,11 +15,11 @@ class AclStream extends EventEmitter {
|
|
|
15
15
|
this._hci.queueAclDataPkt(this._handle, cid, data);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
push (cid, data) {
|
|
18
|
+
push (handle, cid, data) {
|
|
19
19
|
if (data) {
|
|
20
|
-
this.emit('data', cid, data);
|
|
20
|
+
this.emit('data', handle, cid, data);
|
|
21
21
|
} else {
|
|
22
|
-
this.emit('end');
|
|
22
|
+
this.emit('end', handle);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -20,9 +20,7 @@ class BlenoBindings extends EventEmitter {
|
|
|
20
20
|
this._gap = new Gap(this._hci);
|
|
21
21
|
this._gatt = new Gatt(this._hci);
|
|
22
22
|
|
|
23
|
-
this.
|
|
24
|
-
this._handle = null;
|
|
25
|
-
this._aclStream = null;
|
|
23
|
+
this._connections = new Map();
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
setAddress (address) {
|
|
@@ -32,6 +30,7 @@ class BlenoBindings extends EventEmitter {
|
|
|
32
30
|
startAdvertising (name, serviceUuids) {
|
|
33
31
|
this._advertising = true;
|
|
34
32
|
|
|
33
|
+
this._gatt.updateName(name);
|
|
35
34
|
this._gap.startAdvertising(name, serviceUuids);
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -59,11 +58,15 @@ class BlenoBindings extends EventEmitter {
|
|
|
59
58
|
this.emit('servicesSet');
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
disconnect () {
|
|
63
|
-
if (
|
|
64
|
-
debug('disconnect by server');
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
disconnect (handle = null) {
|
|
62
|
+
if (handle) {
|
|
63
|
+
debug('disconnect by server for handle', handle);
|
|
64
|
+
this._hci.disconnect(handle);
|
|
65
|
+
} else {
|
|
66
|
+
for (const [handle, connection] of this._connections) {
|
|
67
|
+
debug('disconnect by server for handle', handle, connection.address);
|
|
68
|
+
this._hci.disconnect(handle);
|
|
69
|
+
}
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
|
|
@@ -146,16 +149,18 @@ class BlenoBindings extends EventEmitter {
|
|
|
146
149
|
|
|
147
150
|
onLeConnComplete (status, handle, role, addressType, address, interval, latency, supervisionTimeout, masterClockAccuracy) {
|
|
148
151
|
if (role !== 1) {
|
|
149
|
-
// not slave, ignore
|
|
150
152
|
return;
|
|
151
153
|
}
|
|
152
154
|
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
155
|
-
this.
|
|
156
|
-
this._gatt.setAclStream(this._aclStream);
|
|
155
|
+
const aclStream = new AclStream(this._hci, handle, this._hci.addressType, this._hci.address, addressType, address);
|
|
156
|
+
this._connections.set(handle, { address, aclStream });
|
|
157
|
+
this._gatt.registerAclStream(aclStream, handle);
|
|
157
158
|
|
|
158
|
-
this.emit('accept', address);
|
|
159
|
+
this.emit('accept', address, handle);
|
|
160
|
+
|
|
161
|
+
if (this._advertising) {
|
|
162
|
+
this._gap.restartAdvertising();
|
|
163
|
+
}
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
onLeConnUpdateComplete (handle, interval, latency, supervisionTimeout) {
|
|
@@ -163,19 +168,18 @@ class BlenoBindings extends EventEmitter {
|
|
|
163
168
|
}
|
|
164
169
|
|
|
165
170
|
onDisconnComplete (handle, reason) {
|
|
166
|
-
if (this.
|
|
167
|
-
|
|
171
|
+
if (this._connections.has(handle) === false) {
|
|
172
|
+
return;
|
|
168
173
|
}
|
|
169
174
|
|
|
170
|
-
const address = this.
|
|
171
|
-
|
|
172
|
-
this._address = null;
|
|
173
|
-
this._handle = null;
|
|
174
|
-
this._aclStream = null;
|
|
175
|
+
const { address, aclStream } = this._connections.get(handle);
|
|
175
176
|
|
|
176
|
-
if (
|
|
177
|
-
|
|
177
|
+
if (aclStream) {
|
|
178
|
+
aclStream.push(handle, null, null);
|
|
178
179
|
}
|
|
180
|
+
|
|
181
|
+
this._connections.delete(handle);
|
|
182
|
+
this.emit('disconnect', address, handle);
|
|
179
183
|
|
|
180
184
|
if (this._advertising) {
|
|
181
185
|
this._gap.restartAdvertising();
|
|
@@ -183,14 +187,16 @@ class BlenoBindings extends EventEmitter {
|
|
|
183
187
|
}
|
|
184
188
|
|
|
185
189
|
onEncryptChange (handle, encrypt) {
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
const connection = this._connections.get(handle);
|
|
191
|
+
if (connection && connection.aclStream) {
|
|
192
|
+
connection.aclStream.pushEncrypt(encrypt);
|
|
188
193
|
}
|
|
189
194
|
}
|
|
190
195
|
|
|
191
196
|
onLeLtkNegReply (handle) {
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
const connection = this._connections.get(handle);
|
|
198
|
+
if (connection && connection.aclStream) {
|
|
199
|
+
connection.aclStream.pushLtkNegReply();
|
|
194
200
|
}
|
|
195
201
|
}
|
|
196
202
|
|
|
@@ -203,8 +209,9 @@ class BlenoBindings extends EventEmitter {
|
|
|
203
209
|
}
|
|
204
210
|
|
|
205
211
|
onAclDataPkt (handle, cid, data) {
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
const connection = this._connections.get(handle);
|
|
213
|
+
if (connection && connection.aclStream) {
|
|
214
|
+
connection.aclStream.push(handle, cid, data);
|
|
208
215
|
}
|
|
209
216
|
}
|
|
210
217
|
|