incyclist-services 1.9.0 → 1.9.1

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 (48) 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 +13 -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/pairing/guidance.js +9 -5
  31. package/lib/esm/devices/ride/service.js +1 -22
  32. package/lib/esm/ride/display/service.js +13 -3
  33. package/lib/esm/ride/route/GpxDisplayService.js +3 -0
  34. package/lib/esm/workouts/ride/service.js +1 -1
  35. package/lib/types/activities/ride/service.d.ts +1 -1
  36. package/lib/types/activities/types.d.ts +1 -0
  37. package/lib/types/api/ui/index.d.ts +1 -1
  38. package/lib/types/apps/service.d.ts +1 -1
  39. package/lib/types/base/pages/service.d.ts +1 -1
  40. package/lib/types/devices/page/index.d.ts +3 -1
  41. package/lib/types/devices/page/types.d.ts +2 -129
  42. package/lib/types/devices/ride/service.d.ts +0 -1
  43. package/lib/types/ride/base/base.d.ts +1 -2
  44. package/lib/types/ride/base/types.d.ts +1 -0
  45. package/lib/types/ride/display/service.d.ts +9 -7
  46. package/lib/types/routes/list/cards/RouteCard.d.ts +1 -1
  47. package/lib/types/workouts/ride/service.d.ts +1 -1
  48. package/package.json +1 -1
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DESKTOP_MATRIX = void 0;
4
+ exports.DESKTOP_MATRIX = [
5
+ { area: 'buttons', name: 'ready, ride mode', given: 'canStartRide, mode=start', expected: 'primary "Start" (labelOK)' },
6
+ { area: 'buttons', name: 'ready, normal mode', given: 'canStartRide, mode=normal', expected: 'primary "OK"' },
7
+ { area: 'buttons', name: 'not ready, ride mode', given: '!canStartRide, mode=start', expected: 'primary "Simulate", secondary "Cancel" (labelSkip)' },
8
+ { area: 'buttons', name: 'not ready, normal mode', given: '!canStartRide, mode=normal', expected: 'primary "Skip" only - no ride to simulate' },
9
+ { area: 'ok-navigation', name: 'OK in ride mode starts the ride', given: 'isPairingForRide', expected: 'navigate "/rideOK"' },
10
+ { area: 'ok-navigation', name: 'OK outside ride mode returns to the content page', given: '!isPairingForRide', expected: 'navigate "/<persisted page ?? routes>"' },
11
+ { area: 'ok-navigation', name: 'OK closes the visit as ok', given: 'any', expected: 'closeVisit("ok") then devicePairing.prepareStart() and setReadyToStart()' },
12
+ { area: 'skip', name: 'Skip in normal mode returns to the source', given: 'mode=normal, location.state.source set', expected: 'navigate(source); closeVisit("skip")' },
13
+ { area: 'skip', name: 'Skip in normal mode without a source', given: 'mode=normal, no source', expected: 'navigate("/<persisted page ?? routes>"); closeVisit("skip")' },
14
+ { area: 'skip', name: 'Cancel in ride mode returns to the source', given: 'mode=start', expected: 'navigate(source); closeVisit("cancel")' },
15
+ { area: 'simulate', name: 'Simulate in ride mode', given: 'isPairingForRide', expected: 'prepareStart([simulatorId]); navigate "/rideSimulate"; closeVisit("simulate")' },
16
+ { area: 'simulator', name: 'Shift+S adds the simulator', given: 'Shift+S pressed', expected: 'deviceConfig.add({name:"Simulator", interface:"simulator"}); the key is disabled afterwards' },
17
+ { area: 'tiles', name: 'Tile ✕ unselects the capability', given: 'a selected tile', expected: 'devicePairing.unselectDevices(capability)' },
18
+ { area: 'device-list', name: 'Opening a tile opens its device list', given: 'tile clicked', expected: 'DeviceSelector opens for that capability' },
19
+ { area: 'device-list', name: 'Select with changeForAll default for Resistance', given: 'capability=control, device clicked', expected: 'selectDevice(control, udid, true); the dialog closes' },
20
+ { area: 'device-list', name: 'Select with changeForAll default for other capabilities', given: 'capability!=control, device clicked', expected: 'selectDevice(capability, udid, false); the dialog closes' },
21
+ { area: 'device-list', name: 'Select-all is offered for Resistance only', given: 'capability=control', expected: 'canSelectAll true; other capabilities false' },
22
+ { area: 'device-list', name: 'Delete a device in the list', given: 'delete clicked on a device', expected: 'devicePairing.deleteDevice(capability, udid); the list stays open' },
23
+ { area: 'device-list', name: 'Cancel the device list keeps the selection', given: 'Cancel in the list', expected: 'stopDeviceSelection(); onCancel closes the dialog; no unselect', flag: 'Mobile has a "Don\'t use" tick that unselects. Desktop has no tick and uses the tile ✕. The product owner wants an alternative on mobile; a UX suggestion is pending.' },
24
+ { area: 'interfaces', name: 'Interface clicked opens its settings', given: 'an interface tile clicked', expected: 'showInterfaceSettings is populated for that interface (name, protocols, enabled, protocol, port)' },
25
+ { area: 'interfaces', name: 'Interface settings change', given: 'OK in interface settings', expected: 'devicePairing.changeInterfaceSettings(ifName, settings); showInterfaceSettings clears' },
26
+ ];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDirectOrchestrator = void 0;
4
+ class DirectOrchestrator {
5
+ state = 'Idle';
6
+ selectState = 'Closed';
7
+ start(_onUpdate) {
8
+ }
9
+ stop() {
10
+ }
11
+ async pause() {
12
+ }
13
+ resume() {
14
+ }
15
+ onDeviceSelectionOpened() {
16
+ }
17
+ onDeviceSelectionClosed() {
18
+ }
19
+ }
20
+ const createDirectOrchestrator = () => new DirectOrchestrator();
21
+ exports.createDirectOrchestrator = createDirectOrchestrator;
@@ -0,0 +1,253 @@
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.DesktopPairingPageService = void 0;
38
+ const incyclist_devices_1 = require("incyclist-devices");
39
+ const decorators_1 = require("../../../base/decorators");
40
+ const service_1 = require("../base/service");
41
+ const orchestrator_1 = require("./orchestrator");
42
+ const access_1 = require("../../access");
43
+ const pairing_1 = require("../../pairing");
44
+ let DesktopPairingPageService = (() => {
45
+ let _classDecorators = [decorators_1.Singleton];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ let _classSuper = service_1.PairingPageService;
50
+ let _instanceExtraInitializers = [];
51
+ let _getDeviceAccess_decorators;
52
+ var DesktopPairingPageService = class extends _classSuper {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
56
+ _getDeviceAccess_decorators = [decorators_1.Injectable];
57
+ __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);
58
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
59
+ DesktopPairingPageService = _classThis = _classDescriptor.value;
60
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
+ __runInitializers(_classThis, _classExtraInitializers);
62
+ }
63
+ source = __runInitializers(this, _instanceExtraInitializers);
64
+ deviceSelectState;
65
+ interfaceSettingsFor;
66
+ createOrchestrator() {
67
+ return (0, orchestrator_1.createDirectOrchestrator)();
68
+ }
69
+ getUsageMode() {
70
+ return 'direct';
71
+ }
72
+ openPage(forRide, source) {
73
+ this.source = source;
74
+ return super.openPage(forRide);
75
+ }
76
+ getPageDisplayProperties() {
77
+ const title = 'Devices';
78
+ try {
79
+ const caps = this.state.capabilities ?? [];
80
+ const allIfs = this.state.interfaces ?? [];
81
+ const ifs = allIfs.filter(i => !i.invisible);
82
+ this.getDeviceAccess().enrichWithAccessState(ifs);
83
+ const interfaces = ifs.map(i => this.getInterfaceDisplayProps(i));
84
+ const status = (0, pairing_1.getPairingStatusDisplay)({
85
+ platform: 'desktop',
86
+ interfaces: (0, pairing_1.toPairingInterfaceStates)(allIfs),
87
+ capabilities: caps,
88
+ canStartRide: this.canStartRide(),
89
+ loading: this.promiseOpen !== undefined,
90
+ rideMode: this.isPairingForRide,
91
+ });
92
+ const capProps = caps.map(c => this.getCapabilityDisplayProps(c, status.id === 'S1'));
93
+ const CP = (cap) => capProps.find(c => c.capability === cap);
94
+ const top = [
95
+ CP(incyclist_devices_1.IncyclistCapability.Control),
96
+ CP(incyclist_devices_1.IncyclistCapability.Power),
97
+ CP(incyclist_devices_1.IncyclistCapability.Speed)
98
+ ].filter(c => c !== null && c !== undefined);
99
+ const bottom = [
100
+ CP(incyclist_devices_1.IncyclistCapability.HeartRate),
101
+ CP(incyclist_devices_1.IncyclistCapability.Cadence),
102
+ CP(incyclist_devices_1.IncyclistCapability.AppControl)
103
+ ].filter(c => c !== null && c !== undefined);
104
+ const trainerSelected = Boolean(caps.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control)?.selected);
105
+ const rowLabels = {
106
+ top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected)),
107
+ bottom: (0, pairing_1.getPairingGuidanceText)('row-optional'),
108
+ };
109
+ const buttons = this.getButtonsDisplayProps();
110
+ return {
111
+ title,
112
+ readyToStart: this.canStartRide(),
113
+ status,
114
+ capabilities: { top, bottom, rowLabels },
115
+ interfaces,
116
+ deviceSelection: this.getDeviceListDisplayProps(),
117
+ buttons,
118
+ showInterfaceSettings: this.getInterfaceSettingsDisplayProps(),
119
+ };
120
+ }
121
+ catch (err) {
122
+ this.logError(err, 'getPageDisplayProperties');
123
+ return {
124
+ title,
125
+ capabilities: { top: [], bottom: [] },
126
+ interfaces: [],
127
+ buttons: [{ label: 'Skip', primary: true, onClick: this.onSkip.bind(this) }],
128
+ showInterfaceSettings: undefined,
129
+ };
130
+ }
131
+ }
132
+ openDeviceSelection(cap) {
133
+ this.logEvent({ message: 'capability clicked', capability: cap, eventSource: 'user' });
134
+ this.openedCapability = cap;
135
+ this.deviceSelectState = this.getDevicePairing().startDeviceSelection(cap, (newState) => {
136
+ this.deviceSelectState = newState;
137
+ this.updatePage();
138
+ });
139
+ this.updatePage();
140
+ }
141
+ onDeviceSelected(d, addAll) {
142
+ const capability = this.openedCapability;
143
+ this.logEvent({ message: 'device selected', capability, device: d.name });
144
+ const changeForAll = addAll ?? (capability === incyclist_devices_1.IncyclistCapability.Control);
145
+ this.closeDeviceSelection();
146
+ this.getDevicePairing().selectDevice(capability, d.udid, changeForAll)
147
+ .catch(err => { this.logError(err, 'onDeviceSelected'); });
148
+ this.updatePage();
149
+ }
150
+ closeDeviceSelection() {
151
+ this.logEvent({ message: 'capability closed', capability: this.openedCapability });
152
+ this.getDevicePairing().stopDeviceSelection()
153
+ .catch(err => { this.logError(err, 'closeDeviceSelection'); });
154
+ this.openedCapability = undefined;
155
+ this.deviceSelectState = undefined;
156
+ this.updatePage();
157
+ }
158
+ getDeviceListDisplayProps() {
159
+ if (!this.openedCapability)
160
+ return;
161
+ const capDevices = this.deviceSelectState?.devices ?? [];
162
+ const devices = capDevices.map(d => ({
163
+ connectState: d.connectState,
164
+ deviceName: d.name,
165
+ value: d.value,
166
+ interface: d.interface,
167
+ isSelected: d.selected,
168
+ onClick: (addAll) => { this.onDeviceSelected(d, addAll); },
169
+ onDelete: () => { this.onDeviceDelete(d); }
170
+ }));
171
+ const disabled = devices.length > 0 && !devices.some(d => d.isSelected);
172
+ const canSelectAll = this.openedCapability === incyclist_devices_1.IncyclistCapability.Control;
173
+ return {
174
+ capability: this.openedCapability,
175
+ devices,
176
+ isScanning: Boolean(this.deviceSelectState?.isScanning),
177
+ changeForAll: canSelectAll,
178
+ canSelectAll,
179
+ disabled,
180
+ onClose: () => { this.closeDeviceSelection(); },
181
+ };
182
+ }
183
+ getInterfaceDisplayProps(info) {
184
+ const { name, state, isScanning, enabled, protocol, port } = info;
185
+ return {
186
+ name, state, isScanning, enabled, protocol, port,
187
+ onClick: () => { this.openInterfaceSettings(name); }
188
+ };
189
+ }
190
+ openInterfaceSettings(name) {
191
+ this.logEvent({ message: 'interface clicked', interface: name, eventSource: 'user' });
192
+ this.interfaceSettingsFor = name;
193
+ this.updatePage();
194
+ }
195
+ closeInterfaceSettings() {
196
+ this.interfaceSettingsFor = undefined;
197
+ this.updatePage();
198
+ }
199
+ getInterfaceSettingsDisplayProps() {
200
+ const name = this.interfaceSettingsFor;
201
+ if (!name)
202
+ return undefined;
203
+ const current = (this.state.interfaces ?? []).find(i => i.name === name);
204
+ return {
205
+ name,
206
+ protocols: this.getDeviceAccess().getProtocols(name),
207
+ enabled: current?.enabled ?? false,
208
+ protocol: current?.protocol,
209
+ port: current?.port,
210
+ onOK: (settings) => { this.onInterfaceSettingsChanged(name, settings); },
211
+ onClose: () => { this.closeInterfaceSettings(); },
212
+ };
213
+ }
214
+ onInterfaceSettingsChanged(name, settings) {
215
+ this.logEvent({ message: 'interface settings changed', interface: name });
216
+ this.getDevicePairing().changeInterfaceSettings(name, settings)
217
+ .catch(err => { this.logError(err, 'onInterfaceSettingsChanged'); });
218
+ this.closeInterfaceSettings();
219
+ }
220
+ addSimulator() {
221
+ this.getDeviceConfiguration().add({ name: 'Simulator', interface: 'simulator' });
222
+ this.updatePage();
223
+ }
224
+ onOK() {
225
+ this.closeVisit('ok');
226
+ this.prepareForRide();
227
+ this.getDevicePairing().setReadyToStart();
228
+ this.getAppState().setState('paired', true);
229
+ const pathname = this.isPairingForRide ? '/rideOK' : `/${this.getPrevContentPage()}`;
230
+ this.moveTo(pathname, true, { source: this.source });
231
+ }
232
+ onSimulate() {
233
+ this.closeVisit('simulate');
234
+ const simulator = this.getDeviceConfiguration().getSimulatorAdapterId();
235
+ this.prepareForRide([simulator]);
236
+ const pathname = this.isPairingForRide ? '/rideSimulate' : `/${this.getPrevContentPage()}`;
237
+ this.moveTo(pathname, true, { source: this.source });
238
+ }
239
+ onSkip() {
240
+ const via = this.isPairingForRide ? 'cancel' : 'skip';
241
+ this.closeVisit(via);
242
+ this.getDevicePairing().stop()
243
+ .catch(err => { this.logError(err, 'onSkip'); });
244
+ const pathname = this.source ?? `/${this.getPrevContentPage()}`;
245
+ this.moveTo(pathname);
246
+ }
247
+ getDeviceAccess() {
248
+ return (0, access_1.useDeviceAccess)();
249
+ }
250
+ };
251
+ return DesktopPairingPageService = _classThis;
252
+ })();
253
+ exports.DesktopPairingPageService = DesktopPairingPageService;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,23 +1,18 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.initPairingVisitTracker = exports.usePairingVisitTracker = exports.PairingVisitTracker = void 0;
18
- __exportStar(require("./service"), exports);
19
- var visit_log_1 = require("./visit-log");
3
+ exports.getDevicesPageService = exports.initPairingVisitTracker = exports.usePairingVisitTracker = exports.PairingVisitTracker = void 0;
4
+ const api_1 = require("../../api");
5
+ const service_1 = require("./mobile/service");
6
+ const service_2 = require("./desktop/service");
7
+ var visit_log_1 = require("./base/visit-log");
20
8
  Object.defineProperty(exports, "PairingVisitTracker", { enumerable: true, get: function () { return visit_log_1.PairingVisitTracker; } });
21
- var visit_log_factory_1 = require("./visit-log-factory");
9
+ var visit_log_factory_1 = require("./base/visit-log-factory");
22
10
  Object.defineProperty(exports, "usePairingVisitTracker", { enumerable: true, get: function () { return visit_log_factory_1.usePairingVisitTracker; } });
23
11
  Object.defineProperty(exports, "initPairingVisitTracker", { enumerable: true, get: function () { return visit_log_factory_1.initPairingVisitTracker; } });
12
+ const getDevicesPageService = () => {
13
+ const channel = (0, api_1.getBindings)().appInfo.getChannel();
14
+ if (channel === 'desktop' || channel === 'web')
15
+ return new service_2.DesktopPairingPageService();
16
+ return new service_1.MobilePairingPageService();
17
+ };
18
+ exports.getDevicesPageService = getDevicesPageService;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStateMachineOrchestrator = void 0;
4
+ const statemachine_1 = require("./statemachine");
5
+ const createStateMachineOrchestrator = () => new statemachine_1.PairingPageStateMachine();
6
+ exports.createStateMachineOrchestrator = createStateMachineOrchestrator;
@@ -0,0 +1,197 @@
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.DevicesPageService = exports.MobilePairingPageService = void 0;
38
+ const incyclist_devices_1 = require("incyclist-devices");
39
+ const decorators_1 = require("../../../base/decorators");
40
+ const service_1 = require("../base/service");
41
+ const orchestrator_1 = require("./orchestrator");
42
+ const types_1 = require("../../../base/types");
43
+ const access_1 = require("../../access");
44
+ const pairing_1 = require("../../pairing");
45
+ const ui_1 = require("../../../ui");
46
+ let MobilePairingPageService = (() => {
47
+ let _classDecorators = [decorators_1.Singleton];
48
+ let _classDescriptor;
49
+ let _classExtraInitializers = [];
50
+ let _classThis;
51
+ let _classSuper = service_1.PairingPageService;
52
+ let _instanceExtraInitializers = [];
53
+ let _getIncyclist_decorators;
54
+ var MobilePairingPageService = class extends _classSuper {
55
+ static { _classThis = this; }
56
+ static {
57
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
58
+ _getIncyclist_decorators = [decorators_1.Injectable];
59
+ __esDecorate(this, null, _getIncyclist_decorators, { kind: "method", name: "getIncyclist", static: false, private: false, access: { has: obj => "getIncyclist" in obj, get: obj => obj.getIncyclist }, metadata: _metadata }, null, _instanceExtraInitializers);
60
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
+ MobilePairingPageService = _classThis = _classDescriptor.value;
62
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
+ __runInitializers(_classThis, _classExtraInitializers);
64
+ }
65
+ openedInterfaceSettings = __runInitializers(this, _instanceExtraInitializers);
66
+ interfaceSettingsObserver;
67
+ createOrchestrator() {
68
+ return (0, orchestrator_1.createStateMachineOrchestrator)();
69
+ }
70
+ getUsageMode() {
71
+ return 'page';
72
+ }
73
+ getPageDisplayProperties() {
74
+ const title = 'Devices';
75
+ const onExit = () => {
76
+ try {
77
+ const ui = this.getBindings().ui;
78
+ this.getIncyclist().onAppExit()
79
+ .then(() => {
80
+ ui.quit();
81
+ })
82
+ .catch(() => { });
83
+ }
84
+ catch (err) {
85
+ this.logError(err, 'onExit');
86
+ }
87
+ };
88
+ try {
89
+ const caps = this.state.capabilities ?? [];
90
+ const ifs = this.state.interfaces ?? [];
91
+ (0, access_1.useDeviceAccess)().enrichWithAccessState(ifs);
92
+ const interfaces = ifs.map(i => { return this.getInterfaceDisplayProps(i); });
93
+ const loading = this.promiseOpen != undefined;
94
+ const status = (0, pairing_1.getPairingStatusDisplay)({
95
+ platform: 'mobile',
96
+ interfaces: (0, pairing_1.toPairingInterfaceStates)(ifs),
97
+ capabilities: caps,
98
+ canStartRide: this.canStartRide(),
99
+ loading,
100
+ rideMode: this.isPairingForRide,
101
+ });
102
+ const capProps = caps.map(c => this.getCapabilityDisplayProps(c, status.id === 'S1'));
103
+ const CP = (cap) => capProps.find(c => c.capability === cap);
104
+ const top = [
105
+ CP('control'),
106
+ CP('power'),
107
+ CP('speed')
108
+ ].filter(c => c !== null && c !== undefined);
109
+ const bottom = [
110
+ CP('heartrate'),
111
+ CP('cadence'),
112
+ CP('app_control')
113
+ ].filter(c => c !== null && c !== undefined);
114
+ const trainerSelected = Boolean(caps.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control)?.selected);
115
+ const rowLabels = {
116
+ top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected)),
117
+ bottom: (0, pairing_1.getPairingGuidanceText)('row-optional'),
118
+ };
119
+ const buttons = this.getButtonsDisplayProps();
120
+ return {
121
+ title,
122
+ readyToStart: this.canStartRide(),
123
+ status,
124
+ capabilities: { top, bottom, rowLabels },
125
+ interfaces,
126
+ deviceSelection: this.getDeviceListDisplayProps(),
127
+ showInterfaceSettings: this.openedInterfaceSettings,
128
+ buttons,
129
+ onExit
130
+ };
131
+ }
132
+ catch (err) {
133
+ this.logError(err, 'getPageDisplayProperties');
134
+ return {
135
+ title,
136
+ capabilities: { top: [], bottom: [] },
137
+ interfaces: [],
138
+ buttons: [{ label: 'Skip', primary: true, onClick: this.onSkip.bind(this) }],
139
+ showInterfaceSettings: this.openedInterfaceSettings,
140
+ onExit
141
+ };
142
+ }
143
+ }
144
+ getInterfaceSettingsObserver() {
145
+ this.interfaceSettingsObserver = this.interfaceSettingsObserver ?? new types_1.Observer();
146
+ return this.interfaceSettingsObserver;
147
+ }
148
+ getInterfaceSettingsDisplayProps() {
149
+ if (!this.openedInterfaceSettings)
150
+ return;
151
+ const ifs = this.state.interfaces ?? [];
152
+ const info = ifs.find(isd => isd.name == this.openedInterfaceSettings);
153
+ return {
154
+ state: this.mapInterfaceState(info.state),
155
+ enabled: info.enabled,
156
+ };
157
+ }
158
+ enableInterface(i) { }
159
+ disableInterface(i) { }
160
+ reconnectInterface(i) { }
161
+ refreshInterface(i) { }
162
+ closeInterfaceSettings() {
163
+ this.openedInterfaceSettings = undefined;
164
+ this.interfaceSettingsObserver?.stop();
165
+ this.updatePage();
166
+ }
167
+ mapInterfaceState(state) {
168
+ const mapping = {
169
+ connected: 'scanning',
170
+ connecting: "idle",
171
+ disconnected: "error",
172
+ disconnecting: 'idle',
173
+ unavailable: 'error',
174
+ unknown: 'idle'
175
+ };
176
+ return mapping[state];
177
+ }
178
+ getInterfaceDisplayProps(info) {
179
+ const { name, state } = info;
180
+ return {
181
+ name,
182
+ state: this.mapInterfaceState(state),
183
+ onClick: () => { this.openInterfaceSettings(name); }
184
+ };
185
+ }
186
+ openInterfaceSettings(i) {
187
+ this.openedInterfaceSettings = i;
188
+ this.updatePage();
189
+ }
190
+ getIncyclist() {
191
+ return (0, ui_1.useIncyclist)();
192
+ }
193
+ };
194
+ return MobilePairingPageService = _classThis;
195
+ })();
196
+ exports.MobilePairingPageService = MobilePairingPageService;
197
+ exports.DevicesPageService = MobilePairingPageService;