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
@@ -37,6 +37,7 @@ import { useDeviceConfiguration } from "../configuration";
37
37
  import { isCapabilityActive } from "./capability";
38
38
  import { IncyclistCapability } from "incyclist-devices";
39
39
  import { useDeviceRide } from "../ride";
40
+ import { getPairingStartTimeout } from "../ride/timeouts";
40
41
  import clone from "../../utils/clone";
41
42
  import { IncyclistService } from "../../base/service";
42
43
  import { sleep } from "../../utils/sleep";
@@ -86,10 +87,18 @@ let DevicePairingService = (() => {
86
87
  static STALLED_AFTER_MS = 30 * 1000;
87
88
  stalledTimer;
88
89
  stalledLogged = false;
90
+ static ATTEMPT_HUNG_MARGIN_MS = 15 * 1000;
91
+ attemptHungLogged = false;
92
+ retryDelay;
93
+ windingDownAttempt = false;
89
94
  visitOpen = false;
90
95
  visitOpenedAt;
91
96
  pendingConflicts = [];
92
97
  static conflictCounter = 0;
98
+ manualConflicts = new Map();
99
+ settlingConflicts = [];
100
+ conflictSettleTimer;
101
+ static CONFLICT_SETTLE_MS = 2000;
93
102
  static SEARCH_DURATION_MS = { desktop: 60 * 1000, mobile: 30 * 1000 };
94
103
  static STOP_OFFER_DELAY_MS = 2000;
95
104
  search = DevicePairingService.initialSearchState();
@@ -127,7 +136,6 @@ let DevicePairingService = (() => {
127
136
  this.stalledLogged = false;
128
137
  if (this.state.stopped) {
129
138
  this.state.stopped = false;
130
- this.state.deleted = [];
131
139
  }
132
140
  if (this.state.interfaces) {
133
141
  this.initConfigHandlers();
@@ -214,8 +222,10 @@ let DevicePairingService = (() => {
214
222
  if (open) {
215
223
  this.visitOpenedAt ??= Date.now();
216
224
  this.getDeviceConfiguration().clearExclusions({ scope: 'until-next-pairing' });
217
- if (!this.visitOpen)
225
+ if (!this.visitOpen) {
218
226
  this.resetSearch();
227
+ this.attemptHungLogged = false;
228
+ }
219
229
  }
220
230
  else {
221
231
  delete this.visitOpenedAt;
@@ -272,6 +282,35 @@ let DevicePairingService = (() => {
272
282
  this.logError(err, 'searchAgain');
273
283
  }
274
284
  }
285
+ reconnectNow() {
286
+ try {
287
+ if (this.isPairingSettled())
288
+ return [];
289
+ const capabilities = this.getReconnectCapabilities();
290
+ if (!this.isPairing() && !this.windingDownAttempt)
291
+ this.startNextAttempt();
292
+ return capabilities;
293
+ }
294
+ catch (err) {
295
+ this.logError(err, 'reconnectNow');
296
+ return [];
297
+ }
298
+ }
299
+ getReconnectCapabilities() {
300
+ return (this.state.capabilities ?? [])
301
+ .filter(c => isCapabilityActive(c) && c.connectState !== 'connected')
302
+ .map(c => c.capability);
303
+ }
304
+ startNextAttempt() {
305
+ if (this.usage === 'page') {
306
+ this.emit('retry');
307
+ return;
308
+ }
309
+ if (this.retryDelay)
310
+ this.retryDelay.skip();
311
+ else
312
+ this.run().catch(err => { this.logError(err, 'reconnectNow'); });
313
+ }
275
314
  isSearchAllowed() {
276
315
  return !this.visitOpen || this.search.phase !== 'ended';
277
316
  }
@@ -419,20 +458,18 @@ let DevicePairingService = (() => {
419
458
  getPendingConflicts() {
420
459
  return this.pendingConflicts.map(e => clone(e.conflict));
421
460
  }
422
- async resolveConflict(id, replace) {
461
+ async resolveConflict(id, replace, via = 'done') {
423
462
  try {
424
463
  const entry = this.takePendingConflict(id);
425
464
  if (!entry)
426
465
  return;
427
466
  const { udid, conflict } = entry;
428
- const asked = conflict.conflicts.map(c => c.capability);
429
- const stillConflicting = new Set(this.computeSelectionImpact(udid, asked).conflicts.map(c => c.capability));
430
- const toReplace = (replace ?? []).filter(c => stillConflicting.has(c));
467
+ const toReplace = this.getReplaceableRows(udid, conflict, replace);
431
468
  if (toReplace.length > 0) {
432
469
  const [first, ...rest] = toReplace;
433
470
  await this.selectDevice(first, udid, { others: 'fill-empty', replace: rest });
434
471
  }
435
- this.logConflictResolved(conflict, 'done', toReplace.length);
472
+ this.logConflictResolved(conflict, via, toReplace.length);
436
473
  }
437
474
  catch (err) {
438
475
  this.logError(err, 'resolveConflict');
@@ -448,10 +485,72 @@ let DevicePairingService = (() => {
448
485
  this.logError(err, 'dismissConflict');
449
486
  }
450
487
  }
488
+ reevaluatePendingConflicts(changed) {
489
+ try {
490
+ this.pendingConflicts = this.pendingConflicts.filter(entry => this.reevaluateConflict(entry, changed));
491
+ }
492
+ catch (err) {
493
+ this.logError(err, 'reevaluatePendingConflicts');
494
+ }
495
+ }
496
+ reevaluateConflict(entry, changed) {
497
+ const { udid, conflict } = entry;
498
+ const asked = conflict.conflicts.map(c => c.capability);
499
+ if (changed && !asked.some(c => changed.includes(c)))
500
+ return true;
501
+ const current = this.computeSelectionImpact(udid, asked).conflicts;
502
+ if (current.length === 0) {
503
+ this.logConflictResolved(conflict, 'superseded', 0);
504
+ return false;
505
+ }
506
+ conflict.conflicts = current;
507
+ return true;
508
+ }
509
+ startManualConflict(capability, udid) {
510
+ try {
511
+ const { filled, conflicts } = this.previewSelectDevice(capability, udid);
512
+ if (conflicts.length === 0)
513
+ return undefined;
514
+ const deviceName = this.getCapabilityDevice(capability, udid)?.name
515
+ ?? this.getDeviceConfiguration().getAdapter(udid)?.getUniqueName() ?? '';
516
+ const conflict = { id: this.nextConflictId(udid), origin: 'manual', deviceName, filled, conflicts };
517
+ this.manualConflicts.set(conflict.id, { udid, capability, conflict });
518
+ this.logConflictShown(conflict, conflicts.length, 0);
519
+ return clone(conflict);
520
+ }
521
+ catch (err) {
522
+ this.logError(err, 'startManualConflict');
523
+ return undefined;
524
+ }
525
+ }
526
+ async commitManualConflict(id, replace, via = 'done') {
527
+ try {
528
+ const entry = this.manualConflicts.get(id);
529
+ if (!entry)
530
+ return;
531
+ this.manualConflicts.delete(id);
532
+ const { udid, capability, conflict } = entry;
533
+ const toReplace = this.getReplaceableRows(udid, conflict, replace);
534
+ await this.selectDevice(capability, udid, { others: 'fill-empty', replace: toReplace });
535
+ this.logConflictResolved(conflict, via, toReplace.length);
536
+ }
537
+ catch (err) {
538
+ this.logError(err, 'commitManualConflict');
539
+ }
540
+ }
541
+ getReplaceableRows(udid, conflict, replace) {
542
+ const asked = conflict.conflicts.map(c => c.capability);
543
+ const stillConflicting = new Set(this.computeSelectionImpact(udid, asked).conflicts.map(c => c.capability));
544
+ const stale = asked.filter(c => !stillConflicting.has(c)).length;
545
+ if (stale > 0)
546
+ this.logEvent({ message: 'device select conflict stale', origin: conflict.origin, conflictCount: stale });
547
+ return (replace ?? []).filter(c => stillConflicting.has(c));
548
+ }
451
549
  dismissPendingConflicts(via) {
452
550
  const pending = this.pendingConflicts;
453
551
  this.pendingConflicts = [];
454
552
  pending.forEach(e => { this.logConflictResolved(e.conflict, via, 0); });
553
+ this.clearConflictSettleTimer();
455
554
  }
456
555
  takePendingConflict(id) {
457
556
  const idx = this.pendingConflicts.findIndex(e => e.conflict.id === id);
@@ -487,15 +586,33 @@ let DevicePairingService = (() => {
487
586
  this.logConflictResolved(conflict, 'left_page', 0);
488
587
  return;
489
588
  }
490
- const conflict = this.addPendingConflict(udid, deviceName, filled, conflicts);
491
- this.logConflictShown(conflict, conflicts.length, this.pendingConflicts.length - 1);
492
- this.emit('selection-conflict', clone(conflict));
589
+ this.mergeIntoConflictList(this.settlingConflicts, udid, deviceName, filled, conflicts);
590
+ if (this.conflictSettleTimer)
591
+ clearTimeout(this.conflictSettleTimer);
592
+ this.conflictSettleTimer = setTimeout(() => { this.settleDetectionConflicts(); }, DevicePairingService.CONFLICT_SETTLE_MS);
593
+ this.conflictSettleTimer.unref?.();
594
+ }
595
+ settleDetectionConflicts() {
596
+ delete this.conflictSettleTimer;
597
+ const settled = this.settlingConflicts;
598
+ this.settlingConflicts = [];
599
+ settled.forEach(({ udid, conflict }) => {
600
+ const merged = this.mergeIntoConflictList(this.pendingConflicts, udid, conflict.deviceName, conflict.filled, conflict.conflicts);
601
+ this.logConflictShown(merged, merged.conflicts.length, this.pendingConflicts.length - 1);
602
+ this.emit('selection-conflict', clone(merged));
603
+ });
604
+ }
605
+ clearConflictSettleTimer() {
606
+ if (this.conflictSettleTimer)
607
+ clearTimeout(this.conflictSettleTimer);
608
+ delete this.conflictSettleTimer;
609
+ this.settlingConflicts = [];
493
610
  }
494
- addPendingConflict(udid, deviceName, filled, conflicts) {
495
- const existing = this.pendingConflicts.find(e => e.udid === udid)?.conflict;
611
+ mergeIntoConflictList(list, udid, deviceName, filled, conflicts) {
612
+ const existing = list.find(e => e.udid === udid)?.conflict;
496
613
  if (!existing) {
497
614
  const conflict = { id: this.nextConflictId(udid), origin: 'detection', deviceName, filled, conflicts };
498
- this.pendingConflicts.push({ udid, conflict });
615
+ list.push({ udid, conflict });
499
616
  return conflict;
500
617
  }
501
618
  filled.filter(c => !existing.filled.includes(c)).forEach(c => existing.filled.push(c));
@@ -609,7 +726,7 @@ let DevicePairingService = (() => {
609
726
  const capabilityData = this.getCapability(capability);
610
727
  this.settings = Object.assign(this.settings || {}, { onDeviceSelectStateChanged, capabilityForScan: capability });
611
728
  const devices = capabilityData?.devices || [];
612
- const available = devices.filter(d => this.isInterfaceEnabled(d.interface)).filter(d => !this.isOnDeletedList(capability, d.udid));
729
+ const available = devices.filter(d => this.isInterfaceEnabled(d.interface));
613
730
  const startScan = async () => {
614
731
  if (devices.length > 0)
615
732
  await this.stopAdaptersWithCapability(capability);
@@ -689,30 +806,38 @@ let DevicePairingService = (() => {
689
806
  const conflicts = [];
690
807
  candidateCapabilities.forEach(capability => {
691
808
  const c = this.getCapability(capability);
692
- if (!c || c.disabled || this.isOnDeletedList(capability, udid))
809
+ if (!c || c.disabled)
693
810
  return;
694
811
  if (c.selected === udid)
695
812
  unchanged.push(capability);
696
- else if (!c.selected)
697
- filled.push(capability);
813
+ else if (!c.selected) {
814
+ if (!this.isOnDeletedList(capability, udid))
815
+ filled.push(capability);
816
+ }
698
817
  else
699
818
  conflicts.push({ capability, currentName: c.deviceName });
700
819
  });
701
820
  return { filled, unchanged, conflicts };
702
821
  }
703
822
  selectDeviceObjectMode(capability, udid, mode) {
704
- let changed = this.selectCapabilityDevice(capability, udid, false);
705
823
  const adapter = this.getDeviceAdapter(udid);
706
- const others = adapter.getCapabilities().filter(c => c !== capability);
707
- others.forEach(c => {
824
+ const toFill = adapter.getCapabilities().filter(c => {
825
+ if (c === capability)
826
+ return false;
708
827
  const current = this.getCapability(c);
709
- if (!current || current.disabled || this.isOnDeletedList(c, udid))
710
- return;
828
+ if (!current || current.disabled)
829
+ return false;
711
830
  const isEmpty = !current.selected;
712
831
  const shouldReplace = mode.replace.includes(c);
713
- if (!isEmpty && !shouldReplace)
714
- return;
715
- const wasChanged = this.selectCapabilityDevice(c, udid, false);
832
+ if (shouldReplace)
833
+ return true;
834
+ return isEmpty && !this.isOnDeletedList(c, udid);
835
+ });
836
+ const primaryIsLast = toFill.length === 0;
837
+ let changed = this.selectCapabilityDevice(capability, udid, primaryIsLast);
838
+ toFill.forEach((c, idx) => {
839
+ const isLast = idx === toFill.length - 1;
840
+ const wasChanged = this.selectCapabilityDevice(c, udid, isLast);
716
841
  changed = changed || wasChanged;
717
842
  });
718
843
  return changed;
@@ -843,8 +968,7 @@ let DevicePairingService = (() => {
843
968
  const c = this.getCapability(capability);
844
969
  if (!c)
845
970
  return false;
846
- const wouldChange = c.selected !== udid && !this.isOnDeletedList(capability, udid);
847
- return wouldChange;
971
+ return c.selected !== udid;
848
972
  }
849
973
  getCapabilityDevice(capability, udid) {
850
974
  const c = this.getCapability(capability);
@@ -1563,24 +1687,70 @@ let DevicePairingService = (() => {
1563
1687
  const selectedAdapters = target.map(ai => ({ ...ai, isStarted: false }));
1564
1688
  this.setRequestedCapabilties(selectedAdapters);
1565
1689
  this.onPairingStarted();
1690
+ const attemptStartedAt = Date.now();
1566
1691
  const promise = this.rideService.startAdapters(selectedAdapters, 'pair');
1567
1692
  this.state.check = { promise };
1568
1693
  this.logEvent({ message: 'Start Pairing', adapters, props });
1694
+ let settled = true;
1569
1695
  try {
1570
- await this.state.check.promise;
1696
+ settled = await this.waitForAttempt(promise, target);
1571
1697
  }
1572
1698
  catch (err) {
1573
1699
  this.logError(err, 'startPairing');
1574
1700
  }
1575
1701
  if (this.usage !== 'page' && this.isScanning())
1576
1702
  return;
1703
+ if (!settled)
1704
+ this.dropHungAttempt(target, attemptStartedAt);
1705
+ await this.finishAttempt(target, adapters, props, settled);
1706
+ }
1707
+ async waitForAttempt(promise, target) {
1708
+ let watchdog;
1709
+ const expired = new Promise(done => {
1710
+ watchdog = setTimeout(() => { done(false); }, this.getAttemptTimeout(target));
1711
+ });
1712
+ try {
1713
+ return await Promise.race([promise.then(() => true), expired]);
1714
+ }
1715
+ finally {
1716
+ clearTimeout(watchdog);
1717
+ }
1718
+ }
1719
+ getAttemptTimeout(target) {
1720
+ const slowest = Math.max(...target.map(ai => getPairingStartTimeout(ai.adapter)));
1721
+ return slowest + DevicePairingService.ATTEMPT_HUNG_MARGIN_MS;
1722
+ }
1723
+ dropHungAttempt(target, attemptStartedAt) {
1724
+ if (!this.attemptHungLogged) {
1725
+ this.attemptHungLogged = true;
1726
+ const hung = target.filter(ai => !ai.adapter.isStarted())
1727
+ .map(ai => ai.adapter.getSettings?.()?.interface)
1728
+ .filter(name => name !== undefined);
1729
+ this.logEvent({
1730
+ message: 'pairing attempt hung',
1731
+ hungInterfaces: [...new Set(hung)].join(','),
1732
+ attemptMs: Date.now() - attemptStartedAt,
1733
+ platform: this.getPlatform(),
1734
+ });
1735
+ }
1736
+ this.rideService.dropPendingStart();
1737
+ }
1738
+ async finishAttempt(target, adapters, props, settled) {
1577
1739
  this.completeAttempt();
1578
- if (!this.isPairingSettled()) {
1579
- this.logEvent({ message: 'Pairing done', adapters, props });
1740
+ if (this.isPairingSettled())
1741
+ return;
1742
+ this.logEvent({ message: 'Pairing done', adapters, props });
1743
+ if (settled) {
1580
1744
  const failed = target.filter(ai => !ai.adapter.isStarted()).map(ai => ai.udid);
1581
- await this.rideService.stopDevices(failed);
1582
- await this.retryUnsettledPairing();
1745
+ this.windingDownAttempt = true;
1746
+ try {
1747
+ await this.rideService.stopDevices(failed);
1748
+ }
1749
+ finally {
1750
+ this.windingDownAttempt = false;
1751
+ }
1583
1752
  }
1753
+ await this.retryUnsettledPairing();
1584
1754
  }
1585
1755
  getPairingTarget(adapters) {
1586
1756
  const selected = this.state.capabilities.map(c => c.selected);
@@ -1604,10 +1774,23 @@ let DevicePairingService = (() => {
1604
1774
  async retryUnsettledPairing() {
1605
1775
  if (this.usage === 'page' || this.isPairingSettled())
1606
1776
  return;
1607
- await sleep(this.getPairingRetryDelay());
1777
+ await this.waitForRetry(this.getPairingRetryDelay());
1608
1778
  if (!this.state.scan)
1609
1779
  this.run().catch(err => { this.logError(err, 'startPairing'); });
1610
1780
  }
1781
+ waitForRetry(ms) {
1782
+ return new Promise(done => {
1783
+ const delay = { skip: () => { finish(); } };
1784
+ const finish = () => {
1785
+ clearTimeout(timer);
1786
+ if (this.retryDelay === delay)
1787
+ delete this.retryDelay;
1788
+ done();
1789
+ };
1790
+ const timer = setTimeout(finish, ms);
1791
+ this.retryDelay = delay;
1792
+ });
1793
+ }
1611
1794
  setRequestedCapabilties(selectedAdapters) {
1612
1795
  selectedAdapters.forEach(ai => {
1613
1796
  const requested = this.state.capabilities.filter(c => c.selected === ai.udid) ?? [];
@@ -1960,6 +2143,7 @@ let DevicePairingService = (() => {
1960
2143
  selectCapabilityDevice(capability, udid, emitUpdate = true) {
1961
2144
  if (!this.wouldChangeCapability(capability, udid))
1962
2145
  return;
2146
+ this.removeFromDeletedList(capability, udid);
1963
2147
  const c = this.getCapability(capability);
1964
2148
  const device = this.getCapabilityDevice(capability, udid);
1965
2149
  c.value = device?.value;
@@ -2014,6 +2198,12 @@ let DevicePairingService = (() => {
2014
2198
  const c = this.getCapability(capability);
2015
2199
  this.state.deleted.push({ capability: c.capability, udid, settings });
2016
2200
  }
2201
+ removeFromDeletedList(capability, udid) {
2202
+ const c = this.getCapability(capability);
2203
+ if (!c || !this.state.deleted?.length)
2204
+ return;
2205
+ this.state.deleted = this.state.deleted.filter(e => !(e.capability === c.capability && e.udid === udid));
2206
+ }
2017
2207
  isOnDeletedList(c, udid) {
2018
2208
  const capability = this.getCapability(c);
2019
2209
  return this.state.deleted.some(e => e.capability === capability.capability && e.udid === udid);
@@ -2024,8 +2214,8 @@ let DevicePairingService = (() => {
2024
2214
  const available = devices.filter(d => !this.isOnDeletedList(c.capability, d.udid));
2025
2215
  mapped.deviceNames = available.map(d => d.name).join(';');
2026
2216
  mapped.selected = available.find(d => d.selected)?.udid;
2027
- mapped.deviceName = devices.find(d => d.selected)?.name;
2028
- mapped.interface = devices.find(d => d.selected)?.interface;
2217
+ mapped.deviceName = available.find(d => d.selected)?.name;
2218
+ mapped.interface = available.find(d => d.selected)?.interface;
2029
2219
  mapped.devices = devices;
2030
2220
  return mapped;
2031
2221
  }
@@ -2052,7 +2242,10 @@ let DevicePairingService = (() => {
2052
2242
  this.removeScanningCallbacks();
2053
2243
  this.visitOpen = false;
2054
2244
  delete this.visitOpenedAt;
2245
+ this.attemptHungLogged = false;
2055
2246
  this.pendingConflicts = [];
2247
+ this.manualConflicts.clear();
2248
+ this.clearConflictSettleTimer();
2056
2249
  this.resetSearch();
2057
2250
  }
2058
2251
  getUnitConverter() {
@@ -55,6 +55,7 @@ export const getPairingStatusDisplay = (src) => {
55
55
  stillLooking: src.stillLooking,
56
56
  searchEndedWithoutTrainer: src.searchEndedWithoutTrainer,
57
57
  trainerPhase: src.trainerPhase,
58
+ trainerRetry: src.trainerRetry,
58
59
  trainerName: caps.trainer?.deviceName,
59
60
  allRequiredSwitchedOff: caps.allRequiredSwitchedOff,
60
61
  resistanceSwitchedOff: isSwitchedOffWithDevice(caps.trainer),
@@ -43,6 +43,7 @@ import { IncyclistService } from "../../base/service";
43
43
  import { Singleton } from "../../base/types";
44
44
  import { Injectable } from "../../base/decorators/Injection";
45
45
  import { useGoogleMaps } from "../../apps";
46
+ import { getPairingStartTimeout } from "./timeouts";
46
47
  const NO_DATA_THRESHOLD = 10000;
47
48
  const UNHEALTHY_THRESHOLD = 60000;
48
49
  let DeviceRideService = (() => {
@@ -555,7 +556,8 @@ let DeviceRideService = (() => {
555
556
  return allOK;
556
557
  }
557
558
  finally {
558
- this.startPromises = null;
559
+ if (this.startPromises === startPromises)
560
+ this.startPromises = null;
559
561
  }
560
562
  }
561
563
  async startSingleAdapter(ai, duplicates, props, startType) {
@@ -621,9 +623,7 @@ let DeviceRideService = (() => {
621
623
  }
622
624
  }
623
625
  initForPairing(startProps, ai) {
624
- startProps.timeout = 10000;
625
- if (ai.adapter.getSettings().interface === 'ble')
626
- startProps.timeout = 30000;
626
+ startProps.timeout = getPairingStartTimeout(ai.adapter);
627
627
  }
628
628
  initCyclingMode(ai, forceErgMode) {
629
629
  let bike, mode, settings;
@@ -1013,6 +1013,22 @@ let DeviceRideService = (() => {
1013
1013
  delete this.rideAdapters;
1014
1014
  return true;
1015
1015
  }
1016
+ dropPendingStart() {
1017
+ if (!this.startPromises)
1018
+ return;
1019
+ this.logEvent({ message: 'drop pending start' });
1020
+ const adapters = this.getRideAdapters();
1021
+ adapters?.forEach(ai => {
1022
+ const d = ai.adapter;
1023
+ if (d.isStarted())
1024
+ return;
1025
+ this.unsubscribeDeviceEvents(d);
1026
+ this.logEvent({ message: 'drop pending start of device', udid: ai.udid });
1027
+ d.stop().catch(err => { this.logError(err, 'dropPendingStart'); });
1028
+ });
1029
+ this.startPromises = null;
1030
+ delete this.rideAdapters;
1031
+ }
1016
1032
  registerOnDataHandler(adapters) {
1017
1033
  adapters?.forEach(ai => {
1018
1034
  this.unsubscribeDeviceEvents(ai.adapter);
@@ -1038,14 +1038,14 @@ let RideDisplayService = (() => {
1038
1038
  let request;
1039
1039
  if (simMode === 'Power') {
1040
1040
  const currentPowerTarget = mode.getSetting('power');
1041
- const targetPower = Number(currentPowerTarget) + powerInc;
1041
+ const targetPower = Math.max(0, Number(currentPowerTarget) + powerInc);
1042
1042
  mode.setSetting('power', targetPower);
1043
1043
  request = { targetPower };
1044
1044
  }
1045
1045
  else {
1046
1046
  const currentSpeedTarget = mode.getSetting('speed');
1047
1047
  const speedInc = powerInc / 5;
1048
- const speed = Number(currentSpeedTarget) + speedInc;
1048
+ const speed = Math.max(0, Number(currentSpeedTarget) + speedInc, 0);
1049
1049
  mode.setSetting('speed', speed);
1050
1050
  request = { speed };
1051
1051
  }
@@ -56,6 +56,7 @@ const verify = (route) => {
56
56
  const isNoResponseError = (err) => {
57
57
  return err?.message === 'Network Error' ||
58
58
  err?.code === 'ERR_NETWORK' ||
59
+ err?.response?.status === 504 ||
59
60
  (err?.isAxiosError === true && !err.response);
60
61
  };
61
62
  let IncyclistRoutesApi = (() => {
@@ -54,6 +54,7 @@ export declare class ActivitiesRepository {
54
54
  protected _load(): Promise<void>;
55
55
  protected getActivity(id: string): ActivityInfo;
56
56
  protected logError(err: Error, fn: string, logProps?: any): void;
57
+ protected logWarning(err: Error, fn: string, logProps?: any): void;
57
58
  protected getRepo(): JsonRepository;
58
59
  protected getRouteList(): import("../../../routes").RouteListService;
59
60
  protected isMobile(): boolean;
@@ -1,8 +1,8 @@
1
1
  import type { CapabilityData, PairingState } from '../../../pairing/model';
2
- import type { PairingHint, PairingInterfaceId, PairingPlatform, PairingStatusId } from '../../../pairing/guidance';
2
+ import type { PairingHint, PairingInterfaceId, PairingPlatform, PairingStatusId, PairingTrainerRetry } from '../../../pairing/guidance';
3
3
  import type { PairingStatusDisplayProps, PairingStatusSource } from '../../../pairing/status';
4
4
  import type { ContinueWithoutDeviceAction, ContinueWithoutDeviceTarget, PairingHelperReason } from '../../../pairing/helper';
5
- import type { PairingGuidanceDeps, PairingGuidanceExitFields, PairingGuidanceState, PairingGuidanceVisitProps, PairingHelperCloseVia, PairingHelperPhase, PairingHelperState, PairingHelperTrigger, PartialOutage, TrainerPhase, TrainerPhaseCause } from './types';
5
+ import type { PairingCase, PairingFallbackCapability, PairingGuidanceDeps, PairingGuidanceExitFields, PairingGuidanceState, PairingGuidanceVisitProps, PairingHelperCloseVia, PairingHelperPhase, PairingHelperState, PairingHelperTrigger, PartialOutage, RiderRetryResult, RiderRetryTrigger, TrainerPhase, TrainerPhaseCause } from './types';
6
6
  export declare const TRAINER_PHASE_EVENT = "pairing trainer phase changed";
7
7
  export declare const PARTIAL_OUTAGE_EVENT = "pairing partial outage shown";
8
8
  export declare const HELPER_SHOWN_EVENT = "pairing helper shown";
@@ -10,6 +10,11 @@ export declare const HELPER_REASON_EVENT = "pairing helper reason selected";
10
10
  export declare const HELPER_ACTION_EVENT = "pairing helper action";
11
11
  export declare const HELPER_RESOLVED_EVENT = "pairing helper resolved";
12
12
  export declare const HELPER_CLOSED_EVENT = "pairing helper closed";
13
+ export declare const FALLBACK_CHOSEN_EVENT = "pairing fallback chosen";
14
+ export declare const FALLBACK_CANCELLED_EVENT = "pairing fallback cancelled";
15
+ export declare const RIDER_RETRY_EVENT = "pairing trainer retry";
16
+ export declare const RIDER_RETRY_ENDED_EVENT = "pairing trainer retry ended";
17
+ export declare const FALLBACK_REVERTED_DISPLAY_MS = 3000;
13
18
  export declare const HELPER_THRESHOLD_MS: Readonly<Record<PairingPlatform, number>>;
14
19
  export declare const HELPER_RESOLVED_DISPLAY_MS = 2000;
15
20
  export declare const TRAINER_ATTEMPT_TIMEOUT_MS: Readonly<Record<PairingInterfaceId, number>>;
@@ -26,6 +31,23 @@ export declare class PairingGuidance {
26
31
  protected attemptElapsedMs: number;
27
32
  protected attemptResumedAt?: number;
28
33
  protected attemptTimer?: ReturnType<typeof setTimeout>;
34
+ protected unavailableSince?: number;
35
+ protected trainerRetry?: PairingTrainerRetry;
36
+ protected retryIndex: number;
37
+ protected retryCase?: PairingCase;
38
+ protected retrySawConnecting: boolean;
39
+ protected retryStartFields?: Record<string, unknown>;
40
+ protected retryTimeoutMs?: number;
41
+ protected retryElapsedMs: number;
42
+ protected retryResumedAt?: number;
43
+ protected retryTimer?: ReturnType<typeof setTimeout>;
44
+ protected fallback?: {
45
+ capability: PairingFallbackCapability;
46
+ trainerUdid: string;
47
+ since: number;
48
+ };
49
+ protected fallbackReverted: boolean;
50
+ protected fallbackRevertedTimer?: ReturnType<typeof setTimeout>;
29
51
  protected visitId?: string;
30
52
  protected openedAt: number;
31
53
  protected partialOutageSince?: number;
@@ -60,13 +82,24 @@ export declare class PairingGuidance {
60
82
  resumeVisit(): void;
61
83
  onPairingState(state: PairingState): void;
62
84
  onTrainerUnavailable(): void;
85
+ getResistanceUnselectAction(): 'open-helper' | 'unselect';
86
+ openHelperForUnavailableTrainer(trigger: PairingHelperTrigger): void;
63
87
  getState(): PairingGuidanceState;
88
+ getFallbackCandidate(): PairingFallbackCapability | undefined;
89
+ chooseFallback(): boolean;
90
+ cancelFallback(): boolean;
91
+ onFallbackReverted(udid: string): void;
92
+ startRiderRetry({ trigger }: {
93
+ trigger: RiderRetryTrigger;
94
+ }): boolean;
95
+ logRiderRetry(retryCapabilities: ReadonlyArray<string>): void;
64
96
  getStatus(src: PairingStatusSource): PairingStatusDisplayProps;
65
97
  getExitFields(): PairingGuidanceExitFields;
66
98
  getHelper(): PairingHelperState;
67
99
  openHelper(trigger?: PairingHelperTrigger): void;
68
100
  dismissHelper(): void;
69
101
  selectReason(reason: PairingHelperReason): void;
102
+ protected preselectReason(reason: PairingHelperReason): void;
70
103
  setDeviceListOpen(open: boolean): void;
71
104
  getContinueWithoutDeviceAction(): ContinueWithoutDeviceAction;
72
105
  continueWithoutDevice(): ContinueWithoutDeviceTarget;
@@ -93,6 +126,20 @@ export declare class PairingGuidance {
93
126
  protected clearPartialOutage(): void;
94
127
  protected onPartialOutageShown(src: PairingStatusSource, hint: PairingHint): void;
95
128
  protected safeLog(message: string, fields: Record<string, unknown>): void;
129
+ protected followTrainer(state: PairingState): void;
130
+ protected isOnFallback(control: CapabilityData | undefined): boolean;
131
+ protected closeHelperForFallback(capability: PairingFallbackCapability): void;
132
+ protected onFallbackRevertedShown(): void;
133
+ protected clearFallbackRevertedTimer(): void;
134
+ protected followRiderRetry(previousConnectState: string | undefined): void;
135
+ protected endRiderRetry(retryResult: RiderRetryResult): void;
136
+ protected clearRiderRetry(): void;
137
+ protected getRiderRetryStartFields(trigger: RiderRetryTrigger): Record<string, unknown>;
138
+ protected getRetryElapsedMs(): number;
139
+ protected stopRetryClock(): void;
140
+ protected armRetryTimer(): void;
141
+ protected clearRetryTimer(): void;
142
+ protected onRetryTimeout(): void;
96
143
  protected startTrainer(control: CapabilityData): void;
97
144
  protected endTrainer(): void;
98
145
  protected onTrainerConnectState(connectState: string | undefined): void;