incyclist-services 1.5.70 → 1.6.1

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.
@@ -1 +1,2 @@
1
1
  export * from './service';
2
+ export * from './types';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./service"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -1,7 +1,9 @@
1
1
  import { IncyclistService } from "../base/service";
2
+ import { AppFeature } from "./types";
2
3
  export declare class AppStateService extends IncyclistService {
3
4
  protected state: Record<string, any>;
4
5
  constructor();
6
+ hasFeature(feature: AppFeature): any;
5
7
  getPersistedState(key: string): any;
6
8
  setPersistedState(key: string, value: any): void;
7
9
  getState(key: string): any;
@@ -56,6 +56,9 @@ let AppStateService = (() => {
56
56
  super('AppState');
57
57
  this.state = (__runInitializers(this, _instanceExtraInitializers), {});
58
58
  }
59
+ hasFeature(feature) {
60
+ return this.getSetting(feature, false);
61
+ }
59
62
  getPersistedState(key) {
60
63
  return this.getSetting(`state.${key}`, undefined);
61
64
  }
@@ -125,7 +125,7 @@ let DeviceRideService = (() => {
125
125
  return this.data;
126
126
  }
127
127
  getRideAdapters() {
128
- var _a, _b;
128
+ var _a, _b, _c, _d, _e;
129
129
  if ((_a = this.rideAdapters) === null || _a === void 0 ? void 0 : _a.length)
130
130
  return this.rideAdapters;
131
131
  try {
@@ -150,11 +150,24 @@ let DeviceRideService = (() => {
150
150
  if (this.simulatorEnforced) {
151
151
  this.setRequestedCapabilties(this.rideAdapters);
152
152
  }
153
+ if (this.rideAdapters.length === 0) {
154
+ const devices = this.getDeviceConfiguration();
155
+ const adapter = (_c = (_b = devices.getSelected(incyclist_devices_1.IncyclistCapability.Control)) !== null && _b !== void 0 ? _b : devices.getSelected(incyclist_devices_1.IncyclistCapability.Power)) !== null && _c !== void 0 ? _c : devices.getSelected(incyclist_devices_1.IncyclistCapability.Speed);
156
+ if (adapter) {
157
+ const adapters = (_d = this.getConfiguredAdapters(true)) !== null && _d !== void 0 ? _d : [];
158
+ this.logEvent({ message: 'error',
159
+ error: 'incorrect device configuration',
160
+ adapters: adapters.map(ai => `${ai.udid}, ${ai.isControl ? '(C)' : ''}`).join('|'),
161
+ configuredControlDevice: configuredControlDevice === null || configuredControlDevice === void 0 ? void 0 : configuredControlDevice.udid,
162
+ controlDevice: controlDevice === null || controlDevice === void 0 ? void 0 : controlDevice.udid,
163
+ simulatorEnforced: this.simulatorEnforced });
164
+ }
165
+ }
153
166
  return this.rideAdapters;
154
167
  }
155
168
  catch (err) {
156
169
  this.logError(err, 'getRideAdapters');
157
- return (_b = this.rideAdapters) !== null && _b !== void 0 ? _b : [];
170
+ return (_e = this.rideAdapters) !== null && _e !== void 0 ? _e : [];
158
171
  }
159
172
  }
160
173
  getAllAdapters() {
@@ -547,6 +560,7 @@ let DeviceRideService = (() => {
547
560
  logProps.bikeType = (_b = bike.getCyclingMode()) === null || _b === void 0 ? void 0 : _b.getSetting('bikeType');
548
561
  }
549
562
  startProps.capabilities = ai.capabilities;
563
+ ai.isStarted = false;
550
564
  this.logEvent(Object.assign({ message: `${startType} ${sType} request` }, logProps));
551
565
  return ai.adapter.start(startProps)
552
566
  .then((success) => __awaiter(this, void 0, void 0, function* () {
@@ -901,8 +915,8 @@ let DeviceRideService = (() => {
901
915
  return __awaiter(this, void 0, void 0, function* () {
902
916
  yield this.lazyInit();
903
917
  this.cleanInternalCache();
904
- delete this.rideAdapters;
905
918
  const adapters = this.getRideAdapters();
919
+ this.logEvent({ message: 'sending start request', retry: false, deviceInfo: adapters === null || adapters === void 0 ? void 0 : adapters.map(this.getAdapterStateInfo.bind(this)) });
906
920
  this.emit('start-request', adapters === null || adapters === void 0 ? void 0 : adapters.map(this.getAdapterStateInfo.bind(this)));
907
921
  const goodToGo = yield this.waitForPreviousStartToFinish();
908
922
  if (!goodToGo)
@@ -915,7 +929,8 @@ let DeviceRideService = (() => {
915
929
  return __awaiter(this, void 0, void 0, function* () {
916
930
  yield this.lazyInit();
917
931
  const selected = this.getRideAdapters();
918
- this.emit('start-request', selected === null || selected === void 0 ? void 0 : selected.map(this.getAdapterStateInfo));
932
+ this.logEvent({ message: 'sending start request', retry: true, deviceInfo: selected === null || selected === void 0 ? void 0 : selected.map(this.getAdapterStateInfo.bind(this)) });
933
+ this.emit('start-request', selected === null || selected === void 0 ? void 0 : selected.map(this.getAdapterStateInfo.bind(this)));
919
934
  const adapters = selected.filter(ai => !ai.adapter.isStarted());
920
935
  const goodToGo = yield this.waitForPreviousStartToFinish();
921
936
  if (!goodToGo)
@@ -99,21 +99,14 @@ let RideDisplayService = (() => {
99
99
  }
100
100
  init() {
101
101
  return __awaiter(this, void 0, void 0, function* () {
102
- var _a, _b, _c;
103
102
  yield this.closePrevRide();
104
103
  this.observer = new types_1.Observer();
105
104
  try {
106
105
  this.displayService = this.getRideModeService(true);
107
- const ftNewUI = this.getUserSettings().get('NEW_GPX_UI', false);
108
- const isVideo = this.getRideType() === 'Video';
109
- const isMp4 = isVideo && ((_c = (_b = (_a = this.route) === null || _a === void 0 ? void 0 : _a.description) === null || _b === void 0 ? void 0 : _b.videoFormat) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === 'mp4';
110
- const showLegacy = isVideo && !isMp4 && !ftNewUI;
111
- if (!showLegacy) {
112
- this.displayService.init(this);
113
- this.displayService.on('lap-completed', this.onLapCompleted.bind(this));
114
- this.displayService.on('route-completed', this.onRouteCompleted.bind(this));
115
- this.hideAll = false;
116
- }
106
+ this.displayService.init(this);
107
+ this.displayService.on('lap-completed', this.onLapCompleted.bind(this));
108
+ this.displayService.on('route-completed', this.onRouteCompleted.bind(this));
109
+ this.hideAll = false;
117
110
  }
118
111
  catch (err) {
119
112
  this.logError(err, 'init');
@@ -795,7 +788,6 @@ let RideDisplayService = (() => {
795
788
  .on('route-updated', this.onRouteUpdated.bind(this));
796
789
  }
797
790
  onStateUpdate() {
798
- console.log('# state update', this.state);
799
791
  this.checkStartStatus();
800
792
  this.updateStartOverlay();
801
793
  }
@@ -1016,6 +1008,9 @@ let RideDisplayService = (() => {
1016
1008
  isStartDeviceReadyToStart() {
1017
1009
  var _a, _b;
1018
1010
  const devices = (_a = this.deviceInfo) !== null && _a !== void 0 ? _a : [];
1011
+ if (devices.length === 0) {
1012
+ return false;
1013
+ }
1019
1014
  const mandatory = (_b = devices === null || devices === void 0 ? void 0 : devices.filter(d => d.isControl)) !== null && _b !== void 0 ? _b : [];
1020
1015
  return !(mandatory === null || mandatory === void 0 ? void 0 : mandatory.length) || mandatory.filter(d => d.status === 'Started').length == mandatory.length;
1021
1016
  }
@@ -189,11 +189,11 @@ let RLVDisplayService = (() => {
189
189
  return this.infotext;
190
190
  }
191
191
  checkFinishOptions(position) {
192
- var _b, _c;
193
- if (this.videos.length === 0 || !((_b = this.currentVideo) === null || _b === void 0 ? void 0 : _b.loaded)) {
192
+ var _b, _c, _d, _e;
193
+ if (!((_b = this.videos) === null || _b === void 0 ? void 0 : _b.length) || !((_c = this.currentVideo) === null || _c === void 0 ? void 0 : _c.loaded)) {
194
194
  return super.checkFinishOptions(position);
195
195
  }
196
- if (!((_c = this.currentVideo) === null || _c === void 0 ? void 0 : _c.next)) {
196
+ if (!((_d = this.currentVideo) === null || _d === void 0 ? void 0 : _d.next) || ((_e = this.videos) === null || _e === void 0 ? void 0 : _e.length) === 1) {
197
197
  return super.checkFinishOptions(position);
198
198
  }
199
199
  const finished = this.checkIsRouteFinished(position);
@@ -347,8 +347,12 @@ let RLVDisplayService = (() => {
347
347
  video.loaded = false;
348
348
  video.error = this.buildVideoError(error);
349
349
  if (!video.isInitial) {
350
- this.logEvent({ message: 'could not load next video', error: this.buildVideoError(error) });
351
- this.videos = [this.currentVideo];
350
+ this.logEvent({ message: 'could not load next video', video: this.getVideoUrl(video), error: error.message, errorCode: error.code });
351
+ const errIdx = this.videos.indexOf(video);
352
+ if (errIdx !== -1) {
353
+ this.videos.splice(errIdx);
354
+ this.logEvent({ message: 'changed video config', videos: this.videos.map(v => this.getVideoUrl(v)).join('|') });
355
+ }
352
356
  }
353
357
  this.emit('state-update');
354
358
  }
@@ -31,9 +31,9 @@ export interface GetPositionProps {
31
31
  nearest?: boolean;
32
32
  latlng?: LatLng;
33
33
  }
34
- export declare const getPosition: (route: Route, props: GetPositionProps) => RoutePoint;
34
+ export declare const getPosition: (src: Route | Array<RoutePoint>, props: GetPositionProps) => RoutePoint;
35
35
  export declare const getHeading: (route: Route, point: RoutePoint) => number;
36
- export declare const getPointAtDistance: (route: Route | RouteApiDetail, routeDistance: number, nearest?: boolean) => RoutePoint;
36
+ export declare const getPointAtDistance: (src: Route | RouteApiDetail | Array<RoutePoint>, routeDistance: number, nearest?: boolean) => RoutePoint;
37
37
  interface LegacyRouteApiDetail extends RouteApiDetail {
38
38
  decoded?: Array<RoutePoint>;
39
39
  }
@@ -359,18 +359,26 @@ const getNextPosition = (route, props) => {
359
359
  return lapPoint;
360
360
  };
361
361
  exports.getNextPosition = getNextPosition;
362
- const getPosition = (route, props) => {
363
- if (props === undefined || route.points === undefined)
362
+ const getPosition = (src, props) => {
363
+ let route;
364
+ let points;
365
+ if (Array.isArray(src)) {
366
+ points = src;
367
+ }
368
+ else {
369
+ route = src;
370
+ }
371
+ if (props === undefined || ((route === null || route === void 0 ? void 0 : route.points) === undefined && !(points === null || points === void 0 ? void 0 : points.length)))
364
372
  return;
365
373
  const { cnt, distance, nearest = true, latlng } = props;
366
374
  if (props.cnt !== undefined) {
367
- return getPointAtIndex(route, cnt);
375
+ return getPointAtIndex(src, cnt);
368
376
  }
369
377
  if (props.distance !== undefined) {
370
- return (0, exports.getPointAtDistance)(route, distance, nearest);
378
+ return (0, exports.getPointAtDistance)(src, distance, nearest);
371
379
  }
372
380
  if (props.latlng !== undefined) {
373
- return getPointAtLatLng(route, latlng, nearest);
381
+ return getPointAtLatLng(src, latlng, nearest);
374
382
  }
375
383
  };
376
384
  exports.getPosition = getPosition;
@@ -394,16 +402,16 @@ const getHeading = (route, point) => {
394
402
  return (0, geo_1.calculateHeaderFromPoints)(p1, p2);
395
403
  };
396
404
  exports.getHeading = getHeading;
397
- const getPointAtIndex = (route, idx) => {
398
- const points = route.points;
405
+ const getPointAtIndex = (src, idx) => {
406
+ const points = Array.isArray(src) ? src : src.points;
399
407
  if (idx >= points.length || idx < 0)
400
408
  return;
401
409
  const point = Object.assign({}, points[idx]);
402
410
  point.cnt = idx;
403
411
  return point;
404
412
  };
405
- const getPointAtDistance = (route, routeDistance, nearest = true) => {
406
- const points = route.points;
413
+ const getPointAtDistance = (src, routeDistance, nearest = true) => {
414
+ const points = Array.isArray(src) ? src : src.points;
407
415
  if (!points)
408
416
  return;
409
417
  const exact = !nearest;
@@ -432,9 +440,9 @@ const getPointAtDistance = (route, routeDistance, nearest = true) => {
432
440
  return point;
433
441
  };
434
442
  exports.getPointAtDistance = getPointAtDistance;
435
- const getPointAtLatLng = (route, latlng, nearest = true) => {
436
- const points = route.points;
437
- if (!points || !route.description.hasGpx)
443
+ const getPointAtLatLng = (src, latlng, nearest = true) => {
444
+ const points = Array.isArray(src) ? src : src.points;
445
+ if (!points)
438
446
  return;
439
447
  const exact = !nearest;
440
448
  let cnt = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.5.70",
3
+ "version": "1.6.1",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },