incyclist-services 1.0.46 → 1.0.48

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.
@@ -19,11 +19,15 @@ export declare class DeviceConfigurationService extends EventEmitter {
19
19
  userSettings: UserSettingsService;
20
20
  adapters: DeviceAdapterList;
21
21
  protected logger: EventLogger;
22
+ protected features: {
23
+ [index: string]: boolean;
24
+ };
22
25
  constructor();
23
26
  protected logEvent(e: any): void;
24
27
  protected logError(err: Error, fn: string): void;
25
28
  init(): Promise<void>;
26
- protected isNewUi(): any;
29
+ setFeature(name: string, enabled: boolean): void;
30
+ protected isNewUi(): boolean;
27
31
  protected verifyCapabilitySettings(): void;
28
32
  protected initCapabilties(): void;
29
33
  protected initInterfaces(): void;
@@ -31,6 +31,7 @@ class DeviceConfigurationService extends events_1.default {
31
31
  this.adapters = {};
32
32
  this.userSettings = (0, settings_1.useUserSettings)();
33
33
  this.logger = new gd_eventlog_1.EventLogger('DeviceConfig');
34
+ this.features = {};
34
35
  }
35
36
  logEvent(e) {
36
37
  var _a;
@@ -99,10 +100,14 @@ class DeviceConfigurationService extends events_1.default {
99
100
  this.emitInitialized();
100
101
  });
101
102
  }
103
+ setFeature(name, enabled) {
104
+ this.features[name] = enabled;
105
+ }
102
106
  isNewUi() {
103
- return (this.userSettings.isInitialized && this.userSettings.get('NEW_UI', false));
107
+ return this.features['NEW_UI'] === true;
104
108
  }
105
109
  verifyCapabilitySettings() {
110
+ var _a;
106
111
  const { capabilities } = this.settings;
107
112
  const isNewUi = this.isNewUi();
108
113
  const bikeCapIdx = capabilities.findIndex(c => c.capability === 'bike');
@@ -123,10 +128,10 @@ class DeviceConfigurationService extends events_1.default {
123
128
  const bikeCap = capabilities.find(c => c.capability === 'bike');
124
129
  for (const capability of ['bike', incyclist_devices_1.IncyclistCapability.Control]) {
125
130
  const info = capabilities.find(c => c.capability === capability);
126
- if (info && info.devices.length > 0 && info.selected === undefined)
131
+ if (((_a = info === null || info === void 0 ? void 0 : info.devices) === null || _a === void 0 ? void 0 : _a.length) > 0 && (info === null || info === void 0 ? void 0 : info.selected) === undefined)
127
132
  this.select(info.devices[0], capability);
128
133
  }
129
- if (bikeCap && bikeCap.selected) {
134
+ if (bikeCap === null || bikeCap === void 0 ? void 0 : bikeCap.selected) {
130
135
  const bike = bikeCap.selected;
131
136
  const power = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Power && c.selected !== undefined);
132
137
  const control = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control && c.selected !== undefined);
@@ -4,6 +4,7 @@ import { CapabilityData, DevicePairingData, DevicePairingStatus, DeviceSelectSta
4
4
  import { DeviceData, IncyclistCapability, IncyclistDeviceAdapter } from "incyclist-devices";
5
5
  import { AdapterStateInfo, DeviceRideService } from "../ride";
6
6
  import { IncyclistService } from "../../base/service";
7
+ import { EnrichedInterfaceSetting } from "../access";
7
8
  export declare const mappedCapability: (c: CapabilityInformation) => CapabilityData;
8
9
  export declare const mappedCapabilities: (capabilities: DeviceConfigurationInfo) => Array<CapabilityData>;
9
10
  export interface Services {
@@ -38,8 +39,9 @@ export declare class DevicePairingService extends IncyclistService {
38
39
  stopDeviceSelection(): Promise<void>;
39
40
  selectDevice(capability: IncyclistCapability, udid: string, addAll?: boolean): Promise<void>;
40
41
  deleteDevice(capability: IncyclistCapability, udid: string, deleteAll?: boolean): Promise<void>;
42
+ unselectDevices(capability: IncyclistCapability): Promise<void>;
41
43
  changeInterfaceSettings(name: string, settings: InterfaceSetting): Promise<void>;
42
- private restart;
44
+ protected restart(): Promise<void>;
43
45
  protected _stop(): Promise<void>;
44
46
  protected getCapability(capability: IncyclistCapability | CapabilityData): CapabilityData;
45
47
  protected wouldChangeCapability(capability: IncyclistCapability | CapabilityData, udid: string): boolean;
@@ -84,9 +86,15 @@ export declare class DevicePairingService extends IncyclistService {
84
86
  protected pauseScanDelay(): Promise<boolean>;
85
87
  protected getAdaptersOnInterface(ifaceName: string): AdapterInfo[];
86
88
  protected stopAdaptersOnInterface(ifaceName: string, maxRetry?: number): Promise<void>;
87
- protected disableAdaptersOnInterface(name: string): void;
88
89
  protected failAdaptersOnInterface(name: string): void;
90
+ protected disableAdaptersOnInterface(name: string): void;
89
91
  protected enableAdaptersOnInterface(name: string): void;
92
+ protected unselectDisabledInterfaces(): void;
93
+ protected unselectOnInterface(name: string): void;
94
+ protected selectFromInterface(name: string): void;
95
+ protected getCapabilitiesUsingInterface(name: string): CapabilityData[];
96
+ protected getEnabedInterfaces(): EnrichedInterfaceSetting[];
97
+ protected getDisabledInterfaces(): EnrichedInterfaceSetting[];
90
98
  protected getDeviceAdapter(udid: string): IncyclistDeviceAdapter;
91
99
  protected stopAdaptersWithCapability(capability: IncyclistCapability | CapabilityData, udid?: string): Promise<void>;
92
100
  protected pauseAdapters(adapters: AdapterInfo[], enforced?: boolean): void;
@@ -97,7 +97,7 @@ class DevicePairingService extends service_2.IncyclistService {
97
97
  this.logCapabilities();
98
98
  this.state.interfaces.forEach(i => {
99
99
  if (!this.isInterfaceEnabled(i.name))
100
- this.disableAdaptersOnInterface(i.name);
100
+ this.unselectOnInterface(i.name);
101
101
  });
102
102
  this.settings.onStateChanged = onStateChanged;
103
103
  this.emitStateChange(this.state);
@@ -228,6 +228,16 @@ class DevicePairingService extends service_2.IncyclistService {
228
228
  }
229
229
  });
230
230
  }
231
+ unselectDevices(capability) {
232
+ return __awaiter(this, void 0, void 0, function* () {
233
+ try {
234
+ this.configuration.unselect(capability, true);
235
+ }
236
+ catch (err) {
237
+ this.logError(err, 'deleteDevice');
238
+ }
239
+ });
240
+ }
231
241
  changeInterfaceSettings(name, settings) {
232
242
  return __awaiter(this, void 0, void 0, function* () {
233
243
  try {
@@ -349,11 +359,12 @@ class DevicePairingService extends service_2.IncyclistService {
349
359
  if (settings.enabled && !current.enabled) {
350
360
  const { port, protocol } = settings;
351
361
  this.access.enableInterface(ifName, undefined, { port: Number(port), protocol });
352
- this.enableAdaptersOnInterface(ifName);
362
+ this.selectFromInterface(ifName);
353
363
  }
354
364
  else if (!settings.enabled && current.enabled) {
355
365
  this.access.disableInterface(ifName);
356
- this.disableAdaptersOnInterface(ifName);
366
+ this.unselectOnInterface(ifName);
367
+ this.unselectDisabledInterfaces();
357
368
  this.stopAdaptersOnInterface(ifName).catch(err => {
358
369
  this.logError(err, 'stopAdaptersOnInterface()');
359
370
  });
@@ -421,6 +432,10 @@ class DevicePairingService extends service_2.IncyclistService {
421
432
  }
422
433
  else if (ifDetails.state === 'unavailable' && current.state !== 'unavailable') {
423
434
  this.disableAdaptersOnInterface(ifName);
435
+ this.unselectOnInterface(ifName);
436
+ }
437
+ else if (ifDetails.state !== 'unavailable' && current.state === 'unavailable') {
438
+ this.enableAdaptersOnInterface(ifName);
424
439
  }
425
440
  if (changedIdx !== -1) {
426
441
  prev[changedIdx].isScanning = ifDetails.isScanning;
@@ -829,37 +844,31 @@ class DevicePairingService extends service_2.IncyclistService {
829
844
  } while (++tryCnt < maxRetry && target && target.length > 0);
830
845
  });
831
846
  }
832
- disableAdaptersOnInterface(name) {
847
+ failAdaptersOnInterface(name) {
833
848
  const target = this.getAdaptersOnInterface(name);
834
849
  const { capabilities } = this.state;
835
850
  target.forEach(ai => {
836
851
  const { udid } = ai;
837
852
  capabilities.forEach(c => {
838
853
  const device = this.getCapabilityDevice(c, udid);
839
- if (device) {
840
- device.interfaceInactive = true;
854
+ if (device && !device.interfaceInactive) {
855
+ device.connectState = 'failed';
841
856
  if (c.selected === udid) {
842
- this.configuration.unselect(c.capability);
843
- const alternative = c.devices.find(d => !d.interfaceInactive);
844
- if (alternative)
845
- this.configuration.select(alternative.udid, c.capability);
857
+ c.connectState = 'failed';
846
858
  }
847
859
  }
848
860
  });
849
861
  });
850
862
  }
851
- failAdaptersOnInterface(name) {
863
+ disableAdaptersOnInterface(name) {
852
864
  const target = this.getAdaptersOnInterface(name);
853
865
  const { capabilities } = this.state;
854
866
  target.forEach(ai => {
855
867
  const { udid } = ai;
856
868
  capabilities.forEach(c => {
857
869
  const device = this.getCapabilityDevice(c, udid);
858
- if (device && !device.interfaceInactive) {
859
- device.connectState = 'failed';
860
- if (c.selected === udid) {
861
- c.connectState = 'failed';
862
- }
870
+ if (device) {
871
+ device.interfaceInactive = true;
863
872
  }
864
873
  });
865
874
  });
@@ -870,15 +879,51 @@ class DevicePairingService extends service_2.IncyclistService {
870
879
  target.forEach(ai => {
871
880
  const { udid } = ai;
872
881
  capabilities.forEach(c => {
873
- const alternative = c.devices.find(d => !d.interfaceInactive);
874
882
  const device = this.getCapabilityDevice(c, udid);
875
883
  if (device)
876
884
  delete device.interfaceInactive;
877
- if (!c.selected && alternative)
878
- this.configuration.select(alternative.udid, c.capability);
879
885
  });
880
886
  });
881
887
  }
888
+ unselectDisabledInterfaces() {
889
+ const disabled = this.getDisabledInterfaces();
890
+ disabled.forEach(i => this.unselectOnInterface(i.name));
891
+ }
892
+ unselectOnInterface(name) {
893
+ const impactedCapabilties = this.getCapabilitiesUsingInterface(name);
894
+ const enabledInterfaces = this.getEnabedInterfaces().filter(i => i.name !== name).map(i => i.name);
895
+ impactedCapabilties.forEach(c => {
896
+ const available = c.devices.filter(d => d.interface !== name && enabledInterfaces.includes(d.interface));
897
+ if (!(available === null || available === void 0 ? void 0 : available.length)) {
898
+ this.configuration.unselect(c.capability, true);
899
+ }
900
+ else {
901
+ this.configuration.select(available[0].udid, c.capability, { emit: true });
902
+ }
903
+ });
904
+ }
905
+ selectFromInterface(name) {
906
+ const impactedCapabilties = this.state.capabilities.filter(c => !c.selected);
907
+ const enabledInterfaces = this.getEnabedInterfaces().filter(i => i.name !== name).map(i => i.name);
908
+ impactedCapabilties.forEach(c => {
909
+ const available = c.devices.filter(d => d.interface === name || enabledInterfaces.includes(d.interface));
910
+ if ((available === null || available === void 0 ? void 0 : available.length) > 0) {
911
+ this.configuration.select(available[0].udid, c.capability, { emit: true });
912
+ }
913
+ });
914
+ }
915
+ getCapabilitiesUsingInterface(name) {
916
+ return this.state.capabilities.filter(c => {
917
+ var _a;
918
+ return ((_a = this.getCapabilityDevice(c)) === null || _a === void 0 ? void 0 : _a.interface) === name;
919
+ });
920
+ }
921
+ getEnabedInterfaces() {
922
+ return this.state.interfaces.filter(i => i.enabled === true);
923
+ }
924
+ getDisabledInterfaces() {
925
+ return this.state.interfaces.filter(i => !i.enabled);
926
+ }
882
927
  getDeviceAdapter(udid) {
883
928
  const { adapters = [] } = this.state;
884
929
  const target = adapters.find(ai => ai.udid === udid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.24"
6
6
  },