incyclist-services 1.8.7 → 1.8.9

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 (40) hide show
  1. package/lib/cjs/devices/page/index.js +6 -0
  2. package/lib/cjs/devices/page/service.js +69 -5
  3. package/lib/cjs/devices/page/visit-log-factory.js +41 -0
  4. package/lib/cjs/devices/page/visit-log.js +143 -0
  5. package/lib/cjs/devices/page/visit-tracker-factory.js +41 -0
  6. package/lib/cjs/devices/page/visit-tracker.js +142 -0
  7. package/lib/cjs/devices/pairing/guidance.js +152 -0
  8. package/lib/cjs/devices/pairing/index.js +2 -0
  9. package/lib/cjs/devices/pairing/status.js +54 -0
  10. package/lib/cjs/ride/display/service.js +15 -0
  11. package/lib/cjs/routes/list/loaders/api.js +3 -2
  12. package/lib/cjs/ui/service.js +39 -0
  13. package/lib/cjs/utils/settleWithLimit.js +20 -0
  14. package/lib/esm/devices/page/index.js +2 -0
  15. package/lib/esm/devices/page/service.js +70 -6
  16. package/lib/esm/devices/page/visit-log-factory.js +33 -0
  17. package/lib/esm/devices/page/visit-log.js +138 -0
  18. package/lib/esm/devices/page/visit-tracker-factory.js +33 -0
  19. package/lib/esm/devices/page/visit-tracker.js +137 -0
  20. package/lib/esm/devices/pairing/guidance.js +141 -0
  21. package/lib/esm/devices/pairing/index.js +2 -0
  22. package/lib/esm/devices/pairing/status.js +49 -0
  23. package/lib/esm/ride/display/service.js +16 -1
  24. package/lib/esm/routes/list/loaders/api.js +3 -2
  25. package/lib/esm/ui/service.js +40 -1
  26. package/lib/esm/utils/settleWithLimit.js +16 -0
  27. package/lib/types/devices/page/index.d.ts +2 -0
  28. package/lib/types/devices/page/service.d.ts +9 -1
  29. package/lib/types/devices/page/types.d.ts +55 -0
  30. package/lib/types/devices/page/visit-log-factory.d.ts +13 -0
  31. package/lib/types/devices/page/visit-log.d.ts +25 -0
  32. package/lib/types/devices/page/visit-tracker-factory.d.ts +13 -0
  33. package/lib/types/devices/page/visit-tracker.d.ts +25 -0
  34. package/lib/types/devices/pairing/guidance.d.ts +55 -0
  35. package/lib/types/devices/pairing/index.d.ts +2 -0
  36. package/lib/types/devices/pairing/status.d.ts +29 -0
  37. package/lib/types/ride/display/service.d.ts +2 -0
  38. package/lib/types/ui/service.d.ts +4 -0
  39. package/lib/types/utils/settleWithLimit.d.ts +1 -0
  40. package/package.json +1 -1
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEmptyTileFooterText = exports.getCapabilityHelpText = exports.getPairingRowLabelId = exports.getPairingGuidanceText = exports.derivePairingStatus = exports.getPairingHint = exports.getUnavailableInterfaces = exports.canScanWithInterfaces = exports.PAIRING_CAPABILITY_ROLES = void 0;
4
+ const incyclist_devices_1 = require("incyclist-devices");
5
+ exports.PAIRING_CAPABILITY_ROLES = [
6
+ { capability: incyclist_devices_1.IncyclistCapability.Control, role: 'required', descriptor: 'control' },
7
+ { capability: incyclist_devices_1.IncyclistCapability.Power, role: 'required', descriptor: 'power' },
8
+ { capability: incyclist_devices_1.IncyclistCapability.Speed, role: 'required', descriptor: 'speed' },
9
+ { capability: incyclist_devices_1.IncyclistCapability.HeartRate, role: 'optional', descriptor: 'heartrate' },
10
+ { capability: incyclist_devices_1.IncyclistCapability.Cadence, role: 'optional', descriptor: 'cadence' },
11
+ { capability: incyclist_devices_1.IncyclistCapability.AppControl, role: 'optional', descriptor: 'app_control' },
12
+ ];
13
+ const INTERFACE_LABELS = {
14
+ ant: 'ANT+',
15
+ ble: 'Bluetooth',
16
+ serial: 'Serial',
17
+ tcpip: 'TCP/IP',
18
+ wifi: 'Wi-Fi',
19
+ };
20
+ const DESKTOP_SEARCH_INTERFACES = new Set(['ble', 'ant']);
21
+ const searchInterfaces = (interfaces, platform) => platform === 'desktop'
22
+ ? interfaces.filter(i => DESKTOP_SEARCH_INTERFACES.has(i.id))
23
+ : interfaces;
24
+ const canScanWithInterfaces = (interfaces, platform) => searchInterfaces(interfaces, platform).some(i => i.enabled && i.available);
25
+ exports.canScanWithInterfaces = canScanWithInterfaces;
26
+ const getUnavailableInterfaces = (interfaces, platform) => searchInterfaces(interfaces, platform).filter(i => i.enabled && !i.available).map(i => i.id);
27
+ exports.getUnavailableInterfaces = getUnavailableInterfaces;
28
+ const isBrokenInterface = (interfaces, id) => interfaces.find(i => i.id === id && i.enabled && !i.available);
29
+ const getPairingHint = (input) => {
30
+ if (input.anyDeviceSelected)
31
+ return undefined;
32
+ if (input.platform === 'mobile') {
33
+ const ble = isBrokenInterface(input.interfaces, 'ble');
34
+ if (ble)
35
+ return ble.permissionDenied ? 'bluetooth-permission' : 'bluetooth-off';
36
+ if (isBrokenInterface(input.interfaces, 'wifi'))
37
+ return 'wifi-off';
38
+ return undefined;
39
+ }
40
+ if (isBrokenInterface(input.interfaces, 'ant'))
41
+ return 'ant';
42
+ return undefined;
43
+ };
44
+ exports.getPairingHint = getPairingHint;
45
+ const derivePairingStatus = (input) => {
46
+ if (!(0, exports.canScanWithInterfaces)(input.interfaces, input.platform))
47
+ return 'S1';
48
+ if (input.canStartRide)
49
+ return 'S2';
50
+ if (input.connectingDeviceName)
51
+ return 'S3';
52
+ if (input.initialising)
53
+ return 'S4';
54
+ if ((0, exports.getPairingHint)(input))
55
+ return 'S1b';
56
+ return 'S5';
57
+ };
58
+ exports.derivePairingStatus = derivePairingStatus;
59
+ const formatList = (names) => {
60
+ if (names.length <= 1)
61
+ return names.join('');
62
+ return `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
63
+ };
64
+ const getNoSearchText = (params, isShort) => {
65
+ if (params.platform === 'mobile' && params.bluetoothDenied)
66
+ return isShort
67
+ ? { text: 'Bluetooth not allowed.', link: 'Settings' }
68
+ : { text: "Can't search: Bluetooth is not allowed.", link: 'Open settings' };
69
+ const names = (params.unavailable ?? []).map(id => INTERFACE_LABELS[id]);
70
+ if (params.platform === 'mobile') {
71
+ const list = formatList(names);
72
+ const verb = names.length > 1 ? 'are' : 'is';
73
+ const link = names.length === 1 && names[0] === INTERFACE_LABELS.ble ? 'Bluetooth settings' : 'Settings';
74
+ if (isShort)
75
+ return { text: `${list} ${verb} off.`, link: 'Settings' };
76
+ return { text: `Can't search: ${list} ${verb} off.`, link };
77
+ }
78
+ const list = formatList(names);
79
+ if (names.length === 2)
80
+ return { text: `Can't search: ${list} are both unavailable.`, link: 'Check connections' };
81
+ return { text: `Can't search: ${list} unavailable.`, link: 'Check connections' };
82
+ };
83
+ const getHintText = (hint, isShort) => {
84
+ switch (hint) {
85
+ case 'bluetooth-permission':
86
+ return isShort
87
+ ? { text: 'Bluetooth not allowed.', link: 'Settings' }
88
+ : { text: "Incyclist isn't allowed to use Bluetooth, so most trainers won't show up.", link: 'Open settings' };
89
+ case 'bluetooth-off':
90
+ return isShort
91
+ ? { text: 'Bluetooth is off.', link: 'Settings' }
92
+ : { text: "Bluetooth is off, so most trainers won't show up.", link: 'Bluetooth settings' };
93
+ case 'wifi-off':
94
+ return isShort
95
+ ? { text: 'Wi-Fi is off · needed for Wi-Fi trainers' }
96
+ : { text: 'Wi-Fi is off. If your trainer connects over Wi-Fi, turn Wi-Fi on.' };
97
+ case 'ant':
98
+ return { text: 'ANT+ stick not found. If you use one, plug it in, try another USB port, or close other apps that use it.' };
99
+ }
100
+ };
101
+ const getPairingGuidanceText = (id, params = {}, variant = 'full') => {
102
+ const isShort = variant === 'short';
103
+ const device = params.deviceName ?? '';
104
+ switch (id) {
105
+ case 'S1':
106
+ return getNoSearchText(params, isShort);
107
+ case 'S1b':
108
+ return getHintText(params.hint, isShort);
109
+ case 'S2': {
110
+ if (isShort)
111
+ return { text: `Ready to ride with ${device}.` };
112
+ const tail = `You can add optional sensors, or press ${params.rideMode ? 'Start' : 'OK'}.`;
113
+ return { text: `Ready to ride with ${device}. ${tail}` };
114
+ }
115
+ case 'S3':
116
+ if (params.isTrainer)
117
+ return { text: isShort ? `Connecting to ${device}…` : `Connecting to your trainer ${device}…` };
118
+ return { text: `Connecting to ${device}…` };
119
+ case 'S4':
120
+ return { text: 'Getting ready to search…' };
121
+ case 'S5':
122
+ return isShort
123
+ ? { text: 'Searching… Pedal to wake your trainer.' }
124
+ : { text: 'Searching for devices… Tip: pedal a few strokes to wake up your trainer.' };
125
+ case 'row-required':
126
+ return { text: 'TO RIDE', subtext: 'connect any one' };
127
+ case 'row-required-trainer':
128
+ return { text: 'TO RIDE', subtext: 'connecting to your trainer' };
129
+ case 'row-ready':
130
+ return { text: '✓ READY TO RIDE' };
131
+ case 'row-optional':
132
+ return { text: 'OPTIONAL', subtext: 'extras, not needed' };
133
+ }
134
+ };
135
+ exports.getPairingGuidanceText = getPairingGuidanceText;
136
+ const getPairingRowLabelId = (trainerSelected) => trainerSelected ? 'row-required-trainer' : 'row-required';
137
+ exports.getPairingRowLabelId = getPairingRowLabelId;
138
+ const getCapabilityHelpText = (capability, variant = 'full') => {
139
+ const isShort = variant === 'short';
140
+ switch (capability) {
141
+ case 'control': return 'Smart trainer';
142
+ case 'power': return 'Power meter';
143
+ case 'speed': return 'Speed sensor';
144
+ case 'heartrate': return 'Heart-rate monitor';
145
+ case 'cadence': return 'Cadence sensor';
146
+ case 'app_control': return isShort ? 'Remote buttons' : 'Remote buttons, e.g. Zwift Play';
147
+ default: return undefined;
148
+ }
149
+ };
150
+ exports.getCapabilityHelpText = getCapabilityHelpText;
151
+ const getEmptyTileFooterText = (role) => role === 'required' ? 'Searching…' : 'Optional';
152
+ exports.getEmptyTileFooterText = getEmptyTileFooterText;
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./service"), exports);
18
18
  __exportStar(require("./model"), exports);
19
+ __exportStar(require("./guidance"), exports);
20
+ __exportStar(require("./status"), exports);
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPairingStatusDisplay = exports.toPairingInterfaceStates = void 0;
4
+ const guidance_1 = require("./guidance");
5
+ const REQUIRED_CAPABILITIES = ['control', 'power', 'speed'];
6
+ const toPairingInterfaceStates = (interfaces) => interfaces.map(i => ({
7
+ id: i.name,
8
+ enabled: i.enabled !== false,
9
+ available: i.state !== 'disconnected' && i.state !== 'unavailable',
10
+ }));
11
+ exports.toPairingInterfaceStates = toPairingInterfaceStates;
12
+ const DOT_BY_STATUS = { S1: 'red', S2: 'green' };
13
+ const statusDot = (id) => DOT_BY_STATUS[id] ?? 'amber';
14
+ const getPairingStatusDisplay = (src) => {
15
+ const find = (name) => src.capabilities.find(c => c.capability === name);
16
+ const readyCapability = REQUIRED_CAPABILITIES
17
+ .map(find)
18
+ .find(c => c?.selected && c.connectState === 'connected');
19
+ const connectingCapability = src.capabilities.find(c => c.selected && c.connectState === 'connecting');
20
+ const anyDeviceSelected = src.capabilities.some(c => Boolean(c.selected));
21
+ const derived = (0, guidance_1.derivePairingStatus)({
22
+ platform: src.platform,
23
+ interfaces: src.interfaces,
24
+ anyDeviceSelected,
25
+ initialising: src.loading,
26
+ searching: false,
27
+ canStartRide: src.canStartRide,
28
+ readyDeviceName: readyCapability?.deviceName,
29
+ connectingDeviceName: connectingCapability?.deviceName,
30
+ connectingIsTrainer: connectingCapability?.capability === 'control',
31
+ });
32
+ let id = derived === 'S1b' ? 'S5' : derived;
33
+ if (src.loading)
34
+ id = 'S4';
35
+ const deviceName = id === 'S3' ? connectingCapability?.deviceName : readyCapability?.deviceName;
36
+ const params = {
37
+ platform: src.platform,
38
+ unavailable: (0, guidance_1.getUnavailableInterfaces)(src.interfaces, src.platform),
39
+ deviceName,
40
+ isTrainer: connectingCapability?.capability === 'control',
41
+ rideMode: src.rideMode,
42
+ };
43
+ const full = (0, guidance_1.getPairingGuidanceText)(id, params, 'full');
44
+ const short = (0, guidance_1.getPairingGuidanceText)(id, params, 'short');
45
+ return {
46
+ id,
47
+ text: full.text,
48
+ shortText: short.text,
49
+ link: full.link,
50
+ shortLink: short.link,
51
+ dot: statusDot(id),
52
+ };
53
+ };
54
+ exports.getPairingStatusDisplay = getPairingStatusDisplay;
@@ -68,6 +68,7 @@ let RideDisplayService = (() => {
68
68
  let _getDeviceConfiguration_decorators;
69
69
  let _getUIBinding_decorators;
70
70
  let _getCoaches_decorators;
71
+ let _getPairingVisitTracker_decorators;
71
72
  var RideDisplayService = class extends _classSuper {
72
73
  static { _classThis = this; }
73
74
  static {
@@ -81,6 +82,7 @@ let RideDisplayService = (() => {
81
82
  _getDeviceConfiguration_decorators = [decorators_1.Injectable];
82
83
  _getUIBinding_decorators = [decorators_1.Injectable];
83
84
  _getCoaches_decorators = [decorators_1.Injectable];
85
+ _getPairingVisitTracker_decorators = [decorators_1.Injectable];
84
86
  __esDecorate(this, null, _getActivityRide_decorators, { kind: "method", name: "getActivityRide", static: false, private: false, access: { has: obj => "getActivityRide" in obj, get: obj => obj.getActivityRide }, metadata: _metadata }, null, _instanceExtraInitializers);
85
87
  __esDecorate(this, null, _getWorkoutRide_decorators, { kind: "method", name: "getWorkoutRide", static: false, private: false, access: { has: obj => "getWorkoutRide" in obj, get: obj => obj.getWorkoutRide }, metadata: _metadata }, null, _instanceExtraInitializers);
86
88
  __esDecorate(this, null, _getWorkoutList_decorators, { kind: "method", name: "getWorkoutList", static: false, private: false, access: { has: obj => "getWorkoutList" in obj, get: obj => obj.getWorkoutList }, metadata: _metadata }, null, _instanceExtraInitializers);
@@ -90,6 +92,7 @@ let RideDisplayService = (() => {
90
92
  __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);
91
93
  __esDecorate(this, null, _getUIBinding_decorators, { kind: "method", name: "getUIBinding", static: false, private: false, access: { has: obj => "getUIBinding" in obj, get: obj => obj.getUIBinding }, metadata: _metadata }, null, _instanceExtraInitializers);
92
94
  __esDecorate(this, null, _getCoaches_decorators, { kind: "method", name: "getCoaches", static: false, private: false, access: { has: obj => "getCoaches" in obj, get: obj => obj.getCoaches }, metadata: _metadata }, null, _instanceExtraInitializers);
95
+ __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);
93
96
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
94
97
  RideDisplayService = _classThis = _classDescriptor.value;
95
98
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -135,6 +138,7 @@ let RideDisplayService = (() => {
135
138
  try {
136
139
  if (simulate)
137
140
  this.enforceSimulator();
141
+ this.notifyPairingVisitRideStarted(simulate);
138
142
  const rideProps = this.getRideModeService().getLogProps();
139
143
  this.logEvent({ message: 'Start ride', ...rideProps,
140
144
  bike: this.getBike(),
@@ -154,6 +158,14 @@ let RideDisplayService = (() => {
154
158
  this.logError(err, 'start');
155
159
  }
156
160
  }
161
+ notifyPairingVisitRideStarted(simulate) {
162
+ try {
163
+ this.getPairingVisitTracker().onRideStarted({ simulate: simulate === true });
164
+ }
165
+ catch (err) {
166
+ this.logError(err, 'notifyPairingVisitRideStarted');
167
+ }
168
+ }
157
169
  startWithMissingSensors() {
158
170
  try {
159
171
  const props = this.getStartOverlayProps();
@@ -1169,6 +1181,9 @@ let RideDisplayService = (() => {
1169
1181
  getCoaches() {
1170
1182
  return (0, coaches_1.getCoachesService)();
1171
1183
  }
1184
+ getPairingVisitTracker() {
1185
+ return (0, devices_1.usePairingVisitTracker)();
1186
+ }
1172
1187
  };
1173
1188
  return RideDisplayService = _classThis;
1174
1189
  })();
@@ -12,6 +12,8 @@ const route_2 = require("../../base/utils/route");
12
12
  const db_1 = require("./db");
13
13
  const types_1 = require("./types");
14
14
  const sleep_1 = require("../../../utils/sleep");
15
+ const settleWithLimit_1 = require("../../../utils/settleWithLimit");
16
+ const ROUTE_DETAILS_CONCURRENCY = 4;
15
17
  const valid = (v) => (v !== undefined && v !== null);
16
18
  class ApiError extends Error {
17
19
  _type;
@@ -170,8 +172,7 @@ class RoutesApiLoader extends types_1.Loader {
170
172
  this.logger.logEvent({ message: 'error', fn: 'loadDetails#unique', error: err.message, stack: err.stack });
171
173
  }
172
174
  const failed = enforced ? items : await this.loadDetailsFromRepo(items);
173
- const promises = failed.map(i => this.getDetails(i.route));
174
- const res = await Promise.allSettled(promises);
175
+ const res = await (0, settleWithLimit_1.settleWithLimit)(failed, ROUTE_DETAILS_CONCURRENCY, i => this.getDetails(i.route));
175
176
  await this.processLoadDetailsResult(res, items, true);
176
177
  }
177
178
  async processLoadDetailsResult(res, items, save) {
@@ -129,6 +129,7 @@ let UserInterfaceServcie = (() => {
129
129
  this.initLogging();
130
130
  this.logEvent({ message: 'App mounted', channel: platform });
131
131
  this.createUserStats();
132
+ this.initPairingVisits();
132
133
  await this.initDeviceServices();
133
134
  this.preloadData();
134
135
  this.onSessionStart();
@@ -147,6 +148,7 @@ let UserInterfaceServcie = (() => {
147
148
  this.logEvent({ message: 'onAppExit called' });
148
149
  this.stopHeartbeatWorker();
149
150
  this.sendAppExitMessage();
151
+ this.closePairingVisitOnExit();
150
152
  pages_1.IncyclistPageService.closePage();
151
153
  const cleanup = async () => {
152
154
  await (0, utils_1.waitNextTick)();
@@ -173,6 +175,7 @@ let UserInterfaceServcie = (() => {
173
175
  this.appState = 'Background';
174
176
  this.logEvent({ message: 'onAppPause called' });
175
177
  this.stopHeartbeatWorker();
178
+ this.onPairingVisitBackground();
176
179
  (0, devices_1.useDeviceAccess)().pauseBackgroundActivity()
177
180
  .catch((err) => { this.logError(err, 'onAppPause:pauseBackgroundActivity'); });
178
181
  this.backgroundTimer = setTimeout(() => {
@@ -199,6 +202,7 @@ let UserInterfaceServcie = (() => {
199
202
  resumeRequired = false;
200
203
  }
201
204
  this.logEvent({ message: 'onAppResume called' });
205
+ this.onPairingVisitForeground();
202
206
  this.startHeartbeatWorker();
203
207
  this.backgroundPausedByService = false;
204
208
  this.appState = 'Active';
@@ -536,6 +540,41 @@ let UserInterfaceServcie = (() => {
536
540
  }
537
541
  onNewUser() {
538
542
  }
543
+ initPairingVisits() {
544
+ try {
545
+ const isNewUser = this.getUserSettings().isNewUser() ?? false;
546
+ (0, devices_1.initPairingVisitTracker)(this.platform).onAppLaunch(isNewUser);
547
+ }
548
+ catch (err) {
549
+ this.logError(err, 'initPairingVisits');
550
+ }
551
+ }
552
+ closePairingVisitOnExit() {
553
+ try {
554
+ const canStartRide = (0, devices_1.useDevicePairing)().getState()?.canStartRide ?? false;
555
+ (0, devices_1.usePairingVisitTracker)().onAppExit(canStartRide);
556
+ }
557
+ catch (err) {
558
+ this.logError(err, 'closePairingVisitOnExit');
559
+ }
560
+ }
561
+ onPairingVisitBackground() {
562
+ try {
563
+ const canStartRide = (0, devices_1.useDevicePairing)().getState()?.canStartRide;
564
+ (0, devices_1.usePairingVisitTracker)().onBackground({ canStartRide });
565
+ }
566
+ catch (err) {
567
+ this.logError(err, 'onPairingVisitBackground');
568
+ }
569
+ }
570
+ onPairingVisitForeground() {
571
+ try {
572
+ (0, devices_1.usePairingVisitTracker)().onForeground();
573
+ }
574
+ catch (err) {
575
+ this.logError(err, 'onPairingVisitForeground');
576
+ }
577
+ }
539
578
  getMessageQueue() {
540
579
  return (0, api_1.getBindings)().mq;
541
580
  }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.settleWithLimit = void 0;
4
+ const settleWithLimit = async (items, limit, fn) => {
5
+ const results = new Array(items.length);
6
+ let next = 0;
7
+ const worker = () => {
8
+ if (next >= items.length)
9
+ return Promise.resolve();
10
+ const idx = next++;
11
+ return Promise.resolve()
12
+ .then(() => fn(items[idx]))
13
+ .then((value) => { results[idx] = { status: 'fulfilled', value }; }, (reason) => { results[idx] = { status: 'rejected', reason }; })
14
+ .then(worker);
15
+ };
16
+ const workers = Math.min(Math.max(1, limit), items.length);
17
+ await Promise.all(Array.from({ length: workers }, () => worker()));
18
+ return results;
19
+ };
20
+ exports.settleWithLimit = settleWithLimit;
@@ -1 +1,3 @@
1
1
  export * from './service';
2
+ export { PairingVisitTracker } from './visit-log';
3
+ export { usePairingVisitTracker, initPairingVisitTracker } from './visit-log-factory';
@@ -35,14 +35,16 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
35
35
  import { EventLogger } from 'gd-eventlog';
36
36
  import { Injectable, Singleton } from '../../base/decorators';
37
37
  import { IncyclistPageService } from '../../base/pages';
38
- import { useDevicePairing } from '../pairing';
38
+ import { useDevicePairing, PAIRING_CAPABILITY_ROLES, getCapabilityHelpText, getEmptyTileFooterText, getPairingGuidanceText, getPairingRowLabelId, getPairingStatusDisplay, toPairingInterfaceStates } from '../pairing';
39
39
  import { PairingPageStateMachine } from './statemachine';
40
40
  import { PageLogObserver } from './logobserver';
41
41
  import { useDeviceAccess } from '../access';
42
+ import { IncyclistCapability } from 'incyclist-devices';
42
43
  import { useDeviceConfiguration } from '../configuration';
43
44
  import { useIncyclist } from '../../ui';
44
45
  import { Observer } from '../../base/types';
45
46
  import { useDeviceRide } from '../ride';
47
+ import { usePairingVisitTracker } from './visit-log-factory';
46
48
  let DevicesPageService = (() => {
47
49
  let _classDecorators = [Singleton];
48
50
  let _classDescriptor;
@@ -54,6 +56,7 @@ let DevicesPageService = (() => {
54
56
  let _getDeviceRide_decorators;
55
57
  let _getDeviceConfiguration_decorators;
56
58
  let _getIncyclist_decorators;
59
+ let _getPairingVisitTracker_decorators;
57
60
  var DevicesPageService = class extends _classSuper {
58
61
  static { _classThis = this; }
59
62
  static {
@@ -62,10 +65,12 @@ let DevicesPageService = (() => {
62
65
  _getDeviceRide_decorators = [Injectable];
63
66
  _getDeviceConfiguration_decorators = [Injectable];
64
67
  _getIncyclist_decorators = [Injectable];
68
+ _getPairingVisitTracker_decorators = [Injectable];
65
69
  __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);
66
70
  __esDecorate(this, null, _getDeviceRide_decorators, { kind: "method", name: "getDeviceRide", static: false, private: false, access: { has: obj => "getDeviceRide" in obj, get: obj => obj.getDeviceRide }, metadata: _metadata }, null, _instanceExtraInitializers);
67
71
  __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);
68
72
  __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);
73
+ __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);
69
74
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
70
75
  DevicesPageService = _classThis = _classDescriptor.value;
71
76
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -78,6 +83,7 @@ let DevicesPageService = (() => {
78
83
  openedInterfaceSettings;
79
84
  interfaceSettingsObserver;
80
85
  isPairingForRide = false;
86
+ isVisitOpen = false;
81
87
  constructor() {
82
88
  super('pairing');
83
89
  this.stateMachine = new PairingPageStateMachine();
@@ -87,6 +93,7 @@ let DevicesPageService = (() => {
87
93
  try {
88
94
  this.logEvent({ message: 'page shown', page: 'Pairing', forRide });
89
95
  this.isPairingForRide = forRide ?? false;
96
+ this.openVisit();
90
97
  EventLogger.setGlobalConfig('page', 'Pairing');
91
98
  super.openPage();
92
99
  if (this.promiseOpen !== undefined) {
@@ -116,6 +123,7 @@ let DevicesPageService = (() => {
116
123
  closePage() {
117
124
  try {
118
125
  this.logEvent({ message: 'page closed', page: 'Pairing' });
126
+ this.isVisitOpen = false;
119
127
  EventLogger.setGlobalConfig('page', null);
120
128
  this.isPairingForRide = false;
121
129
  super.closePage();
@@ -128,6 +136,7 @@ let DevicesPageService = (() => {
128
136
  }
129
137
  async pausePage() {
130
138
  try {
139
+ this.trackVisit(t => t.onBackground({ canStartRide: this.canStartRide() }), 'onBackground');
131
140
  await this.stateMachine.pause();
132
141
  this.logEvent({ message: 'page paused', page: 'Pairing' });
133
142
  }
@@ -137,6 +146,7 @@ let DevicesPageService = (() => {
137
146
  }
138
147
  async resumePage() {
139
148
  try {
149
+ this.trackVisit(t => t.onForeground(), 'onForeground');
140
150
  this.stateMachine.resume();
141
151
  if (this.promiseOpen !== undefined)
142
152
  return;
@@ -173,23 +183,38 @@ let DevicesPageService = (() => {
173
183
  const ifs = this.state.interfaces ?? [];
174
184
  useDeviceAccess().enrichWithAccessState(ifs);
175
185
  const interfaces = ifs.map(i => { return this.getInterfaceDisplayProps(i); });
176
- const capProps = caps.map(c => this.getCapabilityDisplayProps(c));
177
186
  const loading = this.promiseOpen != undefined;
187
+ const status = getPairingStatusDisplay({
188
+ platform: 'mobile',
189
+ interfaces: toPairingInterfaceStates(ifs),
190
+ capabilities: caps,
191
+ canStartRide: this.canStartRide(),
192
+ loading,
193
+ rideMode: this.isPairingForRide,
194
+ });
195
+ const capProps = caps.map(c => this.getCapabilityDisplayProps(c, status.id === 'S1'));
178
196
  const CP = (cap) => capProps.find(c => c.capability === cap);
179
197
  const top = [
180
198
  CP('control'),
181
199
  CP('power'),
182
- CP('heartrate')
200
+ CP('speed')
183
201
  ].filter(c => c !== null && c !== undefined);
184
202
  const bottom = [
203
+ CP('heartrate'),
185
204
  CP('cadence'),
186
- CP('speed'),
187
205
  CP('app_control')
188
206
  ].filter(c => c !== null && c !== undefined);
207
+ const trainerSelected = Boolean(caps.find(c => c.capability === IncyclistCapability.Control)?.selected);
208
+ const rowLabels = {
209
+ top: getPairingGuidanceText(getPairingRowLabelId(trainerSelected)),
210
+ bottom: getPairingGuidanceText('row-optional'),
211
+ };
189
212
  const buttons = this.getButtonsDisplayProps();
190
213
  return {
191
214
  title,
192
- capabilities: { top, bottom },
215
+ readyToStart: this.canStartRide(),
216
+ status,
217
+ capabilities: { top, bottom, rowLabels },
193
218
  interfaces,
194
219
  deviceSelection: this.getDeviceListDisplayProps(),
195
220
  showInterfaceSettings: this.openedInterfaceSettings,
@@ -232,7 +257,7 @@ let DevicesPageService = (() => {
232
257
  this.interfaceSettingsObserver?.stop();
233
258
  this.updatePage();
234
259
  }
235
- getCapabilityDisplayProps(data) {
260
+ getCapabilityDisplayProps(data, noSearch = false) {
236
261
  const { capability: cap, deviceName, connectState, value, unit, disabled } = data;
237
262
  const capability = this.getTCapability(cap);
238
263
  const adapaters = this.state.adapters ?? [];
@@ -240,8 +265,19 @@ let DevicesPageService = (() => {
240
265
  const ifName = adapter?.adapter?.getInterface();
241
266
  const title = this.getDisplayCapability(cap);
242
267
  const onClick = () => { this.openDeviceSelection(cap); };
268
+ const role = PAIRING_CAPABILITY_ROLES.find(r => r.capability === cap)?.role;
269
+ const helpText = {
270
+ full: getCapabilityHelpText(capability, 'full') ?? '',
271
+ short: getCapabilityHelpText(capability, 'short') ?? '',
272
+ };
273
+ let emptyFooter = undefined;
274
+ if (noSearch)
275
+ emptyFooter = 'Not searching';
276
+ else if (role)
277
+ emptyFooter = getEmptyTileFooterText(role);
243
278
  return {
244
279
  title, capability, deviceName: !disabled ? deviceName : undefined, disabled, connectState, value: value?.toString(), unit, interface: ifName,
280
+ role, helpText, emptyFooter,
245
281
  onClick
246
282
  };
247
283
  }
@@ -371,11 +407,34 @@ let DevicesPageService = (() => {
371
407
  };
372
408
  return mapping[capabability];
373
409
  }
410
+ trackVisit(fn, name) {
411
+ try {
412
+ fn(this.getPairingVisitTracker());
413
+ }
414
+ catch (err) {
415
+ this.logError(err, name);
416
+ }
417
+ }
418
+ openVisit() {
419
+ if (this.isVisitOpen)
420
+ return;
421
+ this.trackVisit(t => t.openVisit({ forRide: this.isPairingForRide }), 'openVisit');
422
+ this.isVisitOpen = true;
423
+ }
424
+ closeVisit(via) {
425
+ this.trackVisit(t => t.closeVisit(via, { canStartRide: this.canStartRide() }), 'closeVisit');
426
+ this.isVisitOpen = false;
427
+ }
428
+ canStartRide() {
429
+ return this.state?.canStartRide ?? false;
430
+ }
374
431
  onSkip() {
432
+ this.closeVisit('skip');
375
433
  const nextPage = this.getAppState().getPersistedState('page') ?? 'routes';
376
434
  this.moveTo(`/${nextPage}`);
377
435
  }
378
436
  onOK() {
437
+ this.closeVisit('ok');
379
438
  this.getDevicePairing().prepareStart();
380
439
  this.getDevicePairing().setReadyToStart();
381
440
  this.getAppState().setState('paired', true);
@@ -392,6 +451,7 @@ let DevicesPageService = (() => {
392
451
  }
393
452
  }
394
453
  onSimulate() {
454
+ this.closeVisit('simulate');
395
455
  const simulator = this.getDeviceConfiguration().getSimulatorAdapterId();
396
456
  this.getDevicePairing().prepareStart([simulator]);
397
457
  const prevContentPage = this.getPrevContentPage();
@@ -401,6 +461,7 @@ let DevicesPageService = (() => {
401
461
  this.moveTo(prevContentPage);
402
462
  }
403
463
  onCancel() {
464
+ this.closeVisit('cancel');
404
465
  const nextPage = this.getAppState().getState('prevPage');
405
466
  this.moveTo(`/${nextPage}`);
406
467
  }
@@ -428,6 +489,9 @@ let DevicesPageService = (() => {
428
489
  getIncyclist() {
429
490
  return useIncyclist();
430
491
  }
492
+ getPairingVisitTracker() {
493
+ return usePairingVisitTracker();
494
+ }
431
495
  };
432
496
  return DevicesPageService = _classThis;
433
497
  })();
@@ -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();