@robotical/webapp-types 3.18.1 → 3.18.3
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.
- package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +4 -1
- package/dist-types/src/application/ApplicationManager/ApplicationManager.js +42 -13
- package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.d.ts +2 -3
- package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.js +10 -10
- package/dist-types/src/application/communicators/WrapperCommunicator.d.ts +0 -1
- package/dist-types/src/application/communicators/WrapperCommunicator.js +6 -2
- package/dist-types/src/store/SelectedRaftContext.d.ts +1 -0
- package/dist-types/src/store/SelectedRaftContext.js +16 -12
- package/dist-types/src/wrapper-app/WrapperAppManager.js +12 -5
- package/dist-types/src/wrapper-app/connectors/Connector.d.ts +12 -0
- package/dist-types/src/wrapper-app/connectors/Connector.js +29 -3
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ import AnalyticsFacade from "@robotical/appv2-analytics-gatherer";
|
|
|
14
14
|
import { CarouselNavigatorManager } from "../../utils/CarouselNavigatorManager";
|
|
15
15
|
import { CustomBluetoothItem, UserDeviceInfo } from "../../types/userDeviceInfo";
|
|
16
16
|
import { UserRoleContextTypes } from "../../store/user-role-context";
|
|
17
|
+
type ConnectResultDisposition = "commit" | "release" | "ignore";
|
|
17
18
|
export default class ApplicationManager {
|
|
18
19
|
selectedLocale: string;
|
|
19
20
|
AnalyticsFacade: typeof AnalyticsFacade;
|
|
@@ -97,6 +98,7 @@ export default class ApplicationManager {
|
|
|
97
98
|
private _clearConnectPromise;
|
|
98
99
|
private _dismissConnectAttempt;
|
|
99
100
|
private _isConnectAttemptActive;
|
|
101
|
+
private _getConnectResultDisposition;
|
|
100
102
|
private _createConnectingModal;
|
|
101
103
|
private _connectGeneric;
|
|
102
104
|
/**
|
|
@@ -108,7 +110,7 @@ export default class ApplicationManager {
|
|
|
108
110
|
* Selects a RAFT in Phone's verification modal
|
|
109
111
|
*/
|
|
110
112
|
selectRaft(ricToConnectTo: FOUND_RAFT_ON_DISCOVERY_RESPONSE['foundRIC'], method: RaftConnectionMethod): Promise<RAFT | null>;
|
|
111
|
-
connectToRIC(method: RaftConnectionMethod, uuids: string[], withoutVerification?: boolean): Promise<RAFT | null>;
|
|
113
|
+
connectToRIC(method: RaftConnectionMethod, uuids: string[], withoutVerification?: boolean, getResultDisposition?: () => ConnectResultDisposition): Promise<RAFT | null>;
|
|
112
114
|
/**
|
|
113
115
|
* Warranty Service bluetooth scan for device
|
|
114
116
|
* It scans for a device and gets the device object
|
|
@@ -187,3 +189,4 @@ export default class ApplicationManager {
|
|
|
187
189
|
injectJS(jsCode: string): Promise<unknown>;
|
|
188
190
|
getTheCurrentlySelectedDeviceOrFirstOfItsKind(deviceType: RaftTypeE): RAFT | undefined;
|
|
189
191
|
}
|
|
192
|
+
export {};
|
|
@@ -546,6 +546,16 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
546
546
|
ApplicationManager.prototype._isConnectAttemptActive = function (connectAttemptId) {
|
|
547
547
|
return this._activeConnectAttemptId === connectAttemptId;
|
|
548
548
|
};
|
|
549
|
+
ApplicationManager.prototype._getConnectResultDisposition = function (connectAttemptId) {
|
|
550
|
+
if (this._isConnectAttemptActive(connectAttemptId)) {
|
|
551
|
+
return "commit";
|
|
552
|
+
}
|
|
553
|
+
// A newer app attempt shares WrapperAppManager's in-flight Bluetooth
|
|
554
|
+
// result. Let that current consumer commit it instead of tearing down the
|
|
555
|
+
// transport underneath it. With no replacement consumer, Dismiss means
|
|
556
|
+
// the late success must be fully released.
|
|
557
|
+
return this._activeConnectAttemptId === null ? "release" : "ignore";
|
|
558
|
+
};
|
|
549
559
|
ApplicationManager.prototype._createConnectingModal = function (connectAttemptId) {
|
|
550
560
|
var _this = this;
|
|
551
561
|
return createElement(ConnectingLoadingSpinnerModal, {
|
|
@@ -633,7 +643,7 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
633
643
|
_a.label = 11;
|
|
634
644
|
case 11:
|
|
635
645
|
_a.trys.push([11, 16, , 17]);
|
|
636
|
-
return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuids, isQRVerification)];
|
|
646
|
+
return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuids, isQRVerification, function () { return _this._getConnectResultDisposition(connectAttemptId); })];
|
|
637
647
|
case 12:
|
|
638
648
|
newRaft = _a.sent();
|
|
639
649
|
if (!this._isConnectAttemptActive(connectAttemptId)) {
|
|
@@ -767,21 +777,31 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
767
777
|
});
|
|
768
778
|
});
|
|
769
779
|
};
|
|
770
|
-
ApplicationManager.prototype.connectToRIC = function (method, uuids, withoutVerification) {
|
|
780
|
+
ApplicationManager.prototype.connectToRIC = function (method, uuids, withoutVerification, getResultDisposition) {
|
|
771
781
|
var _a, _b, _c, _d;
|
|
782
|
+
if (getResultDisposition === void 0) { getResultDisposition = function () { return "commit"; }; }
|
|
772
783
|
return __awaiter(this, void 0, void 0, function () {
|
|
773
|
-
var wasConnectedObj, raftId, raftType, raft;
|
|
784
|
+
var wasConnectedObj, raftId, raftType, resultDisposition, raft;
|
|
774
785
|
return __generator(this, function (_e) {
|
|
775
786
|
switch (_e.label) {
|
|
776
787
|
case 0: return [4 /*yield*/, RAFT.connect(method, uuids)];
|
|
777
788
|
case 1:
|
|
778
789
|
wasConnectedObj = _e.sent();
|
|
779
|
-
if (!wasConnectedObj.success) return [3 /*break*/,
|
|
790
|
+
if (!wasConnectedObj.success) return [3 /*break*/, 7];
|
|
780
791
|
raftId = (_a = wasConnectedObj.data) === null || _a === void 0 ? void 0 : _a.raftId;
|
|
781
792
|
raftType = (_b = wasConnectedObj.data) === null || _b === void 0 ? void 0 : _b.raftType;
|
|
782
793
|
if (!raftId || !raftType) {
|
|
783
794
|
throw new Error("RAFT ID or RAFT Type is missing: ".concat(raftId, " ").concat(raftType));
|
|
784
795
|
}
|
|
796
|
+
resultDisposition = getResultDisposition();
|
|
797
|
+
if (!(resultDisposition !== "commit")) return [3 /*break*/, 4];
|
|
798
|
+
if (!(resultDisposition === "release")) return [3 /*break*/, 3];
|
|
799
|
+
return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_DISCONNECT, { raftId: raftId })];
|
|
800
|
+
case 2:
|
|
801
|
+
_e.sent();
|
|
802
|
+
_e.label = 3;
|
|
803
|
+
case 3: return [2 /*return*/, null];
|
|
804
|
+
case 4:
|
|
785
805
|
raft = void 0;
|
|
786
806
|
switch (raftType) {
|
|
787
807
|
case RaftTypeE.MARTY:
|
|
@@ -799,23 +819,23 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
799
819
|
}
|
|
800
820
|
// get missed Connect event
|
|
801
821
|
publishMissedConnectionEvent(raftId);
|
|
802
|
-
if (!!((_d = wasConnectedObj.data) === null || _d === void 0 ? void 0 : _d.systemInfo)) return [3 /*break*/,
|
|
822
|
+
if (!!((_d = wasConnectedObj.data) === null || _d === void 0 ? void 0 : _d.systemInfo)) return [3 /*break*/, 6];
|
|
803
823
|
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 200); })];
|
|
804
|
-
case
|
|
824
|
+
case 5:
|
|
805
825
|
_e.sent();
|
|
806
|
-
_e.label =
|
|
807
|
-
case
|
|
826
|
+
_e.label = 6;
|
|
827
|
+
case 6:
|
|
808
828
|
// start LED verification process
|
|
809
829
|
if (!withoutVerification) {
|
|
810
830
|
modalState.setModal(createElement(VerificationModal, { connectedRAFT_: raft }), i18n.t("connection.looking_for_raft", { raftType: raft.type }), false);
|
|
811
831
|
}
|
|
812
832
|
return [2 /*return*/, raft];
|
|
813
|
-
case
|
|
833
|
+
case 7:
|
|
814
834
|
if (wasConnectedObj.reason === 'unplugged') {
|
|
815
835
|
modalState.setModal(createElement(InUnpluggedModalContent), i18n.t("calibration_screen.colour_calibration.unplugged_modal_title"));
|
|
816
836
|
}
|
|
817
|
-
_e.label =
|
|
818
|
-
case
|
|
837
|
+
_e.label = 8;
|
|
838
|
+
case 8: return [2 /*return*/, null];
|
|
819
839
|
}
|
|
820
840
|
});
|
|
821
841
|
});
|
|
@@ -1113,12 +1133,21 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
1113
1133
|
}
|
|
1114
1134
|
};
|
|
1115
1135
|
ApplicationManager.prototype.receivedRICEvent = function (raftId, eventType, eventEnum, eventName, eventData) {
|
|
1116
|
-
var _a;
|
|
1117
1136
|
if (raftId === "scanner") {
|
|
1118
1137
|
this.publish(eventType, eventEnum, eventName, eventData);
|
|
1119
1138
|
}
|
|
1120
1139
|
else {
|
|
1121
|
-
|
|
1140
|
+
var raft = this.connectedRafts[raftId];
|
|
1141
|
+
if (!raft) {
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
var isTerminalDisconnectEvent = eventType === "conn" && (eventEnum === RaftConnEvent.CONN_REJECTED ||
|
|
1145
|
+
eventEnum === RaftConnEvent.CONN_DISCONNECTED);
|
|
1146
|
+
if (this._disconnectPromises.has(raft) && !isTerminalDisconnectEvent) {
|
|
1147
|
+
Logger.info(SHOW_LOGS, TAG, "Ignoring ".concat(eventName, " after disconnect started for ").concat(raftId));
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
raft.receivedRICEvent(eventType, eventEnum, eventName, eventData);
|
|
1122
1151
|
}
|
|
1123
1152
|
};
|
|
1124
1153
|
//======================//
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
export default class SelfdestructiveMessagePromise {
|
|
3
3
|
resolve: (value?: any) => void;
|
|
4
4
|
reject: (reason?: any) => void;
|
|
5
|
-
timeout
|
|
6
|
-
TIMEOUT_PERIOD: number;
|
|
5
|
+
timeout?: NodeJS.Timeout;
|
|
7
6
|
constructor(resolve: (value?: any) => void, reject: (reason?: any) => void, id: string, messagePromises: {
|
|
8
7
|
[key: string]: SelfdestructiveMessagePromise | undefined;
|
|
9
|
-
});
|
|
8
|
+
}, timeoutPeriod?: number | null);
|
|
10
9
|
}
|
|
@@ -2,29 +2,29 @@ import Logger from "../../services/logger/Logger";
|
|
|
2
2
|
var SHOW_LOGS = true;
|
|
3
3
|
var TAG = "SelfdestructiveMessagePromise";
|
|
4
4
|
var SelfdestructiveMessagePromise = /** @class */ (function () {
|
|
5
|
-
function SelfdestructiveMessagePromise(resolve, reject, id, messagePromises) {
|
|
5
|
+
function SelfdestructiveMessagePromise(resolve, reject, id, messagePromises, timeoutPeriod) {
|
|
6
|
+
if (timeoutPeriod === void 0) { timeoutPeriod = 30000; }
|
|
6
7
|
var _this = this;
|
|
7
8
|
this.resolve = function () { };
|
|
8
9
|
this.reject = function () { };
|
|
9
|
-
this.TIMEOUT_PERIOD = 30000;
|
|
10
10
|
this.resolve = function (value) {
|
|
11
11
|
resolve(value);
|
|
12
|
-
|
|
12
|
+
if (_this.timeout)
|
|
13
|
+
clearTimeout(_this.timeout);
|
|
13
14
|
delete messagePromises[id];
|
|
14
15
|
};
|
|
15
16
|
this.reject = function (reason) {
|
|
16
17
|
resolve(reason); // on purpose resolving instead of rejecting
|
|
17
|
-
|
|
18
|
+
if (_this.timeout)
|
|
19
|
+
clearTimeout(_this.timeout);
|
|
18
20
|
delete messagePromises[id];
|
|
19
21
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
if (timeoutPeriod !== null) {
|
|
23
|
+
this.timeout = setTimeout(function () {
|
|
22
24
|
Logger.warn(SHOW_LOGS, TAG, "Timeout for message promise with id: ".concat(id));
|
|
23
25
|
_this.reject({ error: "Timeout" });
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
clearTimeout(_this.timeout);
|
|
27
|
-
}, this.TIMEOUT_PERIOD);
|
|
26
|
+
}, timeoutPeriod);
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
29
|
return SelfdestructiveMessagePromise;
|
|
30
30
|
}());
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AppSentMessage, IWrapperSentMessage, WRAPPER_RESPONSE_BASE } from "../../types/communication-between-apps/wrapper-communication";
|
|
2
2
|
export declare class WrapperCommunicator {
|
|
3
3
|
private messagePromises;
|
|
4
|
-
constructor();
|
|
5
4
|
/**
|
|
6
5
|
* Receives a message from the wrapper app
|
|
7
6
|
*/
|
|
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import Logger from "../../services/logger/Logger";
|
|
38
|
-
import { WrapperSentMessage } from "../../types/communication-between-apps/wrapper-communication";
|
|
38
|
+
import { AppSentMessage, WrapperSentMessage } from "../../types/communication-between-apps/wrapper-communication";
|
|
39
39
|
import randomHashGenerator from "../../utils/helpers/randomHashGenerator";
|
|
40
40
|
import isPhoneApp from "../../utils/phone-app-communication/is-phone-app";
|
|
41
41
|
import SelfdestructiveMessagePromise from "./SelfdestructiveMessagePromise";
|
|
@@ -59,7 +59,11 @@ var WrapperCommunicator = /** @class */ (function () {
|
|
|
59
59
|
var _this = this;
|
|
60
60
|
var messagePromiseId = randomHashGenerator();
|
|
61
61
|
var promise = new Promise(function (resolve, reject) {
|
|
62
|
-
_this.messagePromises[messagePromiseId] = new SelfdestructiveMessagePromise(resolve, reject, messagePromiseId, _this.messagePromises
|
|
62
|
+
_this.messagePromises[messagePromiseId] = new SelfdestructiveMessagePromise(resolve, reject, messagePromiseId, _this.messagePromises,
|
|
63
|
+
// Choosing a physical Bluetooth device is user-mediated and has no
|
|
64
|
+
// application-safe deadline. The connecting modal owns cancellation;
|
|
65
|
+
// timing this bridge request out would orphan a later chooser result.
|
|
66
|
+
message === AppSentMessage.RAFT_CONNECT ? null : undefined);
|
|
63
67
|
});
|
|
64
68
|
var messageObject = {
|
|
65
69
|
message: message,
|
|
@@ -8,6 +8,7 @@ export type ConnectedRaftItem = {
|
|
|
8
8
|
type: RaftTypeE;
|
|
9
9
|
isSelected: boolean;
|
|
10
10
|
};
|
|
11
|
+
export declare const removeConnectedRaftFromList: (connectedRafts: ConnectedRaftItem[], connectedRaftId: string) => ConnectedRaftItem[];
|
|
11
12
|
export declare const ConnectedRaftContentProvider: ({ children }: {
|
|
12
13
|
children: React.ReactNode;
|
|
13
14
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -25,6 +25,18 @@ export var NewRobotIdE;
|
|
|
25
25
|
(function (NewRobotIdE) {
|
|
26
26
|
NewRobotIdE["NEW"] = "=+__new__+=";
|
|
27
27
|
})(NewRobotIdE || (NewRobotIdE = {}));
|
|
28
|
+
export var removeConnectedRaftFromList = function (connectedRafts, connectedRaftId) {
|
|
29
|
+
var removedRaftWasSelected = connectedRafts.some(function (connectedRaft) {
|
|
30
|
+
return connectedRaft.id === connectedRaftId && connectedRaft.isSelected;
|
|
31
|
+
});
|
|
32
|
+
var remainingRafts = connectedRafts.filter(function (connectedRaft) { return connectedRaft.id !== connectedRaftId; });
|
|
33
|
+
if (!removedRaftWasSelected) {
|
|
34
|
+
return remainingRafts;
|
|
35
|
+
}
|
|
36
|
+
var fallbackRaft = remainingRafts.find(function (connectedRaft) { return connectedRaft.id !== NewRobotIdE.NEW; }) ||
|
|
37
|
+
remainingRafts[0];
|
|
38
|
+
return remainingRafts.map(function (connectedRaft) { return (__assign(__assign({}, connectedRaft), { isSelected: connectedRaft.id === (fallbackRaft === null || fallbackRaft === void 0 ? void 0 : fallbackRaft.id) })); });
|
|
39
|
+
};
|
|
28
40
|
var ConnectedRaftContext = createContext({
|
|
29
41
|
nameUpdatedState: 0,
|
|
30
42
|
connectedRafts: [],
|
|
@@ -59,17 +71,9 @@ export var ConnectedRaftContentProvider = function (_a) {
|
|
|
59
71
|
setConnectedRafts(function (prev) { return __spreadArray(__spreadArray([], prev, true), [connectedRaft], false); });
|
|
60
72
|
};
|
|
61
73
|
var removeConnectedRaft = function (connectedRaftId) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
setConnectedRafts(function (prev) { return prev
|
|
66
|
-
.filter(function (connectedRaft) { return connectedRaft.id !== connectedRaftId; })
|
|
67
|
-
.map(function (connectedRaft, index) { return (__assign(__assign({}, connectedRaft), { isSelected: index === 1 })); }); });
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
// otherwise just filter out the raft
|
|
71
|
-
setConnectedRafts(function (prev) { return prev.filter(function (connectedRaft) { return connectedRaft.id !== connectedRaftId; }); });
|
|
72
|
-
}
|
|
74
|
+
setConnectedRafts(function (prev) {
|
|
75
|
+
return removeConnectedRaftFromList(prev, connectedRaftId);
|
|
76
|
+
});
|
|
73
77
|
};
|
|
74
78
|
var setSelectedRaft = function (connectedRaftId) {
|
|
75
79
|
// deselect the previously selected raft
|
|
@@ -95,7 +99,7 @@ export var ConnectedRaftContentProvider = function (_a) {
|
|
|
95
99
|
}
|
|
96
100
|
tryAttach();
|
|
97
101
|
return function () { handle && clearTimeout(handle); };
|
|
98
|
-
}, [addConnectedRaft, removeConnectedRaft, setSelectedRaft, nameUpdated]);
|
|
102
|
+
}, [addConnectedRaft, removeConnectedRaft, getSelectedRaft, setSelectedRaft, nameUpdated]);
|
|
99
103
|
return (_jsx(ConnectedRaftContext.Provider, __assign({ value: { connectedRafts: connectedRafts, addConnectedRaft: addConnectedRaft, removeConnectedRaft: removeConnectedRaft, setSelectedRaft: setSelectedRaft, getSelectedRaft: getSelectedRaft, nameUpdated: nameUpdated, nameUpdatedState: nameUpdatedState } }, { children: children })));
|
|
100
104
|
};
|
|
101
105
|
export var useConnectedRafts = function () { return useContext(ConnectedRaftContext); };
|
|
@@ -273,9 +273,10 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
273
273
|
* Re-triggers the connect event which was missed due to the connection logic
|
|
274
274
|
*/
|
|
275
275
|
WrapperAppManager.prototype.getMissedConnEvent = function (raftId) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
var connector = this.connectors[raftId];
|
|
277
|
+
if (connector === null || connector === void 0 ? void 0 : connector.shouldHandleEvent("conn", RaftConnEvent.CONN_CONNECTED)) {
|
|
278
|
+
connector.eventHandler("conn", RaftConnEvent.CONN_CONNECTED, "connect", {});
|
|
279
|
+
connector.publish("conn", RaftConnEvent.CONN_CONNECTED, "connect", {});
|
|
279
280
|
}
|
|
280
281
|
};
|
|
281
282
|
/**
|
|
@@ -283,6 +284,7 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
283
284
|
*/
|
|
284
285
|
WrapperAppManager.prototype.confirmVerifiedRaft = function (raftId) {
|
|
285
286
|
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
+
var connector;
|
|
286
288
|
return __generator(this, function (_a) {
|
|
287
289
|
switch (_a.label) {
|
|
288
290
|
case 0:
|
|
@@ -290,10 +292,14 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
290
292
|
Logger.warn(SHOW_LOGS, TAG, "confirmVerifiedRaft: No connector found for raftId: ".concat(raftId));
|
|
291
293
|
return [2 /*return*/, false];
|
|
292
294
|
}
|
|
293
|
-
|
|
295
|
+
connector = this.connectors[raftId];
|
|
296
|
+
if (!connector.shouldHandleEvent("conn", RaftConnEvent.CONN_VERIFIED_CORRECT)) {
|
|
297
|
+
return [2 /*return*/, false];
|
|
298
|
+
}
|
|
299
|
+
return [4 /*yield*/, connector.eventHandler("conn", RaftConnEvent.CONN_VERIFIED_CORRECT, "VERIFIED_CORRECT", {})];
|
|
294
300
|
case 1:
|
|
295
301
|
_a.sent();
|
|
296
|
-
|
|
302
|
+
connector.publish("conn", RaftConnEvent.CONN_VERIFIED_CORRECT, "VERIFIED_CORRECT", {});
|
|
297
303
|
return [2 /*return*/, true];
|
|
298
304
|
}
|
|
299
305
|
});
|
|
@@ -378,6 +384,7 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
378
384
|
if ((inFlightDisconnect === null || inFlightDisconnect === void 0 ? void 0 : inFlightDisconnect.connector) === connector) {
|
|
379
385
|
return inFlightDisconnect.promise;
|
|
380
386
|
}
|
|
387
|
+
connector.beginDisconnect();
|
|
381
388
|
var operation = Promise.resolve().then(function () { return connector.disconnect(); });
|
|
382
389
|
var disconnectPromise;
|
|
383
390
|
disconnectPromise = operation.finally(function () {
|
|
@@ -12,6 +12,7 @@ declare class Connector implements ConnectorInterface {
|
|
|
12
12
|
[key: string]: Array<RaftObserver>;
|
|
13
13
|
};
|
|
14
14
|
private _onDisconnected?;
|
|
15
|
+
private _disconnectStarted;
|
|
15
16
|
connManager: ConnManager;
|
|
16
17
|
constructor(id: string, connManager: ConnManager);
|
|
17
18
|
/**
|
|
@@ -38,6 +39,17 @@ declare class Connector implements ConnectorInterface {
|
|
|
38
39
|
* Disconnect from a RAFT
|
|
39
40
|
*/
|
|
40
41
|
disconnect(): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Marks this connector as teardown-owned before asynchronous disconnect work
|
|
44
|
+
* can yield. Late nonterminal callbacks must not revive application state or
|
|
45
|
+
* install listeners while the connector is going away.
|
|
46
|
+
*/
|
|
47
|
+
beginDisconnect(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Rejection and disconnection are terminal lifecycle notifications and must
|
|
50
|
+
* still propagate while teardown is pending. All other late events are stale.
|
|
51
|
+
*/
|
|
52
|
+
shouldHandleEvent(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent): boolean;
|
|
41
53
|
/**
|
|
42
54
|
* Register the manager-owned cleanup callback for a terminal disconnect event.
|
|
43
55
|
*/
|
|
@@ -60,11 +60,16 @@ var Connector = /** @class */ (function () {
|
|
|
60
60
|
// RAFT
|
|
61
61
|
// Observers
|
|
62
62
|
this._observers = {};
|
|
63
|
+
this._disconnectStarted = false;
|
|
63
64
|
this.connManager = connManager;
|
|
64
65
|
// Set the listener function
|
|
65
66
|
// Subscribe to connManager events
|
|
66
67
|
this.connManager.setConnectionEventListener(function (eventType, eventEnum, eventName, eventData) {
|
|
67
68
|
var _a;
|
|
69
|
+
if (!_this.shouldHandleEvent(eventType, eventEnum)) {
|
|
70
|
+
Logger.info(SHOW_LOGS, TAG, "Ignoring ".concat(eventName, " after disconnect started for ").concat(_this.id));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
68
73
|
if (eventType === "pub") {
|
|
69
74
|
// if it's a pub event, we are publishing it from _pubEventHandler method (in child classes)
|
|
70
75
|
}
|
|
@@ -151,9 +156,10 @@ var Connector = /** @class */ (function () {
|
|
|
151
156
|
return __awaiter(this, void 0, void 0, function () {
|
|
152
157
|
return __generator(this, function (_a) {
|
|
153
158
|
switch (_a.label) {
|
|
154
|
-
case 0:
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
case 0:
|
|
160
|
+
this.beginDisconnect();
|
|
161
|
+
// this.sendRestMessage('blerestart');
|
|
162
|
+
return [4 /*yield*/, this.connManager.disconnect()];
|
|
157
163
|
case 1:
|
|
158
164
|
// this.sendRestMessage('blerestart');
|
|
159
165
|
_a.sent();
|
|
@@ -162,6 +168,25 @@ var Connector = /** @class */ (function () {
|
|
|
162
168
|
});
|
|
163
169
|
});
|
|
164
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Marks this connector as teardown-owned before asynchronous disconnect work
|
|
173
|
+
* can yield. Late nonterminal callbacks must not revive application state or
|
|
174
|
+
* install listeners while the connector is going away.
|
|
175
|
+
*/
|
|
176
|
+
Connector.prototype.beginDisconnect = function () {
|
|
177
|
+
this._disconnectStarted = true;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Rejection and disconnection are terminal lifecycle notifications and must
|
|
181
|
+
* still propagate while teardown is pending. All other late events are stale.
|
|
182
|
+
*/
|
|
183
|
+
Connector.prototype.shouldHandleEvent = function (eventType, eventEnum) {
|
|
184
|
+
if (!this._disconnectStarted) {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
return eventType === "conn" && (eventEnum === RaftConnEvent.CONN_REJECTED ||
|
|
188
|
+
eventEnum === RaftConnEvent.CONN_DISCONNECTED);
|
|
189
|
+
};
|
|
165
190
|
/**
|
|
166
191
|
* Register the manager-owned cleanup callback for a terminal disconnect event.
|
|
167
192
|
*/
|
|
@@ -175,6 +200,7 @@ var Connector = /** @class */ (function () {
|
|
|
175
200
|
* RoboticalJS package while the new ConnManager API is being released.
|
|
176
201
|
*/
|
|
177
202
|
Connector.prototype.disconnectForPageUnload = function () {
|
|
203
|
+
this.beginDisconnect();
|
|
178
204
|
var connManagerWithPageUnload = this.connManager;
|
|
179
205
|
if (typeof connManagerWithPageUnload.disconnectForPageUnload === "function") {
|
|
180
206
|
connManagerWithPageUnload.disconnectForPageUnload();
|