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.
- package/lib/activities/ride/service.js +58 -39
- package/package.json +1 -1
|
@@ -265,30 +265,44 @@ let ActivityRideService = (() => {
|
|
|
265
265
|
this.current.position = position;
|
|
266
266
|
}
|
|
267
267
|
onDeviceData(data) {
|
|
268
|
-
this.current
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
update
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
281
|
-
|
|
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
|
-
|
|
285
|
-
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
this.logError(err, 'onDeviceData');
|
|
286
293
|
}
|
|
287
294
|
}
|
|
288
295
|
onDeviceHealthUpdate(udid, status, capabilities) {
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
this.
|
|
512
|
-
this.updateRepo();
|
|
529
|
+
}
|
|
530
|
+
catch (err) {
|
|
531
|
+
this.logError(err, 'update');
|
|
513
532
|
}
|
|
514
533
|
}
|
|
515
534
|
createFreeRide(settings) {
|