incyclist-services 1.0.16 → 1.0.18

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,6 +1,6 @@
1
1
  import { DeviceSettings, IncyclistCapability } from "incyclist-devices";
2
- export declare type InterfaceState = 'connected' | 'disconnected' | 'unknown' | 'connecting' | 'disconnecting' | 'unavailable';
3
- export declare type ScanState = 'start-requested' | 'started' | 'stop-requested' | 'stopped' | 'idle';
2
+ export type InterfaceState = 'connected' | 'disconnected' | 'unknown' | 'connecting' | 'disconnecting' | 'unavailable';
3
+ export type ScanState = 'start-requested' | 'started' | 'stop-requested' | 'stopped' | 'idle';
4
4
  export interface InterfaceInfo {
5
5
  name: string;
6
6
  enabled: boolean;
@@ -21,6 +21,11 @@ const merge_1 = require("../../utils/merge");
21
21
  const sleep_1 = require("../../utils/sleep");
22
22
  const configuration_1 = require("../configuration");
23
23
  class DeviceAccessService extends events_1.default {
24
+ static getInstance() {
25
+ if (!DeviceAccessService._instance)
26
+ DeviceAccessService._instance = new DeviceAccessService();
27
+ return DeviceAccessService._instance;
28
+ }
24
29
  constructor() {
25
30
  super();
26
31
  this.interfaces = {};
@@ -28,11 +33,6 @@ class DeviceAccessService extends events_1.default {
28
33
  this.logger = new gd_eventlog_1.EventLogger('DeviceAccess');
29
34
  this.defaultProps = {};
30
35
  }
31
- static getInstance() {
32
- if (!DeviceAccessService._instance)
33
- DeviceAccessService._instance = new DeviceAccessService();
34
- return DeviceAccessService._instance;
35
- }
36
36
  logEvent(event) {
37
37
  this.logger.logEvent(event);
38
38
  const w = global.window;
@@ -1,5 +1,5 @@
1
1
  import { IncyclistCapability } from 'incyclist-devices';
2
- export declare type ExtendedIncyclistCapability = IncyclistCapability | 'bike';
2
+ export type ExtendedIncyclistCapability = IncyclistCapability | 'bike';
3
3
  export interface DeviceInformation {
4
4
  udid: string;
5
5
  name: string;
@@ -1,6 +1,6 @@
1
1
  import { SerialDeviceSettings, AntDeviceSettings, BleDeviceSettings } from 'incyclist-devices';
2
2
  import { ExtendedIncyclistCapability } from '../app';
3
- export declare type IncyclistDeviceSettings = SerialDeviceSettings | AntDeviceSettings | BleDeviceSettings;
3
+ export type IncyclistDeviceSettings = SerialDeviceSettings | AntDeviceSettings | BleDeviceSettings;
4
4
  export * from './legacy';
5
5
  export interface DeviceListEntry {
6
6
  udid: string;
@@ -22,7 +22,7 @@ export interface ModeListEntry {
22
22
  mode: string;
23
23
  setting: any;
24
24
  }
25
- export declare type CapabilitySetting = {
25
+ export type CapabilitySetting = {
26
26
  selected: string | undefined;
27
27
  capability: ExtendedIncyclistCapability;
28
28
  disabled?: boolean;
@@ -20,17 +20,17 @@ const events_1 = __importDefault(require("events"));
20
20
  const merge_1 = require("../../utils/merge");
21
21
  const gd_eventlog_1 = require("gd-eventlog");
22
22
  class DeviceConfigurationService extends events_1.default {
23
+ static getInstance() {
24
+ if (!DeviceConfigurationService._instance)
25
+ DeviceConfigurationService._instance = new DeviceConfigurationService();
26
+ return DeviceConfigurationService._instance;
27
+ }
23
28
  constructor() {
24
29
  super();
25
30
  this.adapters = {};
26
31
  this.userSettings = (0, settings_1.useUserSettings)();
27
32
  this.logger = new gd_eventlog_1.EventLogger('DeviceConfig');
28
33
  }
29
- static getInstance() {
30
- if (!DeviceConfigurationService._instance)
31
- DeviceConfigurationService._instance = new DeviceConfigurationService();
32
- return DeviceConfigurationService._instance;
33
- }
34
34
  logEvent(e) {
35
35
  var _a;
36
36
  (_a = this.logger) === null || _a === void 0 ? void 0 : _a.logEvent(e);
@@ -87,7 +87,7 @@ class DeviceConfigurationService extends events_1.default {
87
87
  this.adapters[d.udid] = incyclist_devices_1.AdapterFactory.create(d.settings);
88
88
  }
89
89
  catch (err) {
90
- this.logError(err, 'init()->Adapterfactory.create()');
90
+ this.logEvent({ message: 'error', fn: 'init()->Adapterfactory.create()', error: err.message, udid: d.udid, settings: d.settings, devices: this.settings.devices, stack: err.stack, });
91
91
  }
92
92
  });
93
93
  const { capabilities } = this.settings;
@@ -294,18 +294,22 @@ class DeviceConfigurationService extends events_1.default {
294
294
  this.emitCapabiltyChanged();
295
295
  }
296
296
  select(udid, capability, props) {
297
- var _a, _b, _c;
297
+ var _a, _b, _c, _d;
298
298
  this.logEvent({ message: 'select device', udid, capability, props });
299
299
  const { noRecursive = false, legacy = false } = props || {};
300
300
  const deviceSettings = (_b = (_a = this.settings.devices) === null || _a === void 0 ? void 0 : _a.find(d => d.udid === udid)) === null || _b === void 0 ? void 0 : _b.settings;
301
301
  if (!deviceSettings)
302
302
  return;
303
303
  const adapter = this.adapters[udid] || incyclist_devices_1.AdapterFactory.create(deviceSettings);
304
+ if (!adapter) {
305
+ this.logEvent({ message: 'error: could not find adapter', fn: 'select', udid, capability, adapters: (_c = Object.keys(this.adapters)) === null || _c === void 0 ? void 0 : _c.join(',') });
306
+ return;
307
+ }
304
308
  if (capability === 'bike' && !adapter.isControllable())
305
309
  return;
306
310
  const isControl = adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control) || (legacy && capability === 'bike');
307
311
  this.addToCapability(udid, capability);
308
- const capSettings = (_c = this.settings.capabilities) === null || _c === void 0 ? void 0 : _c.find(c => c.capability === capability);
312
+ const capSettings = (_d = this.settings.capabilities) === null || _d === void 0 ? void 0 : _d.find(c => c.capability === capability);
309
313
  capSettings.selected = udid;
310
314
  if (capSettings.disabled)
311
315
  delete capSettings.disabled;
@@ -530,7 +534,7 @@ class DeviceConfigurationService extends events_1.default {
530
534
  this.getSelected(incyclist_devices_1.IncyclistCapability.Speed) !== undefined);
531
535
  }
532
536
  getModeSettings(requestedUdid, requestedMode) {
533
- var _a, _b;
537
+ var _a, _b, _c;
534
538
  const { capabilities, devices } = this.settings;
535
539
  if (!this.isInitialized())
536
540
  return;
@@ -546,6 +550,10 @@ class DeviceConfigurationService extends events_1.default {
546
550
  let mode, modes, settings;
547
551
  let modeObj;
548
552
  const adapter = incyclist_devices_1.AdapterFactory.create(device.settings);
553
+ if (!adapter) {
554
+ this.logEvent({ message: 'Error: could not find adapter', requestedUdid, requestedMode, devices, adapters: (_c = Object.keys(this.adapters)) === null || _c === void 0 ? void 0 : _c.join(',') });
555
+ return;
556
+ }
549
557
  mode = requestedMode || device.mode;
550
558
  if (adapter.getSupportedCyclingModes) {
551
559
  modes = adapter.getSupportedCyclingModes();
@@ -23,6 +23,11 @@ const settings_1 = require("../../settings");
23
23
  const gd_eventlog_1 = require("gd-eventlog");
24
24
  const logging_1 = require("../../utils/logging");
25
25
  class DeviceRideService extends events_1.default {
26
+ static getInstance() {
27
+ if (!DeviceRideService._instance)
28
+ DeviceRideService._instance = new DeviceRideService();
29
+ return DeviceRideService._instance;
30
+ }
26
31
  constructor() {
27
32
  super();
28
33
  this.data = {};
@@ -32,11 +37,6 @@ class DeviceRideService extends events_1.default {
32
37
  this.logger = new gd_eventlog_1.EventLogger('Ride');
33
38
  this.debug = false;
34
39
  }
35
- static getInstance() {
36
- if (!DeviceRideService._instance)
37
- DeviceRideService._instance = new DeviceRideService();
38
- return DeviceRideService._instance;
39
- }
40
40
  logEvent(event) {
41
41
  this.logger.logEvent(event);
42
42
  const w = global.window;
@@ -338,7 +338,7 @@ class DeviceRideService extends events_1.default {
338
338
  startProps.timeout = 30000;
339
339
  }
340
340
  if (startType === 'start') {
341
- if (ai.adapter.isControllable()) {
341
+ if (ai.adapter && ai.adapter.isControllable()) {
342
342
  const d = ai.adapter;
343
343
  let mode, settings;
344
344
  if (!this.simulatorEnforced) {
@@ -508,7 +508,7 @@ class DeviceRideService extends events_1.default {
508
508
  sendUpdate(request) {
509
509
  const adapters = this.getAdapterList();
510
510
  adapters === null || adapters === void 0 ? void 0 : adapters.forEach(ai => {
511
- if (ai.adapter.isControllable()) {
511
+ if (ai.adapter && ai.adapter.isControllable()) {
512
512
  const d = ai.adapter;
513
513
  d.sendUpdate(request);
514
514
  }
@@ -16,16 +16,16 @@ const types_1 = require("./types");
16
16
  const promises_1 = __importDefault(require("fs/promises"));
17
17
  const DEFAULT_PATH = './settings.json';
18
18
  class JSONFileBindig extends types_1.UserSettingsBinding {
19
- constructor(path = DEFAULT_PATH) {
20
- super();
21
- this.path = path;
22
- this.savePromise = null;
23
- }
24
19
  static getInstance(path) {
25
20
  if (!JSONFileBindig._instance)
26
21
  JSONFileBindig._instance = new JSONFileBindig(path);
27
22
  return JSONFileBindig._instance;
28
23
  }
24
+ constructor(path = DEFAULT_PATH) {
25
+ super();
26
+ this.path = path;
27
+ this.savePromise = null;
28
+ }
29
29
  getAll() {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
31
  const settings = yield promises_1.default.readFile(this.path);
@@ -18,6 +18,12 @@ const clone_1 = __importDefault(require("../../utils/clone"));
18
18
  const merge_1 = require("../../utils/merge");
19
19
  const valid_1 = require("../../utils/valid");
20
20
  class UserSettingsService {
21
+ static getInstance() {
22
+ if (!UserSettingsService._instance) {
23
+ UserSettingsService._instance = new UserSettingsService();
24
+ }
25
+ return UserSettingsService._instance;
26
+ }
21
27
  constructor() {
22
28
  this.settings = {};
23
29
  this.logger = new gd_eventlog_1.EventLogger('UserSettings');
@@ -25,12 +31,6 @@ class UserSettingsService {
25
31
  this.isDirty = false;
26
32
  this.savePromise = null;
27
33
  }
28
- static getInstance() {
29
- if (!UserSettingsService._instance) {
30
- UserSettingsService._instance = new UserSettingsService();
31
- }
32
- return UserSettingsService._instance;
33
- }
34
34
  setBinding(binding) {
35
35
  this.binding = binding;
36
36
  }
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "peerDependencies": {
5
- "gd-eventlog": "^0.1.22"
5
+ "gd-eventlog": "^0.1.24"
6
6
  },
7
7
  "devDependencies": {
8
- "@types/jest": "^29.4.0",
9
- "@types/node": "^18.14.1",
10
- "@typescript-eslint/eslint-plugin": "^5.53.0",
11
- "@typescript-eslint/parser": "^5.53.0",
12
- "eslint": "^8.34.0",
13
- "jest": "^29.4.3",
8
+ "@types/jest": "^29.5.3",
9
+ "@types/node": "^20.5.0",
10
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
11
+ "@typescript-eslint/parser": "^6.4.0",
12
+ "eslint": "^8.47.0",
13
+ "eslint-config-react-app": "^7.0.1",
14
+ "jest": "^29.6.2",
14
15
  "jsdoc": "^4.0.2",
15
- "ts-jest": "^29.0.5",
16
- "typedoc": "^0.23.25",
17
- "typedoc-plugin-markdown": "^3.14.0",
16
+ "ts-jest": "^29.1.1",
17
+ "typedoc": "^0.24.8",
18
+ "typedoc-plugin-markdown": "^3.15.4",
18
19
  "typedoc-plugin-no-inherit": "^1.4.0",
19
- "typescript": "^4.9.5"
20
+ "typescript": "^5.1.6"
20
21
  },
21
22
  "scripts": {
22
23
  "lint": "eslint . --ext .ts",
@@ -36,7 +37,7 @@
36
37
  "lib": "./src"
37
38
  },
38
39
  "dependencies": {
39
- "incyclist-devices": "^2.0.15",
40
+ "incyclist-devices": "^2.0.16",
40
41
  "uuid": "^9.0.0"
41
42
  }
42
43
  }