@stoprocent/bleno 0.10.0 → 0.10.2

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.
@@ -11,16 +11,17 @@ class AclStream extends EventEmitter {
11
11
  this._smp = new Smp(this, localAddressType, localAddress, remoteAddressType, remoteAddress);
12
12
  }
13
13
 
14
+ close () {
15
+ this.emit('end', this._handle);
16
+ this._smp.close();
17
+ }
18
+
14
19
  write (cid, data) {
15
20
  this._hci.queueAclDataPkt(this._handle, cid, data);
16
21
  }
17
22
 
18
- push (handle, cid, data) {
19
- if (data) {
20
- this.emit('data', handle, cid, data);
21
- } else {
22
- this.emit('end', handle);
23
- }
23
+ push (cid, data) {
24
+ this.emit('data', this._handle, cid, data);
24
25
  }
25
26
 
26
27
  pushEncrypt (encrypt) {
@@ -77,6 +77,7 @@ class BlenoBindings extends EventEmitter {
77
77
  }
78
78
 
79
79
  init () {
80
+
80
81
  this._sigIntHandler = this.onSigInt.bind(this);
81
82
  this._exitHandler = this.onExit.bind(this);
82
83
 
@@ -173,12 +174,13 @@ class BlenoBindings extends EventEmitter {
173
174
  }
174
175
 
175
176
  const { address, aclStream } = this._connections.get(handle);
176
-
177
+
177
178
  if (aclStream) {
178
- aclStream.push(handle, null, null);
179
+ aclStream.close();
179
180
  }
180
181
 
181
182
  this._connections.delete(handle);
183
+
182
184
  this.emit('disconnect', address, handle);
183
185
 
184
186
  if (this._advertising) {
@@ -211,7 +213,7 @@ class BlenoBindings extends EventEmitter {
211
213
  onAclDataPkt (handle, cid, data) {
212
214
  const connection = this._connections.get(handle);
213
215
  if (connection && connection.aclStream) {
214
- connection.aclStream.push(handle, cid, data);
216
+ connection.aclStream.push(cid, data);
215
217
  }
216
218
  }
217
219
 
@@ -278,14 +278,13 @@ class Gatt extends EventEmitter {
278
278
  aclStream,
279
279
  mtu: 23,
280
280
  });
281
-
282
281
  this._aclStreamCallbacks.set(connection, {
283
282
  onData: function (connection, cid, data) {
284
283
  this.onAclStreamData(connection, cid, data);
285
- },
284
+ }.bind(this),
286
285
  onEnd: function (connection) {
287
286
  this.onAclStreamEnd(connection);
288
- }
287
+ }.bind(this)
289
288
  });
290
289
 
291
290
  aclStream.on('data', this._aclStreamCallbacks.get(connection).onData.bind(this));
@@ -308,8 +307,8 @@ class Gatt extends EventEmitter {
308
307
  const { aclStream } = this._connections.get(connection);
309
308
 
310
309
  aclStream.removeListener('data', this._aclStreamCallbacks.get(connection).onData);
311
- aclStream.removeListener('end', this._aclStreamCallbacks.get(connection).onEnd);
312
-
310
+ aclStream.removeListener('end', this._aclStreamCallbacks.get(connection).onEnd);
311
+
313
312
  // Clean up subscriptions for this connection
314
313
  for (let i = 0; i < this._handles.length; i++) {
315
314
  if (this._handles[i] &&
@@ -327,6 +326,7 @@ class Gatt extends EventEmitter {
327
326
  }
328
327
 
329
328
  this._connections.delete(connection);
329
+ this._aclStreamCallbacks.delete(connection);
330
330
  this._preparedWriteRequests.delete(connection);
331
331
  }
332
332
 
@@ -740,6 +740,10 @@ class Gatt extends EventEmitter {
740
740
  data = this._handles[valueHandle].value;
741
741
  }
742
742
 
743
+ if (!data && this._handles[valueHandle].uuid === '2902' && this._connections.get(connection)) {
744
+ data = Buffer.from([0x00, 0x00]);
745
+ }
746
+
743
747
  if (data) {
744
748
  callback(ATT_ECODE_SUCCESS, data);
745
749
  } else if (handleAttribute) {
@@ -18,6 +18,10 @@ class Mgmt {
18
18
  this._socket.start();
19
19
  }
20
20
 
21
+ close () {
22
+ this._socket.stop();
23
+ }
24
+
21
25
  onSocketData (data) {
22
26
  debug('on data ->' + data.toString('hex'));
23
27
  }
@@ -41,6 +41,10 @@ class Smp extends EventEmitter {
41
41
  this._aclStream.on('end', this.onAclStreamEndBinded);
42
42
  }
43
43
 
44
+ close () {
45
+ this._mgmt.close();
46
+ }
47
+
44
48
  onAclStreamData (cid, data) {
45
49
  if (cid !== SMP_CID) {
46
50
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoprocent/bleno",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -69,7 +69,7 @@
69
69
  "node-gyp-build": "^4.8.4"
70
70
  },
71
71
  "optionalDependencies": {
72
- "@stoprocent/bluetooth-hci-socket": "^2.1.0"
72
+ "@stoprocent/bluetooth-hci-socket": "^2.1.1"
73
73
  },
74
74
  "publishConfig": {
75
75
  "access": "public"