@stoprocent/noble 1.17.4 → 1.18.0
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.
|
@@ -61,20 +61,26 @@ NobleBindings.prototype.connect = function (peripheralUuid, parameters = {}) {
|
|
|
61
61
|
addressType = parameters && parameters.addressType ? parameters.addressType : 'random';
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
// Add connection request to queue
|
|
65
|
+
this._connectionQueue.push({
|
|
66
|
+
id: peripheralUuid,
|
|
67
|
+
address,
|
|
68
|
+
addressType,
|
|
69
|
+
params: parameters
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const processNextConnection = () => {
|
|
73
|
+
if (this._connectionQueue.length === 0) return;
|
|
74
|
+
|
|
75
|
+
const nextConn = this._connectionQueue[0]; // Look at next connection but don't remove yet
|
|
76
|
+
this._hci.createLeConn(nextConn.address, nextConn.addressType, nextConn.params);
|
|
71
77
|
};
|
|
72
78
|
|
|
73
79
|
if (this._isScanning) {
|
|
74
|
-
this.once('scanStop',
|
|
80
|
+
this.once('scanStop', processNextConnection);
|
|
75
81
|
this.stopScanning();
|
|
76
82
|
} else {
|
|
77
|
-
|
|
83
|
+
processNextConnection();
|
|
78
84
|
}
|
|
79
85
|
};
|
|
80
86
|
|
|
@@ -128,6 +134,21 @@ NobleBindings.prototype.onSigInt = function () {
|
|
|
128
134
|
const sigIntListeners = process.listeners('SIGINT');
|
|
129
135
|
|
|
130
136
|
if (sigIntListeners[sigIntListeners.length - 1] === this.onSigIntBinded) {
|
|
137
|
+
// Stop scanning if active
|
|
138
|
+
if (this._isScanning) {
|
|
139
|
+
this.stopScanning();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Disconnect all active connections
|
|
143
|
+
for (const handle in this._handles) {
|
|
144
|
+
if (this._handles.hasOwnProperty(handle)) {
|
|
145
|
+
this.disconnect(this._handles[handle]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Clear connection queue
|
|
150
|
+
this._connectionQueue = [];
|
|
151
|
+
|
|
131
152
|
// we are the last listener, so exit
|
|
132
153
|
// this will trigger onExit, and clean up
|
|
133
154
|
process.exit(1);
|
|
@@ -259,8 +280,8 @@ NobleBindings.prototype.onLeConnComplete = function (
|
|
|
259
280
|
// not master, ignore
|
|
260
281
|
return;
|
|
261
282
|
}
|
|
262
|
-
let uuid = null;
|
|
263
283
|
|
|
284
|
+
let uuid = null;
|
|
264
285
|
let error = null;
|
|
265
286
|
|
|
266
287
|
if (status === 0) {
|
|
@@ -351,27 +372,23 @@ NobleBindings.prototype.onLeConnComplete = function (
|
|
|
351
372
|
|
|
352
373
|
this._gatts[handle].exchangeMtu();
|
|
353
374
|
} else {
|
|
354
|
-
|
|
375
|
+
const currentConn = this._connectionQueue[0];
|
|
376
|
+
uuid = currentConn ? currentConn.id : null;
|
|
355
377
|
let statusMessage = Hci.STATUS_MAPPER[status] || 'HCI Error: Unknown';
|
|
356
378
|
const errorCode = ` (0x${status.toString(16)})`;
|
|
357
379
|
statusMessage = statusMessage + errorCode;
|
|
358
380
|
error = new Error(statusMessage);
|
|
359
381
|
}
|
|
360
382
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (this._connectionQueue.length > 0) {
|
|
364
|
-
const queueItem = this._connectionQueue.shift();
|
|
365
|
-
const peripheralUuid = queueItem.id;
|
|
383
|
+
// Remove the completed/failed connection attempt from queue
|
|
384
|
+
this._connectionQueue.shift();
|
|
366
385
|
|
|
367
|
-
|
|
368
|
-
addressType = this._addresseTypes[peripheralUuid];
|
|
369
|
-
|
|
370
|
-
this._pendingConnectionUuid = peripheralUuid;
|
|
386
|
+
this.emit('connect', uuid, error);
|
|
371
387
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
388
|
+
// Process next connection in queue if any
|
|
389
|
+
if (this._connectionQueue.length > 0 && !this._isScanning) {
|
|
390
|
+
const nextConn = this._connectionQueue[0];
|
|
391
|
+
this._hci.createLeConn(nextConn.address, nextConn.addressType, nextConn.params);
|
|
375
392
|
}
|
|
376
393
|
};
|
|
377
394
|
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|