@stoprocent/bleno 0.10.1 → 0.10.3

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
 
@@ -5,6 +5,7 @@ const debug = require('debug')('gatt');
5
5
 
6
6
  const { EventEmitter } = require('events');
7
7
  const os = require('os');
8
+ const Characteristic = require('../characteristic');
8
9
 
9
10
  const ATT_OP_ERROR = 0x01;
10
11
  const ATT_OP_MTU_REQ = 0x02;
@@ -103,32 +104,34 @@ class Gatt extends EventEmitter {
103
104
  {
104
105
  uuid: '1800',
105
106
  characteristics: [
106
- {
107
+ new Characteristic({
107
108
  uuid: '2a00',
108
109
  properties: ['read'],
109
110
  secure: [],
110
111
  value: Buffer.from(this._name),
111
112
  descriptors: []
112
- },
113
- {
113
+ }),
114
+ new Characteristic({
114
115
  uuid: '2a01',
115
116
  properties: ['read'],
116
117
  secure: [],
117
118
  value: Buffer.from([0x80, 0x00]),
118
119
  descriptors: []
119
- }
120
+ })
120
121
  ]
121
122
  },
122
123
  {
123
124
  uuid: '1801',
124
125
  characteristics: [
125
- {
126
+ new Characteristic({
126
127
  uuid: '2a05',
127
128
  properties: ['indicate'],
128
129
  secure: [],
129
- value: Buffer.from([0x00, 0x00, 0x00, 0x00]),
130
- descriptors: []
131
- }
130
+ descriptors: [],
131
+ onIndicate: function (connection) {
132
+ this.notify(connection, Buffer.from([0x00, 0x00, 0x00, 0x00]));
133
+ }
134
+ })
132
135
  ]
133
136
  }
134
137
  ].concat(services);
@@ -278,14 +281,13 @@ class Gatt extends EventEmitter {
278
281
  aclStream,
279
282
  mtu: 23,
280
283
  });
281
-
282
284
  this._aclStreamCallbacks.set(connection, {
283
285
  onData: function (connection, cid, data) {
284
286
  this.onAclStreamData(connection, cid, data);
285
- },
287
+ }.bind(this),
286
288
  onEnd: function (connection) {
287
289
  this.onAclStreamEnd(connection);
288
- }
290
+ }.bind(this)
289
291
  });
290
292
 
291
293
  aclStream.on('data', this._aclStreamCallbacks.get(connection).onData.bind(this));
@@ -308,8 +310,8 @@ class Gatt extends EventEmitter {
308
310
  const { aclStream } = this._connections.get(connection);
309
311
 
310
312
  aclStream.removeListener('data', this._aclStreamCallbacks.get(connection).onData);
311
- aclStream.removeListener('end', this._aclStreamCallbacks.get(connection).onEnd);
312
-
313
+ aclStream.removeListener('end', this._aclStreamCallbacks.get(connection).onEnd);
314
+
313
315
  // Clean up subscriptions for this connection
314
316
  for (let i = 0; i < this._handles.length; i++) {
315
317
  if (this._handles[i] &&
@@ -327,6 +329,7 @@ class Gatt extends EventEmitter {
327
329
  }
328
330
 
329
331
  this._connections.delete(connection);
332
+ this._aclStreamCallbacks.delete(connection);
330
333
  this._preparedWriteRequests.delete(connection);
331
334
  }
332
335
 
@@ -743,7 +746,7 @@ class Gatt extends EventEmitter {
743
746
  if (!data && this._handles[valueHandle].uuid === '2902' && this._connections.get(connection)) {
744
747
  data = Buffer.from([0x00, 0x00]);
745
748
  }
746
-
749
+
747
750
  if (data) {
748
751
  callback(ATT_ECODE_SUCCESS, data);
749
752
  } else if (handleAttribute) {
@@ -777,7 +780,7 @@ class Gatt extends EventEmitter {
777
780
  return function (result, data) {
778
781
  let callbackResponse;
779
782
  const { mtu } = this._connections.get(connection);
780
-
783
+
781
784
  if (ATT_ECODE_SUCCESS === result) {
782
785
  const dataLength = Math.min(data.length, mtu - 1);
783
786
  callbackResponse = Buffer.alloc(1 + dataLength);
@@ -824,7 +827,16 @@ class Gatt extends EventEmitter {
824
827
  if (handleSecure & 0x02 && !this._connections.get(connection).aclStream.encrypted) {
825
828
  result = ATT_ECODE_AUTHENTICATION;
826
829
  } else {
827
- data = handle.value;
830
+ if (handle.values && handle.values.has(connection)) {
831
+ data = handle.values.get(connection);
832
+ }
833
+ else {
834
+ data = handle.value;
835
+ }
836
+
837
+ if (!data && handle.uuid === '2902' && this._connections.get(connection)) {
838
+ data = Buffer.from([0x00, 0x00]);
839
+ }
828
840
 
829
841
  if (data) {
830
842
  result = ATT_ECODE_SUCCESS;
@@ -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.1",
3
+ "version": "0.10.3",
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"