@stoprocent/noble 1.18.2 → 1.18.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.
@@ -105,7 +105,13 @@ NobleBindings.prototype.updateRssi = function (peripheralUuid) {
105
105
  };
106
106
 
107
107
  NobleBindings.prototype.init = function () {
108
- this.onSigIntBinded = this.onSigInt.bind(this);
108
+ /* Add exit handlers after `init()` has completed. If no adaptor
109
+ is present it can throw an exception - in which case we don't
110
+ want to try and clear up afterwards (issue #502) */
111
+ this._sigIntHandler = this.onSigInt.bind(this);
112
+ this._exitHandler = this.stop.bind(this);
113
+ process.on('SIGINT', this._sigIntHandler);
114
+ process.on('exit', this._exitHandler);
109
115
 
110
116
  this._gap.on('scanParametersSet', this.onScanParametersSet.bind(this));
111
117
  this._gap.on('scanStart', this.onScanStart.bind(this));
@@ -122,18 +128,12 @@ NobleBindings.prototype.init = function () {
122
128
  this._hci.on('aclDataPkt', this.onAclDataPkt.bind(this));
123
129
 
124
130
  this._hci.init();
125
-
126
- /* Add exit handlers after `init()` has completed. If no adaptor
127
- is present it can throw an exception - in which case we don't
128
- want to try and clear up afterwards (issue #502) */
129
- process.on('SIGINT', this.onSigIntBinded);
130
- process.on('exit', this.stop.bind(this));
131
131
  };
132
132
 
133
133
  NobleBindings.prototype.onSigInt = function () {
134
134
  const sigIntListeners = process.listeners('SIGINT');
135
135
 
136
- if (sigIntListeners[sigIntListeners.length - 1] === this.onSigIntBinded) {
136
+ if (sigIntListeners[sigIntListeners.length - 1] === this._sigIntHandler) {
137
137
  // we are the last listener, so exit
138
138
  // this will trigger onExit, and clean up
139
139
  process.exit(1);
@@ -141,6 +141,9 @@ NobleBindings.prototype.onSigInt = function () {
141
141
  };
142
142
 
143
143
  NobleBindings.prototype.stop = function () {
144
+ process.removeListener('exit', this._exitHandler);
145
+ process.removeListener('SIGINT', this._sigIntHandler);
146
+
144
147
  this.stopScanning();
145
148
  for (const handle in this._aclStreams) {
146
149
  this._hci.disconnect(handle);
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "license": "MIT",
7
7
  "name": "@stoprocent/noble",
8
8
  "description": "A Node.js BLE (Bluetooth Low Energy) central library.",
9
- "version": "1.18.2",
9
+ "version": "1.18.3",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/stoprocent/noble.git"
@@ -34,7 +34,7 @@
34
34
  "node-gyp-build": "^4.8.1"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@stoprocent/bluetooth-hci-socket": "^1.4.4"
37
+ "@stoprocent/bluetooth-hci-socket": "^1.4.5"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@commitlint/cli": "^19.3.0",
@@ -78,13 +78,13 @@ describe('hci-socket bindings', () => {
78
78
  describe('onSigInt', () => {
79
79
  it('should exit', () => {
80
80
  const sigIntListeners = process.listeners('SIGINT');
81
- bindings.onSigIntBinded = sigIntListeners[sigIntListeners.length - 1];
81
+ bindings._sigIntHandler = sigIntListeners[sigIntListeners.length - 1];
82
82
  bindings.onSigInt();
83
83
  assert.calledOnceWithExactly(process.exit, 1);
84
84
  });
85
85
 
86
86
  it('should not exit', () => {
87
- bindings.onSigIntBinded = sinon.spy();
87
+ bindings._sigIntHandler = sinon.spy();
88
88
  bindings.onSigInt();
89
89
  assert.notCalled(process.exit);
90
90
  });
@@ -292,7 +292,9 @@ describe('hci-socket bindings', () => {
292
292
  bindings._gap.stopScanning = fake.resolves(null);
293
293
  bindings._hci.reset = fake.resolves(null);
294
294
  bindings._hci.stop = fake.resolves(null);
295
-
295
+ bindings._sigIntHandler = fake.resolves(null);
296
+ bindings._exitHandler = fake.resolves(null);
297
+
296
298
  bindings.stop();
297
299
 
298
300
  assert.calledOnce(bindings._gap.stopScanning);
@@ -305,6 +307,8 @@ describe('hci-socket bindings', () => {
305
307
  bindings._hci.disconnect = fake.resolves(null);
306
308
  bindings._hci.reset = fake.resolves(null);
307
309
  bindings._hci.stop = fake.resolves(null);
310
+ bindings._sigIntHandler = fake.resolves(null);
311
+ bindings._exitHandler = fake.resolves(null);
308
312
 
309
313
  bindings._aclStreams = [1, 2, 3];
310
314