incyclist-services 1.0.55 → 1.0.56

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.
@@ -52,10 +52,12 @@ export interface InternalPairingState extends PairingState {
52
52
  scanTo?: NodeJS.Timeout;
53
53
  tsPrevStart?: number;
54
54
  check?: {
55
- promise: Promise<boolean>;
55
+ preparing?: number;
56
+ promise?: Promise<boolean>;
56
57
  };
57
58
  scan?: {
58
- promise: Promise<DeviceSettings[]>;
59
+ preparing?: number;
60
+ promise?: Promise<DeviceSettings[]>;
59
61
  adapters?: Array<{
60
62
  udid: string;
61
63
  adapter: IncyclistDeviceAdapter;
@@ -12,6 +12,8 @@ export interface Services {
12
12
  }
13
13
  export declare class DevicePairingService extends IncyclistService {
14
14
  protected static _instance: DevicePairingService;
15
+ protected static checkCounter: number;
16
+ protected static scanCounter: number;
15
17
  protected configuration: DeviceConfigurationService;
16
18
  protected access: DeviceAccessService;
17
19
  protected rideService: DeviceRideService;
@@ -431,7 +431,6 @@ class DevicePairingService extends service_2.IncyclistService {
431
431
  const current = getInterfaceSettings(ifName, prev);
432
432
  const changed = (current.state !== ifDetails.state || current.isScanning !== ifDetails.isScanning || current.enabled !== ifDetails.enabled);
433
433
  if (!changed) {
434
- console.log('~~~ DEUBUG: if change, no change', ifName, ifDetails);
435
434
  return;
436
435
  }
437
436
  this.logEvent({ message: 'interface state changed', interface: ifName, state: ifDetails.state });
@@ -765,6 +764,10 @@ class DevicePairingService extends service_2.IncyclistService {
765
764
  }
766
765
  startPairing(adapters, props) {
767
766
  return __awaiter(this, void 0, void 0, function* () {
767
+ if (this.isPairing())
768
+ return;
769
+ const preparing = DevicePairingService.checkCounter++;
770
+ this.state.check = { preparing };
768
771
  this.emit('pairing-start');
769
772
  const requiredInterfaces = this.getPairingInterfaces();
770
773
  const busyRequired = this.state.interfaces
@@ -773,8 +776,10 @@ class DevicePairingService extends service_2.IncyclistService {
773
776
  const isReady = busyRequired === undefined;
774
777
  if (!isReady) {
775
778
  setTimeout(() => {
776
- if (!this.isPairing() && !this.isScanning())
779
+ if ((!this.isPairing() || this.state.check.preparing === preparing) && !this.isScanning()) {
780
+ delete this.state.check;
777
781
  this.run();
782
+ }
778
783
  }, 1000);
779
784
  return;
780
785
  }
@@ -782,6 +787,9 @@ class DevicePairingService extends service_2.IncyclistService {
782
787
  this.processConnectedDevices(adapters);
783
788
  const selected = this.state.capabilities.map(c => c.selected);
784
789
  const target = adapters.filter(ai => !ai.adapter.isStarted() && selected.includes(ai.udid));
790
+ if (this.isPairing() && this.state.check.preparing !== preparing) {
791
+ return;
792
+ }
785
793
  this.initPairingCallbacks();
786
794
  const selectedAdapters = target.map(ai => (Object.assign(Object.assign({}, ai), { isStarted: false })));
787
795
  const promise = this.rideService.startAdapters(selectedAdapters, 'pair');
@@ -819,18 +827,26 @@ class DevicePairingService extends service_2.IncyclistService {
819
827
  return __awaiter(this, void 0, void 0, function* () {
820
828
  const interfaces = this.state.interfaces.filter(i => this.isInterfaceEnabled(i) && i.state === 'connected')
821
829
  .map(i => i.name);
830
+ if (this.isScanning())
831
+ return;
832
+ const preparing = DevicePairingService.scanCounter++;
833
+ this.state.scan = { preparing };
822
834
  if (interfaces.length === 0) {
823
835
  if (this.state.scanTo)
824
836
  return;
825
837
  this.state.scanTo = setTimeout(() => {
826
838
  delete this.state.scanTo;
827
- if (!this.isPairing() && !this.isScanning())
839
+ if (!this.isPairing() && (!this.isScanning() || this.state.scan.preparing === preparing)) {
840
+ delete this.state.scan;
828
841
  this.run();
842
+ }
829
843
  }, 1000);
830
844
  return;
831
845
  }
832
846
  this.emit('scanning-start');
833
847
  this.state.tsPrevStart = Date.now();
848
+ if (this.isScanning() && this.state.scan.preparing !== preparing)
849
+ return;
834
850
  this.logEvent({ message: 'Start Scanning', interfaces: interfaces.join(','), props });
835
851
  this.initScanningCallbacks();
836
852
  const timeout = props.enforcedScan ? 1000 * 60 * 60 : undefined;
@@ -1139,5 +1155,7 @@ class DevicePairingService extends service_2.IncyclistService {
1139
1155
  }
1140
1156
  }
1141
1157
  exports.DevicePairingService = DevicePairingService;
1158
+ DevicePairingService.checkCounter = 0;
1159
+ DevicePairingService.scanCounter = 0;
1142
1160
  const useDevicePairing = () => DevicePairingService.getInstance();
1143
1161
  exports.useDevicePairing = useDevicePairing;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.55",
3
+ "version": "1.0.56",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "axios": "^1.6.1",
42
- "incyclist-devices": "^2.1.22",
42
+ "incyclist-devices": "^2.1.23",
43
43
  "uuid": "^9.0.0"
44
44
  }
45
45
  }