incyclist-services 1.7.57 → 1.7.58

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.
@@ -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,15 @@ let UserInterfaceServcie = (() => {
178
183
  this.isTerminated = false;
179
184
  this.isTerminating = false;
180
185
  try {
186
+ this.startHeartbeatWorker();
187
+ this.backgroundPausedByService = false;
181
188
  this.appState = 'Active';
182
189
  this.logEvent({ message: 'onAppResume called' });
183
- (0, devices_1.useDeviceAccess)().connect();
184
- pages_1.IncyclistPageService.resumePage();
185
- this.startHeartbeatWorker();
190
+ if (this.backgroundTimer) {
191
+ clearTimeout(this.backgroundTimer);
192
+ return;
193
+ }
194
+ this.resume();
186
195
  }
187
196
  catch (err) {
188
197
  this.logError(err, 'onAppPause');
@@ -217,6 +226,18 @@ let UserInterfaceServcie = (() => {
217
226
  this.logError(err, 'onSessionStart');
218
227
  }
219
228
  }
229
+ async pause() {
230
+ await pages_1.IncyclistPageService.pausePage();
231
+ (0, devices_1.useDeviceAccess)().disconnect();
232
+ if (this.getMessageQueue().disconnect)
233
+ this.getMessageQueue().disconnect();
234
+ }
235
+ resume() {
236
+ if (this.getMessageQueue().connect)
237
+ this.getMessageQueue().connect();
238
+ (0, devices_1.useDeviceAccess)().connect();
239
+ pages_1.IncyclistPageService.resumePage();
240
+ }
220
241
  startHeartbeatWorker() {
221
242
  if (this.heartbeatIv)
222
243
  return;
@@ -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,15 @@ let UserInterfaceServcie = (() => {
175
180
  this.isTerminated = false;
176
181
  this.isTerminating = false;
177
182
  try {
183
+ this.startHeartbeatWorker();
184
+ this.backgroundPausedByService = false;
178
185
  this.appState = 'Active';
179
186
  this.logEvent({ message: 'onAppResume called' });
180
- useDeviceAccess().connect();
181
- IncyclistPageService.resumePage();
182
- this.startHeartbeatWorker();
187
+ if (this.backgroundTimer) {
188
+ clearTimeout(this.backgroundTimer);
189
+ return;
190
+ }
191
+ this.resume();
183
192
  }
184
193
  catch (err) {
185
194
  this.logError(err, 'onAppPause');
@@ -214,6 +223,18 @@ let UserInterfaceServcie = (() => {
214
223
  this.logError(err, 'onSessionStart');
215
224
  }
216
225
  }
226
+ async pause() {
227
+ await IncyclistPageService.pausePage();
228
+ useDeviceAccess().disconnect();
229
+ if (this.getMessageQueue().disconnect)
230
+ this.getMessageQueue().disconnect();
231
+ }
232
+ resume() {
233
+ if (this.getMessageQueue().connect)
234
+ this.getMessageQueue().connect();
235
+ useDeviceAccess().connect();
236
+ IncyclistPageService.resumePage();
237
+ }
217
238
  startHeartbeatWorker() {
218
239
  if (this.heartbeatIv)
219
240
  return;
@@ -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(): void;
29
33
  protected startHeartbeatWorker(): void;
30
34
  protected stopHeartbeatWorker(): void;
31
35
  protected sendHeartbeat(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.57",
3
+ "version": "1.7.58",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },