incyclist-services 1.7.57 → 1.7.59

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.
@@ -222,7 +222,7 @@ let DeviceAccessService = (() => {
222
222
  this.interfaces[ifaceName].state = 'connecting';
223
223
  this.emit('interface-changed', ifaceName, { ...this.interfaces[ifaceName], state: 'connecting' });
224
224
  await impl.disconnect();
225
- const connected = await impl.connect();
225
+ const connected = await impl.connect(true);
226
226
  const state = connected ? 'connected' : 'disconnected';
227
227
  this.interfaces[ifaceName].state = state;
228
228
  this.emit('interface-changed', ifaceName, this.interfaces[ifaceName]);
@@ -205,9 +205,10 @@ let DevicePairingService = (() => {
205
205
  async prepareStart(adapterFilter = []) {
206
206
  const stillPairing = this.isPairing();
207
207
  const stillScanning = this.isScanning();
208
+ const adapters = this.state?.adapters ?? [];
208
209
  this.logEvent({ message: 'Stop Pairing (OK)', stillPairing, stillScanning });
209
210
  try {
210
- this.pauseAdapters(this.state.adapters.filter(a => !adapterFilter.includes(a.udid)));
211
+ this.pauseAdapters(adapters.filter(a => !adapterFilter.includes(a.udid)));
211
212
  if (this.isPairing()) {
212
213
  this.removePairingCallbacks();
213
214
  }
@@ -42,7 +42,7 @@ const display_1 = require("../display");
42
42
  const sleep_1 = require("../../utils/sleep");
43
43
  const api_1 = require("../../api");
44
44
  const monitoring_1 = require("../../monitoring");
45
- const BACKGROUND_PAUSE_TIMEOUT_MS = 60000;
45
+ const BACKGROUND_PAUSE_TIMEOUT_MS = 300000;
46
46
  let RidePageService = (() => {
47
47
  let _classDecorators = [decorators_1.Singleton];
48
48
  let _classDescriptor;
@@ -50,6 +50,7 @@ const monitoring_1 = require("../monitoring");
50
50
  const appstate_1 = require("../appstate");
51
51
  const pages_1 = require("../base/pages");
52
52
  const utils_1 = require("../utils");
53
+ const BACKGROUND_PAUSE_TIMEOUT_MS = 300000;
53
54
  let UserInterfaceServcie = (() => {
54
55
  let _classDecorators = [decorators_1.Singleton];
55
56
  let _classDescriptor;
@@ -91,6 +92,8 @@ let UserInterfaceServcie = (() => {
91
92
  heartbeatIv;
92
93
  appFeatures;
93
94
  appState = 'Inactive';
95
+ backgroundTimer;
96
+ backgroundPausedByService = false;
94
97
  constructor() {
95
98
  super('Incyclist');
96
99
  this.bindings = this.getBindings();
@@ -162,8 +165,10 @@ let UserInterfaceServcie = (() => {
162
165
  this.appState = 'Background';
163
166
  this.logEvent({ message: 'onAppPause called' });
164
167
  this.stopHeartbeatWorker();
165
- await pages_1.IncyclistPageService.pausePage();
166
- (0, devices_1.useDeviceAccess)().disconnect();
168
+ this.backgroundTimer = setTimeout(() => {
169
+ this.backgroundPausedByService = true;
170
+ this.pause();
171
+ }, BACKGROUND_PAUSE_TIMEOUT_MS);
167
172
  }
168
173
  catch (err) {
169
174
  this.logError(err, 'onAppPause');
@@ -178,11 +183,18 @@ let UserInterfaceServcie = (() => {
178
183
  this.isTerminated = false;
179
184
  this.isTerminating = false;
180
185
  try {
181
- this.appState = 'Active';
186
+ let resumeRequired = true;
187
+ if (this.backgroundTimer) {
188
+ clearTimeout(this.backgroundTimer);
189
+ resumeRequired = false;
190
+ }
182
191
  this.logEvent({ message: 'onAppResume called' });
183
- (0, devices_1.useDeviceAccess)().connect();
184
- pages_1.IncyclistPageService.resumePage();
185
192
  this.startHeartbeatWorker();
193
+ this.backgroundPausedByService = false;
194
+ this.appState = 'Active';
195
+ if (resumeRequired) {
196
+ this.resume();
197
+ }
186
198
  }
187
199
  catch (err) {
188
200
  this.logError(err, 'onAppPause');
@@ -217,6 +229,18 @@ let UserInterfaceServcie = (() => {
217
229
  this.logError(err, 'onSessionStart');
218
230
  }
219
231
  }
232
+ async pause() {
233
+ await pages_1.IncyclistPageService.pausePage();
234
+ await (0, devices_1.useDeviceAccess)().disconnect();
235
+ if (this.getMessageQueue().disconnect)
236
+ this.getMessageQueue().disconnect();
237
+ }
238
+ async resume() {
239
+ if (this.getMessageQueue().connect)
240
+ this.getMessageQueue().connect();
241
+ await (0, devices_1.useDeviceAccess)().connect();
242
+ await pages_1.IncyclistPageService.resumePage();
243
+ }
220
244
  startHeartbeatWorker() {
221
245
  if (this.heartbeatIv)
222
246
  return;
@@ -442,7 +442,7 @@ class VideoSyncHelper extends service_1.IncyclistService {
442
442
  }
443
443
  const s0 = mapping.distance;
444
444
  const v = mapping.videoSpeed / 3.6;
445
- const t = mapping.time + (distance - s0) / v;
445
+ const t = mapping.time === 0 ? mapping.time + distance / v : mapping.time + (distance - s0) / v;
446
446
  if (!Number.isNaN(t)) {
447
447
  return t;
448
448
  }
@@ -216,7 +216,7 @@ let DeviceAccessService = (() => {
216
216
  this.interfaces[ifaceName].state = 'connecting';
217
217
  this.emit('interface-changed', ifaceName, { ...this.interfaces[ifaceName], state: 'connecting' });
218
218
  await impl.disconnect();
219
- const connected = await impl.connect();
219
+ const connected = await impl.connect(true);
220
220
  const state = connected ? 'connected' : 'disconnected';
221
221
  this.interfaces[ifaceName].state = state;
222
222
  this.emit('interface-changed', ifaceName, this.interfaces[ifaceName]);
@@ -199,9 +199,10 @@ let DevicePairingService = (() => {
199
199
  async prepareStart(adapterFilter = []) {
200
200
  const stillPairing = this.isPairing();
201
201
  const stillScanning = this.isScanning();
202
+ const adapters = this.state?.adapters ?? [];
202
203
  this.logEvent({ message: 'Stop Pairing (OK)', stillPairing, stillScanning });
203
204
  try {
204
- this.pauseAdapters(this.state.adapters.filter(a => !adapterFilter.includes(a.udid)));
205
+ this.pauseAdapters(adapters.filter(a => !adapterFilter.includes(a.udid)));
205
206
  if (this.isPairing()) {
206
207
  this.removePairingCallbacks();
207
208
  }
@@ -39,7 +39,7 @@ import { useRideDisplay } from "../display";
39
39
  import { sleep } from "../../utils/sleep";
40
40
  import { getBindings } from "../../api";
41
41
  import { useOnlineStatusMonitoring } from "../../monitoring";
42
- const BACKGROUND_PAUSE_TIMEOUT_MS = 60000;
42
+ const BACKGROUND_PAUSE_TIMEOUT_MS = 300000;
43
43
  let RidePageService = (() => {
44
44
  let _classDecorators = [Singleton];
45
45
  let _classDescriptor;
@@ -47,6 +47,7 @@ import { useOnlineStatusMonitoring } from "../monitoring";
47
47
  import { useAppState } from "../appstate";
48
48
  import { IncyclistPageService } from "../base/pages";
49
49
  import { waitNextTick } from "../utils";
50
+ const BACKGROUND_PAUSE_TIMEOUT_MS = 300000;
50
51
  let UserInterfaceServcie = (() => {
51
52
  let _classDecorators = [Singleton];
52
53
  let _classDescriptor;
@@ -88,6 +89,8 @@ let UserInterfaceServcie = (() => {
88
89
  heartbeatIv;
89
90
  appFeatures;
90
91
  appState = 'Inactive';
92
+ backgroundTimer;
93
+ backgroundPausedByService = false;
91
94
  constructor() {
92
95
  super('Incyclist');
93
96
  this.bindings = this.getBindings();
@@ -159,8 +162,10 @@ let UserInterfaceServcie = (() => {
159
162
  this.appState = 'Background';
160
163
  this.logEvent({ message: 'onAppPause called' });
161
164
  this.stopHeartbeatWorker();
162
- await IncyclistPageService.pausePage();
163
- useDeviceAccess().disconnect();
165
+ this.backgroundTimer = setTimeout(() => {
166
+ this.backgroundPausedByService = true;
167
+ this.pause();
168
+ }, BACKGROUND_PAUSE_TIMEOUT_MS);
164
169
  }
165
170
  catch (err) {
166
171
  this.logError(err, 'onAppPause');
@@ -175,11 +180,18 @@ let UserInterfaceServcie = (() => {
175
180
  this.isTerminated = false;
176
181
  this.isTerminating = false;
177
182
  try {
178
- this.appState = 'Active';
183
+ let resumeRequired = true;
184
+ if (this.backgroundTimer) {
185
+ clearTimeout(this.backgroundTimer);
186
+ resumeRequired = false;
187
+ }
179
188
  this.logEvent({ message: 'onAppResume called' });
180
- useDeviceAccess().connect();
181
- IncyclistPageService.resumePage();
182
189
  this.startHeartbeatWorker();
190
+ this.backgroundPausedByService = false;
191
+ this.appState = 'Active';
192
+ if (resumeRequired) {
193
+ this.resume();
194
+ }
183
195
  }
184
196
  catch (err) {
185
197
  this.logError(err, 'onAppPause');
@@ -214,6 +226,18 @@ let UserInterfaceServcie = (() => {
214
226
  this.logError(err, 'onSessionStart');
215
227
  }
216
228
  }
229
+ async pause() {
230
+ await IncyclistPageService.pausePage();
231
+ await useDeviceAccess().disconnect();
232
+ if (this.getMessageQueue().disconnect)
233
+ this.getMessageQueue().disconnect();
234
+ }
235
+ async resume() {
236
+ if (this.getMessageQueue().connect)
237
+ this.getMessageQueue().connect();
238
+ await useDeviceAccess().connect();
239
+ await IncyclistPageService.resumePage();
240
+ }
217
241
  startHeartbeatWorker() {
218
242
  if (this.heartbeatIv)
219
243
  return;
@@ -439,7 +439,7 @@ export class VideoSyncHelper extends IncyclistService {
439
439
  }
440
440
  const s0 = mapping.distance;
441
441
  const v = mapping.videoSpeed / 3.6;
442
- const t = mapping.time + (distance - s0) / v;
442
+ const t = mapping.time === 0 ? mapping.time + distance / v : mapping.time + (distance - s0) / v;
443
443
  if (!Number.isNaN(t)) {
444
444
  return t;
445
445
  }
@@ -4,4 +4,6 @@ export interface IMessageQueueBinding extends EventEmitter {
4
4
  subscribe(topic: string): any;
5
5
  unsubscribe(topic: string): any;
6
6
  publish(topic: string, payload: object): any;
7
+ connect?(): Promise<boolean>;
8
+ disconnect?(): void;
7
9
  }
@@ -18,6 +18,8 @@ export declare class UserInterfaceServcie extends IncyclistService {
18
18
  protected heartbeatIv: NodeJS.Timeout;
19
19
  protected appFeatures: AppFeatures;
20
20
  protected appState: 'Inactive' | 'Active' | 'Background' | 'Stopped';
21
+ protected backgroundTimer: NodeJS.Timeout | undefined;
22
+ protected backgroundPausedByService: boolean;
21
23
  constructor();
22
24
  getBindings(): IncyclistBindings;
23
25
  setBindings(bindings: IncyclistBindings): void;
@@ -26,6 +28,8 @@ export declare class UserInterfaceServcie extends IncyclistService {
26
28
  onAppPause(): Promise<boolean>;
27
29
  onAppResume(): Promise<boolean>;
28
30
  protected onSessionStart(): void;
31
+ protected pause(): Promise<void>;
32
+ protected resume(): Promise<void>;
29
33
  protected startHeartbeatWorker(): void;
30
34
  protected stopHeartbeatWorker(): void;
31
35
  protected sendHeartbeat(): void;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.57",
3
+ "version": "1.7.59",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },
7
7
  "dependencies": {
8
8
  "@garmin/fitsdk": "^21.200.0",
9
9
  "axios": "^1.15.2",
10
- "incyclist-devices": "^3.0.14",
10
+ "incyclist-devices": "^3.0.15",
11
11
  "promise.any": "^2.0.6",
12
12
  "semver": "^7.7.4",
13
13
  "tcx-builder": "^1.1.1",