@stoprocent/bleno 0.8.5 → 0.9.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 (39) hide show
  1. package/README.md +197 -30
  2. package/examples/echo/async.js +47 -0
  3. package/examples/echo/characteristic.js +15 -17
  4. package/examples/echo/main.js +19 -1
  5. package/examples/uart/main.js +3 -2
  6. package/examples/with-bindings/main.js +35 -0
  7. package/index.d.ts +166 -121
  8. package/index.js +5 -1
  9. package/lib/bleno.js +108 -17
  10. package/lib/characteristic.js +27 -10
  11. package/lib/hci-socket/acl-stream.js +3 -3
  12. package/lib/hci-socket/bindings.js +36 -29
  13. package/lib/hci-socket/gatt.js +177 -105
  14. package/lib/hci-socket/hci.js +5 -3
  15. package/lib/hci-socket/mgmt.js +1 -1
  16. package/lib/hci-socket/smp.js +5 -4
  17. package/lib/mac/src/ble_peripheral_manager.h +3 -7
  18. package/lib/mac/src/ble_peripheral_manager.mm +117 -162
  19. package/lib/mac/src/bleno_mac.h +0 -1
  20. package/lib/mac/src/bleno_mac.mm +21 -33
  21. package/lib/mac/src/callbacks.h +12 -48
  22. package/lib/mac/src/callbacks.mm +34 -45
  23. package/lib/mac/src/napi_objc.mm +9 -30
  24. package/lib/mac/src/objc_cpp.h +2 -2
  25. package/lib/mac/src/objc_cpp.mm +3 -37
  26. package/lib/resolve-bindings.js +27 -6
  27. package/package.json +7 -9
  28. package/prebuilds/darwin-x64+arm64/@stoprocent+bleno.node +0 -0
  29. package/prebuilds/win32-ia32/@stoprocent+bleno.node +0 -0
  30. package/prebuilds/win32-x64/@stoprocent+bleno.node +0 -0
  31. package/test/characteristic.test.js +158 -11
  32. package/examples/battery-service/README.md +0 -14
  33. package/examples/blink1/README.md +0 -44
  34. package/examples/pizza/README.md +0 -16
  35. package/lib/mac/src/noble_mac.h +0 -34
  36. package/lib/mac/src/noble_mac.mm +0 -267
  37. package/lib/mac/src/peripheral.h +0 -23
  38. package/with-bindings.js +0 -5
  39. package/with-custom-binding.js +0 -6
@@ -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._address = null;
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 (this._handle) {
64
- debug('disconnect by server');
65
-
66
- this._hci.disconnect(this._handle);
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._address = address;
154
- this._handle = handle;
155
- this._aclStream = new AclStream(this._hci, handle, this._hci.addressType, this._hci.address, addressType, address);
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._aclStream) {
167
- this._aclStream.push(null, null);
171
+ if (this._connections.has(handle) === false) {
172
+ return;
168
173
  }
169
174
 
170
- const address = this._address;
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 (address) {
177
- this.emit('disconnect', address); // TODO: use reason
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
- if (this._handle === handle && this._aclStream) {
187
- this._aclStream.pushEncrypt(encrypt);
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
- if (this._handle === handle && this._aclStream) {
193
- this._aclStream.pushLtkNegReply();
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
- if (this._handle === handle && this._aclStream) {
207
- this._aclStream.push(cid, data);
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