incyclist-services 1.0.9 → 1.0.10

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;
@@ -18,7 +18,7 @@ export declare class DeviceAccessService extends EventEmitter {
18
18
  protected logEvent(event: any): void;
19
19
  setDefaultInterfaceProperties(props: InterfaceAccessProps): void;
20
20
  enableInterface(ifaceName: string, binding?: any, props?: InterfaceAccessProps): void;
21
- disableInterface(ifaceName: string): void;
21
+ disableInterface(ifaceName: string, avalailable?: boolean): void;
22
22
  setInterfaceProperties(ifaceName: string, props: InterfaceAccessProps): void;
23
23
  getInterfaceInfo(ifaceName: string): InterfaceInfo;
24
24
  protected getInterface(ifaceName: string): IncyclistInterface;
@@ -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;
@@ -69,7 +69,7 @@ class DeviceAccessService extends events_1.default {
69
69
  this.emit('interface-changed', ifaceName, this.interfaces[ifaceName]);
70
70
  }
71
71
  }
72
- disableInterface(ifaceName) {
72
+ disableInterface(ifaceName, avalailable = true) {
73
73
  const existing = this.interfaces[ifaceName];
74
74
  if (!existing)
75
75
  return;
@@ -84,6 +84,12 @@ class DeviceAccessService extends events_1.default {
84
84
  return;
85
85
  }
86
86
  existing.enabled = false;
87
+ if (!avalailable) {
88
+ existing.state = 'unavailable';
89
+ existing.unavailable = true;
90
+ this.emit('interface-changed', ifaceName, { name: ifaceName, state: 'unavailable', isScanning: false });
91
+ return;
92
+ }
87
93
  this.emit('interface-changed', ifaceName, this.interfaces[ifaceName]);
88
94
  }
89
95
  setInterfaceProperties(ifaceName, props) {
@@ -175,21 +181,17 @@ class DeviceAccessService extends events_1.default {
175
181
  interfaces.forEach((i) => {
176
182
  i.on('device', (deviceSettings) => __awaiter(this, void 0, void 0, function* () {
177
183
  var _a, _b;
178
- console.log('~~~ detected device:', deviceSettings);
179
184
  if (adapters.find(a => a.isEqual(deviceSettings))) {
180
- console.log('~~~ device already detected');
181
185
  return;
182
186
  }
183
187
  if (filter.profile && deviceSettings.profile !== filter.profile) {
184
- console.log('~~~ device does not match profile', filter.profile);
185
188
  return;
186
189
  }
187
190
  if (filter.protocol && deviceSettings.protocol !== filter.protocol) {
188
- console.log('~~~ device does not match protocol', filter.protocol);
189
191
  return;
190
192
  }
191
193
  if (filter.protocols && !filter.protocols.includes(deviceSettings.protocol)) {
192
- console.log('~~~ device does not match protocols', filter.protocol);
194
+ return;
193
195
  }
194
196
  const adapter = incyclist_devices_1.AdapterFactory.create(deviceSettings);
195
197
  if (filter.capabilities) {
@@ -198,7 +200,6 @@ class DeviceAccessService extends events_1.default {
198
200
  found = found || adapter.getCapabilities().includes(capability);
199
201
  });
200
202
  if (!found) {
201
- console.log('~~~ device does not match capabilties', filter.capabilities);
202
203
  return;
203
204
  }
204
205
  }
@@ -219,11 +220,11 @@ class DeviceAccessService extends events_1.default {
219
220
  yield adapter.stop();
220
221
  }
221
222
  catch (err) {
222
- console.log(err);
223
+ this.logEvent({ message: 'could not start device', device: adapter === null || adapter === void 0 ? void 0 : adapter.getUniqueName(), reason: err.message });
223
224
  }
224
225
  }
225
226
  catch (err) {
226
- console.log('~~~ start error', err);
227
+ this.logEvent({ message: 'error', fn: 'scan#adapte', error: err.message, stack: err.stack });
227
228
  }
228
229
  }
229
230
  }));
@@ -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);
@@ -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;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.22"
6
6
  },
@@ -36,7 +36,7 @@
36
36
  "lib": "./src"
37
37
  },
38
38
  "dependencies": {
39
- "incyclist-devices": "^2.0.8",
39
+ "incyclist-devices": "^2.0.9",
40
40
  "uuid": "^9.0.0"
41
41
  }
42
42
  }