incyclist-services 1.9.21 → 1.9.22

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.
Files changed (46) hide show
  1. package/lib/cjs/activities/base/repo/db.js +7 -1
  2. package/lib/cjs/devices/page/base/guidance/guidance.js +277 -16
  3. package/lib/cjs/devices/page/base/service.js +245 -16
  4. package/lib/cjs/devices/page/desktop/matrix.js +2 -1
  5. package/lib/cjs/devices/page/desktop/service.js +4 -11
  6. package/lib/cjs/devices/page/mobile/service.js +1 -0
  7. package/lib/cjs/devices/pairing/conflict.js +47 -0
  8. package/lib/cjs/devices/pairing/guidance.js +40 -4
  9. package/lib/cjs/devices/pairing/helper.js +3 -1
  10. package/lib/cjs/devices/pairing/index.js +1 -0
  11. package/lib/cjs/devices/pairing/service.js +228 -35
  12. package/lib/cjs/devices/pairing/status.js +1 -0
  13. package/lib/cjs/devices/ride/service.js +20 -4
  14. package/lib/cjs/devices/ride/timeouts.js +9 -0
  15. package/lib/cjs/ride/display/service.js +2 -2
  16. package/lib/cjs/routes/base/api/api.js +1 -0
  17. package/lib/esm/activities/base/repo/db.js +7 -1
  18. package/lib/esm/devices/page/base/guidance/guidance.js +276 -15
  19. package/lib/esm/devices/page/base/service.js +246 -17
  20. package/lib/esm/devices/page/desktop/matrix.js +2 -1
  21. package/lib/esm/devices/page/desktop/service.js +4 -11
  22. package/lib/esm/devices/page/mobile/service.js +1 -0
  23. package/lib/esm/devices/pairing/conflict.js +9 -4
  24. package/lib/esm/devices/pairing/guidance.js +40 -4
  25. package/lib/esm/devices/pairing/helper.js +1 -0
  26. package/lib/esm/devices/pairing/index.js +1 -0
  27. package/lib/esm/devices/pairing/service.js +228 -35
  28. package/lib/esm/devices/pairing/status.js +1 -0
  29. package/lib/esm/devices/ride/service.js +20 -4
  30. package/lib/esm/ride/display/service.js +2 -2
  31. package/lib/esm/routes/base/api/api.js +1 -0
  32. package/lib/types/activities/base/repo/db.d.ts +1 -0
  33. package/lib/types/devices/page/base/guidance/guidance.d.ts +49 -2
  34. package/lib/types/devices/page/base/guidance/types.d.ts +20 -2
  35. package/lib/types/devices/page/base/service.d.ts +36 -2
  36. package/lib/types/devices/page/base/types.d.ts +31 -0
  37. package/lib/types/devices/page/desktop/service.d.ts +1 -2
  38. package/lib/types/devices/pairing/conflict.d.ts +4 -1
  39. package/lib/types/devices/pairing/guidance.d.ts +9 -4
  40. package/lib/types/devices/pairing/helper.d.ts +1 -0
  41. package/lib/types/devices/pairing/index.d.ts +1 -0
  42. package/lib/types/devices/pairing/model.d.ts +1 -0
  43. package/lib/types/devices/pairing/service.d.ts +43 -4
  44. package/lib/types/devices/pairing/status.d.ts +2 -1
  45. package/lib/types/devices/ride/service.d.ts +1 -0
  46. package/package.json +2 -2
@@ -43,6 +43,7 @@ const configuration_1 = require("../configuration");
43
43
  const capability_1 = require("./capability");
44
44
  const incyclist_devices_1 = require("incyclist-devices");
45
45
  const ride_1 = require("../ride");
46
+ const timeouts_1 = require("../ride/timeouts");
46
47
  const clone_1 = __importDefault(require("../../utils/clone"));
47
48
  const service_2 = require("../../base/service");
48
49
  const sleep_1 = require("../../utils/sleep");
@@ -92,10 +93,18 @@ let DevicePairingService = (() => {
92
93
  static STALLED_AFTER_MS = 30 * 1000;
93
94
  stalledTimer;
94
95
  stalledLogged = false;
96
+ static ATTEMPT_HUNG_MARGIN_MS = 15 * 1000;
97
+ attemptHungLogged = false;
98
+ retryDelay;
99
+ windingDownAttempt = false;
95
100
  visitOpen = false;
96
101
  visitOpenedAt;
97
102
  pendingConflicts = [];
98
103
  static conflictCounter = 0;
104
+ manualConflicts = new Map();
105
+ settlingConflicts = [];
106
+ conflictSettleTimer;
107
+ static CONFLICT_SETTLE_MS = 2000;
99
108
  static SEARCH_DURATION_MS = { desktop: 60 * 1000, mobile: 30 * 1000 };
100
109
  static STOP_OFFER_DELAY_MS = 2000;
101
110
  search = DevicePairingService.initialSearchState();
@@ -133,7 +142,6 @@ let DevicePairingService = (() => {
133
142
  this.stalledLogged = false;
134
143
  if (this.state.stopped) {
135
144
  this.state.stopped = false;
136
- this.state.deleted = [];
137
145
  }
138
146
  if (this.state.interfaces) {
139
147
  this.initConfigHandlers();
@@ -220,8 +228,10 @@ let DevicePairingService = (() => {
220
228
  if (open) {
221
229
  this.visitOpenedAt ??= Date.now();
222
230
  this.getDeviceConfiguration().clearExclusions({ scope: 'until-next-pairing' });
223
- if (!this.visitOpen)
231
+ if (!this.visitOpen) {
224
232
  this.resetSearch();
233
+ this.attemptHungLogged = false;
234
+ }
225
235
  }
226
236
  else {
227
237
  delete this.visitOpenedAt;
@@ -278,6 +288,35 @@ let DevicePairingService = (() => {
278
288
  this.logError(err, 'searchAgain');
279
289
  }
280
290
  }
291
+ reconnectNow() {
292
+ try {
293
+ if (this.isPairingSettled())
294
+ return [];
295
+ const capabilities = this.getReconnectCapabilities();
296
+ if (!this.isPairing() && !this.windingDownAttempt)
297
+ this.startNextAttempt();
298
+ return capabilities;
299
+ }
300
+ catch (err) {
301
+ this.logError(err, 'reconnectNow');
302
+ return [];
303
+ }
304
+ }
305
+ getReconnectCapabilities() {
306
+ return (this.state.capabilities ?? [])
307
+ .filter(c => (0, capability_1.isCapabilityActive)(c) && c.connectState !== 'connected')
308
+ .map(c => c.capability);
309
+ }
310
+ startNextAttempt() {
311
+ if (this.usage === 'page') {
312
+ this.emit('retry');
313
+ return;
314
+ }
315
+ if (this.retryDelay)
316
+ this.retryDelay.skip();
317
+ else
318
+ this.run().catch(err => { this.logError(err, 'reconnectNow'); });
319
+ }
281
320
  isSearchAllowed() {
282
321
  return !this.visitOpen || this.search.phase !== 'ended';
283
322
  }
@@ -425,20 +464,18 @@ let DevicePairingService = (() => {
425
464
  getPendingConflicts() {
426
465
  return this.pendingConflicts.map(e => (0, clone_1.default)(e.conflict));
427
466
  }
428
- async resolveConflict(id, replace) {
467
+ async resolveConflict(id, replace, via = 'done') {
429
468
  try {
430
469
  const entry = this.takePendingConflict(id);
431
470
  if (!entry)
432
471
  return;
433
472
  const { udid, conflict } = entry;
434
- const asked = conflict.conflicts.map(c => c.capability);
435
- const stillConflicting = new Set(this.computeSelectionImpact(udid, asked).conflicts.map(c => c.capability));
436
- const toReplace = (replace ?? []).filter(c => stillConflicting.has(c));
473
+ const toReplace = this.getReplaceableRows(udid, conflict, replace);
437
474
  if (toReplace.length > 0) {
438
475
  const [first, ...rest] = toReplace;
439
476
  await this.selectDevice(first, udid, { others: 'fill-empty', replace: rest });
440
477
  }
441
- this.logConflictResolved(conflict, 'done', toReplace.length);
478
+ this.logConflictResolved(conflict, via, toReplace.length);
442
479
  }
443
480
  catch (err) {
444
481
  this.logError(err, 'resolveConflict');
@@ -454,10 +491,72 @@ let DevicePairingService = (() => {
454
491
  this.logError(err, 'dismissConflict');
455
492
  }
456
493
  }
494
+ reevaluatePendingConflicts(changed) {
495
+ try {
496
+ this.pendingConflicts = this.pendingConflicts.filter(entry => this.reevaluateConflict(entry, changed));
497
+ }
498
+ catch (err) {
499
+ this.logError(err, 'reevaluatePendingConflicts');
500
+ }
501
+ }
502
+ reevaluateConflict(entry, changed) {
503
+ const { udid, conflict } = entry;
504
+ const asked = conflict.conflicts.map(c => c.capability);
505
+ if (changed && !asked.some(c => changed.includes(c)))
506
+ return true;
507
+ const current = this.computeSelectionImpact(udid, asked).conflicts;
508
+ if (current.length === 0) {
509
+ this.logConflictResolved(conflict, 'superseded', 0);
510
+ return false;
511
+ }
512
+ conflict.conflicts = current;
513
+ return true;
514
+ }
515
+ startManualConflict(capability, udid) {
516
+ try {
517
+ const { filled, conflicts } = this.previewSelectDevice(capability, udid);
518
+ if (conflicts.length === 0)
519
+ return undefined;
520
+ const deviceName = this.getCapabilityDevice(capability, udid)?.name
521
+ ?? this.getDeviceConfiguration().getAdapter(udid)?.getUniqueName() ?? '';
522
+ const conflict = { id: this.nextConflictId(udid), origin: 'manual', deviceName, filled, conflicts };
523
+ this.manualConflicts.set(conflict.id, { udid, capability, conflict });
524
+ this.logConflictShown(conflict, conflicts.length, 0);
525
+ return (0, clone_1.default)(conflict);
526
+ }
527
+ catch (err) {
528
+ this.logError(err, 'startManualConflict');
529
+ return undefined;
530
+ }
531
+ }
532
+ async commitManualConflict(id, replace, via = 'done') {
533
+ try {
534
+ const entry = this.manualConflicts.get(id);
535
+ if (!entry)
536
+ return;
537
+ this.manualConflicts.delete(id);
538
+ const { udid, capability, conflict } = entry;
539
+ const toReplace = this.getReplaceableRows(udid, conflict, replace);
540
+ await this.selectDevice(capability, udid, { others: 'fill-empty', replace: toReplace });
541
+ this.logConflictResolved(conflict, via, toReplace.length);
542
+ }
543
+ catch (err) {
544
+ this.logError(err, 'commitManualConflict');
545
+ }
546
+ }
547
+ getReplaceableRows(udid, conflict, replace) {
548
+ const asked = conflict.conflicts.map(c => c.capability);
549
+ const stillConflicting = new Set(this.computeSelectionImpact(udid, asked).conflicts.map(c => c.capability));
550
+ const stale = asked.filter(c => !stillConflicting.has(c)).length;
551
+ if (stale > 0)
552
+ this.logEvent({ message: 'device select conflict stale', origin: conflict.origin, conflictCount: stale });
553
+ return (replace ?? []).filter(c => stillConflicting.has(c));
554
+ }
457
555
  dismissPendingConflicts(via) {
458
556
  const pending = this.pendingConflicts;
459
557
  this.pendingConflicts = [];
460
558
  pending.forEach(e => { this.logConflictResolved(e.conflict, via, 0); });
559
+ this.clearConflictSettleTimer();
461
560
  }
462
561
  takePendingConflict(id) {
463
562
  const idx = this.pendingConflicts.findIndex(e => e.conflict.id === id);
@@ -493,15 +592,33 @@ let DevicePairingService = (() => {
493
592
  this.logConflictResolved(conflict, 'left_page', 0);
494
593
  return;
495
594
  }
496
- const conflict = this.addPendingConflict(udid, deviceName, filled, conflicts);
497
- this.logConflictShown(conflict, conflicts.length, this.pendingConflicts.length - 1);
498
- this.emit('selection-conflict', (0, clone_1.default)(conflict));
595
+ this.mergeIntoConflictList(this.settlingConflicts, udid, deviceName, filled, conflicts);
596
+ if (this.conflictSettleTimer)
597
+ clearTimeout(this.conflictSettleTimer);
598
+ this.conflictSettleTimer = setTimeout(() => { this.settleDetectionConflicts(); }, DevicePairingService.CONFLICT_SETTLE_MS);
599
+ this.conflictSettleTimer.unref?.();
600
+ }
601
+ settleDetectionConflicts() {
602
+ delete this.conflictSettleTimer;
603
+ const settled = this.settlingConflicts;
604
+ this.settlingConflicts = [];
605
+ settled.forEach(({ udid, conflict }) => {
606
+ const merged = this.mergeIntoConflictList(this.pendingConflicts, udid, conflict.deviceName, conflict.filled, conflict.conflicts);
607
+ this.logConflictShown(merged, merged.conflicts.length, this.pendingConflicts.length - 1);
608
+ this.emit('selection-conflict', (0, clone_1.default)(merged));
609
+ });
610
+ }
611
+ clearConflictSettleTimer() {
612
+ if (this.conflictSettleTimer)
613
+ clearTimeout(this.conflictSettleTimer);
614
+ delete this.conflictSettleTimer;
615
+ this.settlingConflicts = [];
499
616
  }
500
- addPendingConflict(udid, deviceName, filled, conflicts) {
501
- const existing = this.pendingConflicts.find(e => e.udid === udid)?.conflict;
617
+ mergeIntoConflictList(list, udid, deviceName, filled, conflicts) {
618
+ const existing = list.find(e => e.udid === udid)?.conflict;
502
619
  if (!existing) {
503
620
  const conflict = { id: this.nextConflictId(udid), origin: 'detection', deviceName, filled, conflicts };
504
- this.pendingConflicts.push({ udid, conflict });
621
+ list.push({ udid, conflict });
505
622
  return conflict;
506
623
  }
507
624
  filled.filter(c => !existing.filled.includes(c)).forEach(c => existing.filled.push(c));
@@ -615,7 +732,7 @@ let DevicePairingService = (() => {
615
732
  const capabilityData = this.getCapability(capability);
616
733
  this.settings = Object.assign(this.settings || {}, { onDeviceSelectStateChanged, capabilityForScan: capability });
617
734
  const devices = capabilityData?.devices || [];
618
- const available = devices.filter(d => this.isInterfaceEnabled(d.interface)).filter(d => !this.isOnDeletedList(capability, d.udid));
735
+ const available = devices.filter(d => this.isInterfaceEnabled(d.interface));
619
736
  const startScan = async () => {
620
737
  if (devices.length > 0)
621
738
  await this.stopAdaptersWithCapability(capability);
@@ -695,30 +812,38 @@ let DevicePairingService = (() => {
695
812
  const conflicts = [];
696
813
  candidateCapabilities.forEach(capability => {
697
814
  const c = this.getCapability(capability);
698
- if (!c || c.disabled || this.isOnDeletedList(capability, udid))
815
+ if (!c || c.disabled)
699
816
  return;
700
817
  if (c.selected === udid)
701
818
  unchanged.push(capability);
702
- else if (!c.selected)
703
- filled.push(capability);
819
+ else if (!c.selected) {
820
+ if (!this.isOnDeletedList(capability, udid))
821
+ filled.push(capability);
822
+ }
704
823
  else
705
824
  conflicts.push({ capability, currentName: c.deviceName });
706
825
  });
707
826
  return { filled, unchanged, conflicts };
708
827
  }
709
828
  selectDeviceObjectMode(capability, udid, mode) {
710
- let changed = this.selectCapabilityDevice(capability, udid, false);
711
829
  const adapter = this.getDeviceAdapter(udid);
712
- const others = adapter.getCapabilities().filter(c => c !== capability);
713
- others.forEach(c => {
830
+ const toFill = adapter.getCapabilities().filter(c => {
831
+ if (c === capability)
832
+ return false;
714
833
  const current = this.getCapability(c);
715
- if (!current || current.disabled || this.isOnDeletedList(c, udid))
716
- return;
834
+ if (!current || current.disabled)
835
+ return false;
717
836
  const isEmpty = !current.selected;
718
837
  const shouldReplace = mode.replace.includes(c);
719
- if (!isEmpty && !shouldReplace)
720
- return;
721
- const wasChanged = this.selectCapabilityDevice(c, udid, false);
838
+ if (shouldReplace)
839
+ return true;
840
+ return isEmpty && !this.isOnDeletedList(c, udid);
841
+ });
842
+ const primaryIsLast = toFill.length === 0;
843
+ let changed = this.selectCapabilityDevice(capability, udid, primaryIsLast);
844
+ toFill.forEach((c, idx) => {
845
+ const isLast = idx === toFill.length - 1;
846
+ const wasChanged = this.selectCapabilityDevice(c, udid, isLast);
722
847
  changed = changed || wasChanged;
723
848
  });
724
849
  return changed;
@@ -849,8 +974,7 @@ let DevicePairingService = (() => {
849
974
  const c = this.getCapability(capability);
850
975
  if (!c)
851
976
  return false;
852
- const wouldChange = c.selected !== udid && !this.isOnDeletedList(capability, udid);
853
- return wouldChange;
977
+ return c.selected !== udid;
854
978
  }
855
979
  getCapabilityDevice(capability, udid) {
856
980
  const c = this.getCapability(capability);
@@ -1569,24 +1693,70 @@ let DevicePairingService = (() => {
1569
1693
  const selectedAdapters = target.map(ai => ({ ...ai, isStarted: false }));
1570
1694
  this.setRequestedCapabilties(selectedAdapters);
1571
1695
  this.onPairingStarted();
1696
+ const attemptStartedAt = Date.now();
1572
1697
  const promise = this.rideService.startAdapters(selectedAdapters, 'pair');
1573
1698
  this.state.check = { promise };
1574
1699
  this.logEvent({ message: 'Start Pairing', adapters, props });
1700
+ let settled = true;
1575
1701
  try {
1576
- await this.state.check.promise;
1702
+ settled = await this.waitForAttempt(promise, target);
1577
1703
  }
1578
1704
  catch (err) {
1579
1705
  this.logError(err, 'startPairing');
1580
1706
  }
1581
1707
  if (this.usage !== 'page' && this.isScanning())
1582
1708
  return;
1709
+ if (!settled)
1710
+ this.dropHungAttempt(target, attemptStartedAt);
1711
+ await this.finishAttempt(target, adapters, props, settled);
1712
+ }
1713
+ async waitForAttempt(promise, target) {
1714
+ let watchdog;
1715
+ const expired = new Promise(done => {
1716
+ watchdog = setTimeout(() => { done(false); }, this.getAttemptTimeout(target));
1717
+ });
1718
+ try {
1719
+ return await Promise.race([promise.then(() => true), expired]);
1720
+ }
1721
+ finally {
1722
+ clearTimeout(watchdog);
1723
+ }
1724
+ }
1725
+ getAttemptTimeout(target) {
1726
+ const slowest = Math.max(...target.map(ai => (0, timeouts_1.getPairingStartTimeout)(ai.adapter)));
1727
+ return slowest + DevicePairingService.ATTEMPT_HUNG_MARGIN_MS;
1728
+ }
1729
+ dropHungAttempt(target, attemptStartedAt) {
1730
+ if (!this.attemptHungLogged) {
1731
+ this.attemptHungLogged = true;
1732
+ const hung = target.filter(ai => !ai.adapter.isStarted())
1733
+ .map(ai => ai.adapter.getSettings?.()?.interface)
1734
+ .filter(name => name !== undefined);
1735
+ this.logEvent({
1736
+ message: 'pairing attempt hung',
1737
+ hungInterfaces: [...new Set(hung)].join(','),
1738
+ attemptMs: Date.now() - attemptStartedAt,
1739
+ platform: this.getPlatform(),
1740
+ });
1741
+ }
1742
+ this.rideService.dropPendingStart();
1743
+ }
1744
+ async finishAttempt(target, adapters, props, settled) {
1583
1745
  this.completeAttempt();
1584
- if (!this.isPairingSettled()) {
1585
- this.logEvent({ message: 'Pairing done', adapters, props });
1746
+ if (this.isPairingSettled())
1747
+ return;
1748
+ this.logEvent({ message: 'Pairing done', adapters, props });
1749
+ if (settled) {
1586
1750
  const failed = target.filter(ai => !ai.adapter.isStarted()).map(ai => ai.udid);
1587
- await this.rideService.stopDevices(failed);
1588
- await this.retryUnsettledPairing();
1751
+ this.windingDownAttempt = true;
1752
+ try {
1753
+ await this.rideService.stopDevices(failed);
1754
+ }
1755
+ finally {
1756
+ this.windingDownAttempt = false;
1757
+ }
1589
1758
  }
1759
+ await this.retryUnsettledPairing();
1590
1760
  }
1591
1761
  getPairingTarget(adapters) {
1592
1762
  const selected = this.state.capabilities.map(c => c.selected);
@@ -1610,10 +1780,23 @@ let DevicePairingService = (() => {
1610
1780
  async retryUnsettledPairing() {
1611
1781
  if (this.usage === 'page' || this.isPairingSettled())
1612
1782
  return;
1613
- await (0, sleep_1.sleep)(this.getPairingRetryDelay());
1783
+ await this.waitForRetry(this.getPairingRetryDelay());
1614
1784
  if (!this.state.scan)
1615
1785
  this.run().catch(err => { this.logError(err, 'startPairing'); });
1616
1786
  }
1787
+ waitForRetry(ms) {
1788
+ return new Promise(done => {
1789
+ const delay = { skip: () => { finish(); } };
1790
+ const finish = () => {
1791
+ clearTimeout(timer);
1792
+ if (this.retryDelay === delay)
1793
+ delete this.retryDelay;
1794
+ done();
1795
+ };
1796
+ const timer = setTimeout(finish, ms);
1797
+ this.retryDelay = delay;
1798
+ });
1799
+ }
1617
1800
  setRequestedCapabilties(selectedAdapters) {
1618
1801
  selectedAdapters.forEach(ai => {
1619
1802
  const requested = this.state.capabilities.filter(c => c.selected === ai.udid) ?? [];
@@ -1966,6 +2149,7 @@ let DevicePairingService = (() => {
1966
2149
  selectCapabilityDevice(capability, udid, emitUpdate = true) {
1967
2150
  if (!this.wouldChangeCapability(capability, udid))
1968
2151
  return;
2152
+ this.removeFromDeletedList(capability, udid);
1969
2153
  const c = this.getCapability(capability);
1970
2154
  const device = this.getCapabilityDevice(capability, udid);
1971
2155
  c.value = device?.value;
@@ -2020,6 +2204,12 @@ let DevicePairingService = (() => {
2020
2204
  const c = this.getCapability(capability);
2021
2205
  this.state.deleted.push({ capability: c.capability, udid, settings });
2022
2206
  }
2207
+ removeFromDeletedList(capability, udid) {
2208
+ const c = this.getCapability(capability);
2209
+ if (!c || !this.state.deleted?.length)
2210
+ return;
2211
+ this.state.deleted = this.state.deleted.filter(e => !(e.capability === c.capability && e.udid === udid));
2212
+ }
2023
2213
  isOnDeletedList(c, udid) {
2024
2214
  const capability = this.getCapability(c);
2025
2215
  return this.state.deleted.some(e => e.capability === capability.capability && e.udid === udid);
@@ -2030,8 +2220,8 @@ let DevicePairingService = (() => {
2030
2220
  const available = devices.filter(d => !this.isOnDeletedList(c.capability, d.udid));
2031
2221
  mapped.deviceNames = available.map(d => d.name).join(';');
2032
2222
  mapped.selected = available.find(d => d.selected)?.udid;
2033
- mapped.deviceName = devices.find(d => d.selected)?.name;
2034
- mapped.interface = devices.find(d => d.selected)?.interface;
2223
+ mapped.deviceName = available.find(d => d.selected)?.name;
2224
+ mapped.interface = available.find(d => d.selected)?.interface;
2035
2225
  mapped.devices = devices;
2036
2226
  return mapped;
2037
2227
  }
@@ -2058,7 +2248,10 @@ let DevicePairingService = (() => {
2058
2248
  this.removeScanningCallbacks();
2059
2249
  this.visitOpen = false;
2060
2250
  delete this.visitOpenedAt;
2251
+ this.attemptHungLogged = false;
2061
2252
  this.pendingConflicts = [];
2253
+ this.manualConflicts.clear();
2254
+ this.clearConflictSettleTimer();
2062
2255
  this.resetSearch();
2063
2256
  }
2064
2257
  getUnitConverter() {
@@ -60,6 +60,7 @@ const getPairingStatusDisplay = (src) => {
60
60
  stillLooking: src.stillLooking,
61
61
  searchEndedWithoutTrainer: src.searchEndedWithoutTrainer,
62
62
  trainerPhase: src.trainerPhase,
63
+ trainerRetry: src.trainerRetry,
63
64
  trainerName: caps.trainer?.deviceName,
64
65
  allRequiredSwitchedOff: caps.allRequiredSwitchedOff,
65
66
  resistanceSwitchedOff: isSwitchedOffWithDevice(caps.trainer),
@@ -49,6 +49,7 @@ const service_2 = require("../../base/service");
49
49
  const types_1 = require("../../base/types");
50
50
  const Injection_1 = require("../../base/decorators/Injection");
51
51
  const apps_1 = require("../../apps");
52
+ const timeouts_1 = require("./timeouts");
52
53
  const NO_DATA_THRESHOLD = 10000;
53
54
  const UNHEALTHY_THRESHOLD = 60000;
54
55
  let DeviceRideService = (() => {
@@ -561,7 +562,8 @@ let DeviceRideService = (() => {
561
562
  return allOK;
562
563
  }
563
564
  finally {
564
- this.startPromises = null;
565
+ if (this.startPromises === startPromises)
566
+ this.startPromises = null;
565
567
  }
566
568
  }
567
569
  async startSingleAdapter(ai, duplicates, props, startType) {
@@ -627,9 +629,7 @@ let DeviceRideService = (() => {
627
629
  }
628
630
  }
629
631
  initForPairing(startProps, ai) {
630
- startProps.timeout = 10000;
631
- if (ai.adapter.getSettings().interface === 'ble')
632
- startProps.timeout = 30000;
632
+ startProps.timeout = (0, timeouts_1.getPairingStartTimeout)(ai.adapter);
633
633
  }
634
634
  initCyclingMode(ai, forceErgMode) {
635
635
  let bike, mode, settings;
@@ -1019,6 +1019,22 @@ let DeviceRideService = (() => {
1019
1019
  delete this.rideAdapters;
1020
1020
  return true;
1021
1021
  }
1022
+ dropPendingStart() {
1023
+ if (!this.startPromises)
1024
+ return;
1025
+ this.logEvent({ message: 'drop pending start' });
1026
+ const adapters = this.getRideAdapters();
1027
+ adapters?.forEach(ai => {
1028
+ const d = ai.adapter;
1029
+ if (d.isStarted())
1030
+ return;
1031
+ this.unsubscribeDeviceEvents(d);
1032
+ this.logEvent({ message: 'drop pending start of device', udid: ai.udid });
1033
+ d.stop().catch(err => { this.logError(err, 'dropPendingStart'); });
1034
+ });
1035
+ this.startPromises = null;
1036
+ delete this.rideAdapters;
1037
+ }
1022
1038
  registerOnDataHandler(adapters) {
1023
1039
  adapters?.forEach(ai => {
1024
1040
  this.unsubscribeDeviceEvents(ai.adapter);
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPairingStartTimeout = void 0;
4
+ const PAIRING_START_TIMEOUT_MS = 10 * 1000;
5
+ const BLE_PAIRING_START_TIMEOUT_MS = 30 * 1000;
6
+ const getPairingStartTimeout = (adapter) => {
7
+ return adapter?.getSettings?.()?.interface === 'ble' ? BLE_PAIRING_START_TIMEOUT_MS : PAIRING_START_TIMEOUT_MS;
8
+ };
9
+ exports.getPairingStartTimeout = getPairingStartTimeout;
@@ -1041,14 +1041,14 @@ let RideDisplayService = (() => {
1041
1041
  let request;
1042
1042
  if (simMode === 'Power') {
1043
1043
  const currentPowerTarget = mode.getSetting('power');
1044
- const targetPower = Number(currentPowerTarget) + powerInc;
1044
+ const targetPower = Math.max(0, Number(currentPowerTarget) + powerInc);
1045
1045
  mode.setSetting('power', targetPower);
1046
1046
  request = { targetPower };
1047
1047
  }
1048
1048
  else {
1049
1049
  const currentSpeedTarget = mode.getSetting('speed');
1050
1050
  const speedInc = powerInc / 5;
1051
- const speed = Number(currentSpeedTarget) + speedInc;
1051
+ const speed = Math.max(0, Number(currentSpeedTarget) + speedInc, 0);
1052
1052
  mode.setSetting('speed', speed);
1053
1053
  request = { speed };
1054
1054
  }
@@ -58,6 +58,7 @@ const verify = (route) => {
58
58
  const isNoResponseError = (err) => {
59
59
  return err?.message === 'Network Error' ||
60
60
  err?.code === 'ERR_NETWORK' ||
61
+ err?.response?.status === 504 ||
61
62
  (err?.isAxiosError === true && !err.response);
62
63
  };
63
64
  let IncyclistRoutesApi = (() => {
@@ -362,7 +362,9 @@ let ActivitiesRepository = (() => {
362
362
  if (this.isDirty && (this.tsLastWrite === undefined || Date.now() - this.tsLastWrite >= 1000)) {
363
363
  this.isDirty = false;
364
364
  this.tsLastWrite = Date.now();
365
- this.writeRepo().catch(err => { this.logError(err, 'write'); });
365
+ this.writeRepo().catch(err => {
366
+ this.logWarning(err, 'write');
367
+ });
366
368
  }
367
369
  if (this.isDirty && Date.now() - this.tsLastWrite < 1000) {
368
370
  setTimeout(() => { this.write(); }, this.tsLastWrite + 1000 - Date.now());
@@ -516,6 +518,10 @@ let ActivitiesRepository = (() => {
516
518
  const props = logProps ?? {};
517
519
  this.logger.logEvent({ message: 'error', fn, error: err.message, ...props, stack: err.stack });
518
520
  }
521
+ logWarning(err, fn, logProps) {
522
+ const props = logProps ?? {};
523
+ this.logger.logEvent({ message: 'warning', fn, error: err.message, ...props });
524
+ }
519
525
  getRepo() {
520
526
  if (!this.repo)
521
527
  this.repo = JsonRepository.create('activities');