incyclist-devices 3.0.27 → 3.0.28

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.
@@ -345,7 +345,10 @@ class BleAdapter extends adpater_js_1.default {
345
345
  }
346
346
  const sensor = this.getSensor();
347
347
  let connected = await sensor.startSensor();
348
- await sensor.subscribe();
348
+ const subscribed = await sensor.subscribe();
349
+ if (connected && !subscribed) {
350
+ connected = false;
351
+ }
349
352
  if (connected) {
350
353
  sensor.on('data', this.onDeviceDataHandler);
351
354
  sensor.on('disconnected', this.onDeviceDisconnectHandler);
@@ -15,6 +15,7 @@ class BlePeripheral {
15
15
  disconnecting = false;
16
16
  disconnectedSignalled = false;
17
17
  discoveredServiceUUIds;
18
+ serviceDiscoveryIncomplete = false;
18
19
  discoverServicesPromise;
19
20
  discoverCharacteristicsPromise = {};
20
21
  onErrorHandler = this.onPeripheralError.bind(this);
@@ -159,8 +160,11 @@ class BlePeripheral {
159
160
  const res = await promise;
160
161
  (0, utils_js_1.sleep)(0).then(() => { delete this.discoverServicesPromise; });
161
162
  const isComplete = this.checkAnnouncedServices(res);
163
+ this.serviceDiscoveryIncomplete = !isComplete;
162
164
  if (!isComplete) {
163
- this.logEvent({ message: 'service data incomplete - disconnecting' });
165
+ const { name, address } = this.getInfo();
166
+ this.logEvent({ message: 'service data incomplete - disconnecting', name, address,
167
+ announced: this.getAnnouncedServices(), discovered: this.getDiscoveredServices() });
164
168
  }
165
169
  return res;
166
170
  }
@@ -324,6 +328,14 @@ class BlePeripheral {
324
328
  }
325
329
  catch { }
326
330
  }
331
+ if (this.serviceDiscoveryIncomplete) {
332
+ this.logEvent({ message: 'peripheral subscribe selected failed', uuids, reason: 'service discovery incomplete',
333
+ announced: this.getAnnouncedServices(), discovered: this.getDiscoveredServices() });
334
+ this.discoveredServiceUUIds = undefined;
335
+ this.serviceDiscoveryIncomplete = false;
336
+ await this.disconnect().catch(() => { });
337
+ return false;
338
+ }
327
339
  try {
328
340
  if (Object.keys(this.characteristics).length === 0) {
329
341
  await this.discoverAllCharacteristics();
@@ -364,6 +376,11 @@ class BlePeripheral {
364
376
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], []);
365
377
  const found = [];
366
378
  const uuids = [];
379
+ const freshUuids = new Set(res.characteristics.map(c => (0, utils_js_2.beautifyUUID)(c.uuid)));
380
+ Object.keys(this.characteristics).forEach(existing => {
381
+ if (!freshUuids.has(existing))
382
+ delete this.characteristics[existing];
383
+ });
367
384
  res.characteristics.forEach(c => {
368
385
  this.characteristics[(0, utils_js_2.beautifyUUID)(c.uuid)] = c;
369
386
  found.push(c.uuid);
@@ -382,6 +399,12 @@ class BlePeripheral {
382
399
  const target = characteristics.map(c => (0, utils_js_2.fullUUID)(c));
383
400
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], target);
384
401
  const found = [];
402
+ const freshUuids = new Set(res.characteristics.map(c => (0, utils_js_2.beautifyUUID)(c.uuid)));
403
+ characteristics.forEach(requested => {
404
+ const requestedUuid = (0, utils_js_2.beautifyUUID)(requested);
405
+ if (!freshUuids.has(requestedUuid))
406
+ delete this.characteristics[requestedUuid];
407
+ });
385
408
  res.characteristics.forEach(c => {
386
409
  this.characteristics[(0, utils_js_2.beautifyUUID)(c.uuid)] = c;
387
410
  found.push(c.uuid);
@@ -79,6 +79,7 @@ class TBleSensor extends node_events_1.EventEmitter {
79
79
  }
80
80
  this.connectPromise = this.connectPromise ?? this.peripheral.connect();
81
81
  const connected = await this.connectPromise;
82
+ delete this.connectPromise;
82
83
  if (!connected)
83
84
  return false;
84
85
  if (!reconnect)
@@ -340,7 +340,10 @@ export default class BleAdapter extends IncyclistDevice {
340
340
  }
341
341
  const sensor = this.getSensor();
342
342
  let connected = await sensor.startSensor();
343
- await sensor.subscribe();
343
+ const subscribed = await sensor.subscribe();
344
+ if (connected && !subscribed) {
345
+ connected = false;
346
+ }
344
347
  if (connected) {
345
348
  sensor.on('data', this.onDeviceDataHandler);
346
349
  sensor.on('disconnected', this.onDeviceDisconnectHandler);
@@ -12,6 +12,7 @@ export class BlePeripheral {
12
12
  disconnecting = false;
13
13
  disconnectedSignalled = false;
14
14
  discoveredServiceUUIds;
15
+ serviceDiscoveryIncomplete = false;
15
16
  discoverServicesPromise;
16
17
  discoverCharacteristicsPromise = {};
17
18
  onErrorHandler = this.onPeripheralError.bind(this);
@@ -156,8 +157,11 @@ export class BlePeripheral {
156
157
  const res = await promise;
157
158
  sleep(0).then(() => { delete this.discoverServicesPromise; });
158
159
  const isComplete = this.checkAnnouncedServices(res);
160
+ this.serviceDiscoveryIncomplete = !isComplete;
159
161
  if (!isComplete) {
160
- this.logEvent({ message: 'service data incomplete - disconnecting' });
162
+ const { name, address } = this.getInfo();
163
+ this.logEvent({ message: 'service data incomplete - disconnecting', name, address,
164
+ announced: this.getAnnouncedServices(), discovered: this.getDiscoveredServices() });
161
165
  }
162
166
  return res;
163
167
  }
@@ -321,6 +325,14 @@ export class BlePeripheral {
321
325
  }
322
326
  catch { }
323
327
  }
328
+ if (this.serviceDiscoveryIncomplete) {
329
+ this.logEvent({ message: 'peripheral subscribe selected failed', uuids, reason: 'service discovery incomplete',
330
+ announced: this.getAnnouncedServices(), discovered: this.getDiscoveredServices() });
331
+ this.discoveredServiceUUIds = undefined;
332
+ this.serviceDiscoveryIncomplete = false;
333
+ await this.disconnect().catch(() => { });
334
+ return false;
335
+ }
324
336
  try {
325
337
  if (Object.keys(this.characteristics).length === 0) {
326
338
  await this.discoverAllCharacteristics();
@@ -361,6 +373,11 @@ export class BlePeripheral {
361
373
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], []);
362
374
  const found = [];
363
375
  const uuids = [];
376
+ const freshUuids = new Set(res.characteristics.map(c => beautifyUUID(c.uuid)));
377
+ Object.keys(this.characteristics).forEach(existing => {
378
+ if (!freshUuids.has(existing))
379
+ delete this.characteristics[existing];
380
+ });
364
381
  res.characteristics.forEach(c => {
365
382
  this.characteristics[beautifyUUID(c.uuid)] = c;
366
383
  found.push(c.uuid);
@@ -379,6 +396,12 @@ export class BlePeripheral {
379
396
  const target = characteristics.map(c => fullUUID(c));
380
397
  const res = await this.getPeripheral().discoverSomeServicesAndCharacteristicsAsync([], target);
381
398
  const found = [];
399
+ const freshUuids = new Set(res.characteristics.map(c => beautifyUUID(c.uuid)));
400
+ characteristics.forEach(requested => {
401
+ const requestedUuid = beautifyUUID(requested);
402
+ if (!freshUuids.has(requestedUuid))
403
+ delete this.characteristics[requestedUuid];
404
+ });
382
405
  res.characteristics.forEach(c => {
383
406
  this.characteristics[beautifyUUID(c.uuid)] = c;
384
407
  found.push(c.uuid);
@@ -76,6 +76,7 @@ export class TBleSensor extends EventEmitter {
76
76
  }
77
77
  this.connectPromise = this.connectPromise ?? this.peripheral.connect();
78
78
  const connected = await this.connectPromise;
79
+ delete this.connectPromise;
79
80
  if (!connected)
80
81
  return false;
81
82
  if (!reconnect)
@@ -14,6 +14,7 @@ export declare class BlePeripheral implements IBlePeripheral {
14
14
  protected disconnecting: boolean;
15
15
  protected disconnectedSignalled: boolean;
16
16
  protected discoveredServiceUUIds: Array<string> | undefined;
17
+ protected serviceDiscoveryIncomplete: boolean;
17
18
  protected discoverServicesPromise: Promise<string[]> | undefined;
18
19
  protected discoverCharacteristicsPromise: Record<string, Promise<BleCharacteristic[]> | undefined>;
19
20
  protected onErrorHandler: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.27",
3
+ "version": "3.0.28",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",