incyclist-services 1.8.8 → 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.
- package/lib/cjs/devices/page/index.js +6 -0
- package/lib/cjs/devices/page/service.js +69 -5
- package/lib/cjs/devices/page/visit-log-factory.js +41 -0
- package/lib/cjs/devices/page/visit-log.js +143 -0
- package/lib/cjs/devices/page/visit-tracker-factory.js +41 -0
- package/lib/cjs/devices/page/visit-tracker.js +142 -0
- package/lib/cjs/devices/pairing/guidance.js +152 -0
- package/lib/cjs/devices/pairing/index.js +2 -0
- package/lib/cjs/devices/pairing/status.js +54 -0
- package/lib/cjs/ride/display/service.js +15 -0
- package/lib/cjs/ui/service.js +39 -0
- package/lib/esm/devices/page/__tests__/desktop-matrix.js +23 -0
- package/lib/esm/devices/page/base/logobserver.js +15 -0
- package/lib/esm/devices/page/base/orchestrator.js +1 -0
- package/lib/esm/devices/page/base/service.js +380 -0
- package/lib/esm/devices/page/base/types.js +1 -0
- package/lib/esm/devices/page/base/visit-log-factory.js +33 -0
- package/lib/esm/devices/page/base/visit-log.js +138 -0
- package/lib/esm/devices/page/desktop/matrix.js +23 -0
- package/lib/esm/devices/page/desktop/orchestrator.js +17 -0
- package/lib/esm/devices/page/desktop/service.js +250 -0
- package/lib/esm/devices/page/desktop/types.js +1 -0
- package/lib/esm/devices/page/desktop-service.js +204 -0
- package/lib/esm/devices/page/index.js +11 -1
- package/lib/esm/devices/page/mobile/orchestrator.js +2 -0
- package/lib/esm/devices/page/mobile/service.js +194 -0
- package/lib/esm/devices/page/mobile/statemachine.js +345 -0
- package/lib/esm/devices/page/orchestrator.js +19 -0
- package/lib/esm/devices/page/pairing-page-service.js +385 -0
- package/lib/esm/devices/page/service.js +70 -6
- package/lib/esm/devices/page/visit-log-factory.js +33 -0
- package/lib/esm/devices/page/visit-log.js +138 -0
- package/lib/esm/devices/page/visit-tracker-factory.js +33 -0
- package/lib/esm/devices/page/visit-tracker.js +137 -0
- package/lib/esm/devices/pairing/guidance.js +141 -0
- package/lib/esm/devices/pairing/index.js +2 -0
- package/lib/esm/devices/pairing/service.js +54 -1
- package/lib/esm/devices/pairing/status.js +49 -0
- package/lib/esm/ride/display/service.js +16 -1
- package/lib/esm/ui/service.js +43 -1
- package/lib/types/activities/ride/service.d.ts +1 -1
- package/lib/types/devices/page/__tests__/desktop-matrix.d.ts +8 -0
- package/lib/types/devices/page/base/logobserver.d.ts +8 -0
- package/lib/types/devices/page/base/orchestrator.d.ts +11 -0
- package/lib/types/devices/page/base/service.d.ts +54 -0
- package/lib/types/devices/page/base/types.d.ts +130 -0
- package/lib/types/devices/page/base/visit-log-factory.d.ts +13 -0
- package/lib/types/devices/page/base/visit-log.d.ts +25 -0
- package/lib/types/devices/page/desktop/matrix.d.ts +8 -0
- package/lib/types/devices/page/desktop/orchestrator.d.ts +2 -0
- package/lib/types/devices/page/desktop/service.d.ts +32 -0
- package/lib/types/devices/page/desktop/types.d.ts +25 -0
- package/lib/types/devices/page/desktop-service.d.ts +28 -0
- package/lib/types/devices/page/index.d.ts +3 -1
- package/lib/types/devices/page/mobile/orchestrator.d.ts +2 -0
- package/lib/types/devices/page/mobile/service.d.ts +24 -0
- package/lib/types/devices/page/mobile/statemachine.d.ts +49 -0
- package/lib/types/devices/page/orchestrator.d.ts +13 -0
- package/lib/types/devices/page/pairing-page-service.d.ts +53 -0
- package/lib/types/devices/page/service.d.ts +9 -1
- package/lib/types/devices/page/types.d.ts +55 -0
- package/lib/types/devices/page/visit-log-factory.d.ts +13 -0
- package/lib/types/devices/page/visit-log.d.ts +25 -0
- package/lib/types/devices/page/visit-tracker-factory.d.ts +13 -0
- package/lib/types/devices/page/visit-tracker.d.ts +25 -0
- package/lib/types/devices/pairing/guidance.d.ts +55 -0
- package/lib/types/devices/pairing/index.d.ts +2 -0
- package/lib/types/devices/pairing/service.d.ts +8 -0
- package/lib/types/devices/pairing/status.d.ts +29 -0
- package/lib/types/ride/display/service.d.ts +3 -1
- package/lib/types/ui/service.d.ts +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,380 @@
|
|
|
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 { EventLogger } from 'gd-eventlog';
|
|
36
|
+
import { Injectable } from '../../../base/decorators';
|
|
37
|
+
import { IncyclistPageService } from '../../../base/pages';
|
|
38
|
+
import { useDevicePairing, PAIRING_CAPABILITY_ROLES, getCapabilityHelpText, getEmptyTileFooterText } from '../../pairing';
|
|
39
|
+
import { PageLogObserver } from './logobserver';
|
|
40
|
+
import { useDeviceConfiguration } from '../../configuration';
|
|
41
|
+
import { usePairingVisitTracker } from './visit-log-factory';
|
|
42
|
+
let PairingPageService = (() => {
|
|
43
|
+
let _classSuper = IncyclistPageService;
|
|
44
|
+
let _instanceExtraInitializers = [];
|
|
45
|
+
let _getDevicePairing_decorators;
|
|
46
|
+
let _getDeviceConfiguration_decorators;
|
|
47
|
+
let _getPairingVisitTracker_decorators;
|
|
48
|
+
return class PairingPageService extends _classSuper {
|
|
49
|
+
static {
|
|
50
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
51
|
+
_getDevicePairing_decorators = [Injectable];
|
|
52
|
+
_getDeviceConfiguration_decorators = [Injectable];
|
|
53
|
+
_getPairingVisitTracker_decorators = [Injectable];
|
|
54
|
+
__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);
|
|
55
|
+
__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);
|
|
56
|
+
__esDecorate(this, null, _getPairingVisitTracker_decorators, { kind: "method", name: "getPairingVisitTracker", static: false, private: false, access: { has: obj => "getPairingVisitTracker" in obj, get: obj => obj.getPairingVisitTracker }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
57
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
58
|
+
}
|
|
59
|
+
promiseOpen = __runInitializers(this, _instanceExtraInitializers);
|
|
60
|
+
stateMachine;
|
|
61
|
+
logObserver;
|
|
62
|
+
openedCapability;
|
|
63
|
+
isPairingForRide = false;
|
|
64
|
+
isVisitOpen = false;
|
|
65
|
+
handingOffToRide = false;
|
|
66
|
+
constructor() {
|
|
67
|
+
super('pairing');
|
|
68
|
+
this.stateMachine = this.createOrchestrator();
|
|
69
|
+
this.logObserver = new PageLogObserver('Pairing');
|
|
70
|
+
}
|
|
71
|
+
openPage(forRide) {
|
|
72
|
+
try {
|
|
73
|
+
this.logEvent({ message: 'page shown', page: 'Pairing', forRide });
|
|
74
|
+
this.isPairingForRide = forRide ?? false;
|
|
75
|
+
this.handingOffToRide = false;
|
|
76
|
+
this.openVisit();
|
|
77
|
+
EventLogger.setGlobalConfig('page', 'Pairing');
|
|
78
|
+
super.openPage();
|
|
79
|
+
if (this.promiseOpen !== undefined) {
|
|
80
|
+
return this.getPageObserver();
|
|
81
|
+
}
|
|
82
|
+
const onStateMachineUpdate = () => {
|
|
83
|
+
this.getPageObserver().emit('page-update');
|
|
84
|
+
};
|
|
85
|
+
this.stateMachine.start(onStateMachineUpdate);
|
|
86
|
+
if (this.stateMachine.state !== 'Idle') {
|
|
87
|
+
this.logEvent({ message: 'state machine was not in expected state on open, resetting', page: 'Pairing', state: this.stateMachine.state });
|
|
88
|
+
void this.stateMachine.stop();
|
|
89
|
+
this.stateMachine.start(onStateMachineUpdate);
|
|
90
|
+
}
|
|
91
|
+
this.promiseOpen = new Promise((done) => {
|
|
92
|
+
this.start()
|
|
93
|
+
.catch((err) => { this.logError(err, 'openPage'); })
|
|
94
|
+
.finally(done);
|
|
95
|
+
})
|
|
96
|
+
.then(() => { delete this.promiseOpen; });
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
this.logError(err, 'openPage');
|
|
100
|
+
}
|
|
101
|
+
return this.getPageObserver();
|
|
102
|
+
}
|
|
103
|
+
closePage() {
|
|
104
|
+
try {
|
|
105
|
+
this.logEvent({ message: 'page closed', page: 'Pairing' });
|
|
106
|
+
this.isVisitOpen = false;
|
|
107
|
+
EventLogger.setGlobalConfig('page', null);
|
|
108
|
+
this.isPairingForRide = false;
|
|
109
|
+
super.closePage();
|
|
110
|
+
if (!this.handingOffToRide)
|
|
111
|
+
this.stop().catch(err => { this.logError(err, 'closePage'); });
|
|
112
|
+
this.handingOffToRide = false;
|
|
113
|
+
void this.stateMachine.stop();
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
this.logError(err, 'closePage');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async pausePage() {
|
|
120
|
+
try {
|
|
121
|
+
this.trackVisit(t => t.onBackground({ canStartRide: this.canStartRide() }), 'onBackground');
|
|
122
|
+
await this.stateMachine.pause();
|
|
123
|
+
this.logEvent({ message: 'page paused', page: 'Pairing' });
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
this.logError(err, 'pausePage');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async resumePage() {
|
|
130
|
+
try {
|
|
131
|
+
this.trackVisit(t => t.onForeground(), 'onForeground');
|
|
132
|
+
this.stateMachine.resume();
|
|
133
|
+
if (this.promiseOpen !== undefined)
|
|
134
|
+
return;
|
|
135
|
+
this.promiseOpen = new Promise((done) => {
|
|
136
|
+
this.start()
|
|
137
|
+
.catch((err) => { this.logError(err, 'openPage'); })
|
|
138
|
+
.finally(done);
|
|
139
|
+
});
|
|
140
|
+
await this.promiseOpen;
|
|
141
|
+
delete this.promiseOpen;
|
|
142
|
+
this.logEvent({ message: 'page resumed', page: 'Pairing' });
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
this.logError(err, 'pausePage');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
getCapabilityDisplayProps(data, noSearch = false) {
|
|
149
|
+
const { capability: cap, deviceName, connectState, value, unit, disabled } = data;
|
|
150
|
+
const capability = this.getTCapability(cap);
|
|
151
|
+
const title = this.getDisplayCapability(cap);
|
|
152
|
+
const onClick = () => { this.openDeviceSelection(cap); };
|
|
153
|
+
const role = PAIRING_CAPABILITY_ROLES.find(r => r.capability === cap)?.role;
|
|
154
|
+
const helpText = {
|
|
155
|
+
full: getCapabilityHelpText(capability, 'full') ?? '',
|
|
156
|
+
short: getCapabilityHelpText(capability, 'short') ?? '',
|
|
157
|
+
};
|
|
158
|
+
if (disabled) {
|
|
159
|
+
const hasRememberedDevice = Boolean(deviceName);
|
|
160
|
+
return {
|
|
161
|
+
title, capability,
|
|
162
|
+
deviceName: hasRememberedDevice ? deviceName : undefined,
|
|
163
|
+
disabled: true,
|
|
164
|
+
role, helpText,
|
|
165
|
+
emptyFooter: hasRememberedDevice ? 'Not used' : 'Not used · tap to search',
|
|
166
|
+
onClick,
|
|
167
|
+
onUse: hasRememberedDevice ? () => { this.onCapabilityUse(cap); } : undefined,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const adapaters = this.state.adapters ?? [];
|
|
171
|
+
const adapter = adapaters.find(ai => data.selected && ai.udid === data.selected);
|
|
172
|
+
const ifName = adapter?.adapter?.getInterface();
|
|
173
|
+
const onUnselect = data.selected ? () => { this.onCapabilityUnselect(cap); } : undefined;
|
|
174
|
+
let emptyFooter = undefined;
|
|
175
|
+
if (noSearch)
|
|
176
|
+
emptyFooter = 'Not searching';
|
|
177
|
+
else if (role)
|
|
178
|
+
emptyFooter = getEmptyTileFooterText(role);
|
|
179
|
+
return {
|
|
180
|
+
title, capability, deviceName, disabled: false, connectState, value: value?.toString(), unit, interface: ifName,
|
|
181
|
+
role, helpText, emptyFooter,
|
|
182
|
+
onClick, onUnselect
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
getDeviceListDisplayProps() {
|
|
186
|
+
if (!this.openedCapability)
|
|
187
|
+
return;
|
|
188
|
+
const all = this.state.capabilities ?? [];
|
|
189
|
+
const requested = all.find(c => c.capability === this.openedCapability);
|
|
190
|
+
const capDevices = requested?.devices ?? [];
|
|
191
|
+
const devices = capDevices.map(d => ({
|
|
192
|
+
connectState: d.connectState,
|
|
193
|
+
deviceName: d.name,
|
|
194
|
+
value: d.value,
|
|
195
|
+
interface: d.interface,
|
|
196
|
+
isSelected: d.selected,
|
|
197
|
+
onClick: (addAll) => { this.onDeviceSelected(d, addAll); },
|
|
198
|
+
onDelete: () => { this.onDeviceDelete(d); }
|
|
199
|
+
}));
|
|
200
|
+
const disabled = devices.length > 0 && !devices.some(d => d.isSelected);
|
|
201
|
+
return {
|
|
202
|
+
capability: this.openedCapability,
|
|
203
|
+
devices,
|
|
204
|
+
isScanning: this.stateMachine.selectState === 'Active',
|
|
205
|
+
changeForAll: false,
|
|
206
|
+
canSelectAll: this.openedCapability === 'control',
|
|
207
|
+
disabled,
|
|
208
|
+
onClose: () => { this.closeDeviceSelection(); },
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
updatePage() {
|
|
212
|
+
this.getPageObserver().emit('page-update');
|
|
213
|
+
}
|
|
214
|
+
onEnableCapability(enabled) {
|
|
215
|
+
const all = this.state.capabilities ?? [];
|
|
216
|
+
const requested = all.find(c => c.capability === this.openedCapability);
|
|
217
|
+
requested.disabled = !enabled;
|
|
218
|
+
this.updatePage();
|
|
219
|
+
}
|
|
220
|
+
openDeviceSelection(cap) {
|
|
221
|
+
this.logEvent({ message: 'capability clicked', capability: cap, eventSource: 'user' });
|
|
222
|
+
this.openedCapability = cap;
|
|
223
|
+
this.stateMachine.onDeviceSelectionOpened(() => { this.updatePage(); });
|
|
224
|
+
this.updatePage();
|
|
225
|
+
}
|
|
226
|
+
onDeviceSelected(d, addAll) {
|
|
227
|
+
const capability = this.openedCapability;
|
|
228
|
+
this.logEvent({ message: 'device selected', capability, device: d.name });
|
|
229
|
+
this.closeDeviceSelection();
|
|
230
|
+
this.getDevicePairing().selectDevice(capability, d.udid, addAll);
|
|
231
|
+
this.updatePage();
|
|
232
|
+
}
|
|
233
|
+
onCapabilityUnselect(cap) {
|
|
234
|
+
this.logEvent({ message: 'capability unselect clicked', capability: cap, eventSource: 'user' });
|
|
235
|
+
this.getDevicePairing().unselectDevices(cap)
|
|
236
|
+
.catch(err => { this.logError(err, 'onCapabilityUnselect'); });
|
|
237
|
+
this.updatePage();
|
|
238
|
+
}
|
|
239
|
+
onCapabilityUse(cap) {
|
|
240
|
+
this.logEvent({ message: 'capability use clicked', capability: cap, eventSource: 'user' });
|
|
241
|
+
this.getDevicePairing().useCapability(cap);
|
|
242
|
+
this.updatePage();
|
|
243
|
+
}
|
|
244
|
+
onDeviceDelete(d) {
|
|
245
|
+
const capability = this.openedCapability;
|
|
246
|
+
this.logEvent({ message: 'device delete requested', capability, device: d.name });
|
|
247
|
+
this.getDevicePairing().deleteDevice(capability, d.udid);
|
|
248
|
+
this.updatePage();
|
|
249
|
+
}
|
|
250
|
+
closeDeviceSelection() {
|
|
251
|
+
this.logEvent({ message: 'capability closed', capability: this.openedCapability, caller: new Error().stack });
|
|
252
|
+
this.openedCapability = undefined;
|
|
253
|
+
this.stateMachine.onDeviceSelectionClosed();
|
|
254
|
+
this.updatePage();
|
|
255
|
+
}
|
|
256
|
+
getButtonsDisplayProps() {
|
|
257
|
+
const labelOK = this.isPairingForRide ? 'Start' : 'OK';
|
|
258
|
+
const labelSkip = this.isPairingForRide ? 'Cancel' : 'Skip';
|
|
259
|
+
if (this.state?.canStartRide)
|
|
260
|
+
return [
|
|
261
|
+
{ label: labelOK, primary: true, onClick: this.onOK.bind(this) }
|
|
262
|
+
];
|
|
263
|
+
if (!this.isPairingForRide)
|
|
264
|
+
return [
|
|
265
|
+
{ label: labelSkip, primary: true, onClick: this.onSkip.bind(this) }
|
|
266
|
+
];
|
|
267
|
+
return [
|
|
268
|
+
{ label: 'Simulate', primary: true, onClick: this.onSimulate.bind(this) },
|
|
269
|
+
{ label: labelSkip, primary: false, onClick: this.onSkip.bind(this) }
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
getTCapability(capabability) {
|
|
273
|
+
const mapping = {
|
|
274
|
+
'app_control': 'app_control',
|
|
275
|
+
'cadence': 'cadence',
|
|
276
|
+
'control': 'control',
|
|
277
|
+
'heartrate': 'heartrate',
|
|
278
|
+
'power': 'power',
|
|
279
|
+
'speed': 'speed'
|
|
280
|
+
};
|
|
281
|
+
return mapping[capabability];
|
|
282
|
+
}
|
|
283
|
+
getDisplayCapability(capabability) {
|
|
284
|
+
const mapping = {
|
|
285
|
+
'app_control': 'controller',
|
|
286
|
+
'cadence': 'cadence',
|
|
287
|
+
'control': 'resistance',
|
|
288
|
+
'heartrate': 'heartrate',
|
|
289
|
+
'power': 'power',
|
|
290
|
+
'speed': 'speed'
|
|
291
|
+
};
|
|
292
|
+
return mapping[capabability];
|
|
293
|
+
}
|
|
294
|
+
trackVisit(fn, name) {
|
|
295
|
+
try {
|
|
296
|
+
fn(this.getPairingVisitTracker());
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
this.logError(err, name);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
openVisit() {
|
|
303
|
+
if (this.isVisitOpen)
|
|
304
|
+
return;
|
|
305
|
+
this.trackVisit(t => t.openVisit({ forRide: this.isPairingForRide }), 'openVisit');
|
|
306
|
+
this.isVisitOpen = true;
|
|
307
|
+
}
|
|
308
|
+
closeVisit(via) {
|
|
309
|
+
this.trackVisit(t => t.closeVisit(via, { canStartRide: this.canStartRide() }), 'closeVisit');
|
|
310
|
+
this.isVisitOpen = false;
|
|
311
|
+
}
|
|
312
|
+
canStartRide() {
|
|
313
|
+
return this.state?.canStartRide ?? false;
|
|
314
|
+
}
|
|
315
|
+
onSkip() {
|
|
316
|
+
this.closeVisit('skip');
|
|
317
|
+
const nextPage = this.getAppState().getPersistedState('page') ?? 'routes';
|
|
318
|
+
this.moveTo(`/${nextPage}`);
|
|
319
|
+
}
|
|
320
|
+
prepareForRide(adapterFilter = []) {
|
|
321
|
+
this.getDevicePairing().prepareStart(adapterFilter)
|
|
322
|
+
.catch(err => { this.logError(err, 'prepareForRide'); });
|
|
323
|
+
this.handingOffToRide = true;
|
|
324
|
+
}
|
|
325
|
+
onOK() {
|
|
326
|
+
this.closeVisit('ok');
|
|
327
|
+
this.prepareForRide();
|
|
328
|
+
this.getDevicePairing().setReadyToStart();
|
|
329
|
+
this.getAppState().setState('paired', true);
|
|
330
|
+
const prevContentPage = this.getPrevContentPage();
|
|
331
|
+
const prevPage = this.getAppState().getState('prevPage');
|
|
332
|
+
if (!prevPage) {
|
|
333
|
+
this.moveTo(`/${prevContentPage}`);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
if (this.isPairingForRide)
|
|
337
|
+
this.moveTo('/rideDeviceOK');
|
|
338
|
+
else
|
|
339
|
+
this.moveTo(`/${prevContentPage}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
onSimulate() {
|
|
343
|
+
this.closeVisit('simulate');
|
|
344
|
+
const simulator = this.getDeviceConfiguration().getSimulatorAdapterId();
|
|
345
|
+
this.prepareForRide([simulator]);
|
|
346
|
+
const prevContentPage = this.getPrevContentPage();
|
|
347
|
+
if (this.isPairingForRide)
|
|
348
|
+
this.moveTo('/rideSimulate');
|
|
349
|
+
else
|
|
350
|
+
this.moveTo(`/${prevContentPage}`);
|
|
351
|
+
}
|
|
352
|
+
onCancel() {
|
|
353
|
+
this.closeVisit('cancel');
|
|
354
|
+
const nextPage = this.getAppState().getState('prevPage');
|
|
355
|
+
this.moveTo(`/${nextPage}`);
|
|
356
|
+
}
|
|
357
|
+
async start() {
|
|
358
|
+
this.getDevicePairing().usage = this.getUsageMode();
|
|
359
|
+
this.getDevicePairing().start(() => {
|
|
360
|
+
this.updatePage();
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
async stop(adapters = [], forExit = false) {
|
|
364
|
+
return await this.getDevicePairing().stop(adapters, forExit);
|
|
365
|
+
}
|
|
366
|
+
get state() {
|
|
367
|
+
return this.getDevicePairing().getState();
|
|
368
|
+
}
|
|
369
|
+
getDevicePairing() {
|
|
370
|
+
return useDevicePairing();
|
|
371
|
+
}
|
|
372
|
+
getDeviceConfiguration() {
|
|
373
|
+
return useDeviceConfiguration();
|
|
374
|
+
}
|
|
375
|
+
getPairingVisitTracker() {
|
|
376
|
+
return usePairingVisitTracker();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
})();
|
|
380
|
+
export { PairingPageService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventLogger } from 'gd-eventlog';
|
|
2
|
+
import { getBindings } from '../../../api';
|
|
3
|
+
import { useAppState } from '../../../appstate';
|
|
4
|
+
import { PairingVisitTracker } from './visit-log';
|
|
5
|
+
export const PAIRING_VISITS_STATE_KEY = 'pairingVisits';
|
|
6
|
+
let instance;
|
|
7
|
+
let logger;
|
|
8
|
+
export const createPairingVisitStore = (appState) => ({
|
|
9
|
+
get: () => appState.getPersistedState(PAIRING_VISITS_STATE_KEY) ?? undefined,
|
|
10
|
+
set: (record) => { appState.setPersistedState(PAIRING_VISITS_STATE_KEY, record); },
|
|
11
|
+
});
|
|
12
|
+
export const formatLocalDate = (date) => {
|
|
13
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
14
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
15
|
+
};
|
|
16
|
+
export const toVisitPlatform = (platform) => platform?.startsWith('mobile') ? 'mobile' : 'desktop';
|
|
17
|
+
const log = (message, fields) => {
|
|
18
|
+
logger = logger ?? new EventLogger('Pairing');
|
|
19
|
+
logger.logEvent({ message, ...fields });
|
|
20
|
+
};
|
|
21
|
+
export const initPairingVisitTracker = (platform) => {
|
|
22
|
+
const appInfo = getBindings()?.appInfo;
|
|
23
|
+
instance = new PairingVisitTracker({
|
|
24
|
+
store: createPairingVisitStore(useAppState()),
|
|
25
|
+
sessionId: appInfo?.session ?? '',
|
|
26
|
+
platform: toVisitPlatform(platform ?? appInfo?.getChannel()),
|
|
27
|
+
now: () => Date.now(),
|
|
28
|
+
today: () => formatLocalDate(new Date()),
|
|
29
|
+
log,
|
|
30
|
+
});
|
|
31
|
+
return instance;
|
|
32
|
+
};
|
|
33
|
+
export const usePairingVisitTracker = () => instance ?? initPairingVisitTracker();
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
let visitSequence = 0;
|
|
2
|
+
export const PAGE_LEFT_EVENT = 'pairing page left';
|
|
3
|
+
export const VISIT_UNCLOSED_EVENT = 'pairing visit unclosed';
|
|
4
|
+
export const getPreviousVisitOutcome = (last) => {
|
|
5
|
+
if (!last || !last.closed || !last.via)
|
|
6
|
+
return 'none';
|
|
7
|
+
switch (last.via) {
|
|
8
|
+
case 'ok':
|
|
9
|
+
return 'ready';
|
|
10
|
+
case 'simulate':
|
|
11
|
+
return 'simulate';
|
|
12
|
+
case 'skip':
|
|
13
|
+
case 'cancel':
|
|
14
|
+
if (last.rideAfter === 'device')
|
|
15
|
+
return 'skip-then-ride';
|
|
16
|
+
if (last.rideAfter === 'simulate')
|
|
17
|
+
return 'simulate';
|
|
18
|
+
return 'skip-no-ride';
|
|
19
|
+
case 'app_exit':
|
|
20
|
+
return last.canStartRide ? 'app-exit-ready' : 'app-exit-not-ready';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export class PairingVisitTracker {
|
|
24
|
+
deps;
|
|
25
|
+
constructor(deps) {
|
|
26
|
+
this.deps = deps;
|
|
27
|
+
}
|
|
28
|
+
onAppLaunch(isNewUser) {
|
|
29
|
+
const record = this.deps.store.get();
|
|
30
|
+
if (!record) {
|
|
31
|
+
this.deps.store.set({ date: this.deps.today(), countToday: 0, firstEverPending: isNewUser });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const last = record.last;
|
|
35
|
+
if (!last || last.closed)
|
|
36
|
+
return;
|
|
37
|
+
const now = this.deps.now();
|
|
38
|
+
this.deps.log(VISIT_UNCLOSED_EVENT, {
|
|
39
|
+
visitId: last.visitId,
|
|
40
|
+
visitSessionId: last.sessionId,
|
|
41
|
+
dwellMs: last.backgroundedAt !== undefined ? last.backgroundedAt - last.openedAt : null,
|
|
42
|
+
backgroundMs: last.backgroundMs,
|
|
43
|
+
forRide: last.forRide,
|
|
44
|
+
canStartRide: last.canStartRide,
|
|
45
|
+
visitIndexToday: last.visitIndexToday,
|
|
46
|
+
firstEverVisit: last.firstEverVisit,
|
|
47
|
+
visitAgeMs: now - last.openedAt,
|
|
48
|
+
platform: this.deps.platform,
|
|
49
|
+
});
|
|
50
|
+
this.deps.store.set({
|
|
51
|
+
...record,
|
|
52
|
+
last: { ...last, closed: true, via: 'app_exit', inferred: true, closedAt: last.backgroundedAt ?? last.openedAt, backgroundedAt: undefined },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
openVisit({ forRide }) {
|
|
56
|
+
const now = this.deps.now();
|
|
57
|
+
const today = this.deps.today();
|
|
58
|
+
const previous = this.deps.store.get();
|
|
59
|
+
if (previous?.last && !previous.last.closed)
|
|
60
|
+
this.closeVisit('app_exit', { canStartRide: previous.last.canStartRide });
|
|
61
|
+
const record = this.deps.store.get() ?? { date: today, countToday: 0, firstEverPending: false };
|
|
62
|
+
const countToday = record.date === today ? record.countToday + 1 : 1;
|
|
63
|
+
const visitId = `${now}-${++visitSequence}`;
|
|
64
|
+
const prevLast = record.last;
|
|
65
|
+
this.deps.store.set({
|
|
66
|
+
date: today,
|
|
67
|
+
countToday,
|
|
68
|
+
firstEverPending: false,
|
|
69
|
+
last: {
|
|
70
|
+
visitId,
|
|
71
|
+
sessionId: this.deps.sessionId,
|
|
72
|
+
openedAt: now,
|
|
73
|
+
backgroundMs: 0,
|
|
74
|
+
forRide,
|
|
75
|
+
canStartRide: false,
|
|
76
|
+
visitIndexToday: countToday,
|
|
77
|
+
firstEverVisit: record.firstEverPending,
|
|
78
|
+
previousVisitOutcome: getPreviousVisitOutcome(prevLast),
|
|
79
|
+
previousVisitAgeMs: prevLast?.closedAt !== undefined ? now - prevLast.closedAt : undefined,
|
|
80
|
+
closed: false,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return { visitId };
|
|
84
|
+
}
|
|
85
|
+
onBackground({ canStartRide } = {}) {
|
|
86
|
+
const record = this.deps.store.get();
|
|
87
|
+
const last = record?.last;
|
|
88
|
+
if (!record || !last || last.closed || last.backgroundedAt !== undefined)
|
|
89
|
+
return;
|
|
90
|
+
const refreshed = canStartRide ?? last.canStartRide;
|
|
91
|
+
this.deps.store.set({ ...record, last: { ...last, canStartRide: refreshed, backgroundedAt: this.deps.now() } });
|
|
92
|
+
}
|
|
93
|
+
onForeground() {
|
|
94
|
+
const record = this.deps.store.get();
|
|
95
|
+
const last = record?.last;
|
|
96
|
+
if (!record || !last || last.closed || last.backgroundedAt === undefined)
|
|
97
|
+
return;
|
|
98
|
+
const backgroundMs = last.backgroundMs + (this.deps.now() - last.backgroundedAt);
|
|
99
|
+
this.deps.store.set({ ...record, last: { ...last, backgroundMs, backgroundedAt: undefined } });
|
|
100
|
+
}
|
|
101
|
+
closeVisit(via, { canStartRide }) {
|
|
102
|
+
const record = this.deps.store.get();
|
|
103
|
+
const last = record?.last;
|
|
104
|
+
if (!record || !last || last.closed)
|
|
105
|
+
return;
|
|
106
|
+
const now = this.deps.now();
|
|
107
|
+
const backgroundMs = last.backgroundMs + (last.backgroundedAt !== undefined ? now - last.backgroundedAt : 0);
|
|
108
|
+
this.deps.log(PAGE_LEFT_EVENT, {
|
|
109
|
+
visitId: last.visitId,
|
|
110
|
+
via,
|
|
111
|
+
dwellMs: now - last.openedAt,
|
|
112
|
+
backgroundMs,
|
|
113
|
+
forRide: last.forRide,
|
|
114
|
+
canStartRide,
|
|
115
|
+
visitIndexToday: last.visitIndexToday,
|
|
116
|
+
firstEverVisit: last.firstEverVisit,
|
|
117
|
+
previousVisitOutcome: last.previousVisitOutcome,
|
|
118
|
+
previousVisitAgeMs: last.previousVisitAgeMs,
|
|
119
|
+
platform: this.deps.platform,
|
|
120
|
+
});
|
|
121
|
+
this.deps.store.set({
|
|
122
|
+
...record,
|
|
123
|
+
last: { ...last, closed: true, via, canStartRide, backgroundMs, backgroundedAt: undefined, closedAt: now },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
onAppExit(canStartRide) {
|
|
127
|
+
this.closeVisit('app_exit', { canStartRide });
|
|
128
|
+
}
|
|
129
|
+
onRideStarted({ simulate }) {
|
|
130
|
+
const record = this.deps.store.get();
|
|
131
|
+
const last = record?.last;
|
|
132
|
+
if (!record || !last || !last.closed || last.rideAfter)
|
|
133
|
+
return;
|
|
134
|
+
if (last.via !== 'skip' && last.via !== 'cancel')
|
|
135
|
+
return;
|
|
136
|
+
this.deps.store.set({ ...record, last: { ...last, rideAfter: simulate ? 'simulate' : 'device' } });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const DESKTOP_MATRIX = [
|
|
2
|
+
{ area: 'buttons', name: 'ready, ride mode', given: 'canStartRide, mode=start', expected: 'primary "Start" (labelOK)' },
|
|
3
|
+
{ area: 'buttons', name: 'ready, normal mode', given: 'canStartRide, mode=normal', expected: 'primary "OK"' },
|
|
4
|
+
{ area: 'buttons', name: 'not ready, ride mode', given: '!canStartRide, mode=start', expected: 'primary "Simulate", secondary "Cancel" (labelSkip)' },
|
|
5
|
+
{ area: 'buttons', name: 'not ready, normal mode', given: '!canStartRide, mode=normal', expected: 'primary "Skip" only - no ride to simulate' },
|
|
6
|
+
{ area: 'ok-navigation', name: 'OK in ride mode starts the ride', given: 'isPairingForRide', expected: 'navigate "/rideOK"' },
|
|
7
|
+
{ area: 'ok-navigation', name: 'OK outside ride mode returns to the content page', given: '!isPairingForRide', expected: 'navigate "/<persisted page ?? routes>"' },
|
|
8
|
+
{ area: 'ok-navigation', name: 'OK closes the visit as ok', given: 'any', expected: 'closeVisit("ok") then devicePairing.prepareStart() and setReadyToStart()' },
|
|
9
|
+
{ area: 'skip', name: 'Skip in normal mode returns to the source', given: 'mode=normal, location.state.source set', expected: 'navigate(source); closeVisit("skip")' },
|
|
10
|
+
{ area: 'skip', name: 'Skip in normal mode without a source', given: 'mode=normal, no source', expected: 'navigate("/<persisted page ?? routes>"); closeVisit("skip")' },
|
|
11
|
+
{ area: 'skip', name: 'Cancel in ride mode returns to the source', given: 'mode=start', expected: 'navigate(source); closeVisit("cancel")' },
|
|
12
|
+
{ area: 'simulate', name: 'Simulate in ride mode', given: 'isPairingForRide', expected: 'prepareStart([simulatorId]); navigate "/rideSimulate"; closeVisit("simulate")' },
|
|
13
|
+
{ area: 'simulator', name: 'Shift+S adds the simulator', given: 'Shift+S pressed', expected: 'deviceConfig.add({name:"Simulator", interface:"simulator"}); the key is disabled afterwards' },
|
|
14
|
+
{ area: 'tiles', name: 'Tile ✕ unselects the capability', given: 'a selected tile', expected: 'devicePairing.unselectDevices(capability)' },
|
|
15
|
+
{ area: 'device-list', name: 'Opening a tile opens its device list', given: 'tile clicked', expected: 'DeviceSelector opens for that capability' },
|
|
16
|
+
{ area: 'device-list', name: 'Select with changeForAll default for Resistance', given: 'capability=control, device clicked', expected: 'selectDevice(control, udid, true); the dialog closes' },
|
|
17
|
+
{ area: 'device-list', name: 'Select with changeForAll default for other capabilities', given: 'capability!=control, device clicked', expected: 'selectDevice(capability, udid, false); the dialog closes' },
|
|
18
|
+
{ area: 'device-list', name: 'Select-all is offered for Resistance only', given: 'capability=control', expected: 'canSelectAll true; other capabilities false' },
|
|
19
|
+
{ 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' },
|
|
20
|
+
{ 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.' },
|
|
21
|
+
{ 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)' },
|
|
22
|
+
{ area: 'interfaces', name: 'Interface settings change', given: 'OK in interface settings', expected: 'devicePairing.changeInterfaceSettings(ifName, settings); showInterfaceSettings clears' },
|
|
23
|
+
];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class DirectOrchestrator {
|
|
2
|
+
state = 'Idle';
|
|
3
|
+
selectState = 'Closed';
|
|
4
|
+
start(_onUpdate) {
|
|
5
|
+
}
|
|
6
|
+
stop() {
|
|
7
|
+
}
|
|
8
|
+
async pause() {
|
|
9
|
+
}
|
|
10
|
+
resume() {
|
|
11
|
+
}
|
|
12
|
+
onDeviceSelectionOpened() {
|
|
13
|
+
}
|
|
14
|
+
onDeviceSelectionClosed() {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const createDirectOrchestrator = () => new DirectOrchestrator();
|