incyclist-services 1.0.45 → 1.0.47
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
|
-
|
|
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,8 +100,11 @@ 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
|
|
107
|
+
return this.features['NEW_UI'] === true;
|
|
104
108
|
}
|
|
105
109
|
verifyCapabilitySettings() {
|
|
106
110
|
const { capabilities } = this.settings;
|
|
@@ -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,10 +39,12 @@ 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
|
-
|
|
44
|
+
protected restart(): Promise<void>;
|
|
43
45
|
protected _stop(): Promise<void>;
|
|
44
46
|
protected getCapability(capability: IncyclistCapability | CapabilityData): CapabilityData;
|
|
47
|
+
protected wouldChangeCapability(capability: IncyclistCapability | CapabilityData, udid: string): boolean;
|
|
45
48
|
protected getCapabilityDevice(capability: IncyclistCapability | CapabilityData, udid?: string): DevicePairingData;
|
|
46
49
|
protected onConfigLoaded(capabilitiesLoaded: DeviceConfigurationInfo, interfacesLoaded: Array<InterfaceSetting>): Promise<void>;
|
|
47
50
|
protected waitForInit(): Promise<void>;
|
|
@@ -83,9 +86,15 @@ export declare class DevicePairingService extends IncyclistService {
|
|
|
83
86
|
protected pauseScanDelay(): Promise<boolean>;
|
|
84
87
|
protected getAdaptersOnInterface(ifaceName: string): AdapterInfo[];
|
|
85
88
|
protected stopAdaptersOnInterface(ifaceName: string, maxRetry?: number): Promise<void>;
|
|
86
|
-
protected disableAdaptersOnInterface(name: string): void;
|
|
87
89
|
protected failAdaptersOnInterface(name: string): void;
|
|
90
|
+
protected disableAdaptersOnInterface(name: string): void;
|
|
88
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[];
|
|
89
98
|
protected getDeviceAdapter(udid: string): IncyclistDeviceAdapter;
|
|
90
99
|
protected stopAdaptersWithCapability(capability: IncyclistCapability | CapabilityData, udid?: string): Promise<void>;
|
|
91
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.
|
|
100
|
+
this.unselectOnInterface(i.name);
|
|
101
101
|
});
|
|
102
102
|
this.settings.onStateChanged = onStateChanged;
|
|
103
103
|
this.emitStateChange(this.state);
|
|
@@ -184,7 +184,7 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
184
184
|
try {
|
|
185
185
|
if (addAll) {
|
|
186
186
|
const adapter = this.getDeviceAdapter(udid);
|
|
187
|
-
const capabilities = adapter.getCapabilities().filter(name => this.
|
|
187
|
+
const capabilities = adapter.getCapabilities().filter(name => this.wouldChangeCapability(name, udid));
|
|
188
188
|
capabilities.forEach((c, idx) => {
|
|
189
189
|
const shouldEmit = (idx === capabilities.length - 1);
|
|
190
190
|
const wasChanged = this.selectCapabilityDevice(c, udid, shouldEmit);
|
|
@@ -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 {
|
|
@@ -270,6 +280,12 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
270
280
|
const { capabilities = [] } = this.state;
|
|
271
281
|
return capabilities.find(c => c.capability === target);
|
|
272
282
|
}
|
|
283
|
+
wouldChangeCapability(capability, udid) {
|
|
284
|
+
const c = this.getCapability(capability);
|
|
285
|
+
if (!c)
|
|
286
|
+
return false;
|
|
287
|
+
return c.selected !== udid;
|
|
288
|
+
}
|
|
273
289
|
getCapabilityDevice(capability, udid) {
|
|
274
290
|
const c = this.getCapability(capability);
|
|
275
291
|
if (!(c === null || c === void 0 ? void 0 : c.devices))
|
|
@@ -343,11 +359,12 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
343
359
|
if (settings.enabled && !current.enabled) {
|
|
344
360
|
const { port, protocol } = settings;
|
|
345
361
|
this.access.enableInterface(ifName, undefined, { port: Number(port), protocol });
|
|
346
|
-
this.
|
|
362
|
+
this.selectFromInterface(ifName);
|
|
347
363
|
}
|
|
348
364
|
else if (!settings.enabled && current.enabled) {
|
|
349
365
|
this.access.disableInterface(ifName);
|
|
350
|
-
this.
|
|
366
|
+
this.unselectOnInterface(ifName);
|
|
367
|
+
this.unselectDisabledInterfaces();
|
|
351
368
|
this.stopAdaptersOnInterface(ifName).catch(err => {
|
|
352
369
|
this.logError(err, 'stopAdaptersOnInterface()');
|
|
353
370
|
});
|
|
@@ -415,6 +432,10 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
415
432
|
}
|
|
416
433
|
else if (ifDetails.state === 'unavailable' && current.state !== 'unavailable') {
|
|
417
434
|
this.disableAdaptersOnInterface(ifName);
|
|
435
|
+
this.unselectOnInterface(ifName);
|
|
436
|
+
}
|
|
437
|
+
else if (ifDetails.state !== 'unavailable' && current.state === 'unavailable') {
|
|
438
|
+
this.enableAdaptersOnInterface(ifName);
|
|
418
439
|
}
|
|
419
440
|
if (changedIdx !== -1) {
|
|
420
441
|
prev[changedIdx].isScanning = ifDetails.isScanning;
|
|
@@ -823,37 +844,31 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
823
844
|
} while (++tryCnt < maxRetry && target && target.length > 0);
|
|
824
845
|
});
|
|
825
846
|
}
|
|
826
|
-
|
|
847
|
+
failAdaptersOnInterface(name) {
|
|
827
848
|
const target = this.getAdaptersOnInterface(name);
|
|
828
849
|
const { capabilities } = this.state;
|
|
829
850
|
target.forEach(ai => {
|
|
830
851
|
const { udid } = ai;
|
|
831
852
|
capabilities.forEach(c => {
|
|
832
853
|
const device = this.getCapabilityDevice(c, udid);
|
|
833
|
-
if (device) {
|
|
834
|
-
device.
|
|
854
|
+
if (device && !device.interfaceInactive) {
|
|
855
|
+
device.connectState = 'failed';
|
|
835
856
|
if (c.selected === udid) {
|
|
836
|
-
|
|
837
|
-
const alternative = c.devices.find(d => !d.interfaceInactive);
|
|
838
|
-
if (alternative)
|
|
839
|
-
this.configuration.select(alternative.udid, c.capability);
|
|
857
|
+
c.connectState = 'failed';
|
|
840
858
|
}
|
|
841
859
|
}
|
|
842
860
|
});
|
|
843
861
|
});
|
|
844
862
|
}
|
|
845
|
-
|
|
863
|
+
disableAdaptersOnInterface(name) {
|
|
846
864
|
const target = this.getAdaptersOnInterface(name);
|
|
847
865
|
const { capabilities } = this.state;
|
|
848
866
|
target.forEach(ai => {
|
|
849
867
|
const { udid } = ai;
|
|
850
868
|
capabilities.forEach(c => {
|
|
851
869
|
const device = this.getCapabilityDevice(c, udid);
|
|
852
|
-
if (device
|
|
853
|
-
device.
|
|
854
|
-
if (c.selected === udid) {
|
|
855
|
-
c.connectState = 'failed';
|
|
856
|
-
}
|
|
870
|
+
if (device) {
|
|
871
|
+
device.interfaceInactive = true;
|
|
857
872
|
}
|
|
858
873
|
});
|
|
859
874
|
});
|
|
@@ -864,15 +879,51 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
864
879
|
target.forEach(ai => {
|
|
865
880
|
const { udid } = ai;
|
|
866
881
|
capabilities.forEach(c => {
|
|
867
|
-
const alternative = c.devices.find(d => !d.interfaceInactive);
|
|
868
882
|
const device = this.getCapabilityDevice(c, udid);
|
|
869
883
|
if (device)
|
|
870
884
|
delete device.interfaceInactive;
|
|
871
|
-
if (!c.selected && alternative)
|
|
872
|
-
this.configuration.select(alternative.udid, c.capability);
|
|
873
885
|
});
|
|
874
886
|
});
|
|
875
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
|
+
}
|
|
876
927
|
getDeviceAdapter(udid) {
|
|
877
928
|
const { adapters = [] } = this.state;
|
|
878
929
|
const target = adapters.find(ai => ai.udid === udid);
|
|
@@ -931,9 +982,9 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
931
982
|
this.checkCanStart();
|
|
932
983
|
}
|
|
933
984
|
selectCapabilityDevice(capability, udid, emitUpdate = true) {
|
|
985
|
+
if (!this.wouldChangeCapability(capability, udid))
|
|
986
|
+
return;
|
|
934
987
|
const c = this.getCapability(capability);
|
|
935
|
-
if (!c || c.selected === udid)
|
|
936
|
-
return false;
|
|
937
988
|
const device = this.getCapabilityDevice(capability, udid);
|
|
938
989
|
c.value = device === null || device === void 0 ? void 0 : device.value;
|
|
939
990
|
this.configuration.select(udid, capability, { emit: emitUpdate });
|