incyclist-services 1.5.49 → 1.5.51

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.
@@ -264,37 +264,45 @@ let ActiveRidesService = (() => {
264
264
  }
265
265
  getDisplayProps() {
266
266
  const items = this.get();
267
- if (!items.length)
268
- return [];
269
- const displayProps = [];
270
- items.forEach(item => {
271
- var _a, _b;
272
- const displayItem = {
273
- isUser: item.sessionId === this.session,
274
- name: this.getName(item),
275
- diffDistance: this.getDistanceDiff(item),
276
- distance: item.currentRideDistance,
277
- avatar: this.getAvatar(item),
278
- lap: this.getLap(item, true),
279
- power: item.currentPower,
280
- mpower: this.getRelativePower(item),
281
- speed: item.currentSpeed,
282
- lat: (_a = item.currentPosition) === null || _a === void 0 ? void 0 : _a.lat,
283
- lng: (_b = item.currentPosition) === null || _b === void 0 ? void 0 : _b.lng,
284
- };
285
- displayProps.push(displayItem);
286
- });
287
- if (displayProps.length > this.maxLength) {
288
- const absDiff = (r) => Math.abs(r.diffDistance);
267
+ try {
268
+ if (!items.length)
269
+ return [];
270
+ const displayProps = [];
271
+ items.forEach(item => {
272
+ var _a, _b, _c, _d;
273
+ if (!(item === null || item === void 0 ? void 0 : item.id) && !((_b = (_a = item === null || item === void 0 ? void 0 : item.user) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.length) && (item === null || item === void 0 ? void 0 : item.sessionId) !== this.session)
274
+ return;
275
+ const displayItem = {
276
+ isUser: item.sessionId === this.session,
277
+ name: this.getName(item),
278
+ diffDistance: this.getDistanceDiff(item),
279
+ distance: item.currentRideDistance,
280
+ avatar: this.getAvatar(item),
281
+ lap: this.getLap(item, true),
282
+ power: item.currentPower,
283
+ mpower: this.getRelativePower(item),
284
+ speed: item.currentSpeed,
285
+ lat: (_c = item.currentPosition) === null || _c === void 0 ? void 0 : _c.lat,
286
+ lng: (_d = item.currentPosition) === null || _d === void 0 ? void 0 : _d.lng,
287
+ };
288
+ displayProps.push(displayItem);
289
+ });
290
+ if (displayProps.length > this.maxLength) {
291
+ const absDiff = (r) => Math.abs(r.diffDistance);
292
+ displayProps.sort((a, b) => {
293
+ return absDiff(b) > absDiff(a) ? -1 : 1;
294
+ });
295
+ return displayProps.filter((_r, idx) => idx < this.maxLength);
296
+ }
289
297
  displayProps.sort((a, b) => {
290
- return absDiff(b) > absDiff(a) ? -1 : 1;
298
+ return b.diffDistance > a.diffDistance ? -1 : 1;
291
299
  });
292
- return displayProps.filter((_r, idx) => idx < this.maxLength);
300
+ return displayProps;
301
+ }
302
+ catch (err) {
303
+ this.logError(err, 'getDisplayProps', { items });
304
+ return [];
293
305
  }
294
- displayProps.sort((a, b) => {
295
- return b.diffDistance > a.diffDistance ? -1 : 1;
296
- });
297
- return displayProps;
298
306
  }
299
307
  validName(str) {
300
308
  if (!(str === null || str === void 0 ? void 0 : str.length))
@@ -309,6 +317,8 @@ let ActiveRidesService = (() => {
309
317
  return this.validName((_f = item.user) === null || _f === void 0 ? void 0 : _f.name) ? (_g = item.user) === null || _g === void 0 ? void 0 : _g.name : this.randomName((_h = item.user) === null || _h === void 0 ? void 0 : _h.id);
310
318
  }
311
319
  randomName(id) {
320
+ if (!id)
321
+ return 'Anonymous';
312
322
  const names = ['Alex', 'Bart', 'Cosmas', 'Dirk', 'Ernesto', 'Frank', 'Guido', 'Hans', 'Irene', 'John', 'Kai', 'Lorenzo', 'Martin', 'Naijb', 'Oswaldo', 'Pete', 'Quentin', 'Rachel', 'Sophia', 'Trevor', 'Ute', 'Vivian', 'Wil', 'Xaver', 'Younes', 'Zoe'];
313
323
  const fnKey = id.charAt(0).toLowerCase();
314
324
  const idx = !isNaN(parseInt(fnKey)) ? parseInt(fnKey) : fnKey.charCodeAt(0) - 96;
@@ -514,21 +524,25 @@ let ActiveRidesService = (() => {
514
524
  this.getMessageQueue().sendMessage(topic, payload);
515
525
  }
516
526
  onActivityStartEvent(session, payload) {
517
- var _a, _b, _c, _d, _e, _f;
527
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
518
528
  const prevActive = (_a = this.others) === null || _a === void 0 ? void 0 : _a.length;
519
529
  try {
520
530
  const others = (_b = this.others) !== null && _b !== void 0 ? _b : [];
521
- if (others.find(ar => ar.sessionId === session))
531
+ if (others.some(ar => ar.sessionId === session))
532
+ return;
533
+ if (((_c = payload.user) === null || _c === void 0 ? void 0 : _c.id) && ((_d = payload.user) === null || _d === void 0 ? void 0 : _d.id) === ((_e = this.current.user) === null || _e === void 0 ? void 0 : _e.id))
534
+ return;
535
+ if (((_f = payload.user) === null || _f === void 0 ? void 0 : _f.id) && others.some(ar => { var _a, _b; return ((_a = ar.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = payload.user) === null || _b === void 0 ? void 0 : _b.id); }))
522
536
  return;
523
537
  const entry = Object.assign(Object.assign({ id: Date.now().toString(), tsLastUpdate: Date.now() }, payload), { sessionId: session });
524
538
  this.addActiveRide(entry);
525
539
  if (prevActive === 0) {
526
540
  this.isStarted = true;
527
- this.logEvent({ message: 'group ride started', active: this.others.length + 1, activityId: (_c = this.activity) === null || _c === void 0 ? void 0 : _c.id, route: (_d = this.activity.route) === null || _d === void 0 ? void 0 : _d.title, routeHash: this.getRouteHash() });
541
+ this.logEvent({ message: 'group ride started', active: this.others.length + 1, activityId: (_g = this.activity) === null || _g === void 0 ? void 0 : _g.id, route: (_h = this.activity.route) === null || _h === void 0 ? void 0 : _h.title, routeHash: this.getRouteHash() });
528
542
  }
529
543
  else {
530
544
  this.isStarted = true;
531
- this.logEvent({ message: 'group ride user joined', active: this.others.length + 1, activityId: (_e = this.activity) === null || _e === void 0 ? void 0 : _e.id, route: (_f = this.activity.route) === null || _f === void 0 ? void 0 : _f.title, routeHash: this.getRouteHash() });
545
+ this.logEvent({ message: 'group ride user joined', active: this.others.length + 1, activityId: (_j = this.activity) === null || _j === void 0 ? void 0 : _j.id, route: (_k = this.activity.route) === null || _k === void 0 ? void 0 : _k.title, routeHash: this.getRouteHash(), user: (_l = payload === null || payload === void 0 ? void 0 : payload.user) === null || _l === void 0 ? void 0 : _l.id });
532
546
  }
533
547
  if (!payload.user) {
534
548
  this.getRemoteActivityDetails(session);
@@ -644,31 +658,36 @@ let ActiveRidesService = (() => {
644
658
  }
645
659
  }
646
660
  updateCoaches() {
647
- if (!this.current)
648
- return;
649
- const coachesService = this.getCoachesService();
650
- const coaches = coachesService.getCoaches();
651
- if (!(coaches === null || coaches === void 0 ? void 0 : coaches.length)) {
652
- this.coaches = undefined;
653
- return;
654
- }
655
- this.coaches = coaches.map(c => {
656
- var _a;
657
- const props = c.getDisplayProperties();
658
- const rideEntry = {
659
- id: `coach:${props.name}`,
660
- user: {
661
- name: props.name,
661
+ try {
662
+ if (!this.current)
663
+ return;
664
+ const coachesService = this.getCoachesService();
665
+ const coaches = coachesService.getCoaches();
666
+ if (!(coaches === null || coaches === void 0 ? void 0 : coaches.length)) {
667
+ this.coaches = undefined;
668
+ return;
669
+ }
670
+ this.coaches = coaches.map(c => {
671
+ var _a;
672
+ const props = c.getDisplayProperties();
673
+ const rideEntry = {
662
674
  id: `coach:${props.name}`,
663
- },
664
- ride: (_a = this.current) === null || _a === void 0 ? void 0 : _a.ride,
665
- tsLastUpdate: Date.now(),
666
- currentRideDistance: c.getProgess(),
667
- currentPosition: c.getPosition(),
668
- isCoach: true
669
- };
670
- return rideEntry;
671
- });
675
+ user: {
676
+ name: props.name,
677
+ id: `coach:${props.name}`,
678
+ },
679
+ ride: (_a = this.current) === null || _a === void 0 ? void 0 : _a.ride,
680
+ tsLastUpdate: Date.now(),
681
+ currentRideDistance: c.getProgess(),
682
+ currentPosition: c.getPosition(),
683
+ isCoach: true
684
+ };
685
+ return rideEntry;
686
+ });
687
+ }
688
+ catch (err) {
689
+ this.logError(err, 'updateCoaches');
690
+ }
672
691
  }
673
692
  cleanup() {
674
693
  delete this.current;
@@ -334,7 +334,10 @@ let ActivityRideService = (() => {
334
334
  }
335
335
  }
336
336
  canShowDonate() {
337
- if (this.isDonateShown)
337
+ var _a, _b, _c, _d;
338
+ if (!((_b = (_a = this.activity) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.uuid))
339
+ return false;
340
+ if (this.isDonateShown || !((_d = (_c = this.activity) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.uuid))
338
341
  return true;
339
342
  let trialGroup;
340
343
  if (this.activity.user.uuid.startsWith('1') || this.activity.user.uuid.startsWith('a')) {
@@ -92,6 +92,7 @@ export declare class DeviceConfigurationService extends IncyclistService {
92
92
  protected getUserSettings(): import("../../settings").UserSettingsService;
93
93
  protected getAdapterFactory(): typeof AdapterFactory;
94
94
  protected getDevicesFeatureToggle(): import("incyclist-devices").FeatureToggle;
95
+ protected getDirectConnectInterface(): import("incyclist-devices").SerialInterface | import("incyclist-devices").AntInterface | import("incyclist-devices").BleInterface | import("incyclist-devices/lib/direct-connect/base/interface").default;
95
96
  }
96
97
  export declare const useDeviceConfiguration: () => DeviceConfigurationService;
97
98
  export {};
@@ -70,6 +70,7 @@ let DeviceConfigurationService = (() => {
70
70
  let _getUserSettings_decorators;
71
71
  let _getAdapterFactory_decorators;
72
72
  let _getDevicesFeatureToggle_decorators;
73
+ let _getDirectConnectInterface_decorators;
73
74
  var DeviceConfigurationService = _classThis = class extends _classSuper {
74
75
  constructor() {
75
76
  super('DeviceConfig');
@@ -115,9 +116,15 @@ let DeviceConfigurationService = (() => {
115
116
  this.updateUserSettings();
116
117
  if (!((_c = this.settings) === null || _c === void 0 ? void 0 : _c.devices))
117
118
  this.settings.devices = [];
119
+ let updated = false;
118
120
  this.settings.devices.forEach(d => {
119
- if (!(d === null || d === void 0 ? void 0 : d.udid))
121
+ if (!(d === null || d === void 0 ? void 0 : d.udid)) {
122
+ if ((d === null || d === void 0 ? void 0 : d.settings.interface) === 'wifi') {
123
+ d.udid = (0, uuid_1.v4)();
124
+ updated = true;
125
+ }
120
126
  return;
127
+ }
121
128
  try {
122
129
  this.adapters[d.udid] = this.getAdapterFromSetting(d.settings);
123
130
  }
@@ -125,6 +132,9 @@ let DeviceConfigurationService = (() => {
125
132
  this.logEvent({ message: 'error', fn: 'init()->Adapterfactory.create()', error: err.message, udid: d.udid, settings: d.settings, devices: this.settings.devices, stack: err.stack, });
126
133
  }
127
134
  });
135
+ if (updated) {
136
+ this.getUserSettings().set('devices', this.settings.devices);
137
+ }
128
138
  this.initWifiInterface();
129
139
  this.verifyCapabilitySettings();
130
140
  this.removeLegacySettings();
@@ -229,8 +239,16 @@ let DeviceConfigurationService = (() => {
229
239
  const { legacy = false } = props || {};
230
240
  const deviceAlreadyExists = udid !== undefined;
231
241
  let adapter;
242
+ const updateWifiSettings = (udid) => {
243
+ var _a, _b;
244
+ const settingIdx = this.settings.devices.findIndex(d => d.udid === udid);
245
+ if (settingIdx !== -1 && ((_b = (_a = this.settings.devices[settingIdx]) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.interface) === 'wifi') {
246
+ this.settings.devices[settingIdx].settings = Object.assign(Object.assign({}, this.settings.devices[settingIdx].settings), deviceSettings);
247
+ }
248
+ };
232
249
  if (deviceAlreadyExists && this.adapters[udid]) {
233
250
  adapter = this.adapters[udid];
251
+ updateWifiSettings(udid);
234
252
  }
235
253
  else {
236
254
  this.logEvent({ message: 'add device', udid, deviceSettings, legacy });
@@ -240,7 +258,10 @@ let DeviceConfigurationService = (() => {
240
258
  return;
241
259
  }
242
260
  udid = (_b = (_a = this.settings.devices) === null || _a === void 0 ? void 0 : _a.find(d => adapter.isEqual(d.settings))) === null || _b === void 0 ? void 0 : _b.udid;
243
- if (!udid) {
261
+ if (udid) {
262
+ updateWifiSettings(udid);
263
+ }
264
+ else {
244
265
  if (!this.settings.devices)
245
266
  this.settings.devices = [];
246
267
  udid = (0, uuid_1.v4)();
@@ -512,6 +533,12 @@ let DeviceConfigurationService = (() => {
512
533
  const idx = this.settings.interfaces.indexOf(wifi);
513
534
  this.settings.interfaces[idx] = { name: 'wifi', enabled, invisible };
514
535
  }
536
+ const wifiDevices = this.settings.devices.filter(d => { var _a; return ((_a = d === null || d === void 0 ? void 0 : d.settings) === null || _a === void 0 ? void 0 : _a.interface) === 'wifi'; });
537
+ const dc = this.getDirectConnectInterface();
538
+ wifiDevices.forEach(d => {
539
+ const settings = d.settings;
540
+ dc.addKnownDevice(settings);
541
+ });
515
542
  }
516
543
  confirmWifiInterface() {
517
544
  this.getUserSettings().set('wifiConfirmed', true);
@@ -935,6 +962,9 @@ let DeviceConfigurationService = (() => {
935
962
  getDevicesFeatureToggle() {
936
963
  return (0, incyclist_devices_1.useFeatureToggle)();
937
964
  }
965
+ getDirectConnectInterface() {
966
+ return incyclist_devices_1.InterfaceFactory.create('wifi');
967
+ }
938
968
  };
939
969
  __setFunctionName(_classThis, "DeviceConfigurationService");
940
970
  (() => {
@@ -943,9 +973,11 @@ let DeviceConfigurationService = (() => {
943
973
  _getUserSettings_decorators = [decorators_1.Injectable];
944
974
  _getAdapterFactory_decorators = [decorators_1.Injectable];
945
975
  _getDevicesFeatureToggle_decorators = [decorators_1.Injectable];
976
+ _getDirectConnectInterface_decorators = [decorators_1.Injectable];
946
977
  __esDecorate(_classThis, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
947
978
  __esDecorate(_classThis, null, _getAdapterFactory_decorators, { kind: "method", name: "getAdapterFactory", static: false, private: false, access: { has: obj => "getAdapterFactory" in obj, get: obj => obj.getAdapterFactory }, metadata: _metadata }, null, _instanceExtraInitializers);
948
979
  __esDecorate(_classThis, null, _getDevicesFeatureToggle_decorators, { kind: "method", name: "getDevicesFeatureToggle", static: false, private: false, access: { has: obj => "getDevicesFeatureToggle" in obj, get: obj => obj.getDevicesFeatureToggle }, metadata: _metadata }, null, _instanceExtraInitializers);
980
+ __esDecorate(_classThis, null, _getDirectConnectInterface_decorators, { kind: "method", name: "getDirectConnectInterface", static: false, private: false, access: { has: obj => "getDirectConnectInterface" in obj, get: obj => obj.getDirectConnectInterface }, metadata: _metadata }, null, _instanceExtraInitializers);
949
981
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
950
982
  DeviceConfigurationService = _classThis = _classDescriptor.value;
951
983
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -103,7 +103,8 @@ let RideDisplayService = (() => {
103
103
  try {
104
104
  this.displayService = this.getRideModeService(true);
105
105
  const ftNewUI = this.getUserSettings().get('NEW_GPX_UI', false);
106
- if (ftNewUI || this.displayService instanceof WorkoutDisplayService_1.WorkoutDisplayService) {
106
+ const showLegacy = !ftNewUI && (this.displayService instanceof RLVDisplayService_1.RLVDisplayService);
107
+ if (!showLegacy) {
107
108
  this.displayService.init(this);
108
109
  this.displayService.on('lap-completed', this.onLapCompleted.bind(this));
109
110
  this.displayService.on('route-completed', this.onRouteCompleted.bind(this));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.5.49",
3
+ "version": "1.5.51",
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.3.39",
45
+ "incyclist-devices": "^2.3.41",
46
46
  "promise.any": "^2.0.6",
47
47
  "semver": "^7.6.3",
48
48
  "tcx-builder": "^1.1.1",