@robotical/webapp-types 3.17.3 → 3.17.5
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.js +44 -29
- package/dist-types/src/types/raft.d.ts +2 -0
- package/dist-types/src/wrapper-app/WrapperAppManager.js +8 -2
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +16 -1
- package/package.json +1 -1
|
@@ -61,6 +61,11 @@ import InUnpluggedModalContent from "../../components/modals/InUnplugged";
|
|
|
61
61
|
var SHOW_LOGS = true;
|
|
62
62
|
var TAG = "ApplicationManager";
|
|
63
63
|
var UNSUPPORTED_WEB_BLUETOOTH_BROWSER_MESSAGE = "This browser can't connect to Marty or Cog over Bluetooth. Please use Chrome or Edge, or use the iPad app.";
|
|
64
|
+
var publishMissedConnectionEvent = function (raftId) {
|
|
65
|
+
window.wrapperCommunicator
|
|
66
|
+
.sendMessageAndWait(AppSentMessage.GET_MISSED_CONN_EVENT, { raftId: raftId })
|
|
67
|
+
.catch(function (error) { return Logger.warn(SHOW_LOGS, TAG, "Failed to get missed connection event for ".concat(raftId, ": ").concat(error)); });
|
|
68
|
+
};
|
|
64
69
|
var canUseWebBluetooth = function () {
|
|
65
70
|
var bluetooth = navigator.bluetooth;
|
|
66
71
|
return window.isSecureContext && !!bluetooth && typeof bluetooth.requestDevice === "function";
|
|
@@ -551,15 +556,15 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
551
556
|
* Selects a RAFT in Phone's verification modal
|
|
552
557
|
*/
|
|
553
558
|
ApplicationManager.prototype.selectRaft = function (ricToConnectTo, method) {
|
|
554
|
-
var _a, _b;
|
|
559
|
+
var _a, _b, _c, _d;
|
|
555
560
|
return __awaiter(this, void 0, void 0, function () {
|
|
556
561
|
var selectResults, raftId, raftType, raft;
|
|
557
|
-
return __generator(this, function (
|
|
558
|
-
switch (
|
|
562
|
+
return __generator(this, function (_e) {
|
|
563
|
+
switch (_e.label) {
|
|
559
564
|
case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_SELECT, { discoveredDevice: ricToConnectTo, method: method })];
|
|
560
565
|
case 1:
|
|
561
|
-
selectResults =
|
|
562
|
-
if (!selectResults.success) return [3 /*break*/,
|
|
566
|
+
selectResults = _e.sent();
|
|
567
|
+
if (!selectResults.success) return [3 /*break*/, 4];
|
|
563
568
|
raftId = (_a = selectResults.data) === null || _a === void 0 ? void 0 : _a.raftId;
|
|
564
569
|
raftType = (_b = selectResults.data) === null || _b === void 0 ? void 0 : _b.raftType;
|
|
565
570
|
if (!raftId || !raftType) {
|
|
@@ -577,18 +582,22 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
577
582
|
throw new Error("Unknown RAFT type");
|
|
578
583
|
}
|
|
579
584
|
this.connectedRafts[raftId] = raft;
|
|
585
|
+
if ((_c = selectResults.data) === null || _c === void 0 ? void 0 : _c.systemInfo) {
|
|
586
|
+
raft.systemInfo = selectResults.data.systemInfo;
|
|
587
|
+
}
|
|
580
588
|
// get missed Connect event
|
|
581
|
-
|
|
582
|
-
|
|
589
|
+
publishMissedConnectionEvent(raftId);
|
|
590
|
+
if (!!((_d = selectResults.data) === null || _d === void 0 ? void 0 : _d.systemInfo)) return [3 /*break*/, 3];
|
|
583
591
|
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 200); })];
|
|
584
592
|
case 2:
|
|
585
|
-
|
|
586
|
-
|
|
593
|
+
_e.sent();
|
|
594
|
+
_e.label = 3;
|
|
595
|
+
case 3:
|
|
587
596
|
if (this.ricSelectedCb) {
|
|
588
597
|
this.ricSelectedCb(raft);
|
|
589
598
|
}
|
|
590
599
|
return [2 /*return*/, raft];
|
|
591
|
-
case
|
|
600
|
+
case 4:
|
|
592
601
|
if (selectResults.reason === 'unplugged') {
|
|
593
602
|
modalState.closeModalWithoutAnimation();
|
|
594
603
|
secondaryModalState.closeModalWithoutAnimation();
|
|
@@ -597,22 +606,22 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
597
606
|
else {
|
|
598
607
|
Logger.warn(SHOW_LOGS, TAG, "Failed to select RAFT with id: ".concat(ricToConnectTo._id));
|
|
599
608
|
}
|
|
600
|
-
|
|
601
|
-
case
|
|
609
|
+
_e.label = 5;
|
|
610
|
+
case 5: return [2 /*return*/, null];
|
|
602
611
|
}
|
|
603
612
|
});
|
|
604
613
|
});
|
|
605
614
|
};
|
|
606
615
|
ApplicationManager.prototype.connectToRIC = function (method, uuids, withoutVerification) {
|
|
607
|
-
var _a, _b;
|
|
616
|
+
var _a, _b, _c, _d;
|
|
608
617
|
return __awaiter(this, void 0, void 0, function () {
|
|
609
618
|
var wasConnectedObj, raftId, raftType, raft, oldColours;
|
|
610
|
-
return __generator(this, function (
|
|
611
|
-
switch (
|
|
619
|
+
return __generator(this, function (_e) {
|
|
620
|
+
switch (_e.label) {
|
|
612
621
|
case 0: return [4 /*yield*/, RAFT.connect(method, uuids)];
|
|
613
622
|
case 1:
|
|
614
|
-
wasConnectedObj =
|
|
615
|
-
if (!wasConnectedObj.success) return [3 /*break*/,
|
|
623
|
+
wasConnectedObj = _e.sent();
|
|
624
|
+
if (!wasConnectedObj.success) return [3 /*break*/, 7];
|
|
616
625
|
raftId = (_a = wasConnectedObj.data) === null || _a === void 0 ? void 0 : _a.raftId;
|
|
617
626
|
raftType = (_b = wasConnectedObj.data) === null || _b === void 0 ? void 0 : _b.raftType;
|
|
618
627
|
if (!raftId || !raftType) {
|
|
@@ -630,30 +639,36 @@ var ApplicationManager = /** @class */ (function () {
|
|
|
630
639
|
throw new Error("Unknown RAFT type");
|
|
631
640
|
}
|
|
632
641
|
this.connectedRafts[raftId] = raft;
|
|
642
|
+
if ((_c = wasConnectedObj.data) === null || _c === void 0 ? void 0 : _c.systemInfo) {
|
|
643
|
+
raft.systemInfo = wasConnectedObj.data.systemInfo;
|
|
644
|
+
}
|
|
633
645
|
// get missed Connect event
|
|
634
|
-
|
|
646
|
+
publishMissedConnectionEvent(raftId);
|
|
647
|
+
if (!!((_d = wasConnectedObj.data) === null || _d === void 0 ? void 0 : _d.systemInfo)) return [3 /*break*/, 3];
|
|
635
648
|
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 200); })];
|
|
636
649
|
case 2:
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
modalState.setModal(createElement(VerificationModal, { connectedRAFT_: raft }), i18n.t("connection.looking_for_raft", { raftType: raft.type }), false);
|
|
640
|
-
return [3 /*break*/, 5];
|
|
650
|
+
_e.sent();
|
|
651
|
+
_e.label = 3;
|
|
641
652
|
case 3:
|
|
653
|
+
if (!!withoutVerification) return [3 /*break*/, 4];
|
|
654
|
+
modalState.setModal(createElement(VerificationModal, { connectedRAFT_: raft }), i18n.t("connection.looking_for_raft", { raftType: raft.type }), false);
|
|
655
|
+
return [3 /*break*/, 6];
|
|
656
|
+
case 4:
|
|
642
657
|
oldColours = raft._ledLcdColours;
|
|
643
658
|
raft._ledLcdColours = [];
|
|
644
659
|
return [4 /*yield*/, raft.verifyRaft()];
|
|
645
|
-
case
|
|
646
|
-
|
|
660
|
+
case 5:
|
|
661
|
+
_e.sent();
|
|
647
662
|
raft._ledLcdColours = oldColours;
|
|
648
663
|
raft.stopVerifyingRaft(true);
|
|
649
|
-
|
|
650
|
-
case
|
|
651
|
-
case
|
|
664
|
+
_e.label = 6;
|
|
665
|
+
case 6: return [2 /*return*/, raft];
|
|
666
|
+
case 7:
|
|
652
667
|
if (wasConnectedObj.reason === 'unplugged') {
|
|
653
668
|
modalState.setModal(createElement(InUnpluggedModalContent), i18n.t("calibration_screen.colour_calibration.unplugged_modal_title"));
|
|
654
669
|
}
|
|
655
|
-
|
|
656
|
-
case
|
|
670
|
+
_e.label = 8;
|
|
671
|
+
case 8: return [2 /*return*/, null];
|
|
657
672
|
}
|
|
658
673
|
});
|
|
659
674
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RaftSystemInfo } from "@robotical/raftjs";
|
|
1
2
|
export declare enum RaftConnectionMethod {
|
|
2
3
|
WEB_SOCKET = "WebSocket",
|
|
3
4
|
WEB_BLE = "WebBLE",
|
|
@@ -9,6 +10,7 @@ export type ConnectionAttemptResults = {
|
|
|
9
10
|
data?: {
|
|
10
11
|
raftId: string;
|
|
11
12
|
raftType: RaftTypeE;
|
|
13
|
+
systemInfo?: RaftSystemInfo;
|
|
12
14
|
};
|
|
13
15
|
};
|
|
14
16
|
export declare enum RaftTypeE {
|
|
@@ -75,7 +75,7 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
75
75
|
*/
|
|
76
76
|
WrapperAppManager.prototype.connect = function (method, uuids) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var connector, connectionResults;
|
|
78
|
+
var connector, connectionResults, raftSystemUtils, systemInfo, raftName;
|
|
79
79
|
return __generator(this, function (_a) {
|
|
80
80
|
switch (_a.label) {
|
|
81
81
|
case 0: return [4 /*yield*/, ConnectorFactory.connectToRaftHelper(method, uuids)];
|
|
@@ -90,7 +90,13 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
90
90
|
connectionResults = _a.sent();
|
|
91
91
|
if (connectionResults.success) {
|
|
92
92
|
this.connectors[connector.id] = connector;
|
|
93
|
-
|
|
93
|
+
raftSystemUtils = connector.connManager.getConnector().getRaftSystemUtils();
|
|
94
|
+
systemInfo = raftSystemUtils.getCachedSystemInfo() || undefined;
|
|
95
|
+
raftName = raftSystemUtils.getCachedRaftName() || raftSystemUtils.getFriendlyName();
|
|
96
|
+
if (systemInfo && (raftName === null || raftName === void 0 ? void 0 : raftName.friendlyName)) {
|
|
97
|
+
systemInfo.Friendly = raftName.friendlyName;
|
|
98
|
+
}
|
|
99
|
+
connectionResults.data = { raftId: connector.id, raftType: connector.type, systemInfo: systemInfo };
|
|
94
100
|
}
|
|
95
101
|
else {
|
|
96
102
|
Logger.warn(SHOW_LOGS, TAG, "Failed to connect to RAFT with id: ".concat(connector.id, " and type: ").concat(connector.type));
|
|
@@ -59,6 +59,18 @@ import { RICServoParamUpdater, RICSystemUtils, } from "@robotical/roboticaljs";
|
|
|
59
59
|
import { WrapperSentMessage } from "../../../types/communication-between-apps/wrapper-communication";
|
|
60
60
|
var SHOW_LOGS = true;
|
|
61
61
|
var TAG = "MartyConnector";
|
|
62
|
+
var UNPLUGGED_MODE_CHECK_TIMEOUT_MS = 750;
|
|
63
|
+
var timeout = function (promise, timeoutMs) {
|
|
64
|
+
var timeoutId;
|
|
65
|
+
var timeoutPromise = new Promise(function (resolve) {
|
|
66
|
+
timeoutId = setTimeout(function () { return resolve(null); }, timeoutMs);
|
|
67
|
+
});
|
|
68
|
+
return Promise.race([promise, timeoutPromise]).finally(function () {
|
|
69
|
+
if (timeoutId) {
|
|
70
|
+
clearTimeout(timeoutId);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
62
74
|
var MartyConnector = /** @class */ (function (_super) {
|
|
63
75
|
__extends(MartyConnector, _super);
|
|
64
76
|
function MartyConnector(raftId, connManager) {
|
|
@@ -99,9 +111,12 @@ var MartyConnector = /** @class */ (function (_super) {
|
|
|
99
111
|
// this.emit(RAFT_REJECTED)
|
|
100
112
|
return [2 /*return*/, { success: false, reason: 'no_sys_info' }];
|
|
101
113
|
}
|
|
102
|
-
return [4 /*yield*/, this.sendRestMessage("pystatus")];
|
|
114
|
+
return [4 /*yield*/, timeout(this.sendRestMessage("pystatus"), UNPLUGGED_MODE_CHECK_TIMEOUT_MS)];
|
|
103
115
|
case 2:
|
|
104
116
|
pystatus = _a.sent();
|
|
117
|
+
if (!pystatus) {
|
|
118
|
+
Logger.warn(SHOW_LOGS, TAG, "Marty unplugged-mode check timed out after ".concat(UNPLUGGED_MODE_CHECK_TIMEOUT_MS, "ms; continuing to verification"));
|
|
119
|
+
}
|
|
105
120
|
if (!(pystatus && pystatus.running === "screenfree.py")) return [3 /*break*/, 4];
|
|
106
121
|
Logger.warn(SHOW_LOGS, TAG, "Marty is in unplugged mode");
|
|
107
122
|
return [4 /*yield*/, this.disconnect()];
|