incyclist-services 1.8.9 → 1.9.0

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 (42) hide show
  1. package/lib/esm/devices/page/__tests__/desktop-matrix.js +23 -0
  2. package/lib/esm/devices/page/base/logobserver.js +15 -0
  3. package/lib/esm/devices/page/base/orchestrator.js +1 -0
  4. package/lib/esm/devices/page/base/service.js +380 -0
  5. package/lib/esm/devices/page/base/types.js +1 -0
  6. package/lib/esm/devices/page/base/visit-log-factory.js +33 -0
  7. package/lib/esm/devices/page/base/visit-log.js +138 -0
  8. package/lib/esm/devices/page/desktop/matrix.js +23 -0
  9. package/lib/esm/devices/page/desktop/orchestrator.js +17 -0
  10. package/lib/esm/devices/page/desktop/service.js +250 -0
  11. package/lib/esm/devices/page/desktop/types.js +1 -0
  12. package/lib/esm/devices/page/desktop-service.js +204 -0
  13. package/lib/esm/devices/page/index.js +11 -3
  14. package/lib/esm/devices/page/mobile/orchestrator.js +2 -0
  15. package/lib/esm/devices/page/mobile/service.js +194 -0
  16. package/lib/esm/devices/page/mobile/statemachine.js +345 -0
  17. package/lib/esm/devices/page/orchestrator.js +19 -0
  18. package/lib/esm/devices/page/pairing-page-service.js +385 -0
  19. package/lib/esm/devices/pairing/service.js +54 -1
  20. package/lib/esm/ui/service.js +4 -1
  21. package/lib/types/activities/ride/service.d.ts +1 -1
  22. package/lib/types/devices/page/__tests__/desktop-matrix.d.ts +8 -0
  23. package/lib/types/devices/page/base/logobserver.d.ts +8 -0
  24. package/lib/types/devices/page/base/orchestrator.d.ts +11 -0
  25. package/lib/types/devices/page/base/service.d.ts +54 -0
  26. package/lib/types/devices/page/base/types.d.ts +130 -0
  27. package/lib/types/devices/page/base/visit-log-factory.d.ts +13 -0
  28. package/lib/types/devices/page/base/visit-log.d.ts +25 -0
  29. package/lib/types/devices/page/desktop/matrix.d.ts +8 -0
  30. package/lib/types/devices/page/desktop/orchestrator.d.ts +2 -0
  31. package/lib/types/devices/page/desktop/service.d.ts +32 -0
  32. package/lib/types/devices/page/desktop/types.d.ts +25 -0
  33. package/lib/types/devices/page/desktop-service.d.ts +28 -0
  34. package/lib/types/devices/page/index.d.ts +3 -3
  35. package/lib/types/devices/page/mobile/orchestrator.d.ts +2 -0
  36. package/lib/types/devices/page/mobile/service.d.ts +24 -0
  37. package/lib/types/devices/page/mobile/statemachine.d.ts +49 -0
  38. package/lib/types/devices/page/orchestrator.d.ts +13 -0
  39. package/lib/types/devices/page/pairing-page-service.d.ts +53 -0
  40. package/lib/types/devices/pairing/service.d.ts +8 -0
  41. package/lib/types/ride/display/service.d.ts +2 -2
  42. package/package.json +1 -1
@@ -0,0 +1,250 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import { IncyclistCapability } from 'incyclist-devices';
36
+ import { Injectable, Singleton } from '../../../base/decorators';
37
+ import { PairingPageService } from '../base/service';
38
+ import { createDirectOrchestrator } from './orchestrator';
39
+ import { useDeviceAccess } from '../../access';
40
+ import { getPairingGuidanceText, getPairingRowLabelId, getPairingStatusDisplay, toPairingInterfaceStates } from '../../pairing';
41
+ let DesktopPairingPageService = (() => {
42
+ let _classDecorators = [Singleton];
43
+ let _classDescriptor;
44
+ let _classExtraInitializers = [];
45
+ let _classThis;
46
+ let _classSuper = PairingPageService;
47
+ let _instanceExtraInitializers = [];
48
+ let _getDeviceAccess_decorators;
49
+ var DesktopPairingPageService = class extends _classSuper {
50
+ static { _classThis = this; }
51
+ static {
52
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
53
+ _getDeviceAccess_decorators = [Injectable];
54
+ __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);
55
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
+ DesktopPairingPageService = _classThis = _classDescriptor.value;
57
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
+ __runInitializers(_classThis, _classExtraInitializers);
59
+ }
60
+ source = __runInitializers(this, _instanceExtraInitializers);
61
+ deviceSelectState;
62
+ interfaceSettingsFor;
63
+ createOrchestrator() {
64
+ return createDirectOrchestrator();
65
+ }
66
+ getUsageMode() {
67
+ return 'direct';
68
+ }
69
+ openPage(forRide, source) {
70
+ this.source = source;
71
+ return super.openPage(forRide);
72
+ }
73
+ getPageDisplayProperties() {
74
+ const title = 'Devices';
75
+ try {
76
+ const caps = this.state.capabilities ?? [];
77
+ const allIfs = this.state.interfaces ?? [];
78
+ const ifs = allIfs.filter(i => !i.invisible);
79
+ this.getDeviceAccess().enrichWithAccessState(ifs);
80
+ const interfaces = ifs.map(i => this.getInterfaceDisplayProps(i));
81
+ const status = getPairingStatusDisplay({
82
+ platform: 'desktop',
83
+ interfaces: toPairingInterfaceStates(allIfs),
84
+ capabilities: caps,
85
+ canStartRide: this.canStartRide(),
86
+ loading: this.promiseOpen !== undefined,
87
+ rideMode: this.isPairingForRide,
88
+ });
89
+ const capProps = caps.map(c => this.getCapabilityDisplayProps(c, status.id === 'S1'));
90
+ const CP = (cap) => capProps.find(c => c.capability === cap);
91
+ const top = [
92
+ CP(IncyclistCapability.Control),
93
+ CP(IncyclistCapability.Power),
94
+ CP(IncyclistCapability.Speed)
95
+ ].filter(c => c !== null && c !== undefined);
96
+ const bottom = [
97
+ CP(IncyclistCapability.HeartRate),
98
+ CP(IncyclistCapability.Cadence),
99
+ CP(IncyclistCapability.AppControl)
100
+ ].filter(c => c !== null && c !== undefined);
101
+ const trainerSelected = Boolean(caps.find(c => c.capability === IncyclistCapability.Control)?.selected);
102
+ const rowLabels = {
103
+ top: getPairingGuidanceText(getPairingRowLabelId(trainerSelected)),
104
+ bottom: getPairingGuidanceText('row-optional'),
105
+ };
106
+ const buttons = this.getButtonsDisplayProps();
107
+ return {
108
+ title,
109
+ readyToStart: this.canStartRide(),
110
+ status,
111
+ capabilities: { top, bottom, rowLabels },
112
+ interfaces,
113
+ deviceSelection: this.getDeviceListDisplayProps(),
114
+ buttons,
115
+ showInterfaceSettings: this.getInterfaceSettingsDisplayProps(),
116
+ };
117
+ }
118
+ catch (err) {
119
+ this.logError(err, 'getPageDisplayProperties');
120
+ return {
121
+ title,
122
+ capabilities: { top: [], bottom: [] },
123
+ interfaces: [],
124
+ buttons: [{ label: 'Skip', primary: true, onClick: this.onSkip.bind(this) }],
125
+ showInterfaceSettings: undefined,
126
+ };
127
+ }
128
+ }
129
+ openDeviceSelection(cap) {
130
+ this.logEvent({ message: 'capability clicked', capability: cap, eventSource: 'user' });
131
+ this.openedCapability = cap;
132
+ this.deviceSelectState = this.getDevicePairing().startDeviceSelection(cap, (newState) => {
133
+ this.deviceSelectState = newState;
134
+ this.updatePage();
135
+ });
136
+ this.updatePage();
137
+ }
138
+ onDeviceSelected(d, addAll) {
139
+ const capability = this.openedCapability;
140
+ this.logEvent({ message: 'device selected', capability, device: d.name });
141
+ const changeForAll = addAll ?? (capability === IncyclistCapability.Control);
142
+ this.closeDeviceSelection();
143
+ this.getDevicePairing().selectDevice(capability, d.udid, changeForAll)
144
+ .catch(err => { this.logError(err, 'onDeviceSelected'); });
145
+ this.updatePage();
146
+ }
147
+ closeDeviceSelection() {
148
+ this.logEvent({ message: 'capability closed', capability: this.openedCapability });
149
+ this.getDevicePairing().stopDeviceSelection()
150
+ .catch(err => { this.logError(err, 'closeDeviceSelection'); });
151
+ this.openedCapability = undefined;
152
+ this.deviceSelectState = undefined;
153
+ this.updatePage();
154
+ }
155
+ getDeviceListDisplayProps() {
156
+ if (!this.openedCapability)
157
+ return;
158
+ const capDevices = this.deviceSelectState?.devices ?? [];
159
+ const devices = capDevices.map(d => ({
160
+ connectState: d.connectState,
161
+ deviceName: d.name,
162
+ value: d.value,
163
+ interface: d.interface,
164
+ isSelected: d.selected,
165
+ onClick: (addAll) => { this.onDeviceSelected(d, addAll); },
166
+ onDelete: () => { this.onDeviceDelete(d); }
167
+ }));
168
+ const disabled = devices.length > 0 && !devices.some(d => d.isSelected);
169
+ const canSelectAll = this.openedCapability === IncyclistCapability.Control;
170
+ return {
171
+ capability: this.openedCapability,
172
+ devices,
173
+ isScanning: Boolean(this.deviceSelectState?.isScanning),
174
+ changeForAll: canSelectAll,
175
+ canSelectAll,
176
+ disabled,
177
+ onClose: () => { this.closeDeviceSelection(); },
178
+ };
179
+ }
180
+ getInterfaceDisplayProps(info) {
181
+ const { name, state, isScanning, enabled, protocol, port } = info;
182
+ return {
183
+ name, state, isScanning, enabled, protocol, port,
184
+ onClick: () => { this.openInterfaceSettings(name); }
185
+ };
186
+ }
187
+ openInterfaceSettings(name) {
188
+ this.logEvent({ message: 'interface clicked', interface: name, eventSource: 'user' });
189
+ this.interfaceSettingsFor = name;
190
+ this.updatePage();
191
+ }
192
+ closeInterfaceSettings() {
193
+ this.interfaceSettingsFor = undefined;
194
+ this.updatePage();
195
+ }
196
+ getInterfaceSettingsDisplayProps() {
197
+ const name = this.interfaceSettingsFor;
198
+ if (!name)
199
+ return undefined;
200
+ const current = (this.state.interfaces ?? []).find(i => i.name === name);
201
+ return {
202
+ name,
203
+ protocols: this.getDeviceAccess().getProtocols(name),
204
+ enabled: current?.enabled ?? false,
205
+ protocol: current?.protocol,
206
+ port: current?.port,
207
+ onOK: (settings) => { this.onInterfaceSettingsChanged(name, settings); },
208
+ onClose: () => { this.closeInterfaceSettings(); },
209
+ };
210
+ }
211
+ onInterfaceSettingsChanged(name, settings) {
212
+ this.logEvent({ message: 'interface settings changed', interface: name });
213
+ this.getDevicePairing().changeInterfaceSettings(name, settings)
214
+ .catch(err => { this.logError(err, 'onInterfaceSettingsChanged'); });
215
+ this.closeInterfaceSettings();
216
+ }
217
+ addSimulator() {
218
+ this.getDeviceConfiguration().add({ name: 'Simulator', interface: 'simulator' });
219
+ this.updatePage();
220
+ }
221
+ onOK() {
222
+ this.closeVisit('ok');
223
+ this.prepareForRide();
224
+ this.getDevicePairing().setReadyToStart();
225
+ this.getAppState().setState('paired', true);
226
+ const pathname = this.isPairingForRide ? '/rideOK' : `/${this.getPrevContentPage()}`;
227
+ this.moveTo(pathname, true, { source: this.source });
228
+ }
229
+ onSimulate() {
230
+ this.closeVisit('simulate');
231
+ const simulator = this.getDeviceConfiguration().getSimulatorAdapterId();
232
+ this.prepareForRide([simulator]);
233
+ const pathname = this.isPairingForRide ? '/rideSimulate' : `/${this.getPrevContentPage()}`;
234
+ this.moveTo(pathname, true, { source: this.source });
235
+ }
236
+ onSkip() {
237
+ const via = this.isPairingForRide ? 'cancel' : 'skip';
238
+ this.closeVisit(via);
239
+ this.getDevicePairing().stop()
240
+ .catch(err => { this.logError(err, 'onSkip'); });
241
+ const pathname = this.source ?? `/${this.getPrevContentPage()}`;
242
+ this.moveTo(pathname);
243
+ }
244
+ getDeviceAccess() {
245
+ return useDeviceAccess();
246
+ }
247
+ };
248
+ return DesktopPairingPageService = _classThis;
249
+ })();
250
+ export { DesktopPairingPageService };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,204 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import './service';
36
+ import { Injectable, Singleton } from '../../base/decorators';
37
+ import { useDeviceAccess } from '../access';
38
+ import { IncyclistCapability } from 'incyclist-devices';
39
+ import { PairingPageService } from './pairing-page-service';
40
+ import { createDirectOrchestrator } from './orchestrator';
41
+ let DesktopPairingPageService = (() => {
42
+ let _classDecorators = [Singleton];
43
+ let _classDescriptor;
44
+ let _classExtraInitializers = [];
45
+ let _classThis;
46
+ let _classSuper = PairingPageService;
47
+ let _instanceExtraInitializers = [];
48
+ let _getDeviceAccess_decorators;
49
+ var DesktopPairingPageService = class extends _classSuper {
50
+ static { _classThis = this; }
51
+ static {
52
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
53
+ _getDeviceAccess_decorators = [Injectable];
54
+ __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);
55
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
+ DesktopPairingPageService = _classThis = _classDescriptor.value;
57
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
+ __runInitializers(_classThis, _classExtraInitializers);
59
+ }
60
+ source = __runInitializers(this, _instanceExtraInitializers);
61
+ showSimulateCache = false;
62
+ deviceSelectState;
63
+ createOrchestrator() {
64
+ return createDirectOrchestrator();
65
+ }
66
+ getUsageMode() {
67
+ return 'direct';
68
+ }
69
+ openPage(forRide, source) {
70
+ this.source = source;
71
+ this.showSimulateCache = forRide ? this.getDeviceRide().canEnforceSimulator() : false;
72
+ return super.openPage(forRide);
73
+ }
74
+ getPageDisplayProperties() {
75
+ const title = this.isPairingForRide ? 'Paired Devices for Ride' : 'Paired Devices';
76
+ const labelOK = this.isPairingForRide ? 'Start' : 'OK';
77
+ const labelSkip = this.isPairingForRide ? 'Cancel' : 'Skip';
78
+ try {
79
+ const caps = this.state.capabilities ?? [];
80
+ const ifs = this.state.interfaces ?? [];
81
+ this.getDeviceAccess().enrichWithAccessState(ifs);
82
+ const interfaces = ifs.map(i => this.getInterfaceDisplayProps(i));
83
+ const capProps = caps.map(c => this.getCapabilityDisplayProps(c, false));
84
+ const CP = (cap) => capProps.find(c => c.capability === cap);
85
+ const top = [
86
+ CP(IncyclistCapability.Control),
87
+ CP(IncyclistCapability.Power),
88
+ CP(IncyclistCapability.Speed)
89
+ ].filter(c => c !== null && c !== undefined);
90
+ const bottom = [
91
+ CP(IncyclistCapability.HeartRate),
92
+ CP(IncyclistCapability.Cadence),
93
+ CP(IncyclistCapability.AppControl)
94
+ ].filter(c => c !== null && c !== undefined);
95
+ const buttons = this.getButtonsDisplayProps();
96
+ return {
97
+ title, labelOK, labelSkip,
98
+ readyToStart: this.canStartRide(),
99
+ showSimulate: this.isPairingForRide && this.showSimulateCache,
100
+ capabilities: { top, bottom },
101
+ interfaces,
102
+ deviceSelection: this.getDeviceListDisplayProps(),
103
+ buttons,
104
+ showInterfaceSettings: undefined,
105
+ };
106
+ }
107
+ catch (err) {
108
+ this.logError(err, 'getPageDisplayProperties');
109
+ return {
110
+ title, labelOK, labelSkip,
111
+ capabilities: { top: [], bottom: [] },
112
+ interfaces: [],
113
+ buttons: [{ label: labelSkip, primary: true, onClick: this.onSkip.bind(this) }],
114
+ showInterfaceSettings: undefined,
115
+ };
116
+ }
117
+ }
118
+ openDeviceSelection(cap) {
119
+ this.logEvent({ message: 'capability clicked', capability: cap, eventSource: 'user' });
120
+ this.openedCapability = cap;
121
+ this.deviceSelectState = this.getDevicePairing().startDeviceSelection(cap, (newState) => {
122
+ this.deviceSelectState = newState;
123
+ this.updatePage();
124
+ });
125
+ this.updatePage();
126
+ }
127
+ onDeviceSelected(d, addAll) {
128
+ const capability = this.openedCapability;
129
+ this.logEvent({ message: 'device selected', capability, device: d.name });
130
+ const changeForAll = addAll ?? (capability === IncyclistCapability.Control);
131
+ this.closeDeviceSelection();
132
+ this.getDevicePairing().selectDevice(capability, d.udid, changeForAll);
133
+ this.updatePage();
134
+ }
135
+ closeDeviceSelection() {
136
+ this.logEvent({ message: 'capability closed', capability: this.openedCapability });
137
+ this.getDevicePairing().stopDeviceSelection();
138
+ this.openedCapability = undefined;
139
+ this.deviceSelectState = undefined;
140
+ this.updatePage();
141
+ }
142
+ getDeviceListDisplayProps() {
143
+ if (!this.openedCapability)
144
+ return;
145
+ const capDevices = this.deviceSelectState?.devices ?? [];
146
+ const devices = capDevices.map(d => ({
147
+ connectState: d.connectState,
148
+ deviceName: d.name,
149
+ value: d.value,
150
+ interface: d.interface,
151
+ isSelected: d.selected,
152
+ onClick: (addAll) => { this.onDeviceSelected(d, addAll); },
153
+ onDelete: () => { this.onDeviceDelete(d); }
154
+ }));
155
+ const disabled = devices.length > 0 && !devices.some(d => d.isSelected);
156
+ const canSelectAll = this.openedCapability === IncyclistCapability.Control;
157
+ return {
158
+ capability: this.openedCapability,
159
+ devices,
160
+ isScanning: Boolean(this.deviceSelectState?.isScanning),
161
+ changeForAll: canSelectAll,
162
+ canSelectAll,
163
+ disabled,
164
+ onClose: () => { this.closeDeviceSelection(); },
165
+ };
166
+ }
167
+ getInterfaceDisplayProps(info) {
168
+ const { name, state, isScanning, enabled, protocol, port } = info;
169
+ return {
170
+ name, state, isScanning, enabled, protocol, port,
171
+ onClick: () => { this.logEvent({ message: 'interface clicked', interface: name, eventSource: 'user' }); }
172
+ };
173
+ }
174
+ onInterfaceSettingsChanged(name, settings) {
175
+ this.logEvent({ message: 'interface settings changed', interface: name });
176
+ this.getDevicePairing().changeInterfaceSettings(name, settings);
177
+ this.updatePage();
178
+ }
179
+ addSimulator() {
180
+ this.getDeviceConfiguration().add({ name: 'Simulator', interface: 'simulator' });
181
+ this.updatePage();
182
+ }
183
+ onOK() {
184
+ this.closeVisit('ok');
185
+ this.getDevicePairing().prepareStart();
186
+ this.getDevicePairing().setReadyToStart();
187
+ this.getAppState().setState('paired', true);
188
+ const pathname = this.isPairingForRide ? '/rideOK' : `/${this.getPrevContentPage()}`;
189
+ this.moveTo(pathname);
190
+ }
191
+ onSkip() {
192
+ const via = this.isPairingForRide ? 'cancel' : 'skip';
193
+ this.closeVisit(via);
194
+ this.getDevicePairing().stop();
195
+ const pathname = this.source ?? `/${this.getPrevContentPage()}`;
196
+ this.moveTo(pathname);
197
+ }
198
+ getDeviceAccess() {
199
+ return useDeviceAccess();
200
+ }
201
+ };
202
+ return DesktopPairingPageService = _classThis;
203
+ })();
204
+ export { DesktopPairingPageService };
@@ -1,3 +1,11 @@
1
- export * from './service';
2
- export { PairingVisitTracker } from './visit-log';
3
- export { usePairingVisitTracker, initPairingVisitTracker } from './visit-log-factory';
1
+ import { getBindings } from '../../api';
2
+ import { MobilePairingPageService } from './mobile/service';
3
+ import { DesktopPairingPageService } from './desktop/service';
4
+ export { PairingVisitTracker } from './base/visit-log';
5
+ export { usePairingVisitTracker, initPairingVisitTracker } from './base/visit-log-factory';
6
+ export const getDevicesPageService = () => {
7
+ const channel = getBindings().appInfo.getChannel();
8
+ if (channel === 'desktop' || channel === 'web')
9
+ return new DesktopPairingPageService();
10
+ return new MobilePairingPageService();
11
+ };
@@ -0,0 +1,2 @@
1
+ import { PairingPageStateMachine } from './statemachine';
2
+ export const createStateMachineOrchestrator = () => new PairingPageStateMachine();
@@ -0,0 +1,194 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import { IncyclistCapability } from 'incyclist-devices';
36
+ import { Injectable, Singleton } from '../../../base/decorators';
37
+ import { PairingPageService } from '../base/service';
38
+ import { createStateMachineOrchestrator } from './orchestrator';
39
+ import { Observer } from '../../../base/types';
40
+ import { useDeviceAccess } from '../../access';
41
+ import { getPairingGuidanceText, getPairingRowLabelId, getPairingStatusDisplay, toPairingInterfaceStates } from '../../pairing';
42
+ import { useIncyclist } from '../../../ui';
43
+ let MobilePairingPageService = (() => {
44
+ let _classDecorators = [Singleton];
45
+ let _classDescriptor;
46
+ let _classExtraInitializers = [];
47
+ let _classThis;
48
+ let _classSuper = PairingPageService;
49
+ let _instanceExtraInitializers = [];
50
+ let _getIncyclist_decorators;
51
+ var MobilePairingPageService = class extends _classSuper {
52
+ static { _classThis = this; }
53
+ static {
54
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
55
+ _getIncyclist_decorators = [Injectable];
56
+ __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);
57
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
58
+ MobilePairingPageService = _classThis = _classDescriptor.value;
59
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
60
+ __runInitializers(_classThis, _classExtraInitializers);
61
+ }
62
+ openedInterfaceSettings = __runInitializers(this, _instanceExtraInitializers);
63
+ interfaceSettingsObserver;
64
+ createOrchestrator() {
65
+ return createStateMachineOrchestrator();
66
+ }
67
+ getUsageMode() {
68
+ return 'page';
69
+ }
70
+ getPageDisplayProperties() {
71
+ const title = 'Devices';
72
+ const onExit = () => {
73
+ try {
74
+ const ui = this.getBindings().ui;
75
+ this.getIncyclist().onAppExit()
76
+ .then(() => {
77
+ ui.quit();
78
+ })
79
+ .catch(() => { });
80
+ }
81
+ catch (err) {
82
+ this.logError(err, 'onExit');
83
+ }
84
+ };
85
+ try {
86
+ const caps = this.state.capabilities ?? [];
87
+ const ifs = this.state.interfaces ?? [];
88
+ useDeviceAccess().enrichWithAccessState(ifs);
89
+ const interfaces = ifs.map(i => { return this.getInterfaceDisplayProps(i); });
90
+ const loading = this.promiseOpen != undefined;
91
+ const status = getPairingStatusDisplay({
92
+ platform: 'mobile',
93
+ interfaces: toPairingInterfaceStates(ifs),
94
+ capabilities: caps,
95
+ canStartRide: this.canStartRide(),
96
+ loading,
97
+ rideMode: this.isPairingForRide,
98
+ });
99
+ const capProps = caps.map(c => this.getCapabilityDisplayProps(c, status.id === 'S1'));
100
+ const CP = (cap) => capProps.find(c => c.capability === cap);
101
+ const top = [
102
+ CP('control'),
103
+ CP('power'),
104
+ CP('speed')
105
+ ].filter(c => c !== null && c !== undefined);
106
+ const bottom = [
107
+ CP('heartrate'),
108
+ CP('cadence'),
109
+ CP('app_control')
110
+ ].filter(c => c !== null && c !== undefined);
111
+ const trainerSelected = Boolean(caps.find(c => c.capability === IncyclistCapability.Control)?.selected);
112
+ const rowLabels = {
113
+ top: getPairingGuidanceText(getPairingRowLabelId(trainerSelected)),
114
+ bottom: getPairingGuidanceText('row-optional'),
115
+ };
116
+ const buttons = this.getButtonsDisplayProps();
117
+ return {
118
+ title,
119
+ readyToStart: this.canStartRide(),
120
+ status,
121
+ capabilities: { top, bottom, rowLabels },
122
+ interfaces,
123
+ deviceSelection: this.getDeviceListDisplayProps(),
124
+ showInterfaceSettings: this.openedInterfaceSettings,
125
+ buttons,
126
+ onExit
127
+ };
128
+ }
129
+ catch (err) {
130
+ this.logError(err, 'getPageDisplayProperties');
131
+ return {
132
+ title,
133
+ capabilities: { top: [], bottom: [] },
134
+ interfaces: [],
135
+ buttons: [{ label: 'Skip', primary: true, onClick: this.onSkip.bind(this) }],
136
+ showInterfaceSettings: this.openedInterfaceSettings,
137
+ onExit
138
+ };
139
+ }
140
+ }
141
+ getInterfaceSettingsObserver() {
142
+ this.interfaceSettingsObserver = this.interfaceSettingsObserver ?? new Observer();
143
+ return this.interfaceSettingsObserver;
144
+ }
145
+ getInterfaceSettingsDisplayProps() {
146
+ if (!this.openedInterfaceSettings)
147
+ return;
148
+ const ifs = this.state.interfaces ?? [];
149
+ const info = ifs.find(isd => isd.name == this.openedInterfaceSettings);
150
+ return {
151
+ state: this.mapInterfaceState(info.state),
152
+ enabled: info.enabled,
153
+ };
154
+ }
155
+ enableInterface(i) { }
156
+ disableInterface(i) { }
157
+ reconnectInterface(i) { }
158
+ refreshInterface(i) { }
159
+ closeInterfaceSettings() {
160
+ this.openedInterfaceSettings = undefined;
161
+ this.interfaceSettingsObserver?.stop();
162
+ this.updatePage();
163
+ }
164
+ mapInterfaceState(state) {
165
+ const mapping = {
166
+ connected: 'scanning',
167
+ connecting: "idle",
168
+ disconnected: "error",
169
+ disconnecting: 'idle',
170
+ unavailable: 'error',
171
+ unknown: 'idle'
172
+ };
173
+ return mapping[state];
174
+ }
175
+ getInterfaceDisplayProps(info) {
176
+ const { name, state } = info;
177
+ return {
178
+ name,
179
+ state: this.mapInterfaceState(state),
180
+ onClick: () => { this.openInterfaceSettings(name); }
181
+ };
182
+ }
183
+ openInterfaceSettings(i) {
184
+ this.openedInterfaceSettings = i;
185
+ this.updatePage();
186
+ }
187
+ getIncyclist() {
188
+ return useIncyclist();
189
+ }
190
+ };
191
+ return MobilePairingPageService = _classThis;
192
+ })();
193
+ export { MobilePairingPageService };
194
+ export { MobilePairingPageService as DevicesPageService };