incyclist-devices 2.3.1 → 2.3.2

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.
@@ -33,6 +33,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
33
33
  protected instanceId: number;
34
34
  protected connectedPeripherals: IBlePeripheral[];
35
35
  protected connectAttemptCnt: number;
36
+ protected emitted: BlePeripheralAnnouncement[];
36
37
  static getInstance(props?: InterfaceProps): BleInterface;
37
38
  protected constructor(props: InterfaceProps);
38
39
  setProps(props: InterfaceProps): void;
@@ -74,6 +75,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
74
75
  protected startScan(): Promise<unknown>;
75
76
  private emitCachedDevices;
76
77
  protected emitDevice(service: BlePeripheralAnnouncement): void;
78
+ protected alreadyEmitted(service: BlePeripheralAnnouncement): boolean;
77
79
  protected buildDeviceSettings(matching?: string[]): BleDeviceSettings[];
78
80
  protected addCompleting(service: BlePeripheralAnnouncement): void;
79
81
  protected addUnsupported(service: BlePeripheralAnnouncement): void;
@@ -51,6 +51,7 @@ class BleInterface extends events_1.default {
51
51
  this.matching = [];
52
52
  this.connectedPeripherals = [];
53
53
  this.connectAttemptCnt = 0;
54
+ this.emitted = [];
54
55
  this.instanceId = ++instanceCount;
55
56
  this.props = props;
56
57
  this.logEnabled = props.log || true;
@@ -426,6 +427,7 @@ class BleInterface extends events_1.default {
426
427
  }
427
428
  startScan() {
428
429
  this.logEvent({ message: 'scan started', scanning: this.isScanning() });
430
+ this.emitted = [];
429
431
  this.emitCachedDevices();
430
432
  return new Promise(() => {
431
433
  });
@@ -438,9 +440,16 @@ class BleInterface extends events_1.default {
438
440
  });
439
441
  }
440
442
  emitDevice(service) {
443
+ if (this.alreadyEmitted(service)) {
444
+ return;
445
+ }
441
446
  const settings = this.createDeviceSetting(service);
442
447
  this.logEvent({ message: 'device found', settings });
443
448
  this.emit('device', settings, service);
449
+ this.emitted.push(service);
450
+ }
451
+ alreadyEmitted(service) {
452
+ return this.emitted.find(s => s.name === service.name || s.peripheral.address === service.peripheral.address) !== undefined;
444
453
  }
445
454
  buildDeviceSettings(matching = []) {
446
455
  return matching.map((name) => {
@@ -79,7 +79,7 @@ class BlePeripheral {
79
79
  }
80
80
  onPeripheralDisconnect() {
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
- this.logEvent({ message: 'disconnect' });
82
+ this.logEvent({ message: 'peripheral disconnected' });
83
83
  try {
84
84
  yield this.disconnect(true);
85
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",