incyclist-services 1.0.73 → 1.0.74
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.
|
@@ -53,11 +53,13 @@ export declare class DevicePairingService extends IncyclistService {
|
|
|
53
53
|
protected waitForInit(): Promise<void>;
|
|
54
54
|
protected getExternaState(toEmit: PairingState): PairingState;
|
|
55
55
|
protected emitStateChange(newState?: PairingState): void;
|
|
56
|
+
protected emitStartStatus(): void;
|
|
56
57
|
protected onInterfaceConfigChanged(ifName: string, settings: InterfaceSetting): void;
|
|
57
58
|
protected mergeState(current: any, newState: any): void;
|
|
58
59
|
protected onConfigurationUpdate(newCapabilities: DeviceConfigurationInfo): void;
|
|
59
60
|
protected onInterfaceStateChanged(ifName: any, ifDetails: any, interfacesNew?: any): Promise<any>;
|
|
60
61
|
protected isInterfaceEnabled(target: string | InterfaceSetting): boolean;
|
|
62
|
+
protected isInterfaceInUse(target: string | InterfaceSetting): CapabilityData;
|
|
61
63
|
protected logCapabilities(capabilities?: Array<CapabilityData>): CapabilityData[];
|
|
62
64
|
protected initPairingCallbacks(): void;
|
|
63
65
|
protected removePairingCallbacks(): void;
|
|
@@ -74,6 +76,7 @@ export declare class DevicePairingService extends IncyclistService {
|
|
|
74
76
|
private markConnected;
|
|
75
77
|
protected disconnectInterface(name: string): void;
|
|
76
78
|
protected connectInterface(name: string): void;
|
|
79
|
+
protected updateCapabilityConfig(): void;
|
|
77
80
|
protected checkCanStart(): boolean;
|
|
78
81
|
protected checkPairingSuccess(): boolean;
|
|
79
82
|
private stopScanning;
|
|
@@ -64,19 +64,22 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
64
64
|
this.state.deleted = [];
|
|
65
65
|
}
|
|
66
66
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
yield this.loadConfiguration();
|
|
68
|
+
this.updateCapabilityConfig();
|
|
69
|
+
const alreadyInitialized = this.settings.onStateChanged !== undefined && this.settings.onStateChanged !== null;
|
|
70
|
+
this.settings.onStateChanged = onStateChanged;
|
|
71
|
+
if (alreadyInitialized) {
|
|
69
72
|
this.emitStateChange(this.state);
|
|
73
|
+
this.emitStartStatus();
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
|
-
|
|
76
|
+
this.initConfigHandlers();
|
|
73
77
|
this.state.interfaces.forEach(i => {
|
|
74
78
|
if (!this.isInterfaceEnabled(i.name))
|
|
75
79
|
this.unselectOnInterface(i.name);
|
|
76
80
|
});
|
|
77
|
-
this.settings.onStateChanged = onStateChanged;
|
|
78
81
|
this.emitStateChange(this.state);
|
|
79
|
-
this.
|
|
82
|
+
this.emitStartStatus();
|
|
80
83
|
this.run();
|
|
81
84
|
}
|
|
82
85
|
catch (err) {
|
|
@@ -88,8 +91,6 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
88
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
92
|
yield this.waitForInit();
|
|
90
93
|
const { capabilities, interfaces } = this.configuration.load();
|
|
91
|
-
const state = Object.assign({}, this.state);
|
|
92
|
-
delete state.adapters;
|
|
93
94
|
this.state.capabilities = this.mappedCapabilities(capabilities);
|
|
94
95
|
this.state.interfaces = this.access.enrichWithAccessState(interfaces);
|
|
95
96
|
this.state.canStartRide = this.configuration.canStartRide();
|
|
@@ -378,6 +379,13 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
378
379
|
if (onDeviceSelectStateChanged && typeof onDeviceSelectStateChanged === 'function')
|
|
379
380
|
onDeviceSelectStateChanged(this.getDeviceSelectionState());
|
|
380
381
|
}
|
|
382
|
+
emitStartStatus() {
|
|
383
|
+
const { onStateChanged } = this.settings || {};
|
|
384
|
+
const { canStartRide } = this.state;
|
|
385
|
+
if (onStateChanged && typeof onStateChanged === 'function') {
|
|
386
|
+
onStateChanged({ canStartRide });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
381
389
|
onInterfaceConfigChanged(ifName, settings) {
|
|
382
390
|
this.logEvent({ message: 'Interface Config changed', interface: ifName, settings });
|
|
383
391
|
const prev = this.state.interfaces;
|
|
@@ -488,7 +496,7 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
488
496
|
else if (ifDetails.state !== 'unavailable' && current.state === 'unavailable') {
|
|
489
497
|
this.enableAdaptersOnInterface(ifName);
|
|
490
498
|
}
|
|
491
|
-
else if (ifDetails.state === 'connected' && current.state !== 'connected' && !this.isPairing()) {
|
|
499
|
+
else if (ifDetails.state === 'connected' && current.state !== 'connected' && !this.isPairing() && !this.state.canStartRide) {
|
|
492
500
|
restartScan = true;
|
|
493
501
|
}
|
|
494
502
|
else if (ifDetails.state === 'connected' && current.state !== 'connected' && this.isPairingWaiting()) {
|
|
@@ -498,9 +506,10 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
498
506
|
prev[changedIdx].isScanning = ifDetails.isScanning;
|
|
499
507
|
prev[changedIdx].state = ifDetails.state;
|
|
500
508
|
}
|
|
501
|
-
if (restartScan)
|
|
509
|
+
if (restartScan) {
|
|
502
510
|
this.restart();
|
|
503
|
-
|
|
511
|
+
}
|
|
512
|
+
if (restartPair && this.isInterfaceInUse(ifName)) {
|
|
504
513
|
this.restartPair();
|
|
505
514
|
}
|
|
506
515
|
this.emitStateChange({ interfaces: this.state.interfaces });
|
|
@@ -518,6 +527,12 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
518
527
|
const { interfaces } = this.state;
|
|
519
528
|
return interfaces.find(i => i.name === name && i.enabled && i.state !== 'unavailable') !== undefined;
|
|
520
529
|
}
|
|
530
|
+
isInterfaceInUse(target) {
|
|
531
|
+
const name = (typeof target === 'string') ? target : target.name;
|
|
532
|
+
const { capabilities } = this.state;
|
|
533
|
+
const res = capabilities.find(c => c.interface === name);
|
|
534
|
+
return res;
|
|
535
|
+
}
|
|
521
536
|
logCapabilities(capabilities) {
|
|
522
537
|
const ci = capabilities || this.state.capabilities;
|
|
523
538
|
ci.forEach(c => {
|
|
@@ -713,6 +728,19 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
713
728
|
this.logError(err, 'enableInterface');
|
|
714
729
|
}
|
|
715
730
|
}
|
|
731
|
+
updateCapabilityConfig() {
|
|
732
|
+
try {
|
|
733
|
+
const { capabilities } = this.state;
|
|
734
|
+
capabilities.forEach(c => {
|
|
735
|
+
var _a;
|
|
736
|
+
if (c.connectState !== 'connected' && c.selected && ((_a = this.getDeviceAdapter(c.selected)) === null || _a === void 0 ? void 0 : _a.isStarted()))
|
|
737
|
+
c.connectState = 'connected';
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
catch (err) {
|
|
741
|
+
console.log(err);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
716
744
|
checkCanStart() {
|
|
717
745
|
try {
|
|
718
746
|
const prev = this.state.canStartRide;
|
|
@@ -725,8 +753,8 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
725
753
|
const power = this.getCapability(incyclist_devices_1.IncyclistCapability.Power);
|
|
726
754
|
const canStartRide = ((control === null || control === void 0 ? void 0 : control.connectState) === 'connected' || (power === null || power === void 0 ? void 0 : power.connectState) === 'connected');
|
|
727
755
|
this.state.canStartRide = canStartRide;
|
|
728
|
-
if (
|
|
729
|
-
this.
|
|
756
|
+
if (canStartRide !== prev) {
|
|
757
|
+
this.emitStartStatus();
|
|
730
758
|
}
|
|
731
759
|
}
|
|
732
760
|
catch (err) {
|
|
@@ -793,7 +821,10 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
793
821
|
return;
|
|
794
822
|
}
|
|
795
823
|
if (configOKToStart && !this.deviceSelectState && !props.enforcedScan) {
|
|
796
|
-
|
|
824
|
+
if (!(this.checkPairingSuccess() === true))
|
|
825
|
+
yield this.startPairing(adapters, props);
|
|
826
|
+
else
|
|
827
|
+
this.emitStateChange();
|
|
797
828
|
}
|
|
798
829
|
else {
|
|
799
830
|
yield this.startScanning(adapters, props);
|
|
@@ -802,7 +833,7 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
802
833
|
}
|
|
803
834
|
startPairing(adapters, props) {
|
|
804
835
|
return __awaiter(this, void 0, void 0, function* () {
|
|
805
|
-
if (this.isPairing())
|
|
836
|
+
if (this.isPairing() || this.checkPairingSuccess())
|
|
806
837
|
return;
|
|
807
838
|
const preparing = DevicePairingService.checkCounter++;
|
|
808
839
|
this.state.check = { preparing };
|
|
@@ -824,7 +855,7 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
824
855
|
this.processConnectedDevices(adapters);
|
|
825
856
|
const selected = this.state.capabilities.map(c => c.selected);
|
|
826
857
|
const target = adapters.filter(ai => selected.includes(ai.udid));
|
|
827
|
-
if (this.isPairing() && this.state.check.preparing !== preparing) {
|
|
858
|
+
if ((this.isPairing() && this.state.check.preparing !== preparing) || (this.checkPairingSuccess() === true)) {
|
|
828
859
|
return;
|
|
829
860
|
}
|
|
830
861
|
this.initPairingCallbacks();
|
|
@@ -834,6 +865,7 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
834
865
|
this.onPairingStarted();
|
|
835
866
|
this.logEvent({ message: 'Start Pairing', adapters, props });
|
|
836
867
|
yield this.state.check.promise;
|
|
868
|
+
this.checkCanStart();
|
|
837
869
|
if (this.state.check)
|
|
838
870
|
delete this.state.check;
|
|
839
871
|
this.emit('pairing-done');
|