incyclist-services 1.7.5 → 1.7.6

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.
@@ -126,8 +126,9 @@ let ActivityRideService = (() => {
126
126
  }
127
127
  }
128
128
  this.durationCalculator = new duration_1.ActivityDuration(this.activity);
129
- this.getDeviceRide().on('data', this.deviceDataHandler);
130
- this.getDeviceRide().on('gear-change', this.gearChangeHandler);
129
+ const ride = this.getDeviceRide();
130
+ ride.on('data', this.deviceDataHandler);
131
+ ride.on('gear-change', this.gearChangeHandler);
131
132
  (0, utils_1.waitNextTick)().then(() => {
132
133
  this.emit('initialized');
133
134
  });
@@ -213,6 +214,10 @@ let ActivityRideService = (() => {
213
214
  resume(requester = 'user') {
214
215
  if (this.state !== 'paused')
215
216
  return;
217
+ if (requester === 'user') {
218
+ this.current.isAutoResume = true;
219
+ return;
220
+ }
216
221
  const pauseDuration = (Date.now() - this.tsPauseStart) / 1000;
217
222
  this.tsPauseStart = undefined;
218
223
  this.current.isAutoResume = false;
@@ -293,7 +298,7 @@ let ActivityRideService = (() => {
293
298
  }
294
299
  getCurrentValues() {
295
300
  const distance = (this.activity?.distance ?? 0) / 1000;
296
- const speed = (this.current.deviceData?.speed ?? 0);
301
+ let speed = (this.current.deviceData?.speed ?? 0);
297
302
  const power = (this.current.deviceData?.power ?? 0);
298
303
  const slope = this.current.position?.slope;
299
304
  const heartrate = this.current.deviceData?.heartrate;
@@ -303,13 +308,16 @@ let ActivityRideService = (() => {
303
308
  const lap = this.current.lap;
304
309
  const routeDistance = this.current.routeDistance;
305
310
  const gear = this.current.deviceData?.gearStr;
311
+ if (this.state != 'active') {
312
+ speed = 0;
313
+ }
306
314
  let distanceRemaining = (this.getTotalDistance() / 1000 - distance);
307
315
  if (isNaN(distanceRemaining))
308
316
  distanceRemaining = undefined;
309
317
  if (distanceRemaining < 0)
310
318
  distanceRemaining = 0;
311
319
  let timeRemaining;
312
- if (speed > 0) {
320
+ if (speed > 0 && this.durationCalculator) {
313
321
  timeRemaining = this.durationCalculator.getRemainingTime({ route: this.current.route, speed: this.current.deviceData?.speed, routePos: this.activity.distance + (this.activity?.startPos ?? 0), endPos: this.current?.endPos });
314
322
  }
315
323
  return { position, distance, routeDistance, time, speed, power, slope, heartrate, cadence, timeRemaining, distanceRemaining, lap, gear };
@@ -719,17 +727,24 @@ let ActivityRideService = (() => {
719
727
  update.speed = 0;
720
728
  }
721
729
  this.current.deviceData = { ...this.current.deviceData, ...update };
722
- if (this.state !== 'active') {
723
- this.emit('data');
724
- if (this.state === 'paused' && (data.power > 0 || data.cadence > 0) && this.current.isAutoResume) {
730
+ if (this.state === 'active') {
731
+ if (update.speed === 0) {
732
+ this.pause(true);
733
+ return;
734
+ }
735
+ }
736
+ else if (this.state === 'paused') {
737
+ if ((data.power > 0 || data.cadence > 0) && this.current.isAutoResume) {
725
738
  this.resume('system');
726
739
  return;
727
740
  }
741
+ this.emit('data');
742
+ }
743
+ else {
728
744
  if (this.state === 'ininitalized' && (data.speed > 0)) {
729
745
  this.start();
730
- return;
731
746
  }
732
- this.current.deviceData.speed = 0;
747
+ this.emit('data');
733
748
  return;
734
749
  }
735
750
  }
@@ -62,11 +62,20 @@ let DevicePairingService = (() => {
62
62
  let _classSuper = service_2.IncyclistService;
63
63
  let _instanceExtraInitializers = [];
64
64
  let _getUnitConverter_decorators;
65
+ let _getDeviceConfiguration_decorators;
66
+ let _getDeviceAccess_decorators;
67
+ let _getDeviceRide_decorators;
65
68
  return class DevicePairingService extends _classSuper {
66
69
  static {
67
70
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
68
71
  _getUnitConverter_decorators = [decorators_1.Injectable];
72
+ _getDeviceConfiguration_decorators = [decorators_1.Injectable];
73
+ _getDeviceAccess_decorators = [decorators_1.Injectable];
74
+ _getDeviceRide_decorators = [decorators_1.Injectable];
69
75
  __esDecorate(this, null, _getUnitConverter_decorators, { kind: "method", name: "getUnitConverter", static: false, private: false, access: { has: obj => "getUnitConverter" in obj, get: obj => obj.getUnitConverter }, metadata: _metadata }, null, _instanceExtraInitializers);
76
+ __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);
77
+ __esDecorate(this, null, _getDeviceAccess_decorators, { kind: "method", name: "getDeviceAccess", static: false, private: false, access: { has: obj => "getDeviceAccess" in obj, get: obj => obj.getDeviceAccess }, metadata: _metadata }, null, _instanceExtraInitializers);
78
+ __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);
70
79
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
71
80
  }
72
81
  static _instance;
@@ -403,10 +412,10 @@ let DevicePairingService = (() => {
403
412
  if (this.state.initialized)
404
413
  return;
405
414
  return new Promise(done => {
406
- this.access = this.access || (0, service_1.useDeviceAccess)();
407
- this.rideService = this.rideService || (0, ride_1.useDeviceRide)();
415
+ this.configuration = this.getDeviceConfiguration();
416
+ this.access = this.access || this.getDeviceAccess();
417
+ this.rideService = this.rideService || this.getDeviceRide();
408
418
  this.onScanningDataHandler = this.rideService.onData.bind(this.rideService);
409
- this.configuration = this.configuration || (0, configuration_1.useDeviceConfiguration)();
410
419
  if (this.configuration.isInitialized()) {
411
420
  this.state.initialized = true;
412
421
  return done();
@@ -718,7 +727,6 @@ let DevicePairingService = (() => {
718
727
  }
719
728
  }
720
729
  onDeviceData(data, udid) {
721
- console.log('# got data', data);
722
730
  const capabilities = this.state.capabilities;
723
731
  if (!this.state.data) {
724
732
  this.state.data = [];
@@ -1370,6 +1378,15 @@ let DevicePairingService = (() => {
1370
1378
  getUnitConverter() {
1371
1379
  return (0, i18n_1.useUnitConverter)();
1372
1380
  }
1381
+ getDeviceConfiguration() {
1382
+ return this.configuration ?? (0, configuration_1.useDeviceConfiguration)();
1383
+ }
1384
+ getDeviceAccess() {
1385
+ return this.access ?? (0, service_1.useDeviceAccess)();
1386
+ }
1387
+ getDeviceRide() {
1388
+ return this.rideService ?? (0, ride_1.useDeviceRide)();
1389
+ }
1373
1390
  };
1374
1391
  })();
1375
1392
  exports.DevicePairingService = DevicePairingService;
@@ -186,15 +186,14 @@ let RideDisplayService = (() => {
186
186
  }
187
187
  }
188
188
  pause(requester = 'user') {
189
- if (requester === 'device' && this.isResuming) {
190
- return;
191
- }
192
189
  try {
193
190
  if (this.state !== 'Active')
194
191
  return;
195
192
  this.logEvent({ message: "pause activity request", activity: this.activity?.id, userRequested: requester === 'user' });
196
193
  this.state = 'Paused';
197
- this.getActivityRide().pause(requester === 'device');
194
+ if (requester === 'user') {
195
+ this.getActivityRide().pause(false);
196
+ }
198
197
  this.getWorkoutRide().pause();
199
198
  this.displayService.pause();
200
199
  this.observer?.emit('state-update', this.state);
@@ -206,12 +205,14 @@ let RideDisplayService = (() => {
206
205
  }
207
206
  resume(requester = 'user') {
208
207
  try {
209
- if (this.state !== 'Paused' || this.isResuming)
208
+ if (this.state !== 'Paused')
210
209
  return;
211
210
  this.logEvent({ message: "continue activity request", activity: this.activity?.id, userRequested: requester === 'user' });
212
211
  this.isResuming = true;
213
212
  this.state = 'Active';
214
- this.getActivityRide().resume();
213
+ if (requester === 'user') {
214
+ this.getActivityRide().resume('user');
215
+ }
215
216
  this.getWorkoutRide().resume();
216
217
  this.pauseReason = 'device';
217
218
  this.observer?.emit('state-update', this.state);
@@ -525,8 +526,7 @@ let RideDisplayService = (() => {
525
526
  onActivityPaused(autoResume) {
526
527
  if (this.state === 'Paused')
527
528
  return;
528
- if (autoResume && this.state === 'Active')
529
- this.pause('device');
529
+ this.pause('device');
530
530
  }
531
531
  onActivityResumed() {
532
532
  if (this.state !== 'Paused')
@@ -538,10 +538,6 @@ let RideDisplayService = (() => {
538
538
  const currentValues = this.getActivityRide().getCurrentValues();
539
539
  if (!currentValues)
540
540
  return;
541
- if (currentValues.speed === 0 && !this.isResuming) {
542
- this.pause('device');
543
- return;
544
- }
545
541
  if (currentValues.speed > 0 && this.isResuming) {
546
542
  this.displayService.resume();
547
543
  this.isResuming = false;
@@ -104,7 +104,6 @@ let RouteDisplayService = (() => {
104
104
  if (data.power > 0)
105
105
  this.prevPowerTs = Date.now();
106
106
  if (data.power === 0 && (data.speed === 0 || data.speed < 5 && (Date.now() - (this.prevPowerTs ?? 0)) > MAX_INACTIVITY)) {
107
- this.service.pause('device');
108
107
  return;
109
108
  }
110
109
  try {
@@ -120,8 +120,9 @@ let ActivityRideService = (() => {
120
120
  }
121
121
  }
122
122
  this.durationCalculator = new ActivityDuration(this.activity);
123
- this.getDeviceRide().on('data', this.deviceDataHandler);
124
- this.getDeviceRide().on('gear-change', this.gearChangeHandler);
123
+ const ride = this.getDeviceRide();
124
+ ride.on('data', this.deviceDataHandler);
125
+ ride.on('gear-change', this.gearChangeHandler);
125
126
  waitNextTick().then(() => {
126
127
  this.emit('initialized');
127
128
  });
@@ -207,6 +208,10 @@ let ActivityRideService = (() => {
207
208
  resume(requester = 'user') {
208
209
  if (this.state !== 'paused')
209
210
  return;
211
+ if (requester === 'user') {
212
+ this.current.isAutoResume = true;
213
+ return;
214
+ }
210
215
  const pauseDuration = (Date.now() - this.tsPauseStart) / 1000;
211
216
  this.tsPauseStart = undefined;
212
217
  this.current.isAutoResume = false;
@@ -287,7 +292,7 @@ let ActivityRideService = (() => {
287
292
  }
288
293
  getCurrentValues() {
289
294
  const distance = (this.activity?.distance ?? 0) / 1000;
290
- const speed = (this.current.deviceData?.speed ?? 0);
295
+ let speed = (this.current.deviceData?.speed ?? 0);
291
296
  const power = (this.current.deviceData?.power ?? 0);
292
297
  const slope = this.current.position?.slope;
293
298
  const heartrate = this.current.deviceData?.heartrate;
@@ -297,13 +302,16 @@ let ActivityRideService = (() => {
297
302
  const lap = this.current.lap;
298
303
  const routeDistance = this.current.routeDistance;
299
304
  const gear = this.current.deviceData?.gearStr;
305
+ if (this.state != 'active') {
306
+ speed = 0;
307
+ }
300
308
  let distanceRemaining = (this.getTotalDistance() / 1000 - distance);
301
309
  if (isNaN(distanceRemaining))
302
310
  distanceRemaining = undefined;
303
311
  if (distanceRemaining < 0)
304
312
  distanceRemaining = 0;
305
313
  let timeRemaining;
306
- if (speed > 0) {
314
+ if (speed > 0 && this.durationCalculator) {
307
315
  timeRemaining = this.durationCalculator.getRemainingTime({ route: this.current.route, speed: this.current.deviceData?.speed, routePos: this.activity.distance + (this.activity?.startPos ?? 0), endPos: this.current?.endPos });
308
316
  }
309
317
  return { position, distance, routeDistance, time, speed, power, slope, heartrate, cadence, timeRemaining, distanceRemaining, lap, gear };
@@ -713,17 +721,24 @@ let ActivityRideService = (() => {
713
721
  update.speed = 0;
714
722
  }
715
723
  this.current.deviceData = { ...this.current.deviceData, ...update };
716
- if (this.state !== 'active') {
717
- this.emit('data');
718
- if (this.state === 'paused' && (data.power > 0 || data.cadence > 0) && this.current.isAutoResume) {
724
+ if (this.state === 'active') {
725
+ if (update.speed === 0) {
726
+ this.pause(true);
727
+ return;
728
+ }
729
+ }
730
+ else if (this.state === 'paused') {
731
+ if ((data.power > 0 || data.cadence > 0) && this.current.isAutoResume) {
719
732
  this.resume('system');
720
733
  return;
721
734
  }
735
+ this.emit('data');
736
+ }
737
+ else {
722
738
  if (this.state === 'ininitalized' && (data.speed > 0)) {
723
739
  this.start();
724
- return;
725
740
  }
726
- this.current.deviceData.speed = 0;
741
+ this.emit('data');
727
742
  return;
728
743
  }
729
744
  }
@@ -56,11 +56,20 @@ let DevicePairingService = (() => {
56
56
  let _classSuper = IncyclistService;
57
57
  let _instanceExtraInitializers = [];
58
58
  let _getUnitConverter_decorators;
59
+ let _getDeviceConfiguration_decorators;
60
+ let _getDeviceAccess_decorators;
61
+ let _getDeviceRide_decorators;
59
62
  return class DevicePairingService extends _classSuper {
60
63
  static {
61
64
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
62
65
  _getUnitConverter_decorators = [Injectable];
66
+ _getDeviceConfiguration_decorators = [Injectable];
67
+ _getDeviceAccess_decorators = [Injectable];
68
+ _getDeviceRide_decorators = [Injectable];
63
69
  __esDecorate(this, null, _getUnitConverter_decorators, { kind: "method", name: "getUnitConverter", static: false, private: false, access: { has: obj => "getUnitConverter" in obj, get: obj => obj.getUnitConverter }, metadata: _metadata }, null, _instanceExtraInitializers);
70
+ __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);
71
+ __esDecorate(this, null, _getDeviceAccess_decorators, { kind: "method", name: "getDeviceAccess", static: false, private: false, access: { has: obj => "getDeviceAccess" in obj, get: obj => obj.getDeviceAccess }, metadata: _metadata }, null, _instanceExtraInitializers);
72
+ __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);
64
73
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
65
74
  }
66
75
  static _instance;
@@ -397,10 +406,10 @@ let DevicePairingService = (() => {
397
406
  if (this.state.initialized)
398
407
  return;
399
408
  return new Promise(done => {
400
- this.access = this.access || useDeviceAccess();
401
- this.rideService = this.rideService || useDeviceRide();
409
+ this.configuration = this.getDeviceConfiguration();
410
+ this.access = this.access || this.getDeviceAccess();
411
+ this.rideService = this.rideService || this.getDeviceRide();
402
412
  this.onScanningDataHandler = this.rideService.onData.bind(this.rideService);
403
- this.configuration = this.configuration || useDeviceConfiguration();
404
413
  if (this.configuration.isInitialized()) {
405
414
  this.state.initialized = true;
406
415
  return done();
@@ -712,7 +721,6 @@ let DevicePairingService = (() => {
712
721
  }
713
722
  }
714
723
  onDeviceData(data, udid) {
715
- console.log('# got data', data);
716
724
  const capabilities = this.state.capabilities;
717
725
  if (!this.state.data) {
718
726
  this.state.data = [];
@@ -1364,6 +1372,15 @@ let DevicePairingService = (() => {
1364
1372
  getUnitConverter() {
1365
1373
  return useUnitConverter();
1366
1374
  }
1375
+ getDeviceConfiguration() {
1376
+ return this.configuration ?? useDeviceConfiguration();
1377
+ }
1378
+ getDeviceAccess() {
1379
+ return this.access ?? useDeviceAccess();
1380
+ }
1381
+ getDeviceRide() {
1382
+ return this.rideService ?? useDeviceRide();
1383
+ }
1367
1384
  };
1368
1385
  })();
1369
1386
  export { DevicePairingService };
@@ -183,15 +183,14 @@ let RideDisplayService = (() => {
183
183
  }
184
184
  }
185
185
  pause(requester = 'user') {
186
- if (requester === 'device' && this.isResuming) {
187
- return;
188
- }
189
186
  try {
190
187
  if (this.state !== 'Active')
191
188
  return;
192
189
  this.logEvent({ message: "pause activity request", activity: this.activity?.id, userRequested: requester === 'user' });
193
190
  this.state = 'Paused';
194
- this.getActivityRide().pause(requester === 'device');
191
+ if (requester === 'user') {
192
+ this.getActivityRide().pause(false);
193
+ }
195
194
  this.getWorkoutRide().pause();
196
195
  this.displayService.pause();
197
196
  this.observer?.emit('state-update', this.state);
@@ -203,12 +202,14 @@ let RideDisplayService = (() => {
203
202
  }
204
203
  resume(requester = 'user') {
205
204
  try {
206
- if (this.state !== 'Paused' || this.isResuming)
205
+ if (this.state !== 'Paused')
207
206
  return;
208
207
  this.logEvent({ message: "continue activity request", activity: this.activity?.id, userRequested: requester === 'user' });
209
208
  this.isResuming = true;
210
209
  this.state = 'Active';
211
- this.getActivityRide().resume();
210
+ if (requester === 'user') {
211
+ this.getActivityRide().resume('user');
212
+ }
212
213
  this.getWorkoutRide().resume();
213
214
  this.pauseReason = 'device';
214
215
  this.observer?.emit('state-update', this.state);
@@ -522,8 +523,7 @@ let RideDisplayService = (() => {
522
523
  onActivityPaused(autoResume) {
523
524
  if (this.state === 'Paused')
524
525
  return;
525
- if (autoResume && this.state === 'Active')
526
- this.pause('device');
526
+ this.pause('device');
527
527
  }
528
528
  onActivityResumed() {
529
529
  if (this.state !== 'Paused')
@@ -535,10 +535,6 @@ let RideDisplayService = (() => {
535
535
  const currentValues = this.getActivityRide().getCurrentValues();
536
536
  if (!currentValues)
537
537
  return;
538
- if (currentValues.speed === 0 && !this.isResuming) {
539
- this.pause('device');
540
- return;
541
- }
542
538
  if (currentValues.speed > 0 && this.isResuming) {
543
539
  this.displayService.resume();
544
540
  this.isResuming = false;
@@ -98,7 +98,6 @@ let RouteDisplayService = (() => {
98
98
  if (data.power > 0)
99
99
  this.prevPowerTs = Date.now();
100
100
  if (data.power === 0 && (data.speed === 0 || data.speed < 5 && (Date.now() - (this.prevPowerTs ?? 0)) > MAX_INACTIVITY)) {
101
- this.service.pause('device');
102
101
  return;
103
102
  }
104
103
  try {
@@ -138,5 +138,8 @@ export declare class DevicePairingService extends IncyclistService {
138
138
  protected mappedCapabilities(capabilities: DeviceConfigurationInfo): Array<CapabilityData>;
139
139
  reset(): void;
140
140
  protected getUnitConverter(): import("../../i18n").UnitConverterService;
141
+ protected getDeviceConfiguration(): DeviceConfigurationService;
142
+ protected getDeviceAccess(): DeviceAccessService;
143
+ protected getDeviceRide(): DeviceRideService;
141
144
  }
142
145
  export declare const useDevicePairing: () => DevicePairingService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },