incyclist-services 1.3.1 → 1.3.2

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.
@@ -265,30 +265,44 @@ let ActivityRideService = (() => {
265
265
  this.current.position = position;
266
266
  }
267
267
  onDeviceData(data) {
268
- this.current.tsDeviceData = Date.now();
269
- const update = Object.assign({}, data);
270
- if (data.distance < 0 || data.speed === 0) {
271
- update.distance = 0;
272
- update.speed = 0;
273
- }
274
- this.current.deviceData = Object.assign(Object.assign({}, this.current.deviceData), update);
275
- if (this.state !== 'active') {
276
- if (this.state === 'paused' && data.speed > 0 && this.current.isAutoResume) {
277
- this.resume('system');
278
- return;
268
+ if (!this.current)
269
+ return;
270
+ try {
271
+ this.current.tsDeviceData = Date.now();
272
+ const update = Object.assign({}, data);
273
+ if (data.distance < 0 || data.speed === 0) {
274
+ update.distance = 0;
275
+ update.speed = 0;
279
276
  }
280
- if (this.state === 'ininitalized' && data.speed > 0) {
281
- this.start();
277
+ this.current.deviceData = Object.assign(Object.assign({}, this.current.deviceData), update);
278
+ if (this.state !== 'active') {
279
+ if (this.state === 'paused' && data.speed > 0 && this.current.isAutoResume) {
280
+ this.resume('system');
281
+ return;
282
+ }
283
+ if (this.state === 'ininitalized' && data.speed > 0) {
284
+ this.start();
285
+ return;
286
+ }
287
+ this.current.deviceData.speed = 0;
282
288
  return;
283
289
  }
284
- this.current.deviceData.speed = 0;
285
- return;
290
+ }
291
+ catch (err) {
292
+ this.logError(err, 'onDeviceData');
286
293
  }
287
294
  }
288
295
  onDeviceHealthUpdate(udid, status, capabilities) {
289
- capabilities.forEach(capability => {
290
- this.current.dataState[capability.toLowerCase()] = status;
291
- });
296
+ if (!this.current)
297
+ return;
298
+ try {
299
+ capabilities.forEach(capability => {
300
+ this.current.dataState[capability.toLowerCase()] = status;
301
+ });
302
+ }
303
+ catch (err) {
304
+ this.logError(err, 'onDeviceHealthUpdate');
305
+ }
292
306
  }
293
307
  emit(eventName, ...args) {
294
308
  if (!this.observer)
@@ -488,28 +502,33 @@ let ActivityRideService = (() => {
488
502
  }
489
503
  update() {
490
504
  var _a, _b;
491
- const prev = Math.floor(this.activity.time);
492
- this.updateActivityState();
493
- const time = Math.floor(this.activity.time);
494
- if (time !== prev && this.state === 'active') {
495
- const distance = this.current.routeDistance - ((_b = (_a = this.prevEmit) === null || _a === void 0 ? void 0 : _a.routeDistance) !== null && _b !== void 0 ? _b : 0);
496
- const data = {
497
- time: this.activity.time,
498
- speed: this.current.deviceData.speed,
499
- routeDistance: this.current.routeDistance,
500
- distance
501
- };
502
- this.emit('data', data);
503
- this.prevEmit = data;
504
- const logRecord = this.createLogRecord();
505
- if (logRecord) {
506
- this.activity.logs.push(logRecord);
507
- this.statsCalculator.add(logRecord);
505
+ try {
506
+ const prev = Math.floor(this.activity.time);
507
+ this.updateActivityState();
508
+ const time = Math.floor(this.activity.time);
509
+ if (time !== prev && this.state === 'active') {
510
+ const distance = this.current.routeDistance - ((_b = (_a = this.prevEmit) === null || _a === void 0 ? void 0 : _a.routeDistance) !== null && _b !== void 0 ? _b : 0);
511
+ const data = {
512
+ time: this.activity.time,
513
+ speed: this.current.deviceData.speed,
514
+ routeDistance: this.current.routeDistance,
515
+ distance
516
+ };
517
+ this.emit('data', data);
518
+ this.prevEmit = data;
519
+ const logRecord = this.createLogRecord();
520
+ if (logRecord) {
521
+ this.activity.logs.push(logRecord);
522
+ this.statsCalculator.add(logRecord);
523
+ }
524
+ this.activity.distance = this.current.routeDistance - this.activity.startPos;
525
+ this.activity.totalElevation = this.current.elevationGain;
526
+ this.logActivityUpdateMessage();
527
+ this.updateRepo();
508
528
  }
509
- this.activity.distance = this.current.routeDistance - this.activity.startPos;
510
- this.activity.totalElevation = this.current.elevationGain;
511
- this.logActivityUpdateMessage();
512
- this.updateRepo();
529
+ }
530
+ catch (err) {
531
+ this.logError(err, 'update');
513
532
  }
514
533
  }
515
534
  createFreeRide(settings) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },