incyclist-services 1.0.40 → 1.0.42
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.
|
@@ -59,7 +59,7 @@ export declare class DevicePairingService extends EventEmitter {
|
|
|
59
59
|
protected onConfigurationUpdate(newCapabilities: DeviceConfigurationInfo): void;
|
|
60
60
|
protected onInterfaceStateChanged(ifName: any, ifDetails: any, interfacesNew?: any): Promise<any>;
|
|
61
61
|
protected isInterfaceEnabled(target: string | InterfaceSetting): boolean;
|
|
62
|
-
protected logCapabilities(capabilities
|
|
62
|
+
protected logCapabilities(capabilities?: Array<CapabilityData>): CapabilityData[];
|
|
63
63
|
protected initPairingCallbacks(): void;
|
|
64
64
|
protected removePairingCallbacks(): void;
|
|
65
65
|
protected initScanningCallbacks(): void;
|
|
@@ -95,6 +95,9 @@ class DevicePairingService extends events_1.default {
|
|
|
95
95
|
this.state.capabilities = (0, exports.mappedCapabilities)(capabilities);
|
|
96
96
|
this.state.interfaces = this.access.enrichWithAccessState(interfaces);
|
|
97
97
|
this.state.canStartRide = this.configuration.canStartRide();
|
|
98
|
+
this.state.stopRequested = false;
|
|
99
|
+
this.state.stopped = false;
|
|
100
|
+
this.logCapabilities();
|
|
98
101
|
this.state.interfaces.forEach(i => {
|
|
99
102
|
if (!this.isInterfaceEnabled(i.name))
|
|
100
103
|
this.disableAdaptersOnInterface(i.name);
|
|
@@ -121,10 +124,14 @@ class DevicePairingService extends events_1.default {
|
|
|
121
124
|
}
|
|
122
125
|
stop() {
|
|
123
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
this.logEvent({ message: 'Stop Pairing' });
|
|
124
128
|
try {
|
|
125
129
|
yield this._stop();
|
|
130
|
+
this.pauseAdapters(this.state.adapters);
|
|
126
131
|
this.state.stopRequested = true;
|
|
127
132
|
this.removeConfigHandlers();
|
|
133
|
+
this.settings = {};
|
|
134
|
+
this.state.initialized = false;
|
|
128
135
|
}
|
|
129
136
|
catch (err) {
|
|
130
137
|
this.logError(err, 'stop');
|
|
@@ -310,21 +317,21 @@ class DevicePairingService extends events_1.default {
|
|
|
310
317
|
this.onScanningDataHandler = this.rideService.onData.bind(this.rideService);
|
|
311
318
|
this.configuration = this.configuration || (0, configuration_1.useDeviceConfiguration)();
|
|
312
319
|
if (this.configuration.isInitialized()) {
|
|
313
|
-
this.logCapabilities(this.state.capabilities);
|
|
314
320
|
this.state.initialized = true;
|
|
315
321
|
return done();
|
|
316
322
|
}
|
|
317
|
-
|
|
318
|
-
this.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
+
else {
|
|
324
|
+
this.configuration.once('initialized', (capabilitiesLoaded, interfacesLoaded) => {
|
|
325
|
+
this.onConfigLoaded(capabilitiesLoaded, interfacesLoaded);
|
|
326
|
+
done();
|
|
327
|
+
});
|
|
328
|
+
this.configuration.init();
|
|
329
|
+
}
|
|
323
330
|
});
|
|
324
331
|
}
|
|
325
332
|
getExternaState(toEmit) {
|
|
326
333
|
const newState = toEmit || this.state;
|
|
327
|
-
const state = (
|
|
334
|
+
const state = Object.assign({}, newState);
|
|
328
335
|
delete state.adapters;
|
|
329
336
|
delete state.check;
|
|
330
337
|
delete state.scan;
|
|
@@ -334,9 +341,11 @@ class DevicePairingService extends events_1.default {
|
|
|
334
341
|
}
|
|
335
342
|
emitStateChange(newState) {
|
|
336
343
|
const { onStateChanged, onDeviceSelectStateChanged } = this.settings || {};
|
|
344
|
+
if (this.state.stopRequested)
|
|
345
|
+
return;
|
|
337
346
|
const state = this.getExternaState(newState);
|
|
338
347
|
if (onStateChanged && typeof onStateChanged === 'function') {
|
|
339
|
-
onStateChanged((
|
|
348
|
+
onStateChanged(Object.assign({}, state));
|
|
340
349
|
}
|
|
341
350
|
if (onDeviceSelectStateChanged && typeof onDeviceSelectStateChanged === 'function')
|
|
342
351
|
onDeviceSelectStateChanged(this.getDeviceSelectionState());
|
|
@@ -402,9 +411,10 @@ class DevicePairingService extends events_1.default {
|
|
|
402
411
|
return __awaiter(this, void 0, void 0, function* () {
|
|
403
412
|
const prev = this.state.interfaces;
|
|
404
413
|
const current = getInterfaceSettings(ifName, prev);
|
|
405
|
-
const changed = (current.state !== ifDetails.state || current.isScanning !== ifDetails.isScanning || current.enabled
|
|
406
|
-
if (!changed)
|
|
414
|
+
const changed = (current.state !== ifDetails.state || current.isScanning !== ifDetails.isScanning || current.enabled !== ifDetails.enabled);
|
|
415
|
+
if (!changed) {
|
|
407
416
|
return;
|
|
417
|
+
}
|
|
408
418
|
try {
|
|
409
419
|
if (interfacesNew) {
|
|
410
420
|
const getData = (i) => ({ name: i.name, enabled: i.enabled, state: i.state });
|
|
@@ -416,7 +426,6 @@ class DevicePairingService extends events_1.default {
|
|
|
416
426
|
}
|
|
417
427
|
else if (prev) {
|
|
418
428
|
const changedIdx = prev.findIndex(i => i.name === ifName);
|
|
419
|
-
console.log(ifDetails.state, current.state);
|
|
420
429
|
if (ifDetails.state === 'disconnected' && current.state !== 'disconnected') {
|
|
421
430
|
this.failAdaptersOnInterface(ifName);
|
|
422
431
|
}
|
|
@@ -444,7 +453,7 @@ class DevicePairingService extends events_1.default {
|
|
|
444
453
|
return interfaces.find(i => i.name === name && i.enabled && i.state !== 'unavailable') !== undefined;
|
|
445
454
|
}
|
|
446
455
|
logCapabilities(capabilities) {
|
|
447
|
-
const ci = capabilities ||
|
|
456
|
+
const ci = capabilities || this.state.capabilities;
|
|
448
457
|
ci.forEach(c => {
|
|
449
458
|
var _a;
|
|
450
459
|
const { devices = [], disabled } = c;
|
|
@@ -698,8 +707,9 @@ class DevicePairingService extends events_1.default {
|
|
|
698
707
|
this.state.props = props;
|
|
699
708
|
const adapters = this.state.adapters = this.configuration.getAdapters(false);
|
|
700
709
|
const goodToGo = yield this.rideService.waitForPreviousStartToFinish();
|
|
701
|
-
if (!goodToGo)
|
|
710
|
+
if (!goodToGo) {
|
|
702
711
|
return;
|
|
712
|
+
}
|
|
703
713
|
const configOKToStart = this.configuration.canStartRide();
|
|
704
714
|
if (this.state.stopRequested || this.state.stopped) {
|
|
705
715
|
this.state.stopped = true;
|
|
@@ -719,7 +729,8 @@ class DevicePairingService extends events_1.default {
|
|
|
719
729
|
this.emit('pairing-start');
|
|
720
730
|
this.logEvent({ message: 'Start Pairing', adapters, props });
|
|
721
731
|
this.processConnectedDevices(adapters);
|
|
722
|
-
const
|
|
732
|
+
const selected = this.state.capabilities.map(c => c.selected);
|
|
733
|
+
const target = adapters.filter(ai => !ai.adapter.isStarted() && selected.includes(ai.udid));
|
|
723
734
|
this.initPairingCallbacks();
|
|
724
735
|
const selectedAdapters = target.map(ai => (Object.assign(Object.assign({}, ai), { isStarted: false })));
|
|
725
736
|
const promise = this.rideService.startAdapters(selectedAdapters, 'pair');
|
|
@@ -850,7 +861,6 @@ class DevicePairingService extends events_1.default {
|
|
|
850
861
|
failAdaptersOnInterface(name) {
|
|
851
862
|
const target = this.getAdaptersOnInterface(name);
|
|
852
863
|
const { capabilities } = this.state;
|
|
853
|
-
console.log('failAdaptersOnInterface', name, target);
|
|
854
864
|
target.forEach(ai => {
|
|
855
865
|
const { udid } = ai;
|
|
856
866
|
capabilities.forEach(c => {
|