incyclist-services 1.9.34 → 1.9.36
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/api/localLink/types.js +2 -0
- package/lib/cjs/api/loopbackPipe/types.js +2 -0
- package/lib/cjs/api/secureStorage/types.js +2 -0
- package/lib/cjs/apps/base/api/oauth.js +7 -1
- package/lib/cjs/apps/base/api/trainingpeaks/api.js +56 -0
- package/lib/cjs/apps/base/app/OAuthAppConnection.js +14 -13
- package/lib/cjs/apps/komoot/KomootAppConnection.js +7 -8
- package/lib/cjs/apps/trainingpeaks/TrainingPeaksAppConnection.js +4 -2
- package/lib/cjs/base/pages/service.js +2 -1
- package/lib/cjs/devices/access/service.js +24 -4
- package/lib/cjs/devices/index.js +1 -0
- package/lib/cjs/devices/known-names/index.js +22 -0
- package/lib/cjs/devices/known-names/known-device-names.js +55 -0
- package/lib/cjs/devices/known-names/matching.js +26 -0
- package/lib/cjs/devices/known-names/service.js +9 -0
- package/lib/cjs/devices/known-names/types.js +2 -0
- package/lib/cjs/devices/page/base/service.js +19 -1
- package/lib/cjs/devices/page/base/visit-log.js +6 -0
- package/lib/cjs/devices/page/mobile/statemachine.js +116 -24
- package/lib/cjs/devices/pairing/service.js +141 -52
- package/lib/cjs/devices/ride/service.js +150 -31
- package/lib/cjs/link/auth.js +129 -0
- package/lib/cjs/link/channel.js +70 -0
- package/lib/cjs/link/client/browse.js +78 -0
- package/lib/cjs/link/client/connection.js +278 -0
- package/lib/cjs/link/client/consts.js +26 -0
- package/lib/cjs/link/client/index.js +21 -0
- package/lib/cjs/link/client/media.js +78 -0
- package/lib/cjs/link/client/native-requirements.js +30 -0
- package/lib/cjs/link/client/pairing.js +230 -0
- package/lib/cjs/link/client/recovery.js +32 -0
- package/lib/cjs/link/client/service.js +1121 -0
- package/lib/cjs/link/client/store.js +108 -0
- package/lib/cjs/link/client/types.js +2 -0
- package/lib/cjs/link/client/watch.js +133 -0
- package/lib/cjs/link/consts.js +29 -0
- package/lib/cjs/link/envelope.js +49 -0
- package/lib/cjs/link/framing.js +105 -0
- package/lib/cjs/link/host/consts.js +39 -0
- package/lib/cjs/link/host/index.js +18 -0
- package/lib/cjs/link/host/pairing.js +195 -0
- package/lib/cjs/link/host/rate-limit.js +35 -0
- package/lib/cjs/link/host/service.js +842 -0
- package/lib/cjs/link/host/types.js +2 -0
- package/lib/cjs/link/host/utils.js +58 -0
- package/lib/cjs/link/index.js +24 -0
- package/lib/cjs/link/types.js +2 -0
- package/lib/cjs/link/utils.js +77 -0
- package/lib/cjs/link/version.js +41 -0
- package/lib/cjs/ride/display/service.js +66 -1
- package/lib/cjs/ride/route/RouteDisplayService.js +1 -1
- package/lib/cjs/routes/sharing/catalog.js +113 -0
- package/lib/cjs/routes/sharing/client/consts.js +18 -0
- package/lib/cjs/routes/sharing/client/descriptor.js +42 -0
- package/lib/cjs/routes/sharing/client/index.js +23 -0
- package/lib/cjs/routes/sharing/client/markers.js +68 -0
- package/lib/cjs/routes/sharing/client/repo.js +129 -0
- package/lib/cjs/routes/sharing/client/resolver.js +351 -0
- package/lib/cjs/routes/sharing/client/routes.js +125 -0
- package/lib/cjs/routes/sharing/client/service.js +759 -0
- package/lib/cjs/routes/sharing/client/types.js +2 -0
- package/lib/cjs/routes/sharing/consts.js +7 -0
- package/lib/cjs/routes/sharing/copy/index.js +17 -0
- package/lib/cjs/routes/sharing/copy/service.js +357 -0
- package/lib/cjs/routes/sharing/copy/types.js +2 -0
- package/lib/cjs/routes/sharing/descriptor.js +28 -0
- package/lib/cjs/routes/sharing/index.js +24 -0
- package/lib/cjs/routes/sharing/service.js +414 -0
- package/lib/cjs/routes/sharing/types.js +2 -0
- package/lib/cjs/routes/thumbnails/consts.js +10 -0
- package/lib/cjs/routes/thumbnails/index.js +17 -0
- package/lib/cjs/routes/thumbnails/keys.js +29 -0
- package/lib/cjs/routes/thumbnails/service.js +251 -0
- package/lib/cjs/routes/thumbnails/types.js +2 -0
- package/lib/cjs/utils/scrub.js +63 -0
- package/lib/esm/api/localLink/types.js +1 -0
- package/lib/esm/api/loopbackPipe/types.js +1 -0
- package/lib/esm/api/secureStorage/types.js +1 -0
- package/lib/esm/apps/base/api/oauth.js +7 -1
- package/lib/esm/apps/base/api/trainingpeaks/api.js +56 -0
- package/lib/esm/apps/base/app/OAuthAppConnection.js +14 -13
- package/lib/esm/apps/komoot/KomootAppConnection.js +7 -8
- package/lib/esm/apps/trainingpeaks/TrainingPeaksAppConnection.js +4 -2
- package/lib/esm/base/pages/service.js +2 -1
- package/lib/esm/devices/access/service.js +24 -4
- package/lib/esm/devices/index.js +1 -0
- package/lib/esm/devices/known-names/index.js +2 -0
- package/lib/esm/devices/known-names/known-device-names.js +52 -0
- package/lib/esm/devices/known-names/matching.js +20 -0
- package/lib/esm/devices/known-names/service.js +5 -0
- package/lib/esm/devices/known-names/types.js +1 -0
- package/lib/esm/devices/page/base/service.js +19 -1
- package/lib/esm/devices/page/base/visit-log.js +6 -0
- package/lib/esm/devices/page/mobile/statemachine.js +116 -24
- package/lib/esm/devices/pairing/service.js +141 -52
- package/lib/esm/devices/ride/service.js +150 -31
- package/lib/esm/link/auth.js +117 -0
- package/lib/esm/link/channel.js +64 -0
- package/lib/esm/link/client/browse.js +73 -0
- package/lib/esm/link/client/connection.js +273 -0
- package/lib/esm/link/client/consts.js +23 -0
- package/lib/esm/link/client/index.js +3 -0
- package/lib/esm/link/client/media.js +74 -0
- package/lib/esm/link/client/native-requirements.js +23 -0
- package/lib/esm/link/client/pairing.js +226 -0
- package/lib/esm/link/client/recovery.js +28 -0
- package/lib/esm/link/client/service.js +1116 -0
- package/lib/esm/link/client/store.js +102 -0
- package/lib/esm/link/client/types.js +1 -0
- package/lib/esm/link/client/watch.js +129 -0
- package/lib/esm/link/consts.js +26 -0
- package/lib/esm/link/envelope.js +41 -0
- package/lib/esm/link/framing.js +99 -0
- package/lib/esm/link/host/consts.js +36 -0
- package/lib/esm/link/host/index.js +2 -0
- package/lib/esm/link/host/pairing.js +191 -0
- package/lib/esm/link/host/rate-limit.js +31 -0
- package/lib/esm/link/host/service.js +837 -0
- package/lib/esm/link/host/types.js +1 -0
- package/lib/esm/link/host/utils.js +44 -0
- package/lib/esm/link/index.js +8 -0
- package/lib/esm/link/types.js +1 -0
- package/lib/esm/link/utils.js +66 -0
- package/lib/esm/link/version.js +33 -0
- package/lib/esm/ride/display/service.js +66 -1
- package/lib/esm/ride/route/RouteDisplayService.js +1 -1
- package/lib/esm/routes/sharing/catalog.js +105 -0
- package/lib/esm/routes/sharing/client/consts.js +15 -0
- package/lib/esm/routes/sharing/client/descriptor.js +36 -0
- package/lib/esm/routes/sharing/client/index.js +4 -0
- package/lib/esm/routes/sharing/client/markers.js +63 -0
- package/lib/esm/routes/sharing/client/repo.js +123 -0
- package/lib/esm/routes/sharing/client/resolver.js +347 -0
- package/lib/esm/routes/sharing/client/routes.js +121 -0
- package/lib/esm/routes/sharing/client/service.js +753 -0
- package/lib/esm/routes/sharing/client/types.js +1 -0
- package/lib/esm/routes/sharing/consts.js +4 -0
- package/lib/esm/routes/sharing/copy/index.js +1 -0
- package/lib/esm/routes/sharing/copy/service.js +353 -0
- package/lib/esm/routes/sharing/copy/types.js +1 -0
- package/lib/esm/routes/sharing/descriptor.js +24 -0
- package/lib/esm/routes/sharing/index.js +4 -0
- package/lib/esm/routes/sharing/service.js +410 -0
- package/lib/esm/routes/sharing/types.js +1 -0
- package/lib/esm/routes/thumbnails/consts.js +7 -0
- package/lib/esm/routes/thumbnails/index.js +1 -0
- package/lib/esm/routes/thumbnails/keys.js +23 -0
- package/lib/esm/routes/thumbnails/service.js +247 -0
- package/lib/esm/routes/thumbnails/types.js +1 -0
- package/lib/esm/utils/scrub.js +58 -0
- package/lib/types/api/localLink/types.d.ts +178 -0
- package/lib/types/api/loopbackPipe/types.d.ts +10 -0
- package/lib/types/api/secureStorage/types.d.ts +5 -0
- package/lib/types/apps/base/api/oauth.d.ts +3 -1
- package/lib/types/apps/base/api/trainingpeaks/api.d.ts +10 -0
- package/lib/types/apps/base/api/trainingpeaks/types.d.ts +6 -2
- package/lib/types/apps/base/app/OAuthAppConnection.d.ts +1 -0
- package/lib/types/apps/trainingpeaks/types.d.ts +3 -1
- package/lib/types/devices/access/model.d.ts +4 -0
- package/lib/types/devices/access/service.d.ts +9 -2
- package/lib/types/devices/index.d.ts +1 -0
- package/lib/types/devices/known-names/index.d.ts +3 -0
- package/lib/types/devices/known-names/known-device-names.d.ts +2 -0
- package/lib/types/devices/known-names/matching.d.ts +3 -0
- package/lib/types/devices/known-names/service.d.ts +2 -0
- package/lib/types/devices/known-names/types.d.ts +4 -0
- package/lib/types/devices/page/base/service.d.ts +3 -0
- package/lib/types/devices/page/base/visit-log.d.ts +4 -0
- package/lib/types/devices/page/mobile/statemachine.d.ts +24 -4
- package/lib/types/devices/pairing/model.d.ts +18 -0
- package/lib/types/devices/pairing/service.d.ts +23 -8
- package/lib/types/devices/ride/service.d.ts +17 -1
- package/lib/types/devices/ride/types.d.ts +11 -0
- package/lib/types/devices/types.d.ts +1 -0
- package/lib/types/link/auth.d.ts +13 -0
- package/lib/types/link/channel.d.ts +23 -0
- package/lib/types/link/client/browse.d.ts +22 -0
- package/lib/types/link/client/connection.d.ts +69 -0
- package/lib/types/link/client/consts.d.ts +23 -0
- package/lib/types/link/client/index.d.ts +4 -0
- package/lib/types/link/client/media.d.ts +23 -0
- package/lib/types/link/client/native-requirements.d.ts +3 -0
- package/lib/types/link/client/pairing.d.ts +46 -0
- package/lib/types/link/client/recovery.d.ts +10 -0
- package/lib/types/link/client/service.d.ts +177 -0
- package/lib/types/link/client/store.d.ts +20 -0
- package/lib/types/link/client/types.d.ts +139 -0
- package/lib/types/link/client/watch.d.ts +32 -0
- package/lib/types/link/consts.d.ts +16 -0
- package/lib/types/link/envelope.d.ts +6 -0
- package/lib/types/link/framing.d.ts +17 -0
- package/lib/types/link/host/consts.d.ts +34 -0
- package/lib/types/link/host/index.d.ts +3 -0
- package/lib/types/link/host/pairing.d.ts +53 -0
- package/lib/types/link/host/rate-limit.d.ts +14 -0
- package/lib/types/link/host/service.d.ts +121 -0
- package/lib/types/link/host/types.d.ts +87 -0
- package/lib/types/link/host/utils.d.ts +17 -0
- package/lib/types/link/index.d.ts +8 -0
- package/lib/types/link/types.d.ts +220 -0
- package/lib/types/link/utils.d.ts +9 -0
- package/lib/types/link/version.d.ts +6 -0
- package/lib/types/ride/display/service.d.ts +7 -0
- package/lib/types/routes/sharing/catalog.d.ts +27 -0
- package/lib/types/routes/sharing/client/consts.d.ts +15 -0
- package/lib/types/routes/sharing/client/descriptor.d.ts +13 -0
- package/lib/types/routes/sharing/client/index.d.ts +5 -0
- package/lib/types/routes/sharing/client/markers.d.ts +25 -0
- package/lib/types/routes/sharing/client/repo.d.ts +22 -0
- package/lib/types/routes/sharing/client/resolver.d.ts +41 -0
- package/lib/types/routes/sharing/client/routes.d.ts +28 -0
- package/lib/types/routes/sharing/client/service.d.ts +99 -0
- package/lib/types/routes/sharing/client/types.d.ts +99 -0
- package/lib/types/routes/sharing/consts.d.ts +4 -0
- package/lib/types/routes/sharing/copy/index.d.ts +2 -0
- package/lib/types/routes/sharing/copy/service.d.ts +55 -0
- package/lib/types/routes/sharing/copy/types.d.ts +17 -0
- package/lib/types/routes/sharing/descriptor.d.ts +4 -0
- package/lib/types/routes/sharing/index.d.ts +4 -0
- package/lib/types/routes/sharing/service.d.ts +57 -0
- package/lib/types/routes/sharing/types.d.ts +84 -0
- package/lib/types/routes/thumbnails/consts.d.ts +7 -0
- package/lib/types/routes/thumbnails/index.d.ts +2 -0
- package/lib/types/routes/thumbnails/keys.d.ts +4 -0
- package/lib/types/routes/thumbnails/service.d.ts +38 -0
- package/lib/types/routes/thumbnails/types.d.ts +9 -0
- package/lib/types/utils/scrub.d.ts +2 -0
- package/package.json +6 -6
|
@@ -70,6 +70,13 @@ let PairingPageStateMachine = (() => {
|
|
|
70
70
|
selectionTimeout;
|
|
71
71
|
pairingPromise;
|
|
72
72
|
scanningPromise;
|
|
73
|
+
epoch = 0;
|
|
74
|
+
stoppedAt;
|
|
75
|
+
stopWorkPromise;
|
|
76
|
+
resumeCallback;
|
|
77
|
+
currentAttemptId;
|
|
78
|
+
currentScanId;
|
|
79
|
+
adoptedAttempt = false;
|
|
73
80
|
constructor() {
|
|
74
81
|
this.logger = new gd_eventlog_1.EventLogger('PairingPageState');
|
|
75
82
|
}
|
|
@@ -85,10 +92,13 @@ let PairingPageStateMachine = (() => {
|
|
|
85
92
|
this.logError(new Error(`State machine in illegal state ${this.state}`), 'start');
|
|
86
93
|
return;
|
|
87
94
|
}
|
|
95
|
+
this.epoch++;
|
|
88
96
|
this.stateChangeCallback = callback;
|
|
97
|
+
this.resumeCallback = callback;
|
|
89
98
|
this.registerServiceEventHandlers();
|
|
90
99
|
this.setState('Idle');
|
|
91
|
-
this.
|
|
100
|
+
this.adoptWorkInFlight();
|
|
101
|
+
this.logIncomingEvent('start()', undefined, this.state);
|
|
92
102
|
}
|
|
93
103
|
catch (err) {
|
|
94
104
|
this.logError(err, 'start');
|
|
@@ -97,37 +107,82 @@ let PairingPageStateMachine = (() => {
|
|
|
97
107
|
stop() {
|
|
98
108
|
try {
|
|
99
109
|
const prev = this.state;
|
|
100
|
-
this.
|
|
101
|
-
delete this.
|
|
102
|
-
this.resetTimeouts();
|
|
103
|
-
delete this.pairingPromise;
|
|
104
|
-
delete this.scanningPromise;
|
|
105
|
-
this.setState('Closed');
|
|
110
|
+
this.closeSession();
|
|
111
|
+
delete this.resumeCallback;
|
|
106
112
|
this.logIncomingEvent('stop', prev, 'Closed');
|
|
107
113
|
}
|
|
108
114
|
catch (err) {
|
|
109
115
|
this.logError(err, 'stop');
|
|
110
116
|
}
|
|
111
117
|
}
|
|
118
|
+
adoptWorkInFlight() {
|
|
119
|
+
const service = this.getDevicePairing();
|
|
120
|
+
const activity = service.getActivity?.();
|
|
121
|
+
if (!activity)
|
|
122
|
+
return;
|
|
123
|
+
if (activity.pairing) {
|
|
124
|
+
this.currentAttemptId = activity.pairing.attemptId;
|
|
125
|
+
this.adoptedAttempt = true;
|
|
126
|
+
this.setState('Pairing');
|
|
127
|
+
}
|
|
128
|
+
else if (activity.scanning) {
|
|
129
|
+
this.logger.logEvent({ message: 'scan still running on start', scanId: activity.scanning.scanId, kind: activity.scanning.kind });
|
|
130
|
+
service.stopScanning().catch(err => { this.logError(err, 'start'); });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
closeSession() {
|
|
134
|
+
this.epoch++;
|
|
135
|
+
this.stoppedAt = Date.now();
|
|
136
|
+
this.unregisterServiceEventHandlers();
|
|
137
|
+
delete this.stateChangeCallback;
|
|
138
|
+
delete this.selectStateChangeCallback;
|
|
139
|
+
this.resetTimeouts();
|
|
140
|
+
this.stopDeviceSelectionTimeout();
|
|
141
|
+
this._selectState = 'Closed';
|
|
142
|
+
delete this.pairingPromise;
|
|
143
|
+
delete this.scanningPromise;
|
|
144
|
+
delete this.stopWorkPromise;
|
|
145
|
+
delete this.currentAttemptId;
|
|
146
|
+
delete this.currentScanId;
|
|
147
|
+
this.adoptedAttempt = false;
|
|
148
|
+
this.setState('Closed');
|
|
149
|
+
}
|
|
112
150
|
async pause() {
|
|
113
151
|
const prev = this._state;
|
|
114
152
|
const service = this.getDevicePairing();
|
|
115
|
-
|
|
153
|
+
this.closeSession();
|
|
154
|
+
this.logIncomingEvent('pause', prev, this.state);
|
|
155
|
+
if (prev === 'Pairing') {
|
|
116
156
|
await service.stopPairing();
|
|
117
157
|
}
|
|
118
|
-
else if (
|
|
158
|
+
else if (prev === 'Scanning') {
|
|
119
159
|
await service.stopScanning();
|
|
120
160
|
}
|
|
121
161
|
await service.stop([], true);
|
|
122
|
-
this.resetTimeouts();
|
|
123
|
-
this.setState('Closed');
|
|
124
|
-
this.logIncomingEvent('pause', prev, this.state);
|
|
125
162
|
}
|
|
126
163
|
resume() {
|
|
127
164
|
const prev = this._state;
|
|
128
|
-
|
|
165
|
+
if (prev !== 'Closed' || !this.resumeCallback)
|
|
166
|
+
return;
|
|
167
|
+
this.start(this.resumeCallback);
|
|
129
168
|
this.logIncomingEvent('resume', prev, this.state);
|
|
130
169
|
}
|
|
170
|
+
isStale(epoch, fn) {
|
|
171
|
+
if (epoch === this.epoch && this._state !== 'Closed')
|
|
172
|
+
return false;
|
|
173
|
+
this.logger.logEvent({ message: 'stale continuation dropped', fn, msSinceStop: this.stoppedAt === undefined ? -1 : Date.now() - this.stoppedAt });
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
stopWork(stopFn) {
|
|
177
|
+
if (this.stopWorkPromise !== undefined)
|
|
178
|
+
return this.stopWorkPromise;
|
|
179
|
+
const promise = Promise.resolve(stopFn()).finally(() => {
|
|
180
|
+
if (this.stopWorkPromise === promise)
|
|
181
|
+
delete this.stopWorkPromise;
|
|
182
|
+
});
|
|
183
|
+
this.stopWorkPromise = promise;
|
|
184
|
+
return promise;
|
|
185
|
+
}
|
|
131
186
|
setState(state) {
|
|
132
187
|
const prev = this._state;
|
|
133
188
|
this._state = state;
|
|
@@ -176,6 +231,8 @@ let PairingPageStateMachine = (() => {
|
|
|
176
231
|
this.internalEvents.emit(event);
|
|
177
232
|
}
|
|
178
233
|
onPageReady() {
|
|
234
|
+
if (this.state === 'Pairing' && this.adoptedAttempt)
|
|
235
|
+
return;
|
|
179
236
|
if (this.state !== 'Idle') {
|
|
180
237
|
this.logError(new Error('Illegal state'), 'onPageStartedEventHandler');
|
|
181
238
|
return;
|
|
@@ -226,28 +283,44 @@ let PairingPageStateMachine = (() => {
|
|
|
226
283
|
}
|
|
227
284
|
else if (!this.pairingPromise) {
|
|
228
285
|
this.setState('Pairing');
|
|
229
|
-
|
|
286
|
+
const promise = Promise.resolve(service.startPairing(adapters, {}))
|
|
230
287
|
.catch(err => { this.logError(err, 'startPairing'); })
|
|
231
|
-
.finally(() => {
|
|
288
|
+
.finally(() => { if (this.pairingPromise === promise)
|
|
289
|
+
delete this.pairingPromise; });
|
|
290
|
+
this.pairingPromise = promise;
|
|
232
291
|
}
|
|
233
292
|
}
|
|
234
293
|
checkScanningProgress(service, adapters) {
|
|
235
294
|
if (!this.scanningPromise) {
|
|
236
295
|
this.setState('Scanning');
|
|
237
296
|
const props = this.selectState === 'Active' ? { deviceList: true } : {};
|
|
238
|
-
|
|
297
|
+
const promise = Promise.resolve(service.startScanning(adapters, props))
|
|
239
298
|
.catch(err => { this.logError(err, 'startScanning'); })
|
|
240
|
-
.finally(() => {
|
|
299
|
+
.finally(() => { if (this.scanningPromise === promise)
|
|
300
|
+
delete this.scanningPromise; });
|
|
301
|
+
this.scanningPromise = promise;
|
|
241
302
|
}
|
|
242
303
|
}
|
|
243
|
-
|
|
304
|
+
isForeign(event, id, current) {
|
|
305
|
+
if (id === undefined || id === current)
|
|
306
|
+
return false;
|
|
307
|
+
this.logger.logEvent({ message: 'foreign attempt event ignored', event, attemptId: id });
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
onPairingStarted(payload) {
|
|
311
|
+
if (payload?.attemptId !== undefined && this.state === 'Pairing')
|
|
312
|
+
this.currentAttemptId = payload.attemptId;
|
|
244
313
|
if (this.state !== 'Pairing') {
|
|
245
314
|
this.logError(new Error('Illegal state'), 'onPairingStarted');
|
|
246
315
|
return;
|
|
247
316
|
}
|
|
248
317
|
this.sendUpdate();
|
|
249
318
|
}
|
|
250
|
-
onPairingFinished() {
|
|
319
|
+
onPairingFinished(payload) {
|
|
320
|
+
if (this.state === 'Closed' || this.isForeign('pairing-done', payload?.attemptId, this.currentAttemptId))
|
|
321
|
+
return;
|
|
322
|
+
delete this.currentAttemptId;
|
|
323
|
+
this.adoptedAttempt = false;
|
|
251
324
|
const prev = this.state;
|
|
252
325
|
this.setState('Idle');
|
|
253
326
|
if (this._selectState === 'Waiting') {
|
|
@@ -258,6 +331,7 @@ let PairingPageStateMachine = (() => {
|
|
|
258
331
|
}
|
|
259
332
|
else {
|
|
260
333
|
this.logger.logEvent({ message: 'setup retry timeout', delay: PAIRING_RETRY_DELAY });
|
|
334
|
+
this.resetTimeouts();
|
|
261
335
|
this.retryTimeout = setTimeout(() => {
|
|
262
336
|
this.onRetry(prev);
|
|
263
337
|
}, PAIRING_RETRY_DELAY);
|
|
@@ -269,15 +343,21 @@ let PairingPageStateMachine = (() => {
|
|
|
269
343
|
if (this.stateChangeCallback)
|
|
270
344
|
this.stateChangeCallback();
|
|
271
345
|
}
|
|
272
|
-
onScanningStarted() {
|
|
346
|
+
onScanningStarted(payload) {
|
|
347
|
+
if (payload?.scanId !== undefined && this.state === 'Scanning')
|
|
348
|
+
this.currentScanId = payload.scanId;
|
|
273
349
|
if (this.state !== 'Scanning') {
|
|
274
350
|
this.logError(new Error('Illegal state'), 'onScanningStarted');
|
|
275
351
|
return;
|
|
276
352
|
}
|
|
277
353
|
}
|
|
278
|
-
onScanningFinished() {
|
|
354
|
+
onScanningFinished(payload) {
|
|
355
|
+
if (this.state === 'Closed' || this.isForeign('scanning-done', payload?.scanId, this.currentScanId))
|
|
356
|
+
return;
|
|
357
|
+
delete this.currentScanId;
|
|
279
358
|
const prev = this.state;
|
|
280
359
|
this.setState('Idle');
|
|
360
|
+
this.resetTimeouts();
|
|
281
361
|
this.retryTimeout = setTimeout(() => {
|
|
282
362
|
this.onRetry(prev);
|
|
283
363
|
}, SCANNING_RETRY_DELAY);
|
|
@@ -291,6 +371,8 @@ let PairingPageStateMachine = (() => {
|
|
|
291
371
|
this.performCheck(prevState);
|
|
292
372
|
}
|
|
293
373
|
onDeviceSelectionOpened(onSelectionStateChanged) {
|
|
374
|
+
if (this.state === 'Closed')
|
|
375
|
+
return;
|
|
294
376
|
if (this.state === 'Pairing') {
|
|
295
377
|
this.startDeviceSelectionTimeout();
|
|
296
378
|
this._selectState = 'Waiting';
|
|
@@ -304,18 +386,25 @@ let PairingPageStateMachine = (() => {
|
|
|
304
386
|
}
|
|
305
387
|
}
|
|
306
388
|
async onDeviceSelectionClosed() {
|
|
389
|
+
const epoch = this.epoch;
|
|
307
390
|
const prev = this.state;
|
|
308
391
|
this._selectState = 'Closed';
|
|
309
392
|
delete this.selectStateChangeCallback;
|
|
310
393
|
this.stopDeviceSelectionTimeout();
|
|
311
394
|
if (this.state === 'Pairing') {
|
|
312
|
-
await this.getDevicePairing().stopPairing();
|
|
395
|
+
await this.stopWork(() => this.getDevicePairing().stopPairing());
|
|
396
|
+
if (this.isStale(epoch, 'onDeviceSelectionClosed'))
|
|
397
|
+
return;
|
|
313
398
|
this.setState('Idle');
|
|
314
399
|
}
|
|
315
400
|
else if (this.state === 'Scanning') {
|
|
316
|
-
await this.getDevicePairing().stopScanning();
|
|
401
|
+
await this.stopWork(() => this.getDevicePairing().stopScanning());
|
|
402
|
+
if (this.isStale(epoch, 'onDeviceSelectionClosed'))
|
|
403
|
+
return;
|
|
317
404
|
this.setState('Idle');
|
|
318
405
|
}
|
|
406
|
+
else if (this.state === 'Closed')
|
|
407
|
+
return;
|
|
319
408
|
this.logIncomingEvent('list-close', prev, this.state);
|
|
320
409
|
this.performCheck();
|
|
321
410
|
}
|
|
@@ -329,6 +418,7 @@ let PairingPageStateMachine = (() => {
|
|
|
329
418
|
delete this.selectionTimeout;
|
|
330
419
|
}
|
|
331
420
|
async onDeviceSelectionTimeout() {
|
|
421
|
+
const epoch = this.epoch;
|
|
332
422
|
this.stopDeviceSelectionTimeout();
|
|
333
423
|
this.logIncomingEvent('list-timeout', this.state, this.state);
|
|
334
424
|
if (this.state === 'Idle') {
|
|
@@ -336,7 +426,9 @@ let PairingPageStateMachine = (() => {
|
|
|
336
426
|
this.performCheck();
|
|
337
427
|
}
|
|
338
428
|
else if (this.state === 'Pairing') {
|
|
339
|
-
await this.getDevicePairing().stopPairing();
|
|
429
|
+
await this.stopWork(() => this.getDevicePairing().stopPairing());
|
|
430
|
+
if (this.isStale(epoch, 'onDeviceSelectionTimeout'))
|
|
431
|
+
return;
|
|
340
432
|
this._selectState = 'Active';
|
|
341
433
|
this.performCheck();
|
|
342
434
|
}
|