@stoprocent/bleno 0.12.2 → 0.12.4
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/examples/pizza/pizza.js +2 -2
- package/lib/bleno-event-emitter.js +27 -0
- package/lib/bleno.js +8 -8
- package/lib/characteristic.js +2 -2
- package/lib/hci-socket/acl-stream.js +2 -2
- package/lib/hci-socket/bindings.js +2 -2
- package/lib/hci-socket/gap.js +2 -2
- package/lib/hci-socket/gatt.js +2 -2
- package/lib/hci-socket/hci.js +2 -2
- package/lib/hci-socket/smp.js +2 -2
- package/lib/mac/bindings.js +2 -2
- package/lib/primary-service.js +2 -2
- package/package.json +2 -2
- 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/examples/pizza/pizza.js
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { EventEmitter } = require('events');
|
|
2
|
+
|
|
3
|
+
class BlenoEventEmitter extends EventEmitter {
|
|
4
|
+
/**
|
|
5
|
+
* Like once(), but ensures at most one listener exists for the given event.
|
|
6
|
+
* If a previous exclusive listener was registered for the same event, it is
|
|
7
|
+
* removed before the new one is added. This prevents listener accumulation
|
|
8
|
+
* when a method is called repeatedly before the event fires.
|
|
9
|
+
*/
|
|
10
|
+
onceExclusive (event, callback) {
|
|
11
|
+
if (!this._exclusiveCallbacks) {
|
|
12
|
+
this._exclusiveCallbacks = new Map();
|
|
13
|
+
}
|
|
14
|
+
const prev = this._exclusiveCallbacks.get(event);
|
|
15
|
+
if (prev) {
|
|
16
|
+
this.removeListener(event, prev);
|
|
17
|
+
}
|
|
18
|
+
const wrappedCallback = (...args) => {
|
|
19
|
+
this._exclusiveCallbacks.delete(event);
|
|
20
|
+
callback(...args);
|
|
21
|
+
};
|
|
22
|
+
this._exclusiveCallbacks.set(event, wrappedCallback);
|
|
23
|
+
this.once(event, wrappedCallback);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = BlenoEventEmitter;
|
package/lib/bleno.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const debug = require('debug')('bleno');
|
|
2
2
|
const UuidUtil = require('./uuid-util');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const BlenoEventEmitter = require('./bleno-event-emitter');
|
|
5
5
|
|
|
6
6
|
const PrimaryService = require('./primary-service');
|
|
7
7
|
const Characteristic = require('./characteristic');
|
|
8
8
|
const Descriptor = require('./descriptor');
|
|
9
9
|
|
|
10
|
-
class Bleno extends
|
|
10
|
+
class Bleno extends BlenoEventEmitter {
|
|
11
11
|
constructor (bindings) {
|
|
12
12
|
super();
|
|
13
13
|
this.initialized = false;
|
|
@@ -138,7 +138,7 @@ class Bleno extends EventEmitter {
|
|
|
138
138
|
}
|
|
139
139
|
} else {
|
|
140
140
|
if (typeof callback === 'function') {
|
|
141
|
-
this.
|
|
141
|
+
this.onceExclusive('advertisingStart', callback);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
const undashedServiceUuids = [];
|
|
@@ -186,7 +186,7 @@ class Bleno extends EventEmitter {
|
|
|
186
186
|
iBeaconData.writeInt8(measuredPower, uuidDataLength + 4);
|
|
187
187
|
|
|
188
188
|
if (typeof callback === 'function') {
|
|
189
|
-
this.
|
|
189
|
+
this.onceExclusive('advertisingStart', callback);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
debug('iBeacon data = ' + iBeaconData.toString('hex'));
|
|
@@ -225,7 +225,7 @@ class Bleno extends EventEmitter {
|
|
|
225
225
|
}
|
|
226
226
|
} else {
|
|
227
227
|
if (typeof callback === 'function') {
|
|
228
|
-
this.
|
|
228
|
+
this.onceExclusive('advertisingStart', callback);
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
this._bindings.startAdvertisingWithEIRData(advertisementData, scanData);
|
|
@@ -243,7 +243,7 @@ class Bleno extends EventEmitter {
|
|
|
243
243
|
|
|
244
244
|
stopAdvertising (callback) {
|
|
245
245
|
if (typeof callback === 'function') {
|
|
246
|
-
this.
|
|
246
|
+
this.onceExclusive('advertisingStop', callback);
|
|
247
247
|
}
|
|
248
248
|
this._bindings.stopAdvertising();
|
|
249
249
|
}
|
|
@@ -264,7 +264,7 @@ class Bleno extends EventEmitter {
|
|
|
264
264
|
|
|
265
265
|
setServices (services, callback) {
|
|
266
266
|
if (typeof callback === 'function') {
|
|
267
|
-
this.
|
|
267
|
+
this.onceExclusive('servicesSet', callback);
|
|
268
268
|
}
|
|
269
269
|
this._bindings.setServices(services);
|
|
270
270
|
}
|
|
@@ -303,7 +303,7 @@ class Bleno extends EventEmitter {
|
|
|
303
303
|
|
|
304
304
|
updateRssi (callback) {
|
|
305
305
|
if (typeof callback === 'function') {
|
|
306
|
-
this.
|
|
306
|
+
this.onceExclusive('rssiUpdate', (rssi) => callback(null, rssi));
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
this._bindings.updateRssi();
|
package/lib/characteristic.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BlenoEventEmitter = require('./bleno-event-emitter');
|
|
2
2
|
const UuidUtil = require('./uuid-util');
|
|
3
3
|
|
|
4
|
-
class Characteristic extends
|
|
4
|
+
class Characteristic extends BlenoEventEmitter {
|
|
5
5
|
constructor (options) {
|
|
6
6
|
super();
|
|
7
7
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BlenoEventEmitter = require('../bleno-event-emitter');
|
|
2
2
|
const Smp = require('./smp');
|
|
3
3
|
const Mgmt = require('./mgmt');
|
|
4
4
|
|
|
5
|
-
class AclStream extends
|
|
5
|
+
class AclStream extends BlenoEventEmitter {
|
|
6
6
|
constructor (hci, handle, localAddressType, localAddress, remoteAddressType, remoteAddress) {
|
|
7
7
|
super();
|
|
8
8
|
this._hci = hci;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const debug = require('debug')('bindings');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const BlenoEventEmitter = require('../bleno-event-emitter');
|
|
4
4
|
const os = require('os');
|
|
5
5
|
|
|
6
6
|
const AclStream = require('./acl-stream');
|
|
@@ -8,7 +8,7 @@ const Hci = require('./hci');
|
|
|
8
8
|
const Gap = require('./gap');
|
|
9
9
|
const Gatt = require('./gatt');
|
|
10
10
|
|
|
11
|
-
class BlenoBindings extends
|
|
11
|
+
class BlenoBindings extends BlenoEventEmitter {
|
|
12
12
|
constructor (options) {
|
|
13
13
|
super();
|
|
14
14
|
|
package/lib/hci-socket/gap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const debug = require('debug')('gap');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const BlenoEventEmitter = require('../bleno-event-emitter');
|
|
4
4
|
const os = require('os');
|
|
5
5
|
|
|
6
6
|
const Hci = require('./hci');
|
|
@@ -9,7 +9,7 @@ const isLinux = (os.platform() === 'linux');
|
|
|
9
9
|
const isIntelEdison = isLinux && (os.release().includes('edison'));
|
|
10
10
|
const isYocto = isLinux && (os.release().includes('yocto'));
|
|
11
11
|
|
|
12
|
-
class Gap extends
|
|
12
|
+
class Gap extends BlenoEventEmitter {
|
|
13
13
|
constructor (hci) {
|
|
14
14
|
super();
|
|
15
15
|
|
package/lib/hci-socket/gatt.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const debug = require('debug')('gatt');
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const BlenoEventEmitter = require('../bleno-event-emitter');
|
|
7
7
|
const os = require('os');
|
|
8
8
|
const Characteristic = require('../characteristic');
|
|
9
9
|
|
|
@@ -64,7 +64,7 @@ const ATT_ECODE_INSUFF_RESOURCES = 0x11;
|
|
|
64
64
|
|
|
65
65
|
const ATT_CID = 0x0004;
|
|
66
66
|
|
|
67
|
-
class Gatt extends
|
|
67
|
+
class Gatt extends BlenoEventEmitter {
|
|
68
68
|
constructor () {
|
|
69
69
|
super();
|
|
70
70
|
|
package/lib/hci-socket/hci.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const debug = require('debug')('hci');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const BlenoEventEmitter = require('../bleno-event-emitter');
|
|
4
4
|
const { loadDriver } = require('@stoprocent/bluetooth-hci-socket');
|
|
5
5
|
|
|
6
6
|
const vendorSpecific = require('./vs');
|
|
@@ -74,7 +74,7 @@ const HCI_OE_USER_ENDED_CONNECTION = 0x13;
|
|
|
74
74
|
|
|
75
75
|
const STATUS_MAPPER = require('./hci-status');
|
|
76
76
|
|
|
77
|
-
class Hci extends
|
|
77
|
+
class Hci extends BlenoEventEmitter {
|
|
78
78
|
constructor (options) {
|
|
79
79
|
super();
|
|
80
80
|
options = options || {};
|
package/lib/hci-socket/smp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BlenoEventEmitter = require('../bleno-event-emitter');
|
|
2
2
|
const crypto = require('./crypto');
|
|
3
3
|
|
|
4
4
|
const SMP_CID = 0x0006;
|
|
@@ -13,7 +13,7 @@ const SMP_MASTER_IDENT = 0x07;
|
|
|
13
13
|
|
|
14
14
|
const SMP_UNSPECIFIED = 0x08;
|
|
15
15
|
|
|
16
|
-
class Smp extends
|
|
16
|
+
class Smp extends BlenoEventEmitter {
|
|
17
17
|
|
|
18
18
|
constructor (aclStream, mgmt, localAddressType, localAddress, remoteAddressType, remoteAddress) {
|
|
19
19
|
super();
|
package/lib/mac/bindings.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BlenoEventEmitter = require('../bleno-event-emitter');
|
|
2
2
|
|
|
3
3
|
const { resolve } = require('path');
|
|
4
4
|
const dir = resolve(__dirname, '..', '..');
|
|
@@ -6,6 +6,6 @@ const binding = require('node-gyp-build')(dir);
|
|
|
6
6
|
|
|
7
7
|
const { BlenoMac } = binding;
|
|
8
8
|
|
|
9
|
-
Object.setPrototypeOf(BlenoMac.prototype,
|
|
9
|
+
Object.setPrototypeOf(BlenoMac.prototype, BlenoEventEmitter.prototype);
|
|
10
10
|
|
|
11
11
|
module.exports = BlenoMac;
|
package/lib/primary-service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BlenoEventEmitter = require('./bleno-event-emitter');
|
|
2
2
|
const UuidUtil = require('./uuid-util');
|
|
3
3
|
|
|
4
|
-
class PrimaryService extends
|
|
4
|
+
class PrimaryService extends BlenoEventEmitter {
|
|
5
5
|
constructor (options) {
|
|
6
6
|
super();
|
|
7
7
|
this.uuid = UuidUtil.removeDashes(options.uuid);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoprocent/bleno",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
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",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"node-gyp-build": "^4.8.4"
|
|
71
71
|
},
|
|
72
72
|
"optionalDependencies": {
|
|
73
|
-
"@stoprocent/bluetooth-hci-socket": "^2.2.
|
|
73
|
+
"@stoprocent/bluetooth-hci-socket": "^2.2.6"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|