incyclist-services 1.9.34 → 1.9.35

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 (218) hide show
  1. package/lib/cjs/api/localLink/types.js +2 -0
  2. package/lib/cjs/api/loopbackPipe/types.js +2 -0
  3. package/lib/cjs/api/secureStorage/types.js +2 -0
  4. package/lib/cjs/apps/base/app/OAuthAppConnection.js +13 -11
  5. package/lib/cjs/apps/komoot/KomootAppConnection.js +7 -8
  6. package/lib/cjs/base/pages/service.js +2 -1
  7. package/lib/cjs/devices/access/service.js +24 -4
  8. package/lib/cjs/devices/index.js +1 -0
  9. package/lib/cjs/devices/known-names/index.js +22 -0
  10. package/lib/cjs/devices/known-names/known-device-names.js +55 -0
  11. package/lib/cjs/devices/known-names/matching.js +26 -0
  12. package/lib/cjs/devices/known-names/service.js +9 -0
  13. package/lib/cjs/devices/known-names/types.js +2 -0
  14. package/lib/cjs/devices/page/base/service.js +19 -1
  15. package/lib/cjs/devices/page/base/visit-log.js +6 -0
  16. package/lib/cjs/devices/page/mobile/statemachine.js +116 -24
  17. package/lib/cjs/devices/pairing/service.js +141 -52
  18. package/lib/cjs/devices/ride/service.js +137 -27
  19. package/lib/cjs/link/auth.js +129 -0
  20. package/lib/cjs/link/channel.js +70 -0
  21. package/lib/cjs/link/client/browse.js +78 -0
  22. package/lib/cjs/link/client/connection.js +278 -0
  23. package/lib/cjs/link/client/consts.js +26 -0
  24. package/lib/cjs/link/client/index.js +21 -0
  25. package/lib/cjs/link/client/media.js +78 -0
  26. package/lib/cjs/link/client/native-requirements.js +30 -0
  27. package/lib/cjs/link/client/pairing.js +230 -0
  28. package/lib/cjs/link/client/recovery.js +32 -0
  29. package/lib/cjs/link/client/service.js +1121 -0
  30. package/lib/cjs/link/client/store.js +108 -0
  31. package/lib/cjs/link/client/types.js +2 -0
  32. package/lib/cjs/link/client/watch.js +133 -0
  33. package/lib/cjs/link/consts.js +29 -0
  34. package/lib/cjs/link/envelope.js +49 -0
  35. package/lib/cjs/link/framing.js +105 -0
  36. package/lib/cjs/link/host/consts.js +39 -0
  37. package/lib/cjs/link/host/index.js +18 -0
  38. package/lib/cjs/link/host/pairing.js +195 -0
  39. package/lib/cjs/link/host/rate-limit.js +35 -0
  40. package/lib/cjs/link/host/service.js +842 -0
  41. package/lib/cjs/link/host/types.js +2 -0
  42. package/lib/cjs/link/host/utils.js +58 -0
  43. package/lib/cjs/link/index.js +24 -0
  44. package/lib/cjs/link/types.js +2 -0
  45. package/lib/cjs/link/utils.js +77 -0
  46. package/lib/cjs/link/version.js +41 -0
  47. package/lib/cjs/ride/display/service.js +66 -1
  48. package/lib/cjs/ride/route/RouteDisplayService.js +1 -1
  49. package/lib/cjs/routes/sharing/catalog.js +113 -0
  50. package/lib/cjs/routes/sharing/client/consts.js +18 -0
  51. package/lib/cjs/routes/sharing/client/descriptor.js +42 -0
  52. package/lib/cjs/routes/sharing/client/index.js +23 -0
  53. package/lib/cjs/routes/sharing/client/markers.js +68 -0
  54. package/lib/cjs/routes/sharing/client/repo.js +129 -0
  55. package/lib/cjs/routes/sharing/client/resolver.js +351 -0
  56. package/lib/cjs/routes/sharing/client/routes.js +125 -0
  57. package/lib/cjs/routes/sharing/client/service.js +759 -0
  58. package/lib/cjs/routes/sharing/client/types.js +2 -0
  59. package/lib/cjs/routes/sharing/consts.js +7 -0
  60. package/lib/cjs/routes/sharing/copy/index.js +17 -0
  61. package/lib/cjs/routes/sharing/copy/service.js +357 -0
  62. package/lib/cjs/routes/sharing/copy/types.js +2 -0
  63. package/lib/cjs/routes/sharing/descriptor.js +28 -0
  64. package/lib/cjs/routes/sharing/index.js +24 -0
  65. package/lib/cjs/routes/sharing/service.js +414 -0
  66. package/lib/cjs/routes/sharing/types.js +2 -0
  67. package/lib/cjs/routes/thumbnails/consts.js +10 -0
  68. package/lib/cjs/routes/thumbnails/index.js +17 -0
  69. package/lib/cjs/routes/thumbnails/keys.js +29 -0
  70. package/lib/cjs/routes/thumbnails/service.js +251 -0
  71. package/lib/cjs/routes/thumbnails/types.js +2 -0
  72. package/lib/cjs/utils/scrub.js +63 -0
  73. package/lib/esm/api/localLink/types.js +1 -0
  74. package/lib/esm/api/loopbackPipe/types.js +1 -0
  75. package/lib/esm/api/secureStorage/types.js +1 -0
  76. package/lib/esm/apps/base/app/OAuthAppConnection.js +13 -11
  77. package/lib/esm/apps/komoot/KomootAppConnection.js +7 -8
  78. package/lib/esm/base/pages/service.js +2 -1
  79. package/lib/esm/devices/access/service.js +24 -4
  80. package/lib/esm/devices/index.js +1 -0
  81. package/lib/esm/devices/known-names/index.js +2 -0
  82. package/lib/esm/devices/known-names/known-device-names.js +52 -0
  83. package/lib/esm/devices/known-names/matching.js +20 -0
  84. package/lib/esm/devices/known-names/service.js +5 -0
  85. package/lib/esm/devices/known-names/types.js +1 -0
  86. package/lib/esm/devices/page/base/service.js +19 -1
  87. package/lib/esm/devices/page/base/visit-log.js +6 -0
  88. package/lib/esm/devices/page/mobile/statemachine.js +116 -24
  89. package/lib/esm/devices/pairing/service.js +141 -52
  90. package/lib/esm/devices/ride/service.js +137 -27
  91. package/lib/esm/link/auth.js +117 -0
  92. package/lib/esm/link/channel.js +64 -0
  93. package/lib/esm/link/client/browse.js +73 -0
  94. package/lib/esm/link/client/connection.js +273 -0
  95. package/lib/esm/link/client/consts.js +23 -0
  96. package/lib/esm/link/client/index.js +3 -0
  97. package/lib/esm/link/client/media.js +74 -0
  98. package/lib/esm/link/client/native-requirements.js +23 -0
  99. package/lib/esm/link/client/pairing.js +226 -0
  100. package/lib/esm/link/client/recovery.js +28 -0
  101. package/lib/esm/link/client/service.js +1116 -0
  102. package/lib/esm/link/client/store.js +102 -0
  103. package/lib/esm/link/client/types.js +1 -0
  104. package/lib/esm/link/client/watch.js +129 -0
  105. package/lib/esm/link/consts.js +26 -0
  106. package/lib/esm/link/envelope.js +41 -0
  107. package/lib/esm/link/framing.js +99 -0
  108. package/lib/esm/link/host/consts.js +36 -0
  109. package/lib/esm/link/host/index.js +2 -0
  110. package/lib/esm/link/host/pairing.js +191 -0
  111. package/lib/esm/link/host/rate-limit.js +31 -0
  112. package/lib/esm/link/host/service.js +837 -0
  113. package/lib/esm/link/host/types.js +1 -0
  114. package/lib/esm/link/host/utils.js +44 -0
  115. package/lib/esm/link/index.js +8 -0
  116. package/lib/esm/link/types.js +1 -0
  117. package/lib/esm/link/utils.js +66 -0
  118. package/lib/esm/link/version.js +33 -0
  119. package/lib/esm/ride/display/service.js +66 -1
  120. package/lib/esm/ride/route/RouteDisplayService.js +1 -1
  121. package/lib/esm/routes/sharing/catalog.js +105 -0
  122. package/lib/esm/routes/sharing/client/consts.js +15 -0
  123. package/lib/esm/routes/sharing/client/descriptor.js +36 -0
  124. package/lib/esm/routes/sharing/client/index.js +4 -0
  125. package/lib/esm/routes/sharing/client/markers.js +63 -0
  126. package/lib/esm/routes/sharing/client/repo.js +123 -0
  127. package/lib/esm/routes/sharing/client/resolver.js +347 -0
  128. package/lib/esm/routes/sharing/client/routes.js +121 -0
  129. package/lib/esm/routes/sharing/client/service.js +753 -0
  130. package/lib/esm/routes/sharing/client/types.js +1 -0
  131. package/lib/esm/routes/sharing/consts.js +4 -0
  132. package/lib/esm/routes/sharing/copy/index.js +1 -0
  133. package/lib/esm/routes/sharing/copy/service.js +353 -0
  134. package/lib/esm/routes/sharing/copy/types.js +1 -0
  135. package/lib/esm/routes/sharing/descriptor.js +24 -0
  136. package/lib/esm/routes/sharing/index.js +4 -0
  137. package/lib/esm/routes/sharing/service.js +410 -0
  138. package/lib/esm/routes/sharing/types.js +1 -0
  139. package/lib/esm/routes/thumbnails/consts.js +7 -0
  140. package/lib/esm/routes/thumbnails/index.js +1 -0
  141. package/lib/esm/routes/thumbnails/keys.js +23 -0
  142. package/lib/esm/routes/thumbnails/service.js +247 -0
  143. package/lib/esm/routes/thumbnails/types.js +1 -0
  144. package/lib/esm/utils/scrub.js +58 -0
  145. package/lib/types/api/localLink/types.d.ts +178 -0
  146. package/lib/types/api/loopbackPipe/types.d.ts +10 -0
  147. package/lib/types/api/secureStorage/types.d.ts +5 -0
  148. package/lib/types/apps/base/app/OAuthAppConnection.d.ts +1 -0
  149. package/lib/types/devices/access/model.d.ts +4 -0
  150. package/lib/types/devices/access/service.d.ts +9 -2
  151. package/lib/types/devices/index.d.ts +1 -0
  152. package/lib/types/devices/known-names/index.d.ts +3 -0
  153. package/lib/types/devices/known-names/known-device-names.d.ts +2 -0
  154. package/lib/types/devices/known-names/matching.d.ts +3 -0
  155. package/lib/types/devices/known-names/service.d.ts +2 -0
  156. package/lib/types/devices/known-names/types.d.ts +4 -0
  157. package/lib/types/devices/page/base/service.d.ts +3 -0
  158. package/lib/types/devices/page/base/visit-log.d.ts +4 -0
  159. package/lib/types/devices/page/mobile/statemachine.d.ts +24 -4
  160. package/lib/types/devices/pairing/model.d.ts +18 -0
  161. package/lib/types/devices/pairing/service.d.ts +23 -8
  162. package/lib/types/devices/ride/service.d.ts +15 -1
  163. package/lib/types/devices/ride/types.d.ts +11 -0
  164. package/lib/types/devices/types.d.ts +1 -0
  165. package/lib/types/link/auth.d.ts +13 -0
  166. package/lib/types/link/channel.d.ts +23 -0
  167. package/lib/types/link/client/browse.d.ts +22 -0
  168. package/lib/types/link/client/connection.d.ts +69 -0
  169. package/lib/types/link/client/consts.d.ts +23 -0
  170. package/lib/types/link/client/index.d.ts +4 -0
  171. package/lib/types/link/client/media.d.ts +23 -0
  172. package/lib/types/link/client/native-requirements.d.ts +3 -0
  173. package/lib/types/link/client/pairing.d.ts +46 -0
  174. package/lib/types/link/client/recovery.d.ts +10 -0
  175. package/lib/types/link/client/service.d.ts +177 -0
  176. package/lib/types/link/client/store.d.ts +20 -0
  177. package/lib/types/link/client/types.d.ts +139 -0
  178. package/lib/types/link/client/watch.d.ts +32 -0
  179. package/lib/types/link/consts.d.ts +16 -0
  180. package/lib/types/link/envelope.d.ts +6 -0
  181. package/lib/types/link/framing.d.ts +17 -0
  182. package/lib/types/link/host/consts.d.ts +34 -0
  183. package/lib/types/link/host/index.d.ts +3 -0
  184. package/lib/types/link/host/pairing.d.ts +53 -0
  185. package/lib/types/link/host/rate-limit.d.ts +14 -0
  186. package/lib/types/link/host/service.d.ts +121 -0
  187. package/lib/types/link/host/types.d.ts +87 -0
  188. package/lib/types/link/host/utils.d.ts +17 -0
  189. package/lib/types/link/index.d.ts +8 -0
  190. package/lib/types/link/types.d.ts +220 -0
  191. package/lib/types/link/utils.d.ts +9 -0
  192. package/lib/types/link/version.d.ts +6 -0
  193. package/lib/types/ride/display/service.d.ts +7 -0
  194. package/lib/types/routes/sharing/catalog.d.ts +27 -0
  195. package/lib/types/routes/sharing/client/consts.d.ts +15 -0
  196. package/lib/types/routes/sharing/client/descriptor.d.ts +13 -0
  197. package/lib/types/routes/sharing/client/index.d.ts +5 -0
  198. package/lib/types/routes/sharing/client/markers.d.ts +25 -0
  199. package/lib/types/routes/sharing/client/repo.d.ts +22 -0
  200. package/lib/types/routes/sharing/client/resolver.d.ts +41 -0
  201. package/lib/types/routes/sharing/client/routes.d.ts +28 -0
  202. package/lib/types/routes/sharing/client/service.d.ts +99 -0
  203. package/lib/types/routes/sharing/client/types.d.ts +99 -0
  204. package/lib/types/routes/sharing/consts.d.ts +4 -0
  205. package/lib/types/routes/sharing/copy/index.d.ts +2 -0
  206. package/lib/types/routes/sharing/copy/service.d.ts +55 -0
  207. package/lib/types/routes/sharing/copy/types.d.ts +17 -0
  208. package/lib/types/routes/sharing/descriptor.d.ts +4 -0
  209. package/lib/types/routes/sharing/index.d.ts +4 -0
  210. package/lib/types/routes/sharing/service.d.ts +57 -0
  211. package/lib/types/routes/sharing/types.d.ts +84 -0
  212. package/lib/types/routes/thumbnails/consts.d.ts +7 -0
  213. package/lib/types/routes/thumbnails/index.d.ts +2 -0
  214. package/lib/types/routes/thumbnails/keys.d.ts +4 -0
  215. package/lib/types/routes/thumbnails/service.d.ts +38 -0
  216. package/lib/types/routes/thumbnails/types.d.ts +9 -0
  217. package/lib/types/utils/scrub.d.ts +2 -0
  218. 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.logIncomingEvent('start()', undefined, 'Idle');
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.unregisterServiceEventHandlers();
101
- delete this.stateChangeCallback;
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
- if (this.state === 'Pairing') {
153
+ this.closeSession();
154
+ this.logIncomingEvent('pause', prev, this.state);
155
+ if (prev === 'Pairing') {
116
156
  await service.stopPairing();
117
157
  }
118
- else if (this.state === 'Scanning') {
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
- this.setState('Idle');
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
- this.pairingPromise = Promise.resolve(service.startPairing(adapters, {}))
286
+ const promise = Promise.resolve(service.startPairing(adapters, {}))
230
287
  .catch(err => { this.logError(err, 'startPairing'); })
231
- .finally(() => { delete this.pairingPromise; });
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
- this.scanningPromise = Promise.resolve(service.startScanning(adapters, props))
297
+ const promise = Promise.resolve(service.startScanning(adapters, props))
239
298
  .catch(err => { this.logError(err, 'startScanning'); })
240
- .finally(() => { delete this.scanningPromise; });
299
+ .finally(() => { if (this.scanningPromise === promise)
300
+ delete this.scanningPromise; });
301
+ this.scanningPromise = promise;
241
302
  }
242
303
  }
243
- onPairingStarted() {
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
  }