incyclist-services 1.6.2 → 1.6.3

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.
@@ -56,6 +56,7 @@ export declare class ActivityRideService extends IncyclistService {
56
56
  prevRidesLogs?: PastActivityInfo;
57
57
  lap?: number;
58
58
  pointsErrorLogged?: boolean;
59
+ info?: string;
59
60
  };
60
61
  constructor();
61
62
  init(id?: string): Observer;
@@ -225,7 +225,15 @@ let ActivityRideService = (() => {
225
225
  const display = Math.floor(time / 3) % 2;
226
226
  const avgMaxStats = (display === 0) ? this.getAverageValues() : this.getMaximumValues();
227
227
  const info = this.buildDashboardInfo(currentValues, avgMaxStats, display);
228
- this.logEvent({ message: 'Dashboard update', items: info.map(i => { var _a, _b, _c, _d, _e, _f; return `${i.title}:${(_b = (_a = i.data[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''}:${(_d = (_c = i.data[1]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : ''}${((_e = i.data[1]) === null || _e === void 0 ? void 0 : _e.label) ? '(' + ((_f = i.data[1]) === null || _f === void 0 ? void 0 : _f.label) + ')' : ''}`; }).join('|') });
228
+ let showLog = true;
229
+ try {
230
+ const infoStr = JSON.stringify(info);
231
+ showLog = infoStr !== this.current.info;
232
+ this.current.info = infoStr;
233
+ }
234
+ catch (_a) { }
235
+ if (showLog)
236
+ this.logEvent({ message: 'Dashboard update', items: info.map(i => { var _a, _b, _c, _d, _e, _f; return `${i.title}:${(_b = (_a = i.data[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''}:${(_d = (_c = i.data[1]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : ''}${((_e = i.data[1]) === null || _e === void 0 ? void 0 : _e.label) ? '(' + ((_f = i.data[1]) === null || _f === void 0 ? void 0 : _f.label) + ')' : ''}`; }).join('|') });
229
237
  return info;
230
238
  }
231
239
  catch (err) {
@@ -654,6 +662,7 @@ let ActivityRideService = (() => {
654
662
  }
655
663
  this.current.deviceData = Object.assign(Object.assign({}, this.current.deviceData), update);
656
664
  if (this.state !== 'active') {
665
+ this.emit('data');
657
666
  if (this.state === 'paused' && (data.power > 0 || data.cadence > 0) && this.current.isAutoResume) {
658
667
  this.resume('system');
659
668
  return;
@@ -831,7 +831,7 @@ class DevicePairingService extends service_2.IncyclistService {
831
831
  }
832
832
  checkPairingSuccess() {
833
833
  const configReadyToRide = this.configuration.canStartRide();
834
- if (!configReadyToRide)
834
+ if (!configReadyToRide || this.isScanning())
835
835
  return false;
836
836
  const control = this.getCapability(incyclist_devices_1.IncyclistCapability.Control);
837
837
  const power = this.getCapability(incyclist_devices_1.IncyclistCapability.Power);
@@ -164,7 +164,7 @@ let RideDisplayService = (() => {
164
164
  try {
165
165
  const props = this.getStartOverlayProps();
166
166
  this.logEvent({ message: 'button clicked', overlay: 'start overlay', button: 'Cancel', reason: 'user cancel', state: props, eventSource: 'user' });
167
- yield this.stopRide();
167
+ yield this.stopRide({ noStateUpdates: true });
168
168
  }
169
169
  catch (err) {
170
170
  this.logError(err, 'cancelStart');
@@ -76,13 +76,14 @@ export declare class RLVDisplayService extends RouteDisplayService {
76
76
  start: number;
77
77
  end: number;
78
78
  }>, video?: VideoState): void;
79
+ protected getCode(error: MediaError): any;
79
80
  protected onVideoPlaybackError(error: MediaError, video?: VideoState): void;
80
81
  protected onVideoPlayBackUpdate(time: number, rate: number, e: any, video?: VideoState): void;
81
82
  protected onVideoEnded(video?: VideoState): void;
82
83
  onActivityUpdate(activityPos: ActivityUpdate, data: any): void;
83
84
  protected initVideoSource(video: VideoState): VideoConversion;
84
85
  protected initMp4VideoSource(video: VideoState): void;
85
- protected buildVideoError(error: MediaError): string;
86
+ protected buildVideoError(error: MediaError, video?: VideoState): string;
86
87
  protected getVideoUrl(video: VideoState): string;
87
88
  protected getVideoTime(routeDistance: number, video?: VideoState): number;
88
89
  protected initAviVideoSource(video: VideoState): VideoConversion;
@@ -352,9 +352,12 @@ let RLVDisplayService = (() => {
352
352
  }
353
353
  onVideoLoadError(error, video = this.currentVideo) {
354
354
  video.loaded = false;
355
- video.error = this.buildVideoError(error);
356
- if (!video.isInitial) {
357
- this.logEvent({ message: 'could not load next video', video: this.getVideoUrl(video), error: error.message, errorCode: error.code });
355
+ video.error = this.buildVideoError(error, video);
356
+ if (video.isInitial) {
357
+ this.logEvent({ message: 'could not load video', video: this.getVideoUrl(video), error: error.message, errorCode: this.getCode(error) });
358
+ }
359
+ else {
360
+ this.logEvent({ message: 'could not load next video', video: this.getVideoUrl(video), error: error.message, errorCode: this.getCode(error) });
358
361
  const errIdx = this.videos.indexOf(video);
359
362
  if (errIdx !== -1) {
360
363
  this.videos.splice(errIdx);
@@ -370,7 +373,27 @@ let RLVDisplayService = (() => {
370
373
  onVideoWaiting(time, rate, bufferedTime, buffers, video = this.currentVideo) {
371
374
  video.syncHelper.onVideoWaiting(time, rate, bufferedTime, buffers);
372
375
  }
376
+ getCode(error) {
377
+ const codes = ['MEDIA_ERR_ABORTED', 'MEDIA_ERR_NETWORK', 'MEDIA_ERR_DECODE', 'MEDIA_ERR_SRC_NOT_SUPPORTED'];
378
+ try {
379
+ let codeStr;
380
+ if (error.code !== undefined) {
381
+ codeStr = codes === null || codes === void 0 ? void 0 : codes[error.code - 1];
382
+ if (codeStr) {
383
+ codeStr = `${codeStr} (${error.code})`;
384
+ }
385
+ else {
386
+ codeStr = error.code.toString();
387
+ }
388
+ }
389
+ return codeStr;
390
+ }
391
+ catch (err) {
392
+ this.logError(err, 'getCode');
393
+ }
394
+ }
373
395
  onVideoPlaybackError(error, video = this.currentVideo) {
396
+ this.logEvent({ message: 'video playback error', video: this.getVideoUrl(video), error: error.message, errorCode: this.getCode(error) });
374
397
  }
375
398
  onVideoPlayBackUpdate(time, rate, e, video = this.currentVideo) {
376
399
  video.syncHelper.onVideoPlaybackUpdate(time, rate, e);
@@ -413,7 +436,21 @@ let RLVDisplayService = (() => {
413
436
  video.playback = 'native';
414
437
  }
415
438
  }
416
- buildVideoError(error) {
439
+ buildVideoError(error, video = this.currentVideo) {
440
+ const src = this.getVideoUrl(video);
441
+ const remote = src === null || src === void 0 ? void 0 : src.startsWith('http');
442
+ switch (error.code) {
443
+ case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:
444
+ if (error.message.includes('Format error'))
445
+ return remote ? 'Could not load video' : 'Could not open video file';
446
+ return 'Could not decode video';
447
+ case MediaError.MEDIA_ERR_NETWORK:
448
+ return remote ? 'Could not load video' : 'Could not open video file';
449
+ case MediaError.MEDIA_ERR_ABORTED:
450
+ return 'The playback was canceled';
451
+ case MediaError.MEDIA_ERR_DECODE:
452
+ return 'Could not decode video';
453
+ }
417
454
  return error.message;
418
455
  }
419
456
  getVideoUrl(video) {
@@ -207,7 +207,7 @@ class VideoSyncHelper extends service_1.IncyclistService {
207
207
  this.onUpdate(updates);
208
208
  }
209
209
  onUpdate(updates = []) {
210
- var _a, _b, _c;
210
+ var _a, _b, _c, _d;
211
211
  if (this.isStopped || this.rlvStatus.timeRequested)
212
212
  return;
213
213
  try {
@@ -244,13 +244,16 @@ class VideoSyncHelper extends service_1.IncyclistService {
244
244
  this.logEvent({ message: 'video debug', videoState: this.rlvStatus, activityState: this.activityStatus });
245
245
  }
246
246
  };
247
- if (this.loopMode && this.rlvStatus.lap > this.activityStatus.lap) {
248
- rlvDistance = rlvDistance + totalDistance;
247
+ if (this.loopMode && actDistance > totalDistance) {
248
+ actDistance = actDistance % totalDistance;
249
+ rlvDistance = rlvDistance % totalDistance;
249
250
  }
250
- else if (this.loopMode && this.rlvStatus.lap < this.activityStatus.lap) {
251
- actDistance = actDistance + totalDistance;
251
+ let delta = rlvDistance - actDistance;
252
+ if (this.loopMode) {
253
+ const deltaActAhead = rlvDistance - (actDistance + totalDistance);
254
+ const deltaRlvAhead = (rlvDistance + totalDistance) - actDistance;
255
+ delta = [delta, deltaActAhead, deltaRlvAhead].reduce((best, cur) => Math.abs(cur) < Math.abs(best) ? cur : best, delta);
252
256
  }
253
- const delta = rlvDistance - actDistance;
254
257
  if (Math.abs(delta) > Math.abs(this.maxDelta)) {
255
258
  this.maxDelta = delta;
256
259
  }
@@ -278,13 +281,13 @@ class VideoSyncHelper extends service_1.IncyclistService {
278
281
  return;
279
282
  }
280
283
  const tTarget = 5;
281
- const maxCorrection = Math.max(20, this.rlvStatus.time < 100 ? 15 : this.bufferedTime / 2.5 * 15);
284
+ const maxCorrection = Math.max(20, this.rlvStatus.time < 100 ? 15 : ((_c = this.bufferedTime) !== null && _c !== void 0 ? _c : 0) / 2.5 * 15);
282
285
  const correction = Math.sign(delta) * Math.min(Math.abs(delta), maxCorrection);
283
286
  const rate = (this.activityStatus.speed - correction / tTarget * 3.6) / this.rlvStatus.speed;
284
287
  this.updateRate(rate);
285
288
  }
286
289
  }
287
- this.cpuTime = ((_c = this.cpuTime) !== null && _c !== void 0 ? _c : 0) + (Date.now() - tsStart);
290
+ this.cpuTime = ((_d = this.cpuTime) !== null && _d !== void 0 ? _d : 0) + (Date.now() - tsStart);
288
291
  }
289
292
  catch (err) {
290
293
  this.logError(err, 'onUpdate');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "axios": "^1.8.2",
45
- "incyclist-devices": "^2.4.7",
45
+ "incyclist-devices": "^2.4.9",
46
46
  "promise.any": "^2.0.6",
47
47
  "semver": "^7.6.3",
48
48
  "tcx-builder": "^1.1.1",