@robotical/webapp-types 3.18.13 → 3.19.1

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.
Files changed (31) hide show
  1. package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +21 -10
  2. package/dist-types/src/application/ApplicationManager/ApplicationManager.js +297 -83
  3. package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +2 -0
  4. package/dist-types/src/application/RAFTs/Cog/Cog.js +3 -0
  5. package/dist-types/src/application/RAFTs/Marty/Marty.js +7 -3
  6. package/dist-types/src/application/RAFTs/Marty/MartyWifiManager.d.ts +6 -18
  7. package/dist-types/src/application/RAFTs/Marty/MartyWifiManager.js +25 -274
  8. package/dist-types/src/application/RAFTs/RAFT.d.ts +8 -2
  9. package/dist-types/src/application/RAFTs/RAFT.js +23 -4
  10. package/dist-types/src/application/RAFTs/RaftWifiManager.d.ts +24 -0
  11. package/dist-types/src/application/RAFTs/RaftWifiManager.js +329 -0
  12. package/dist-types/src/application/communicators/WrapperCommunicator.js +7 -3
  13. package/dist-types/src/components/modals/VerificationModal/index.js +4 -1
  14. package/dist-types/src/components/modals/WifiConnectionModal/index.d.ts +6 -0
  15. package/dist-types/src/components/modals/WifiConnectionModal/index.js +41 -0
  16. package/dist-types/src/i18n.js +43 -3
  17. package/dist-types/src/store/ConnectionMethodPreference.d.ts +7 -0
  18. package/dist-types/src/store/ConnectionMethodPreference.js +44 -0
  19. package/dist-types/src/store/SelectedRaftContext.d.ts +3 -1
  20. package/dist-types/src/store/SelectedRaftContext.js +1 -1
  21. package/dist-types/src/types/raft.d.ts +23 -0
  22. package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.d.ts +2 -1
  23. package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.js +26 -22
  24. package/dist-types/src/utils/wifi-connection.d.ts +18 -0
  25. package/dist-types/src/utils/wifi-connection.js +97 -0
  26. package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +3 -2
  27. package/dist-types/src/wrapper-app/WrapperAppManager.js +149 -45
  28. package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +1 -1
  29. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.d.ts +1 -0
  30. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.js +15 -11
  31. package/package.json +1 -1
@@ -1,31 +1,35 @@
1
- import isVersionGreater from "./compare-version";
2
1
  import { RaftWifiConnState } from "@robdobsn/raftjs";
3
- export var FW_VERSION_RSSI_WIFI = "1.2.0"; // greater versions than this (1.1.17) have the wifi rssi logic
4
- export default function wifiConfigSub(raft, cachedStatus) {
2
+ // Retained for signal-strength consumers; provisioning support is now probed
3
+ // from NetMan instead of inferred from this version.
4
+ export var FW_VERSION_RSSI_WIFI = "1.2.0";
5
+ export default function wifiConfigSub(raft, cachedStatus, capability) {
6
+ if (capability === void 0) { capability = "supported"; }
5
7
  if (!raft) {
6
- return "No raft connected";
8
+ return "No device connected";
7
9
  }
8
- if (!isVersionGreater(raft.getRaftVersion(), FW_VERSION_RSSI_WIFI)) {
9
- return "Currently, wifi configuration only works in the phone application.";
10
+ if (capability === "checking") {
11
+ return "Checking Wi-Fi support...";
12
+ }
13
+ if (capability === "unsupported") {
14
+ return "Wi-Fi requires compatible ".concat(raft.type, " firmware.");
10
15
  }
11
16
  var isPaused = cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.isPaused;
12
- var conInfo = (cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.connState) === RaftWifiConnState.WIFI_CONN_CONNECTED ||
13
- (cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.ssid)
14
- ? cachedStatus.ipAddress + (isPaused ? "" : " on " + cachedStatus.ssid)
15
- : null;
16
- var isConnected = (cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.connState) === RaftWifiConnState.WIFI_CONN_CONNECTED && (cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.ipAddress);
17
- var subtitle;
17
+ var isConnected = (cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.connState) === RaftWifiConnState.WIFI_CONN_CONNECTED;
18
+ var connectionDetails = [
19
+ cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.ipAddress,
20
+ (cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.ssid) ? "on ".concat(cachedStatus.ssid) : "",
21
+ ].filter(Boolean).join(" ");
18
22
  if (isConnected) {
19
- subtitle = "Connected";
20
- }
21
- if (isConnected && isPaused) {
22
- subtitle = "Connected (Paused for BLE)";
23
- }
24
- if (!isConnected) {
25
- subtitle = "Not Connected";
23
+ var state = isPaused ? "Configured (paused for Bluetooth)" : "Connected";
24
+ return connectionDetails ? "".concat(state, " | ").concat(connectionDetails) : state;
26
25
  }
27
- if (conInfo) {
28
- subtitle += " | " + conInfo;
26
+ if ((cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.ssid) || (cachedStatus === null || cachedStatus === void 0 ? void 0 : cachedStatus.ipAddress)) {
27
+ var state = isPaused
28
+ ? "Configured (paused for Bluetooth)"
29
+ : "Configured (not connected)";
30
+ return cachedStatus.ssid ? "".concat(state, " | ").concat(cachedStatus.ssid) : state;
29
31
  }
30
- return subtitle;
32
+ return isPaused
33
+ ? "Not connected (Wi-Fi paused for Bluetooth)"
34
+ : "Not connected";
31
35
  }
@@ -0,0 +1,18 @@
1
+ import { ConnectableRaftType } from "../types/raft";
2
+ /**
3
+ * Wi-Fi robot connections are deliberately limited to the local network. This
4
+ * is also the trust boundary used by the native wrapper when allowing
5
+ * cleartext ws:// traffic to robot firmware.
6
+ */
7
+ export declare const isLocalWifiHostname: (hostname: string) => boolean;
8
+ /**
9
+ * Turn a user-entered IP address, hostname, or URL into the complete WebSocket
10
+ * locator expected by the browser and native wrapper bridge.
11
+ *
12
+ * The selected robot type is authoritative for the path. This prevents a
13
+ * copied Marty URL from silently being used to connect to a Cog (or vice
14
+ * versa), while still allowing an advanced user to choose ws:// or wss:// and
15
+ * a custom port.
16
+ */
17
+ export declare const normalizeWifiLocator: (input: string, raftType: ConnectableRaftType) => string;
18
+ export declare const getWifiPathForRaftType: (raftType: ConnectableRaftType) => string;
@@ -0,0 +1,97 @@
1
+ var _a;
2
+ import { RaftTypeE } from "../types/raft";
3
+ var WEBSOCKET_PATHS = (_a = {},
4
+ _a[RaftTypeE.MARTY] = "/ws",
5
+ _a[RaftTypeE.COG] = "/wsjson",
6
+ _a);
7
+ var isPrivateOrLocalIpv4 = function (hostname) {
8
+ var parts = hostname.split(".");
9
+ if (parts.length !== 4 || parts.some(function (part) { return !/^\d{1,3}$/.test(part); })) {
10
+ return false;
11
+ }
12
+ var octets = parts.map(Number);
13
+ if (octets.some(function (octet) { return octet > 255; })) {
14
+ return false;
15
+ }
16
+ return (octets[0] === 10 ||
17
+ octets[0] === 127 ||
18
+ (octets[0] === 169 && octets[1] === 254) ||
19
+ (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31) ||
20
+ (octets[0] === 192 && octets[1] === 168));
21
+ };
22
+ var isPrivateOrLocalIpv6 = function (hostname) {
23
+ var unwrappedHostname = hostname.replace(/^\[|\]$/g, "").toLowerCase();
24
+ if (!unwrappedHostname.includes(":")) {
25
+ return false;
26
+ }
27
+ if (unwrappedHostname === "::1") {
28
+ return true;
29
+ }
30
+ var firstSegment = unwrappedHostname.split(":")[0];
31
+ var firstValue = Number.parseInt(firstSegment, 16);
32
+ return (Number.isFinite(firstValue) &&
33
+ // Unique local addresses (fc00::/7).
34
+ (firstValue >= 0xfc00 && firstValue <= 0xfdff ||
35
+ // Link-local addresses (fe80::/10).
36
+ firstValue >= 0xfe80 && firstValue <= 0xfebf));
37
+ };
38
+ /**
39
+ * Wi-Fi robot connections are deliberately limited to the local network. This
40
+ * is also the trust boundary used by the native wrapper when allowing
41
+ * cleartext ws:// traffic to robot firmware.
42
+ */
43
+ export var isLocalWifiHostname = function (hostname) {
44
+ var normalizedHostname = hostname.toLowerCase().replace(/\.$/, "");
45
+ if (normalizedHostname === "localhost" ||
46
+ normalizedHostname.endsWith(".local") ||
47
+ (!normalizedHostname.includes(".") && !normalizedHostname.includes(":"))) {
48
+ return true;
49
+ }
50
+ return (isPrivateOrLocalIpv4(normalizedHostname) ||
51
+ isPrivateOrLocalIpv6(normalizedHostname));
52
+ };
53
+ /**
54
+ * Turn a user-entered IP address, hostname, or URL into the complete WebSocket
55
+ * locator expected by the browser and native wrapper bridge.
56
+ *
57
+ * The selected robot type is authoritative for the path. This prevents a
58
+ * copied Marty URL from silently being used to connect to a Cog (or vice
59
+ * versa), while still allowing an advanced user to choose ws:// or wss:// and
60
+ * a custom port.
61
+ */
62
+ export var normalizeWifiLocator = function (input, raftType) {
63
+ var value = input.trim();
64
+ if (!value) {
65
+ throw new Error("Enter a robot IP address or hostname.");
66
+ }
67
+ var candidate = value;
68
+ if (/^https?:\/\//i.test(candidate)) {
69
+ candidate = candidate.replace(/^http/i, "ws");
70
+ }
71
+ else if (!/^wss?:\/\//i.test(candidate)) {
72
+ candidate = "ws://".concat(candidate);
73
+ }
74
+ var url;
75
+ try {
76
+ url = new URL(candidate);
77
+ }
78
+ catch (_a) {
79
+ throw new Error("Enter a valid IP address or hostname.");
80
+ }
81
+ if (url.protocol !== "ws:" && url.protocol !== "wss:") {
82
+ throw new Error("The connection must use ws:// or wss://.");
83
+ }
84
+ if (!url.hostname || url.username || url.password) {
85
+ throw new Error("Enter a valid robot IP address or hostname.");
86
+ }
87
+ if (!isLocalWifiHostname(url.hostname)) {
88
+ throw new Error("Wi-Fi connections must use a local-network address.");
89
+ }
90
+ url.pathname = WEBSOCKET_PATHS[raftType];
91
+ url.search = "";
92
+ url.hash = "";
93
+ return url.toString();
94
+ };
95
+ export var getWifiPathForRaftType = function (raftType) {
96
+ return WEBSOCKET_PATHS[raftType];
97
+ };
@@ -1,6 +1,6 @@
1
1
  import { RaftInfoEvents } from "../types/events/raft-info";
2
2
  import type { RestMessageOptions } from "../types/communication-between-apps/wrapper-communication";
3
- import { ConnectionAttemptResults, RaftConnectionMethod } from "../types/raft";
3
+ import { ConnectableRaftType, ConnectionAttemptResults, RaftConnectionMethod } from "../types/raft";
4
4
  import Connector from "./connectors/Connector";
5
5
  import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robdobsn/raftjs";
6
6
  import { RICLedLcdColours } from "@robotical/roboticaljs";
@@ -27,6 +27,7 @@ export declare class WrapperAppManager {
27
27
  *
28
28
  */
29
29
  connect(method: RaftConnectionMethod, uuids: string[]): Promise<ConnectionAttemptResults>;
30
+ connect(method: RaftConnectionMethod, locator: string, uuids: string[], expectedRaftType?: ConnectableRaftType): Promise<ConnectionAttemptResults>;
30
31
  private _connect;
31
32
  /**
32
33
  * Gets user's device info
@@ -73,7 +74,7 @@ export declare class WrapperAppManager {
73
74
  disconnect(raftId: string): Promise<boolean>;
74
75
  /**
75
76
  * Best-effort terminal cleanup. Page lifecycle events cannot reliably await
76
- * async Bluetooth work, so each connector forwards to RaftJS synchronously.
77
+ * async transport work, so each connector forwards to RaftJS synchronously.
77
78
  */
78
79
  disconnectAllForPageUnload(): void;
79
80
  private _disconnectConnManagerForPageUnload;
@@ -44,6 +44,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
44
  return to.concat(ar || Array.prototype.slice.call(from));
45
45
  };
46
46
  import { WrapperSentMessage } from "../types/communication-between-apps/wrapper-communication";
47
+ import { RaftConnectionMethod, } from "../types/raft";
47
48
  import Logger from "../services/logger/Logger";
48
49
  import { RaftConnEvent } from "@robdobsn/raftjs";
49
50
  import { ConnManager } from "@robotical/roboticaljs";
@@ -52,6 +53,7 @@ import ColourSensorManualCalibratorMarty from "./utils/ColourSensorManualCalibra
52
53
  import { getBrowserVersion, getOrGenerateDeviceId, getOSName, isTablet } from "./utils/device-info";
53
54
  var SHOW_LOGS = true;
54
55
  var TAG = "WrapperAppManager";
56
+ var WEBSOCKET_CONNECT_TIMEOUT_MS = 20000;
55
57
  var WrapperAppManager = /** @class */ (function () {
56
58
  function WrapperAppManager() {
57
59
  // Connectors
@@ -69,16 +71,11 @@ var WrapperAppManager = /** @class */ (function () {
69
71
  WrapperAppManager.prototype.getConnector = function (raftId) {
70
72
  return this.connectors[raftId];
71
73
  };
72
- /**
73
- * Connect to a RAFT
74
- *
75
- * @param {string} method - can be "WebBLE" or "WebSocket"
76
- * @param {string | object} locator - either a string (WebSocket URL) or an object (WebBLE)
77
- * @returns Promise<ConnectionAttemptResults>
78
- *
79
- */
80
- WrapperAppManager.prototype.connect = function (method, uuids) {
74
+ WrapperAppManager.prototype.connect = function (method, locatorOrUuids, requestUuids, expectedRaftType) {
81
75
  var _this = this;
76
+ if (requestUuids === void 0) { requestUuids = []; }
77
+ var locator = Array.isArray(locatorOrUuids) ? "" : locatorOrUuids;
78
+ var uuids = Array.isArray(locatorOrUuids) ? locatorOrUuids : requestUuids;
82
79
  if (this._pageUnloadStarted) {
83
80
  return Promise.resolve({ success: false, reason: "failed" });
84
81
  }
@@ -86,10 +83,10 @@ var WrapperAppManager = /** @class */ (function () {
86
83
  return this._connectPromise;
87
84
  }
88
85
  if (Object.values(this._disconnectOperations).some(Boolean)) {
89
- Logger.warn(SHOW_LOGS, TAG, "Refusing to start a connection while Bluetooth teardown is in progress");
86
+ Logger.warn(SHOW_LOGS, TAG, "Refusing to start a connection while device teardown is in progress");
90
87
  return Promise.resolve({ success: false, reason: "failed" });
91
88
  }
92
- var connectPromise = this._connect(method, uuids);
89
+ var connectPromise = this._connect(method, locator, uuids, expectedRaftType);
93
90
  this._connectPromise = connectPromise;
94
91
  var clearConnectPromise = function () {
95
92
  if (_this._connectPromise === connectPromise) {
@@ -99,9 +96,9 @@ var WrapperAppManager = /** @class */ (function () {
99
96
  void connectPromise.then(clearConnectPromise, clearConnectPromise);
100
97
  return connectPromise;
101
98
  };
102
- WrapperAppManager.prototype._connect = function (method, uuids) {
99
+ WrapperAppManager.prototype._connect = function (method, locator, uuids, expectedRaftType) {
103
100
  return __awaiter(this, void 0, void 0, function () {
104
- var connector, pendingConnManager, committed, disconnectedBeforeCommit, ownedConnector_1, connectionResults, existingConnector, raftSystemUtils, systemInfo, raftName, error_1;
101
+ var connector, pendingConnManager, committed, disconnectedBeforeCommit, websocketTimedOut, websocketDeadline, connectorPromise, timeoutHandle_1, didTimeOut_1, timeoutPromise, ownedConnector_1, connectorConnectionPromise, connectionResults, setupTimeoutHandle_1, setupTimeout, setupResult, existingConnector, raftSystemUtils, systemInfo, raftName, error_1;
105
102
  var _this = this;
106
103
  return __generator(this, function (_a) {
107
104
  switch (_a.label) {
@@ -110,22 +107,89 @@ var WrapperAppManager = /** @class */ (function () {
110
107
  pendingConnManager = null;
111
108
  committed = false;
112
109
  disconnectedBeforeCommit = false;
110
+ websocketTimedOut = false;
111
+ websocketDeadline = method === RaftConnectionMethod.WEB_SOCKET
112
+ ? Date.now() + WEBSOCKET_CONNECT_TIMEOUT_MS
113
+ : null;
113
114
  _a.label = 1;
114
115
  case 1:
115
- _a.trys.push([1, , 4, 11]);
116
- return [4 /*yield*/, ConnectorFactory.connectToRaftHelper(method, uuids, function (connManager) {
117
- pendingConnManager = connManager;
118
- _this._pendingConnManagers.add(connManager);
119
- if (_this._pageUnloadStarted) {
120
- _this._disconnectConnManagerForPageUnload(connManager);
116
+ _a.trys.push([1, , 16, 23]);
117
+ connectorPromise = ConnectorFactory.connectToRaftHelper(method, locator, uuids, function (connManager) {
118
+ pendingConnManager = connManager;
119
+ _this._pendingConnManagers.add(connManager);
120
+ if (_this._pageUnloadStarted) {
121
+ _this._disconnectConnManagerForPageUnload(connManager);
122
+ }
123
+ });
124
+ if (!(method === RaftConnectionMethod.WEB_SOCKET)) return [3 /*break*/, 6];
125
+ didTimeOut_1 = false;
126
+ timeoutPromise = new Promise(function (resolve) {
127
+ timeoutHandle_1 = setTimeout(function () {
128
+ didTimeOut_1 = true;
129
+ websocketTimedOut = true;
130
+ if (pendingConnManager) {
131
+ _this._disconnectConnManagerForPageUnload(pendingConnManager);
121
132
  }
122
- })];
133
+ resolve(null);
134
+ }, Math.max(0, (websocketDeadline || Date.now()) - Date.now()));
135
+ });
136
+ _a.label = 2;
123
137
  case 2:
138
+ _a.trys.push([2, , 4, 5]);
139
+ return [4 /*yield*/, Promise.race([connectorPromise, timeoutPromise])];
140
+ case 3:
124
141
  connector = _a.sent();
142
+ return [3 /*break*/, 5];
143
+ case 4:
144
+ if (timeoutHandle_1) {
145
+ clearTimeout(timeoutHandle_1);
146
+ }
147
+ return [7 /*endfinally*/];
148
+ case 5:
149
+ if (didTimeOut_1) {
150
+ // A channel can settle after its transport has been closed.
151
+ // ConnectorFactory still owns it until it returns; if it
152
+ // nevertheless creates a Connector, release that late owner.
153
+ void connectorPromise.then(function (lateConnector) { return __awaiter(_this, void 0, void 0, function () {
154
+ var error_2;
155
+ return __generator(this, function (_a) {
156
+ switch (_a.label) {
157
+ case 0:
158
+ if (!lateConnector) return [3 /*break*/, 4];
159
+ _a.label = 1;
160
+ case 1:
161
+ _a.trys.push([1, 3, , 4]);
162
+ return [4 /*yield*/, lateConnector.disconnect()];
163
+ case 2:
164
+ _a.sent();
165
+ return [3 /*break*/, 4];
166
+ case 3:
167
+ error_2 = _a.sent();
168
+ Logger.warn(SHOW_LOGS, TAG, "Failed late WebSocket cleanup: ".concat(error_2));
169
+ return [3 /*break*/, 4];
170
+ case 4: return [2 /*return*/];
171
+ }
172
+ });
173
+ }); }).catch(function (error) {
174
+ Logger.warn(SHOW_LOGS, TAG, "WebSocket connection settled after timeout: ".concat(error));
175
+ });
176
+ Logger.warn(SHOW_LOGS, TAG, "WebSocket connection timed out after ".concat(WEBSOCKET_CONNECT_TIMEOUT_MS, "ms"));
177
+ return [2 /*return*/, { success: false, reason: "failed" }];
178
+ }
179
+ return [3 /*break*/, 8];
180
+ case 6: return [4 /*yield*/, connectorPromise];
181
+ case 7:
182
+ connector = _a.sent();
183
+ _a.label = 8;
184
+ case 8:
125
185
  if (!connector || this._pageUnloadStarted) {
126
186
  Logger.warn(SHOW_LOGS, TAG, "Failed to connect to RAFT with method: ".concat(method));
127
187
  return [2 /*return*/, { success: false, reason: "failed" }];
128
188
  }
189
+ if (expectedRaftType && connector.type !== expectedRaftType) {
190
+ Logger.warn(SHOW_LOGS, TAG, "Connected RAFT type ".concat(connector.type, " did not match expected type ").concat(expectedRaftType));
191
+ return [2 /*return*/, { success: false, reason: "invalid_raft_type" }];
192
+ }
129
193
  ownedConnector_1 = connector;
130
194
  connector.setOnDisconnected(function () {
131
195
  if (!committed) {
@@ -136,9 +200,47 @@ var WrapperAppManager = /** @class */ (function () {
136
200
  if (disconnectedBeforeCommit || !connector.connManager.isConnected()) {
137
201
  return [2 /*return*/, { success: false, reason: "failed" }];
138
202
  }
139
- return [4 /*yield*/, connector.connect()];
140
- case 3:
203
+ connectorConnectionPromise = connector.connect();
204
+ connectionResults = void 0;
205
+ if (!(websocketDeadline !== null)) return [3 /*break*/, 13];
206
+ setupTimeout = new Promise(function (resolve) {
207
+ setupTimeoutHandle_1 = setTimeout(function () {
208
+ websocketTimedOut = true;
209
+ connector === null || connector === void 0 ? void 0 : connector.disconnectForPageUnload();
210
+ resolve(null);
211
+ }, Math.max(0, websocketDeadline - Date.now()));
212
+ });
213
+ setupResult = void 0;
214
+ _a.label = 9;
215
+ case 9:
216
+ _a.trys.push([9, , 11, 12]);
217
+ return [4 /*yield*/, Promise.race([
218
+ connectorConnectionPromise,
219
+ setupTimeout,
220
+ ])];
221
+ case 10:
222
+ setupResult = _a.sent();
223
+ return [3 /*break*/, 12];
224
+ case 11:
225
+ if (setupTimeoutHandle_1) {
226
+ clearTimeout(setupTimeoutHandle_1);
227
+ }
228
+ return [7 /*endfinally*/];
229
+ case 12:
230
+ if (!setupResult) {
231
+ void connectorConnectionPromise.catch(function (error) {
232
+ Logger.warn(SHOW_LOGS, TAG, "WebSocket setup settled after timeout: ".concat(error));
233
+ });
234
+ Logger.warn(SHOW_LOGS, TAG, "WebSocket setup timed out after ".concat(WEBSOCKET_CONNECT_TIMEOUT_MS, "ms"));
235
+ return [2 /*return*/, { success: false, reason: "failed" }];
236
+ }
237
+ connectionResults = setupResult;
238
+ return [3 /*break*/, 15];
239
+ case 13: return [4 /*yield*/, connectorConnectionPromise];
240
+ case 14:
141
241
  connectionResults = _a.sent();
242
+ _a.label = 15;
243
+ case 15:
142
244
  if (!connectionResults.success) {
143
245
  Logger.warn(SHOW_LOGS, TAG, "Failed to connect to RAFT with id: ".concat(connector.id, " and type: ").concat(connector.type));
144
246
  return [2 /*return*/, connectionResults];
@@ -170,28 +272,30 @@ var WrapperAppManager = /** @class */ (function () {
170
272
  committed = true;
171
273
  Logger.info(SHOW_LOGS, TAG, "Connected to RAFT with id: ".concat(connector.id, " and type: ").concat(connector.type));
172
274
  return [2 /*return*/, connectionResults];
173
- case 4:
174
- _a.trys.push([4, , 9, 10]);
175
- if (!(connector && !committed)) return [3 /*break*/, 8];
176
- _a.label = 5;
177
- case 5:
178
- _a.trys.push([5, 7, , 8]);
275
+ case 16:
276
+ _a.trys.push([16, , 21, 22]);
277
+ if (!(connector && !committed)) return [3 /*break*/, 20];
278
+ if (!websocketTimedOut) return [3 /*break*/, 17];
279
+ connector.disconnectForPageUnload();
280
+ return [3 /*break*/, 20];
281
+ case 17:
282
+ _a.trys.push([17, 19, , 20]);
179
283
  return [4 /*yield*/, connector.disconnect()];
180
- case 6:
284
+ case 18:
181
285
  _a.sent();
182
- return [3 /*break*/, 8];
183
- case 7:
286
+ return [3 /*break*/, 20];
287
+ case 19:
184
288
  error_1 = _a.sent();
185
289
  Logger.warn(SHOW_LOGS, TAG, "Failed to clean up uncommitted connector ".concat(connector.id, ": ").concat(error_1));
186
- return [3 /*break*/, 8];
187
- case 8: return [3 /*break*/, 10];
188
- case 9:
290
+ return [3 /*break*/, 20];
291
+ case 20: return [3 /*break*/, 22];
292
+ case 21:
189
293
  if (pendingConnManager) {
190
294
  this._pendingConnManagers.delete(pendingConnManager);
191
295
  }
192
296
  return [7 /*endfinally*/];
193
- case 10: return [7 /*endfinally*/];
194
- case 11: return [2 /*return*/];
297
+ case 22: return [7 /*endfinally*/];
298
+ case 23: return [2 /*return*/];
195
299
  }
196
300
  });
197
301
  });
@@ -402,7 +506,7 @@ var WrapperAppManager = /** @class */ (function () {
402
506
  };
403
507
  /**
404
508
  * Best-effort terminal cleanup. Page lifecycle events cannot reliably await
405
- * async Bluetooth work, so each connector forwards to RaftJS synchronously.
509
+ * async transport work, so each connector forwards to RaftJS synchronously.
406
510
  */
407
511
  WrapperAppManager.prototype.disconnectAllForPageUnload = function () {
408
512
  this._pageUnloadStarted = true;
@@ -490,7 +594,7 @@ var WrapperAppManager = /** @class */ (function () {
490
594
  */
491
595
  WrapperAppManager.prototype.scanForPotentialWarrantyDevice = function (existingDevices) {
492
596
  return __awaiter(this, void 0, void 0, function () {
493
- var namesToIgnore, warrantyConnManager, ownsTemporaryConnection, device_1, isConnected, connector, ricSystem, systemInfo, serialNumber, raftType, newDevice, error_2, error_3;
597
+ var namesToIgnore, warrantyConnManager, ownsTemporaryConnection, device_1, isConnected, connector, ricSystem, systemInfo, serialNumber, raftType, newDevice, error_3, error_4;
494
598
  return __generator(this, function (_a) {
495
599
  switch (_a.label) {
496
600
  case 0:
@@ -543,8 +647,8 @@ var WrapperAppManager = /** @class */ (function () {
543
647
  _a.label = 6;
544
648
  case 6: return [3 /*break*/, 14];
545
649
  case 7:
546
- error_2 = _a.sent();
547
- Logger.error(SHOW_LOGS, TAG, JSON.stringify(error_2));
650
+ error_3 = _a.sent();
651
+ Logger.error(SHOW_LOGS, TAG, JSON.stringify(error_3));
548
652
  return [2 /*return*/, existingDevices];
549
653
  case 8:
550
654
  if (!ownsTemporaryConnection) return [3 /*break*/, 13];
@@ -556,8 +660,8 @@ var WrapperAppManager = /** @class */ (function () {
556
660
  _a.sent();
557
661
  return [3 /*break*/, 13];
558
662
  case 11:
559
- error_3 = _a.sent();
560
- Logger.warn(SHOW_LOGS, TAG, "Failed warranty connection cleanup: ".concat(error_3));
663
+ error_4 = _a.sent();
664
+ Logger.warn(SHOW_LOGS, TAG, "Failed warranty connection cleanup: ".concat(error_4));
561
665
  return [3 /*break*/, 13];
562
666
  case 12:
563
667
  this._pendingConnManagers.delete(warrantyConnManager);
@@ -573,7 +677,7 @@ var WrapperAppManager = /** @class */ (function () {
573
677
  */
574
678
  WrapperAppManager.prototype.sendAtomicReadOperationToMarty = function (raftId) {
575
679
  return __awaiter(this, void 0, void 0, function () {
576
- var raftConnector, systemType, error_4;
680
+ var raftConnector, systemType, error_5;
577
681
  return __generator(this, function (_a) {
578
682
  switch (_a.label) {
579
683
  case 0:
@@ -589,8 +693,8 @@ var WrapperAppManager = /** @class */ (function () {
589
693
  _a.sent();
590
694
  return [2 /*return*/, true];
591
695
  case 3:
592
- error_4 = _a.sent();
593
- Logger.error(SHOW_LOGS, TAG, "Failed to send atomic read operation to Marty: ".concat(error_4));
696
+ error_5 = _a.sent();
697
+ Logger.error(SHOW_LOGS, TAG, "Failed to send atomic read operation to Marty: ".concat(error_5));
594
698
  return [3 /*break*/, 4];
595
699
  case 4: return [3 /*break*/, 6];
596
700
  case 5:
@@ -155,7 +155,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
155
155
  return [3 /*break*/, 55];
156
156
  case 2:
157
157
  _b.trys.push([2, 4, , 5]);
158
- return [4 /*yield*/, wrapperAppManager.connect(data.method, data.uuids)];
158
+ return [4 /*yield*/, wrapperAppManager.connect(data.method, data.locator, data.uuids, data.expectedRaftType)];
159
159
  case 3:
160
160
  connectionResults = _b.sent();
161
161
  window.wrapperCommunicator.onMessageResponse({ success: true, error: "", results: connectionResults, messagePromiseId: messagePromiseId });
@@ -11,5 +11,6 @@ export default class ConnectorFactory {
11
11
  *
12
12
  */
13
13
  static connectToRaftHelper(method: RaftConnectionMethod, uuids: string[], onConnManagerCreated?: (connManager: ConnManager) => void): Promise<Connector | null>;
14
+ static connectToRaftHelper(method: RaftConnectionMethod, locator: string, uuids: string[], onConnManagerCreated?: (connManager: ConnManager) => void): Promise<Connector | null>;
14
15
  static createConnector(raftType: string | undefined, connManager: ConnManager, connectionMethod: RaftConnectionMethod): Connector;
15
16
  }
@@ -44,20 +44,24 @@ var TAG = "ConnectorFactory";
44
44
  var ConnectorFactory = /** @class */ (function () {
45
45
  function ConnectorFactory() {
46
46
  }
47
- /**
48
- * Connect to a RAFT
49
- *
50
- * @param {string} method - can be "WebBLE" or "WebSocket"
51
- * @param {string | object} locator - either a string (WebSocket URL) or an object (WebBLE)
52
- * @returns Promise<ConnectionAttemptResults>
53
- *
54
- */
55
- ConnectorFactory.connectToRaftHelper = function (method, uuids, onConnManagerCreated) {
47
+ ConnectorFactory.connectToRaftHelper = function (method, locatorOrUuids, requestUuidsOrCallback, requestCallback) {
56
48
  return __awaiter(this, void 0, void 0, function () {
57
- var connManager, connectorWasCreated, lowLevelConnectionSucceeded, connectionResult, systemInfo, raftType, connector, error_1;
49
+ var usesLegacySignature, locator, uuids, onConnManagerCreated, connManager, connectorWasCreated, lowLevelConnectionSucceeded, connectionResult, systemInfo, raftType, connector, error_1;
58
50
  return __generator(this, function (_a) {
59
51
  switch (_a.label) {
60
52
  case 0:
53
+ usesLegacySignature = Array.isArray(locatorOrUuids);
54
+ locator = usesLegacySignature ? "" : locatorOrUuids;
55
+ uuids = usesLegacySignature
56
+ ? locatorOrUuids
57
+ : Array.isArray(requestUuidsOrCallback)
58
+ ? requestUuidsOrCallback
59
+ : [];
60
+ onConnManagerCreated = usesLegacySignature
61
+ ? typeof requestUuidsOrCallback === "function"
62
+ ? requestUuidsOrCallback
63
+ : undefined
64
+ : requestCallback;
61
65
  connManager = new ConnManager();
62
66
  connectorWasCreated = false;
63
67
  lowLevelConnectionSucceeded = false;
@@ -66,7 +70,7 @@ var ConnectorFactory = /** @class */ (function () {
66
70
  _a.trys.push([1, , 3, 8]);
67
71
  onConnManagerCreated === null || onConnManagerCreated === void 0 ? void 0 : onConnManagerCreated(connManager);
68
72
  Logger.info(SHOW_LOGS, TAG, "Connecting to RAFT with method: ".concat(method));
69
- return [4 /*yield*/, connManager.connectDetailed(method, "", uuids)];
73
+ return [4 /*yield*/, connManager.connectDetailed(method, locator, uuids)];
70
74
  case 2:
71
75
  connectionResult = _a.sent();
72
76
  lowLevelConnectionSucceeded = connectionResult.status === "success";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "3.18.13",
3
+ "version": "3.19.1",
4
4
  "description": "Type definitions for the Application Manager",
5
5
  "main": "dist/application-manager.d.ts",
6
6
  "types": "dist/application-manager.d.ts",