@stoprocent/bleno 0.12.1 → 0.12.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.
@@ -1,6 +1,6 @@
1
- const events = require('events');
1
+ const BlenoEventEmitter = require('../../lib/bleno-event-emitter');
2
2
 
3
- class Pizza extends events.EventEmitter {
3
+ class Pizza extends BlenoEventEmitter {
4
4
  constructor () {
5
5
  super();
6
6
  this.toppings = PizzaToppings.NONE;
@@ -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 { EventEmitter } = require('events');
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 EventEmitter {
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.once('advertisingStart', callback);
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.once('advertisingStart', callback);
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.once('advertisingStart', callback);
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.once('advertisingStop', callback);
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.once('servicesSet', callback);
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.once('rssiUpdate', (rssi) => callback(null, rssi));
306
+ this.onceExclusive('rssiUpdate', (rssi) => callback(null, rssi));
307
307
  }
308
308
 
309
309
  this._bindings.updateRssi();
@@ -1,7 +1,7 @@
1
- const { EventEmitter } = require('events');
1
+ const BlenoEventEmitter = require('./bleno-event-emitter');
2
2
  const UuidUtil = require('./uuid-util');
3
3
 
4
- class Characteristic extends EventEmitter {
4
+ class Characteristic extends BlenoEventEmitter {
5
5
  constructor (options) {
6
6
  super();
7
7
 
@@ -1,8 +1,8 @@
1
- const { EventEmitter } = require('events');
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 EventEmitter {
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 { EventEmitter } = require('events');
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 EventEmitter {
11
+ class BlenoBindings extends BlenoEventEmitter {
12
12
  constructor (options) {
13
13
  super();
14
14
 
@@ -1,6 +1,6 @@
1
1
  const debug = require('debug')('gap');
2
2
 
3
- const { EventEmitter } = require('events');
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 EventEmitter {
12
+ class Gap extends BlenoEventEmitter {
13
13
  constructor (hci) {
14
14
  super();
15
15
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  const debug = require('debug')('gatt');
5
5
 
6
- const { EventEmitter } = require('events');
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 EventEmitter {
67
+ class Gatt extends BlenoEventEmitter {
68
68
  constructor () {
69
69
  super();
70
70
 
@@ -1,6 +1,6 @@
1
1
  const debug = require('debug')('hci');
2
2
 
3
- const { EventEmitter } = require('events');
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 EventEmitter {
77
+ class Hci extends BlenoEventEmitter {
78
78
  constructor (options) {
79
79
  super();
80
80
  options = options || {};
@@ -1,4 +1,4 @@
1
- const { EventEmitter } = require('events');
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 EventEmitter {
16
+ class Smp extends BlenoEventEmitter {
17
17
 
18
18
  constructor (aclStream, mgmt, localAddressType, localAddress, remoteAddressType, remoteAddress) {
19
19
  super();
@@ -1,4 +1,4 @@
1
- const { EventEmitter } = require('events');
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, EventEmitter.prototype);
9
+ Object.setPrototypeOf(BlenoMac.prototype, BlenoEventEmitter.prototype);
10
10
 
11
11
  module.exports = BlenoMac;
@@ -1,7 +1,7 @@
1
- const { EventEmitter } = require('events');
1
+ const BlenoEventEmitter = require('./bleno-event-emitter');
2
2
  const UuidUtil = require('./uuid-util');
3
3
 
4
- class PrimaryService extends EventEmitter {
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.1",
3
+ "version": "0.12.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",
@@ -19,7 +19,7 @@
19
19
  "lint": "eslint \"**/*.js\"",
20
20
  "lint-fix": "eslint \"**/*.js\" --fix",
21
21
  "prebuildify": "prebuildify --napi --target 14.0.0 --force --strip --verbose",
22
- "prebuildify-cross": "prebuildify-cross --napi --target 14.0.0 --force --strip --verbose",
22
+ "prebuildify-cross": "patch-package && prebuildify-cross --napi --target 14.0.0 --force --strip --verbose",
23
23
  "semantic-release": "semantic-release",
24
24
  "pretest": "npm run rebuild",
25
25
  "rebuild": "node-gyp rebuild",
@@ -65,11 +65,12 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "debug": "^4.4.0",
68
+ "patch-package": "^8.0.0",
68
69
  "node-addon-api": "^8.3.1",
69
70
  "node-gyp-build": "^4.8.4"
70
71
  },
71
72
  "optionalDependencies": {
72
- "@stoprocent/bluetooth-hci-socket": "^2.2.3"
73
+ "@stoprocent/bluetooth-hci-socket": "^2.2.5"
73
74
  },
74
75
  "publishConfig": {
75
76
  "access": "public"
@@ -0,0 +1,13 @@
1
+ diff --git a/node_modules/@thegecko/docker-run/index.js b/node_modules/@thegecko/docker-run/index.js
2
+ index 5299bee..4de15b3 100644
3
+ --- a/node_modules/@thegecko/docker-run/index.js
4
+ +++ b/node_modules/@thegecko/docker-run/index.js
5
+ @@ -14,7 +14,7 @@ var endsWith = function(str, suffix) {
6
+ var run = function(image, opts) {
7
+ if (!opts) opts = {}
8
+
9
+ - var request = docker({host: opts.host, version: opts.version || 'v1.21'})
10
+ + var request = docker({host: opts.host, version: opts.version || 'v1.44'})
11
+ var that = new events.EventEmitter()
12
+ var tty = !!opts.tty
13
+
@@ -0,0 +1,13 @@
1
+ diff --git a/node_modules/@vweevers/docker-pull/index.js b/node_modules/@vweevers/docker-pull/index.js
2
+ index 67b3e73..5fcb567 100644
3
+ --- a/node_modules/@vweevers/docker-pull/index.js
4
+ +++ b/node_modules/@vweevers/docker-pull/index.js
5
+ @@ -12,7 +12,7 @@ var pull = function (image, opts, cb) {
6
+ image = parse(image)
7
+ if (!image) throw new Error('Invalid image')
8
+
9
+ - var request = docker({host: opts.host, version: opts.version || 'v1.21'})
10
+ + var request = docker({host: opts.host, version: opts.version || 'v1.44'})
11
+ var that = new events.EventEmitter()
12
+ var layers = {}
13
+ var progress = {}
@@ -0,0 +1,30 @@
1
+ diff --git a/node_modules/prebuildify-cross/guest.js b/node_modules/prebuildify-cross/guest.js
2
+ index dfd9eb7..6d284fb 100644
3
+ --- a/node_modules/prebuildify-cross/guest.js
4
+ +++ b/node_modules/prebuildify-cross/guest.js
5
+ @@ -9,19 +9,15 @@ const cwd = '/home/node/app'
6
+ const files = JSON.parse(process.env.PREBUILDIFY_CROSS_FILES)
7
+ const argv = process.argv.slice(2)
8
+
9
+ -// Copy host files to working directory
10
+ -for (const file of files) {
11
+ - const a = path.join('/input', file)
12
+ - const b = path.join(cwd, file)
13
+ +// Recursively copy all input files to working directory
14
+ +fs.cpSync('/input', cwd, { recursive: true })
15
+
16
+ - fs.mkdirSync(path.dirname(b), { recursive: true })
17
+ - fs.copyFileSync(a, b, fs.constants.COPYFILE_EXCL)
18
+ - fs.chmodSync(b, 0o644)
19
+ +// Clean build directory if it exists to ensure fresh build
20
+ +const buildDir = path.join(cwd, 'build')
21
+ +if (fs.existsSync(buildDir)) {
22
+ + fs.rmSync(buildDir, { recursive: true, force: true })
23
+ }
24
+
25
+ -// Use node_modules of host to avoid a second install step
26
+ -fs.symlinkSync('/input/node_modules', path.join(cwd, 'node_modules'))
27
+ -
28
+ const stdio = ['ignore', 2, 2]
29
+ const res = cp.spawnSync('npx', ['--no-install', 'prebuildify', ...argv], { cwd, stdio })
30
+