incyclist-services 1.9.0 → 1.9.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.
Files changed (52) hide show
  1. package/lib/cjs/activities/types.js +1 -0
  2. package/lib/cjs/apps/service.js +2 -2
  3. package/lib/cjs/base/pages/service.js +6 -8
  4. package/lib/cjs/devices/configuration/service.js +4 -0
  5. package/lib/cjs/devices/page/base/logobserver.js +19 -0
  6. package/lib/cjs/devices/page/base/orchestrator.js +2 -0
  7. package/lib/cjs/devices/page/base/service.js +383 -0
  8. package/lib/cjs/devices/page/base/types.js +2 -0
  9. package/lib/cjs/devices/page/base/visit-log-factory.js +41 -0
  10. package/lib/cjs/devices/page/base/visit-log.js +143 -0
  11. package/lib/cjs/devices/page/desktop/matrix.js +26 -0
  12. package/lib/cjs/devices/page/desktop/orchestrator.js +21 -0
  13. package/lib/cjs/devices/page/desktop/service.js +253 -0
  14. package/lib/cjs/devices/page/desktop/types.js +2 -0
  15. package/lib/cjs/devices/page/index.js +17 -18
  16. package/lib/cjs/devices/page/mobile/orchestrator.js +6 -0
  17. package/lib/cjs/devices/page/mobile/service.js +197 -0
  18. package/lib/cjs/devices/page/mobile/statemachine.js +348 -0
  19. package/lib/cjs/devices/pairing/guidance.js +9 -5
  20. package/lib/cjs/devices/pairing/service.js +54 -1
  21. package/lib/cjs/devices/ride/service.js +1 -22
  22. package/lib/cjs/ride/display/service.js +21 -11
  23. package/lib/cjs/ride/route/GpxDisplayService.js +3 -0
  24. package/lib/cjs/ui/service.js +20 -17
  25. package/lib/cjs/workouts/ride/service.js +8 -8
  26. package/lib/esm/activities/types.js +1 -0
  27. package/lib/esm/apps/service.js +1 -1
  28. package/lib/esm/base/pages/service.js +6 -8
  29. package/lib/esm/devices/configuration/service.js +4 -0
  30. package/lib/esm/devices/page/index.js +2 -0
  31. package/lib/esm/devices/page/service.js +6 -70
  32. package/lib/esm/devices/pairing/guidance.js +9 -5
  33. package/lib/esm/devices/ride/service.js +1 -22
  34. package/lib/esm/ride/display/service.js +13 -3
  35. package/lib/esm/ride/route/GpxDisplayService.js +3 -0
  36. package/lib/esm/workouts/ride/service.js +1 -1
  37. package/lib/types/activities/ride/service.d.ts +1 -1
  38. package/lib/types/activities/types.d.ts +1 -0
  39. package/lib/types/api/ui/index.d.ts +1 -1
  40. package/lib/types/apps/service.d.ts +1 -1
  41. package/lib/types/appstate/types.d.ts +1 -1
  42. package/lib/types/base/pages/service.d.ts +1 -1
  43. package/lib/types/devices/page/index.d.ts +5 -1
  44. package/lib/types/devices/page/service.d.ts +1 -9
  45. package/lib/types/devices/page/types.d.ts +2 -129
  46. package/lib/types/devices/ride/service.d.ts +0 -1
  47. package/lib/types/ride/base/base.d.ts +1 -2
  48. package/lib/types/ride/base/types.d.ts +1 -0
  49. package/lib/types/ride/display/service.d.ts +9 -7
  50. package/lib/types/routes/list/cards/RouteCard.d.ts +1 -1
  51. package/lib/types/workouts/ride/service.d.ts +1 -1
  52. package/package.json +1 -1
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.PairingPageStateMachine = void 0;
38
+ const gd_eventlog_1 = require("gd-eventlog");
39
+ const decorators_1 = require("../../../base/decorators");
40
+ const pairing_1 = require("../../pairing");
41
+ const configuration_1 = require("../../configuration");
42
+ const node_stream_1 = require("node:stream");
43
+ const api_1 = require("../../../api");
44
+ const PAIRING_RETRY_DELAY = 2000;
45
+ const SCANNING_RETRY_DELAY = 2000;
46
+ let PairingPageStateMachine = (() => {
47
+ let _instanceExtraInitializers = [];
48
+ let _getDevicePairing_decorators;
49
+ let _getDeviceConfiguration_decorators;
50
+ let _getBindings_decorators;
51
+ return class PairingPageStateMachine {
52
+ static {
53
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
54
+ _getDevicePairing_decorators = [decorators_1.Injectable];
55
+ _getDeviceConfiguration_decorators = [decorators_1.Injectable];
56
+ _getBindings_decorators = [decorators_1.Injectable];
57
+ __esDecorate(this, null, _getDevicePairing_decorators, { kind: "method", name: "getDevicePairing", static: false, private: false, access: { has: obj => "getDevicePairing" in obj, get: obj => obj.getDevicePairing }, metadata: _metadata }, null, _instanceExtraInitializers);
58
+ __esDecorate(this, null, _getDeviceConfiguration_decorators, { kind: "method", name: "getDeviceConfiguration", static: false, private: false, access: { has: obj => "getDeviceConfiguration" in obj, get: obj => obj.getDeviceConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
59
+ __esDecorate(this, null, _getBindings_decorators, { kind: "method", name: "getBindings", static: false, private: false, access: { has: obj => "getBindings" in obj, get: obj => obj.getBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
60
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
+ }
62
+ _state = (__runInitializers(this, _instanceExtraInitializers), 'Closed');
63
+ _selectState = 'Closed';
64
+ logger;
65
+ eventHandlers = {};
66
+ internalEvents = new node_stream_1.EventEmitter();
67
+ stateChangeCallback;
68
+ selectStateChangeCallback;
69
+ retryTimeout;
70
+ selectionTimeout;
71
+ pairingPromise;
72
+ scanningPromise;
73
+ constructor() {
74
+ this.logger = new gd_eventlog_1.EventLogger('PairingPageState');
75
+ }
76
+ get state() {
77
+ return this._state;
78
+ }
79
+ get selectState() {
80
+ return this._selectState;
81
+ }
82
+ start(callback) {
83
+ try {
84
+ if (this._state !== 'Closed') {
85
+ this.logError(new Error(`State machine in illegal state ${this.state}`), 'start');
86
+ return;
87
+ }
88
+ this.stateChangeCallback = callback;
89
+ this.registerServiceEventHandlers();
90
+ this.setState('Idle');
91
+ this.logIncomingEvent('start()', undefined, 'Idle');
92
+ }
93
+ catch (err) {
94
+ this.logError(err, 'start');
95
+ }
96
+ }
97
+ stop() {
98
+ try {
99
+ const prev = this.state;
100
+ this.unregisterServiceEventHandlers();
101
+ delete this.stateChangeCallback;
102
+ this.resetTimeouts();
103
+ delete this.pairingPromise;
104
+ delete this.scanningPromise;
105
+ this.setState('Closed');
106
+ this.logIncomingEvent('stop', prev, 'Closed');
107
+ }
108
+ catch (err) {
109
+ this.logError(err, 'stop');
110
+ }
111
+ }
112
+ async pause() {
113
+ const prev = this._state;
114
+ const service = this.getDevicePairing();
115
+ if (this.state === 'Pairing') {
116
+ await service.stopPairing();
117
+ }
118
+ else if (this.state === 'Scanning') {
119
+ await service.stopScanning();
120
+ }
121
+ await service.stop([], true);
122
+ this.resetTimeouts();
123
+ this.setState('Closed');
124
+ this.logIncomingEvent('pause', prev, this.state);
125
+ }
126
+ resume() {
127
+ const prev = this._state;
128
+ this.setState('Idle');
129
+ this.logIncomingEvent('resume', prev, this.state);
130
+ }
131
+ setState(state) {
132
+ const prev = this._state;
133
+ this._state = state;
134
+ if (this.stateChangeCallback) {
135
+ this.stateChangeCallback();
136
+ }
137
+ }
138
+ logError(err, fn) {
139
+ this.logger.logEvent({ message: 'error', fn, error: err.message, stack: err.stack });
140
+ }
141
+ registerServiceEventHandlers() {
142
+ this.registerHandler('page-ready', this.onPageReady.bind(this));
143
+ this.registerHandler('state-update', this.onStateUpdate.bind(this));
144
+ this.registerHandler('pairing-start', this.onPairingStarted.bind(this));
145
+ this.registerHandler('pairing-done', this.onPairingFinished.bind(this));
146
+ this.registerHandler('scanning-start', this.onScanningStarted.bind(this));
147
+ this.registerHandler('scanning-done', this.onScanningFinished.bind(this));
148
+ this.registerHandler('retry', this.onRetry.bind(this));
149
+ }
150
+ unregisterServiceEventHandlers() {
151
+ const service = this.getDevicePairing();
152
+ const registered = Object.keys(this.eventHandlers);
153
+ for (const event of registered) {
154
+ service.off(event, this.eventHandlers[event]);
155
+ this.internalEvents.off(event, this.eventHandlers[event]);
156
+ }
157
+ this.eventHandlers = {};
158
+ }
159
+ registerHandler(event, handler) {
160
+ const service = this.getDevicePairing();
161
+ service.on(event, handler);
162
+ this.internalEvents.on(event, handler);
163
+ this.eventHandlers[event] = handler;
164
+ }
165
+ logIncomingEvent(event, oldState, newState) {
166
+ this.logger.logEvent({ message: 'handle event', notified: event, stateTransition: { from: oldState, to: newState } });
167
+ }
168
+ emit(event) {
169
+ this.internalEvents.emit(event);
170
+ }
171
+ onPageReady() {
172
+ if (this.state !== 'Idle') {
173
+ this.logError(new Error('Illegal state'), 'onPageStartedEventHandler');
174
+ return;
175
+ }
176
+ const prev = this._state;
177
+ this.performCheck();
178
+ this.logIncomingEvent('page-ready', prev, this.state);
179
+ }
180
+ onStateUpdate() {
181
+ if (this.selectState === 'Closed') {
182
+ if (this.stateChangeCallback)
183
+ this.stateChangeCallback();
184
+ }
185
+ else {
186
+ if (this.selectStateChangeCallback)
187
+ this.selectStateChangeCallback();
188
+ }
189
+ }
190
+ performCheck(prevState) {
191
+ try {
192
+ const oldState = this.state;
193
+ const configuration = this.getDeviceConfiguration();
194
+ const service = this.getDevicePairing();
195
+ const hasDevices = configuration.canStartRide();
196
+ const adapters = configuration.getAdapters(false);
197
+ this.logger.logEvent({ message: 'check next action', hasDevices });
198
+ if (hasDevices && this.selectState === 'Closed') {
199
+ const pairingDone = service.checkPairingComplete();
200
+ if (pairingDone) {
201
+ service.prepareForRide();
202
+ this.resetTimeouts();
203
+ this.setState('Done');
204
+ }
205
+ else if (!this.pairingPromise) {
206
+ this.setState('Pairing');
207
+ this.pairingPromise = Promise.resolve(service.startPairing(adapters, {}))
208
+ .catch(err => { this.logError(err, 'startPairing'); })
209
+ .finally(() => { delete this.pairingPromise; });
210
+ }
211
+ }
212
+ else if (this.selectState === 'Closed' || this.selectState === 'Active') {
213
+ if (!this.scanningPromise) {
214
+ this.setState('Scanning');
215
+ this.scanningPromise = Promise.resolve(service.startScanning(adapters, {}))
216
+ .catch(err => { this.logError(err, 'startScanning'); })
217
+ .finally(() => { delete this.scanningPromise; });
218
+ }
219
+ }
220
+ if (this.state !== oldState)
221
+ this.logger.logEvent({ message: 'state changed', stateTransition: { from: oldState, to: this.state } });
222
+ }
223
+ catch (err) {
224
+ this.logError(err, 'performCheck');
225
+ }
226
+ }
227
+ onPairingStarted() {
228
+ if (this.state !== 'Pairing') {
229
+ this.logError(new Error('Illegal state'), 'onPairingStarted');
230
+ return;
231
+ }
232
+ this.sendUpdate();
233
+ }
234
+ onPairingFinished() {
235
+ const prev = this.state;
236
+ this.setState('Idle');
237
+ if (this._selectState === 'Waiting') {
238
+ this.resetTimeouts();
239
+ if (!this.selectionTimeout) {
240
+ this.performCheck();
241
+ }
242
+ }
243
+ else {
244
+ this.logger.logEvent({ message: 'setup retry timeout', delay: PAIRING_RETRY_DELAY });
245
+ this.retryTimeout = setTimeout(() => {
246
+ this.onRetry(prev);
247
+ }, PAIRING_RETRY_DELAY);
248
+ this.sendUpdate();
249
+ this.logIncomingEvent('pairing-done', prev, this.state);
250
+ }
251
+ }
252
+ sendUpdate() {
253
+ if (this.stateChangeCallback)
254
+ this.stateChangeCallback();
255
+ }
256
+ onScanningStarted() {
257
+ if (this.state !== 'Scanning') {
258
+ this.logError(new Error('Illegal state'), 'onScanningStarted');
259
+ return;
260
+ }
261
+ }
262
+ onScanningFinished() {
263
+ const prev = this.state;
264
+ this.setState('Idle');
265
+ this.retryTimeout = setTimeout(() => {
266
+ this.onRetry(prev);
267
+ }, SCANNING_RETRY_DELAY);
268
+ this.logIncomingEvent('started', prev, this.state);
269
+ }
270
+ onRetry(prevState) {
271
+ this.resetTimeouts();
272
+ if (this.state !== 'Idle') {
273
+ return;
274
+ }
275
+ this.performCheck(prevState);
276
+ }
277
+ onDeviceSelectionOpened(onSelectionStateChanged) {
278
+ if (this.state === 'Pairing') {
279
+ this.startDeviceSelectionTimeout();
280
+ this._selectState = 'Waiting';
281
+ }
282
+ else {
283
+ this._selectState = 'Active';
284
+ }
285
+ this.logIncomingEvent('list-open', this.state, this.state);
286
+ if (this.state === 'Idle' || this.state === 'Done') {
287
+ this.performCheck();
288
+ }
289
+ }
290
+ async onDeviceSelectionClosed() {
291
+ const prev = this.state;
292
+ this._selectState = 'Closed';
293
+ delete this.selectStateChangeCallback;
294
+ this.stopDeviceSelectionTimeout();
295
+ if (this.state === 'Pairing') {
296
+ await this.getDevicePairing().stopPairing();
297
+ this.setState('Idle');
298
+ }
299
+ else if (this.state === 'Scanning') {
300
+ await this.getDevicePairing().stopScanning();
301
+ this.setState('Idle');
302
+ }
303
+ this.logIncomingEvent('list-close', prev, this.state);
304
+ this.performCheck();
305
+ }
306
+ startDeviceSelectionTimeout() {
307
+ this.stopDeviceSelectionTimeout();
308
+ this.selectionTimeout = setTimeout(this.onDeviceSelectionTimeout.bind(this), 3000);
309
+ }
310
+ stopDeviceSelectionTimeout() {
311
+ if (this.selectionTimeout)
312
+ clearTimeout(this.selectionTimeout);
313
+ delete this.selectionTimeout;
314
+ }
315
+ async onDeviceSelectionTimeout() {
316
+ this.stopDeviceSelectionTimeout();
317
+ this.logIncomingEvent('list-timeout', this.state, this.state);
318
+ if (this.state === 'Idle') {
319
+ this._selectState = 'Active';
320
+ this.performCheck();
321
+ }
322
+ else if (this.state === 'Pairing') {
323
+ await this.getDevicePairing().stopPairing();
324
+ this._selectState = 'Active';
325
+ this.performCheck();
326
+ }
327
+ }
328
+ resetTimeouts() {
329
+ if (this.retryTimeout !== undefined) {
330
+ clearTimeout(this.retryTimeout);
331
+ delete this.retryTimeout;
332
+ }
333
+ }
334
+ getDevicePairing() {
335
+ return (0, pairing_1.useDevicePairing)();
336
+ }
337
+ getDeviceConfiguration() {
338
+ return (0, configuration_1.useDeviceConfiguration)();
339
+ }
340
+ getBleBinding() {
341
+ return this.getBindings().ble;
342
+ }
343
+ getBindings() {
344
+ return (0, api_1.getBindings)();
345
+ }
346
+ };
347
+ })();
348
+ exports.PairingPageStateMachine = PairingPageStateMachine;
@@ -17,13 +17,17 @@ const INTERFACE_LABELS = {
17
17
  tcpip: 'TCP/IP',
18
18
  wifi: 'Wi-Fi',
19
19
  };
20
- const DESKTOP_SEARCH_INTERFACES = new Set(['ble', 'ant']);
21
- const searchInterfaces = (interfaces, platform) => platform === 'desktop'
22
- ? interfaces.filter(i => DESKTOP_SEARCH_INTERFACES.has(i.id))
20
+ const DESKTOP_SCAN_INTERFACES = new Set(['ble', 'ant', 'wifi']);
21
+ const DESKTOP_NAMED_INTERFACES = new Set(['ble', 'ant']);
22
+ const scanInterfaces = (interfaces, platform) => platform === 'desktop'
23
+ ? interfaces.filter(i => DESKTOP_SCAN_INTERFACES.has(i.id))
23
24
  : interfaces;
24
- const canScanWithInterfaces = (interfaces, platform) => searchInterfaces(interfaces, platform).some(i => i.enabled && i.available);
25
+ const namedInterfaces = (interfaces, platform) => platform === 'desktop'
26
+ ? interfaces.filter(i => DESKTOP_NAMED_INTERFACES.has(i.id))
27
+ : interfaces;
28
+ const canScanWithInterfaces = (interfaces, platform) => scanInterfaces(interfaces, platform).some(i => i.enabled && i.available);
25
29
  exports.canScanWithInterfaces = canScanWithInterfaces;
26
- const getUnavailableInterfaces = (interfaces, platform) => searchInterfaces(interfaces, platform).filter(i => i.enabled && !i.available).map(i => i.id);
30
+ const getUnavailableInterfaces = (interfaces, platform) => namedInterfaces(interfaces, platform).filter(i => i.enabled && !i.available).map(i => i.id);
27
31
  exports.getUnavailableInterfaces = getUnavailableInterfaces;
28
32
  const isBrokenInterface = (interfaces, id) => interfaces.find(i => i.id === id && i.enabled && !i.available);
29
33
  const getPairingHint = (input) => {
@@ -88,6 +88,9 @@ let DevicePairingService = (() => {
88
88
  settings = {};
89
89
  state = { initialized: false, deleted: [] };
90
90
  deviceSelectState = null;
91
+ static STALLED_AFTER_MS = 30 * 1000;
92
+ stalledTimer;
93
+ stalledLogged = false;
91
94
  onPairingStartedHandler = this.onPairingStarted.bind(this);
92
95
  onPairingSuccessHandler = this.onPairingSuccess.bind(this);
93
96
  onPairingErrorHandler = this.onPairingError.bind(this);
@@ -119,6 +122,7 @@ let DevicePairingService = (() => {
119
122
  }
120
123
  async start(onStateChanged) {
121
124
  this.pairingConfirmed = false;
125
+ this.stalledLogged = false;
122
126
  if (this.state.stopped) {
123
127
  this.state.stopped = false;
124
128
  this.state.deleted = [];
@@ -177,6 +181,7 @@ let DevicePairingService = (() => {
177
181
  this.access.off('interface-changed', this.onInterfaceStateChangedHandler);
178
182
  }
179
183
  async stop(adapters = [], forExit = false) {
184
+ this.clearStalledTimer();
180
185
  const adapterFilter = adapters ?? [];
181
186
  if (!forExit) {
182
187
  this.logEvent({ message: 'Stop Pairing (Skip)' });
@@ -324,7 +329,7 @@ let DevicePairingService = (() => {
324
329
  async unselectDevices(capability) {
325
330
  try {
326
331
  const adapater = this.getDeviceConfiguration().getSelected(capability);
327
- this.getDeviceConfiguration().unselect(capability, true);
332
+ this.getDeviceConfiguration().disableCapability(capability, true);
328
333
  if (adapater?.isStarted()) {
329
334
  this.restart();
330
335
  }
@@ -333,6 +338,15 @@ let DevicePairingService = (() => {
333
338
  this.logError(err, 'deleteDevice');
334
339
  }
335
340
  }
341
+ useCapability(capability) {
342
+ try {
343
+ this.getDeviceConfiguration().disableCapability(capability, false);
344
+ this.restart().catch(err => { this.logError(err, 'useCapability'); });
345
+ }
346
+ catch (err) {
347
+ this.logError(err, 'useCapability');
348
+ }
349
+ }
336
350
  async changeInterfaceSettings(name, settings) {
337
351
  try {
338
352
  const _interface = this.state.interfaces.find(i => i.name === name);
@@ -377,6 +391,7 @@ let DevicePairingService = (() => {
377
391
  if (timeSincePrev < 3000) {
378
392
  this.state.tsPrevStart = -1;
379
393
  await (0, sleep_1.sleep)(3000 - timeSincePrev);
394
+ delete this.state.tsPrevStart;
380
395
  }
381
396
  }
382
397
  if (wasActive) {
@@ -468,6 +483,7 @@ let DevicePairingService = (() => {
468
483
  emitStateChange(newState) {
469
484
  const { onStateChanged, onDeviceSelectStateChanged } = this.settings || {};
470
485
  this.checkCanStart();
486
+ this.checkPairingStalled();
471
487
  if (this.state.stopRequested)
472
488
  return;
473
489
  const state = this.getExternaState(newState);
@@ -480,6 +496,43 @@ let DevicePairingService = (() => {
480
496
  if (onDeviceSelectStateChanged && typeof onDeviceSelectStateChanged === 'function')
481
497
  onDeviceSelectStateChanged(this.getDeviceSelectionState());
482
498
  }
499
+ checkPairingStalled() {
500
+ if (this.stalledLogged)
501
+ return;
502
+ if (!this.isStalled()) {
503
+ this.clearStalledTimer();
504
+ return;
505
+ }
506
+ if (!this.stalledTimer)
507
+ this.stalledTimer = setTimeout(() => { this.onPairingStalled(); }, DevicePairingService.STALLED_AFTER_MS);
508
+ }
509
+ isStalled() {
510
+ if (this.isPairing() || this.isScanning())
511
+ return false;
512
+ const selected = (this.state.capabilities ?? []).filter(c => c.selected);
513
+ return selected.length > 0 && selected.every(c => c.connectState === 'waiting');
514
+ }
515
+ onPairingStalled() {
516
+ delete this.stalledTimer;
517
+ if (this.stalledLogged || !this.isStalled())
518
+ return;
519
+ this.stalledLogged = true;
520
+ this.logEvent({
521
+ message: 'pairing stalled',
522
+ usage: this.usage,
523
+ isPairing: this.isPairing(),
524
+ isScanning: this.isScanning(),
525
+ waiting: Boolean(this.state.waiting),
526
+ sentinel: this.state.tsPrevStart === -1,
527
+ interfaces: (this.state.interfaces ?? []).map(i => ({ name: i.name, state: i.state })),
528
+ capabilities: (this.state.capabilities ?? []).filter(c => c.selected).map(c => ({ capability: c.capability, connectState: c.connectState })),
529
+ });
530
+ }
531
+ clearStalledTimer() {
532
+ if (this.stalledTimer)
533
+ clearTimeout(this.stalledTimer);
534
+ delete this.stalledTimer;
535
+ }
483
536
  emitStartStatus() {
484
537
  const { onStateChanged } = this.settings || {};
485
538
  const { canStartRide } = this.state;
@@ -45,12 +45,10 @@ const clone_1 = __importDefault(require("../../utils/clone"));
45
45
  const settings_1 = require("../../settings");
46
46
  const logging_1 = require("../../utils/logging");
47
47
  const incyclist_devices_1 = require("incyclist-devices");
48
- const routes_1 = require("../../routes");
49
48
  const service_2 = require("../../base/service");
50
49
  const types_1 = require("../../base/types");
51
50
  const Injection_1 = require("../../base/decorators/Injection");
52
51
  const apps_1 = require("../../apps");
53
- const workouts_1 = require("../../workouts");
54
52
  const NO_DATA_THRESHOLD = 10000;
55
53
  const UNHEALTHY_THRESHOLD = 60000;
56
54
  let DeviceRideService = (() => {
@@ -64,7 +62,6 @@ let DeviceRideService = (() => {
64
62
  let _getUserSettings_decorators;
65
63
  let _getDeviceAccess_decorators;
66
64
  let _getGoogleMaps_decorators;
67
- let _getWorkoutList_decorators;
68
65
  var DeviceRideService = class extends _classSuper {
69
66
  static { _classThis = this; }
70
67
  static {
@@ -73,12 +70,10 @@ let DeviceRideService = (() => {
73
70
  _getUserSettings_decorators = [Injection_1.Injectable];
74
71
  _getDeviceAccess_decorators = [Injection_1.Injectable];
75
72
  _getGoogleMaps_decorators = [Injection_1.Injectable];
76
- _getWorkoutList_decorators = [Injection_1.Injectable];
77
73
  __esDecorate(this, null, _getDeviceConfiguration_decorators, { kind: "method", name: "getDeviceConfiguration", static: false, private: false, access: { has: obj => "getDeviceConfiguration" in obj, get: obj => obj.getDeviceConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
78
74
  __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
79
75
  __esDecorate(this, null, _getDeviceAccess_decorators, { kind: "method", name: "getDeviceAccess", static: false, private: false, access: { has: obj => "getDeviceAccess" in obj, get: obj => obj.getDeviceAccess }, metadata: _metadata }, null, _instanceExtraInitializers);
80
76
  __esDecorate(this, null, _getGoogleMaps_decorators, { kind: "method", name: "getGoogleMaps", static: false, private: false, access: { has: obj => "getGoogleMaps" in obj, get: obj => obj.getGoogleMaps }, metadata: _metadata }, null, _instanceExtraInitializers);
81
- __esDecorate(this, null, _getWorkoutList_decorators, { kind: "method", name: "getWorkoutList", static: false, private: false, access: { has: obj => "getWorkoutList" in obj, get: obj => obj.getWorkoutList }, metadata: _metadata }, null, _instanceExtraInitializers);
82
77
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
83
78
  DeviceRideService = _classThis = _classDescriptor.value;
84
79
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -1364,20 +1359,7 @@ let DeviceRideService = (() => {
1364
1359
  delete this.rideAdapters;
1365
1360
  }
1366
1361
  canEnforceSimulator() {
1367
- const selected = (0, routes_1.getRouteList)().getSelected();
1368
- if (this.getWorkoutList().getSelected() && !selected)
1369
- return true;
1370
- const personalApiKey = this.getGoogleMaps().hasPersonalApiKey();
1371
- if (!selected?.description)
1372
- return false;
1373
- if (selected?.description?.hasVideo || personalApiKey)
1374
- return true;
1375
- if (!selected.description.hasVideo) {
1376
- const rideView = (0, settings_1.useUserSettings)().getValue('preferences.rideView', null);
1377
- if (rideView === 'map')
1378
- return true;
1379
- }
1380
- return (0, settings_1.useUserSettings)().isNewUser();
1362
+ return true;
1381
1363
  }
1382
1364
  logEvent(event) {
1383
1365
  if (this.logPaused)
@@ -1422,9 +1404,6 @@ let DeviceRideService = (() => {
1422
1404
  getGoogleMaps() {
1423
1405
  return (0, apps_1.useGoogleMaps)();
1424
1406
  }
1425
- getWorkoutList() {
1426
- return (0, workouts_1.useWorkoutList)();
1427
- }
1428
1407
  };
1429
1408
  return DeviceRideService = _classThis;
1430
1409
  })();
@@ -35,13 +35,15 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
35
35
  };
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.useRideDisplay = exports.RideDisplayService = void 0;
38
- const activities_1 = require("../../activities");
39
- const service_1 = require("../../base/service");
38
+ const service_1 = require("../../activities/ride/service");
39
+ const service_2 = require("../../base/service");
40
40
  const types_1 = require("../../base/types");
41
41
  const decorators_1 = require("../../base/decorators");
42
42
  const workouts_1 = require("../../workouts");
43
43
  const routes_1 = require("../../routes");
44
- const devices_1 = require("../../devices");
44
+ const ride_1 = require("../../devices/ride");
45
+ const configuration_1 = require("../../devices/configuration");
46
+ const visit_log_factory_1 = require("../../devices/page/base/visit-log-factory");
45
47
  const settings_1 = require("../../settings");
46
48
  const incyclist_devices_1 = require("incyclist-devices");
47
49
  const utils_1 = require("../../utils");
@@ -57,7 +59,7 @@ let RideDisplayService = (() => {
57
59
  let _classDescriptor;
58
60
  let _classExtraInitializers = [];
59
61
  let _classThis;
60
- let _classSuper = service_1.IncyclistService;
62
+ let _classSuper = service_2.IncyclistService;
61
63
  let _instanceExtraInitializers = [];
62
64
  let _getActivityRide_decorators;
63
65
  let _getWorkoutRide_decorators;
@@ -108,6 +110,7 @@ let RideDisplayService = (() => {
108
110
  deviceData;
109
111
  actualWorkout;
110
112
  hideAll = false;
113
+ simulated = false;
111
114
  onChangeState = this.setState.bind(this);
112
115
  startDeviceHandlers;
113
116
  isResuming;
@@ -119,6 +122,7 @@ let RideDisplayService = (() => {
119
122
  }
120
123
  async init() {
121
124
  await this.closePrevRide();
125
+ this.simulated = false;
122
126
  this.observer = new types_1.Observer();
123
127
  this.controlDevicesReadyNotified = false;
124
128
  try {
@@ -136,8 +140,9 @@ let RideDisplayService = (() => {
136
140
  }
137
141
  start(simulate) {
138
142
  try {
139
- if (simulate)
143
+ if (simulate) {
140
144
  this.enforceSimulator();
145
+ }
141
146
  this.notifyPairingVisitRideStarted(simulate);
142
147
  const rideProps = this.getRideModeService().getLogProps();
143
148
  this.logEvent({ message: 'Start ride', ...rideProps,
@@ -158,6 +163,9 @@ let RideDisplayService = (() => {
158
163
  this.logError(err, 'start');
159
164
  }
160
165
  }
166
+ isSimulated() {
167
+ return this.simulated;
168
+ }
161
169
  notifyPairingVisitRideStarted(simulate) {
162
170
  try {
163
171
  this.getPairingVisitTracker().onRideStarted({ simulate: simulate === true });
@@ -496,6 +504,7 @@ let RideDisplayService = (() => {
496
504
  }
497
505
  if (prevState !== 'Starting')
498
506
  this.enableScreensaver();
507
+ this.simulated = false;
499
508
  }
500
509
  catch (err) {
501
510
  this.logError(err, 'stopRide');
@@ -974,6 +983,7 @@ let RideDisplayService = (() => {
974
983
  this.checkStartStatus();
975
984
  }
976
985
  enforceSimulator() {
986
+ this.simulated = true;
977
987
  this.getDeviceRide().enforceSimulator();
978
988
  }
979
989
  getScreenshotName() {
@@ -1123,7 +1133,7 @@ let RideDisplayService = (() => {
1123
1133
  return adapter?.getUniqueName();
1124
1134
  }
1125
1135
  getBikeInterface() {
1126
- const devices = (0, devices_1.useDeviceConfiguration)();
1136
+ const devices = (0, configuration_1.useDeviceConfiguration)();
1127
1137
  const adapter = devices.getSelected(incyclist_devices_1.IncyclistCapability.Control) ?? devices.getSelected(incyclist_devices_1.IncyclistCapability.Power) ?? devices.getSelected(incyclist_devices_1.IncyclistCapability.Speed);
1128
1138
  return (0, utils_1.getLegacyInterface)(adapter);
1129
1139
  }
@@ -1147,7 +1157,7 @@ let RideDisplayService = (() => {
1147
1157
  isVirtualShiftingEnabled() {
1148
1158
  try {
1149
1159
  const mode = this.getDeviceRide().getCyclingMode();
1150
- return (0, devices_1.isVirtualShiftingEnabled)(mode);
1160
+ return (0, ride_1.isVirtualShiftingEnabled)(mode);
1151
1161
  }
1152
1162
  catch (err) {
1153
1163
  this.logError(err, 'isVirtualShiftingEnabled');
@@ -1155,7 +1165,7 @@ let RideDisplayService = (() => {
1155
1165
  }
1156
1166
  }
1157
1167
  getActivityRide() {
1158
- return (0, activities_1.useActivityRide)();
1168
+ return (0, service_1.useActivityRide)();
1159
1169
  }
1160
1170
  getWorkoutRide() {
1161
1171
  return (0, workouts_1.useWorkoutRide)();
@@ -1167,13 +1177,13 @@ let RideDisplayService = (() => {
1167
1177
  return (0, routes_1.useRouteList)();
1168
1178
  }
1169
1179
  getDeviceRide() {
1170
- return (0, devices_1.useDeviceRide)();
1180
+ return (0, ride_1.useDeviceRide)();
1171
1181
  }
1172
1182
  getUserSettings() {
1173
1183
  return (0, settings_1.useUserSettings)();
1174
1184
  }
1175
1185
  getDeviceConfiguration() {
1176
- return (0, devices_1.useDeviceConfiguration)();
1186
+ return (0, configuration_1.useDeviceConfiguration)();
1177
1187
  }
1178
1188
  getUIBinding() {
1179
1189
  return (0, api_1.getBindings)().ui;
@@ -1182,7 +1192,7 @@ let RideDisplayService = (() => {
1182
1192
  return (0, coaches_1.getCoachesService)();
1183
1193
  }
1184
1194
  getPairingVisitTracker() {
1185
- return (0, devices_1.usePairingVisitTracker)();
1195
+ return (0, visit_log_factory_1.usePairingVisitTracker)();
1186
1196
  }
1187
1197
  };
1188
1198
  return RideDisplayService = _classThis;