@robotical/webapp-types 3.17.51 → 3.18.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.
- package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +18 -10
- package/dist-types/src/application/ApplicationManager/ApplicationManager.js +177 -79
- package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +1 -1
- package/dist-types/src/application/RAFTs/Cog/Cog.js +1 -1
- package/dist-types/src/application/RAFTs/Marty/CalibrationManager.d.ts +1 -1
- package/dist-types/src/application/RAFTs/Marty/CalibrationManager.js +1 -1
- package/dist-types/src/application/RAFTs/Marty/Marty.d.ts +1 -1
- package/dist-types/src/application/RAFTs/Marty/Marty.js +1 -1
- package/dist-types/src/application/RAFTs/Marty/MartyWifiManager.d.ts +1 -1
- package/dist-types/src/application/RAFTs/Marty/MartyWifiManager.js +1 -1
- package/dist-types/src/application/RAFTs/Marty/notifications-manager/ReportedWarningsState.js +1 -1
- package/dist-types/src/application/RAFTs/RAFT.d.ts +1 -1
- package/dist-types/src/application/RAFTs/RAFT.js +2 -2
- package/dist-types/src/application/RAFTs/RAFTInterface.d.ts +1 -1
- package/dist-types/src/application/RAFTs/RaftObserver.d.ts +1 -1
- package/dist-types/src/application/RAFTs/raft-subscription-helpers.js +1 -1
- package/dist-types/src/components/disposables/SwitchableCameraScanner/index.d.ts +4 -0
- package/dist-types/src/components/disposables/SwitchableCameraScanner/index.js +47 -0
- package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.d.ts +4 -2
- package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.js +14 -7
- package/dist-types/src/components/modals/LEDLightsOrQRVerificationModal/index.js +4 -4
- package/dist-types/src/components/modals/VerificationModal/index.js +0 -8
- package/dist-types/src/components/modals/VerificationModalPhoneApp/index.js +17 -32
- package/dist-types/src/components/oneoffs/LEDs/index.js +1 -1
- package/dist-types/src/i18n.js +2 -0
- package/dist-types/src/types/raft.d.ts +1 -1
- package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.d.ts +1 -1
- package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.js +1 -1
- package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +16 -7
- package/dist-types/src/wrapper-app/WrapperAppManager.js +225 -55
- package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +3 -6
- package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.d.ts +1 -1
- package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.js +1 -1
- package/dist-types/src/wrapper-app/connectors/Connector.d.ts +14 -2
- package/dist-types/src/wrapper-app/connectors/Connector.js +25 -1
- package/dist-types/src/wrapper-app/connectors/ConnectorFactory.d.ts +1 -1
- package/dist-types/src/wrapper-app/connectors/ConnectorFactory.js +38 -7
- package/dist-types/src/wrapper-app/connectors/ConnectorInterface.d.ts +1 -1
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.d.ts +1 -1
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +9 -5
- package/dist-types/src/wrapper-app/utils/ColourSensorManualCalibratorMarty.d.ts +1 -1
- package/package.json +10 -1
|
@@ -45,7 +45,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
45
45
|
};
|
|
46
46
|
import { WrapperSentMessage } from "../types/communication-between-apps/wrapper-communication";
|
|
47
47
|
import Logger from "../services/logger/Logger";
|
|
48
|
-
import { RaftConnEvent } from "@
|
|
48
|
+
import { RaftConnEvent } from "@robdobsn/raftjs";
|
|
49
49
|
import { ConnManager } from "@robotical/roboticaljs";
|
|
50
50
|
import ConnectorFactory from "./connectors/ConnectorFactory";
|
|
51
51
|
import ColourSensorManualCalibratorMarty from "./utils/ColourSensorManualCalibratorMarty";
|
|
@@ -56,6 +56,10 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
56
56
|
function WrapperAppManager() {
|
|
57
57
|
// Connectors
|
|
58
58
|
this.connectors = {};
|
|
59
|
+
this._connectPromise = null;
|
|
60
|
+
this._disconnectOperations = {};
|
|
61
|
+
this._pendingConnManagers = new Set();
|
|
62
|
+
this._pageUnloadStarted = false;
|
|
59
63
|
// Observers
|
|
60
64
|
this._observers = {};
|
|
61
65
|
}
|
|
@@ -74,35 +78,120 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
74
78
|
*
|
|
75
79
|
*/
|
|
76
80
|
WrapperAppManager.prototype.connect = function (method, uuids) {
|
|
81
|
+
var _this = this;
|
|
82
|
+
if (this._pageUnloadStarted) {
|
|
83
|
+
return Promise.resolve({ success: false, reason: "failed" });
|
|
84
|
+
}
|
|
85
|
+
if (this._connectPromise) {
|
|
86
|
+
return this._connectPromise;
|
|
87
|
+
}
|
|
88
|
+
if (Object.values(this._disconnectOperations).some(Boolean)) {
|
|
89
|
+
Logger.warn(SHOW_LOGS, TAG, "Refusing to start a connection while Bluetooth teardown is in progress");
|
|
90
|
+
return Promise.resolve({ success: false, reason: "failed" });
|
|
91
|
+
}
|
|
92
|
+
var connectPromise = this._connect(method, uuids);
|
|
93
|
+
this._connectPromise = connectPromise;
|
|
94
|
+
var clearConnectPromise = function () {
|
|
95
|
+
if (_this._connectPromise === connectPromise) {
|
|
96
|
+
_this._connectPromise = null;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
void connectPromise.then(clearConnectPromise, clearConnectPromise);
|
|
100
|
+
return connectPromise;
|
|
101
|
+
};
|
|
102
|
+
WrapperAppManager.prototype._connect = function (method, uuids) {
|
|
77
103
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var connector, connectionResults, raftSystemUtils, systemInfo, raftName;
|
|
104
|
+
var connector, pendingConnManager, committed, disconnectedBeforeCommit, ownedConnector_1, connectionResults, existingConnector, raftSystemUtils, systemInfo, raftName, error_1;
|
|
105
|
+
var _this = this;
|
|
79
106
|
return __generator(this, function (_a) {
|
|
80
107
|
switch (_a.label) {
|
|
81
|
-
case 0:
|
|
108
|
+
case 0:
|
|
109
|
+
connector = null;
|
|
110
|
+
pendingConnManager = null;
|
|
111
|
+
committed = false;
|
|
112
|
+
disconnectedBeforeCommit = false;
|
|
113
|
+
_a.label = 1;
|
|
82
114
|
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);
|
|
121
|
+
}
|
|
122
|
+
})];
|
|
123
|
+
case 2:
|
|
83
124
|
connector = _a.sent();
|
|
84
|
-
if (!connector) {
|
|
125
|
+
if (!connector || this._pageUnloadStarted) {
|
|
85
126
|
Logger.warn(SHOW_LOGS, TAG, "Failed to connect to RAFT with method: ".concat(method));
|
|
86
127
|
return [2 /*return*/, { success: false, reason: "failed" }];
|
|
87
128
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.connectors[connector.id] = connector;
|
|
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;
|
|
129
|
+
ownedConnector_1 = connector;
|
|
130
|
+
connector.setOnDisconnected(function () {
|
|
131
|
+
if (!committed) {
|
|
132
|
+
disconnectedBeforeCommit = true;
|
|
98
133
|
}
|
|
99
|
-
|
|
134
|
+
_this._handleDisconnectedEvent(ownedConnector_1);
|
|
135
|
+
});
|
|
136
|
+
if (disconnectedBeforeCommit || !connector.connManager.isConnected()) {
|
|
137
|
+
return [2 /*return*/, { success: false, reason: "failed" }];
|
|
100
138
|
}
|
|
101
|
-
|
|
139
|
+
return [4 /*yield*/, connector.connect()];
|
|
140
|
+
case 3:
|
|
141
|
+
connectionResults = _a.sent();
|
|
142
|
+
if (!connectionResults.success) {
|
|
102
143
|
Logger.warn(SHOW_LOGS, TAG, "Failed to connect to RAFT with id: ".concat(connector.id, " and type: ").concat(connector.type));
|
|
144
|
+
return [2 /*return*/, connectionResults];
|
|
145
|
+
}
|
|
146
|
+
if (this._pageUnloadStarted ||
|
|
147
|
+
disconnectedBeforeCommit ||
|
|
148
|
+
!connector.connManager.isConnected()) {
|
|
149
|
+
Logger.warn(SHOW_LOGS, TAG, "RAFT disconnected before setup completed: ".concat(connector.id));
|
|
150
|
+
return [2 /*return*/, { success: false, reason: "failed" }];
|
|
151
|
+
}
|
|
152
|
+
existingConnector = this.connectors[connector.id];
|
|
153
|
+
if (existingConnector && existingConnector !== connector) {
|
|
154
|
+
Logger.warn(SHOW_LOGS, TAG, "Refusing to replace active RAFT connector with id: ".concat(connector.id));
|
|
155
|
+
return [2 /*return*/, { success: false, reason: "failed" }];
|
|
156
|
+
}
|
|
157
|
+
raftSystemUtils = connector.connManager.getConnector().getRaftSystemUtils();
|
|
158
|
+
systemInfo = raftSystemUtils.getCachedSystemInfo() || undefined;
|
|
159
|
+
raftName = raftSystemUtils.getCachedRaftName() || raftSystemUtils.getFriendlyName();
|
|
160
|
+
if (systemInfo && (raftName === null || raftName === void 0 ? void 0 : raftName.friendlyName)) {
|
|
161
|
+
systemInfo.Friendly = raftName.friendlyName;
|
|
103
162
|
}
|
|
163
|
+
if (this._pageUnloadStarted ||
|
|
164
|
+
disconnectedBeforeCommit ||
|
|
165
|
+
!connector.connManager.isConnected()) {
|
|
166
|
+
return [2 /*return*/, { success: false, reason: "failed" }];
|
|
167
|
+
}
|
|
168
|
+
connectionResults.data = { raftId: connector.id, raftType: connector.type, systemInfo: systemInfo };
|
|
169
|
+
this.connectors[connector.id] = connector;
|
|
170
|
+
committed = true;
|
|
104
171
|
Logger.info(SHOW_LOGS, TAG, "Connected to RAFT with id: ".concat(connector.id, " and type: ").concat(connector.type));
|
|
105
172
|
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]);
|
|
179
|
+
return [4 /*yield*/, connector.disconnect()];
|
|
180
|
+
case 6:
|
|
181
|
+
_a.sent();
|
|
182
|
+
return [3 /*break*/, 8];
|
|
183
|
+
case 7:
|
|
184
|
+
error_1 = _a.sent();
|
|
185
|
+
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:
|
|
189
|
+
if (pendingConnManager) {
|
|
190
|
+
this._pendingConnManagers.delete(pendingConnManager);
|
|
191
|
+
}
|
|
192
|
+
return [7 /*endfinally*/];
|
|
193
|
+
case 10: return [7 /*endfinally*/];
|
|
194
|
+
case 11: return [2 /*return*/];
|
|
106
195
|
}
|
|
107
196
|
});
|
|
108
197
|
});
|
|
@@ -273,17 +362,75 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
273
362
|
* Stop verifying RAFT
|
|
274
363
|
*/
|
|
275
364
|
WrapperAppManager.prototype.stopVerifyingRaft = function (isCorrectRIC, raftId) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
return this.connectors[raftId].stopVerifyingRaft(isCorrectRIC);
|
|
365
|
+
var _a, _b;
|
|
366
|
+
return (_b = (_a = this.connectors[raftId]) === null || _a === void 0 ? void 0 : _a.stopVerifyingRaft(isCorrectRIC)) !== null && _b !== void 0 ? _b : Promise.resolve(false);
|
|
280
367
|
};
|
|
281
368
|
/**
|
|
282
369
|
* Disconnect from a RAFT
|
|
283
370
|
*/
|
|
284
371
|
WrapperAppManager.prototype.disconnect = function (raftId) {
|
|
285
|
-
this
|
|
286
|
-
|
|
372
|
+
var _this = this;
|
|
373
|
+
var connector = this.connectors[raftId];
|
|
374
|
+
if (!connector) {
|
|
375
|
+
return Promise.resolve(true);
|
|
376
|
+
}
|
|
377
|
+
var inFlightDisconnect = this._disconnectOperations[raftId];
|
|
378
|
+
if ((inFlightDisconnect === null || inFlightDisconnect === void 0 ? void 0 : inFlightDisconnect.connector) === connector) {
|
|
379
|
+
return inFlightDisconnect.promise;
|
|
380
|
+
}
|
|
381
|
+
var operation = Promise.resolve().then(function () { return connector.disconnect(); });
|
|
382
|
+
var disconnectPromise;
|
|
383
|
+
disconnectPromise = operation.finally(function () {
|
|
384
|
+
_this._removeConnectorIfCurrent(connector);
|
|
385
|
+
var trackedOperation = _this._disconnectOperations[raftId];
|
|
386
|
+
if ((trackedOperation === null || trackedOperation === void 0 ? void 0 : trackedOperation.connector) === connector &&
|
|
387
|
+
trackedOperation.promise === disconnectPromise) {
|
|
388
|
+
delete _this._disconnectOperations[raftId];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
// Register ownership before connector code runs. A connector may emit a
|
|
392
|
+
// terminal event synchronously while disconnect() is being invoked.
|
|
393
|
+
this._disconnectOperations[raftId] = { connector: connector, promise: disconnectPromise };
|
|
394
|
+
return disconnectPromise;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Best-effort terminal cleanup. Page lifecycle events cannot reliably await
|
|
398
|
+
* async Bluetooth work, so each connector forwards to RaftJS synchronously.
|
|
399
|
+
*/
|
|
400
|
+
WrapperAppManager.prototype.disconnectAllForPageUnload = function () {
|
|
401
|
+
this._pageUnloadStarted = true;
|
|
402
|
+
var pendingConnManagers = Array.from(this._pendingConnManagers);
|
|
403
|
+
for (var _i = 0, pendingConnManagers_1 = pendingConnManagers; _i < pendingConnManagers_1.length; _i++) {
|
|
404
|
+
var connManager = pendingConnManagers_1[_i];
|
|
405
|
+
this._disconnectConnManagerForPageUnload(connManager);
|
|
406
|
+
}
|
|
407
|
+
var connectors = Object.values(this.connectors);
|
|
408
|
+
for (var _a = 0, connectors_1 = connectors; _a < connectors_1.length; _a++) {
|
|
409
|
+
var connector = connectors_1[_a];
|
|
410
|
+
try {
|
|
411
|
+
connector.disconnectForPageUnload();
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
Logger.warn(SHOW_LOGS, TAG, "Failed page-unload cleanup for connector ".concat(connector.id, ": ").concat(error));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
WrapperAppManager.prototype._disconnectConnManagerForPageUnload = function (connManager) {
|
|
419
|
+
var connManagerWithPageUnload = connManager;
|
|
420
|
+
try {
|
|
421
|
+
if (typeof connManagerWithPageUnload.disconnectForPageUnload === "function") {
|
|
422
|
+
connManagerWithPageUnload.disconnectForPageUnload();
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
connManager.getConnector().disconnectForPageUnload();
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
Logger.warn(SHOW_LOGS, TAG, "Failed pending page-unload cleanup: ".concat(error));
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
WrapperAppManager.prototype.isConnected = function (raftId) {
|
|
432
|
+
var _a, _b;
|
|
433
|
+
return (_b = (_a = this.connectors[raftId]) === null || _a === void 0 ? void 0 : _a.connManager.isConnected()) !== null && _b !== void 0 ? _b : false;
|
|
287
434
|
};
|
|
288
435
|
/**
|
|
289
436
|
* Audio streaming
|
|
@@ -314,16 +461,18 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
314
461
|
});
|
|
315
462
|
});
|
|
316
463
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
var
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
464
|
+
WrapperAppManager.prototype._removeConnectorIfCurrent = function (connector) {
|
|
465
|
+
if (this.connectors[connector.id] === connector) {
|
|
466
|
+
delete this.connectors[connector.id];
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
WrapperAppManager.prototype._handleDisconnectedEvent = function (connector) {
|
|
470
|
+
var _a;
|
|
471
|
+
// A requested disconnect keeps ownership until its Promise settles. An
|
|
472
|
+
// unsolicited terminal event has no such Promise, so release immediately.
|
|
473
|
+
if (((_a = this._disconnectOperations[connector.id]) === null || _a === void 0 ? void 0 : _a.connector) !== connector) {
|
|
474
|
+
this._removeConnectorIfCurrent(connector);
|
|
475
|
+
}
|
|
327
476
|
};
|
|
328
477
|
/**
|
|
329
478
|
* Warranty Service bluetooth scan for device
|
|
@@ -334,17 +483,19 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
334
483
|
*/
|
|
335
484
|
WrapperAppManager.prototype.scanForPotentialWarrantyDevice = function (existingDevices) {
|
|
336
485
|
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
-
var namesToIgnore,
|
|
486
|
+
var namesToIgnore, warrantyConnManager, ownsTemporaryConnection, device_1, isConnected, connector, ricSystem, systemInfo, serialNumber, raftType, newDevice, error_2, error_3;
|
|
338
487
|
return __generator(this, function (_a) {
|
|
339
488
|
switch (_a.label) {
|
|
340
489
|
case 0:
|
|
341
490
|
namesToIgnore = __spreadArray([], existingDevices.map(function (item) {
|
|
342
491
|
return { name: item.name || "" };
|
|
343
492
|
}), true).filter(function (item) { return item.name; });
|
|
493
|
+
warrantyConnManager = new ConnManager();
|
|
494
|
+
ownsTemporaryConnection = false;
|
|
344
495
|
_a.label = 1;
|
|
345
496
|
case 1:
|
|
346
|
-
_a.trys.push([1,
|
|
347
|
-
return [4 /*yield*/,
|
|
497
|
+
_a.trys.push([1, 7, 8, 14]);
|
|
498
|
+
return [4 /*yield*/, warrantyConnManager.getBleDevicesWithGivenNamesToIgnore(namesToIgnore)];
|
|
348
499
|
case 2:
|
|
349
500
|
device_1 = _a.sent();
|
|
350
501
|
if (!device_1) {
|
|
@@ -353,40 +504,59 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
353
504
|
}
|
|
354
505
|
if (!!existingDevices.find(function (deviceInList) {
|
|
355
506
|
return deviceInList.id === device_1.id;
|
|
356
|
-
})) return [3 /*break*/,
|
|
357
|
-
|
|
358
|
-
|
|
507
|
+
})) return [3 /*break*/, 5];
|
|
508
|
+
if (this._pageUnloadStarted) {
|
|
509
|
+
return [2 /*return*/, existingDevices];
|
|
510
|
+
}
|
|
511
|
+
// The selected device remains outside the lease registry until
|
|
512
|
+
// this connection attempt. ConnManager then atomically rejects an
|
|
513
|
+
// ID already owned by the app instead of stealing its GATT server.
|
|
514
|
+
this._pendingConnManagers.add(warrantyConnManager);
|
|
515
|
+
ownsTemporaryConnection = true;
|
|
516
|
+
return [4 /*yield*/, warrantyConnManager.connect("WebBLE", device_1, [ConnManager.RICUUID, ConnManager.COGUUID])];
|
|
359
517
|
case 3:
|
|
360
|
-
_a.sent();
|
|
361
|
-
return [4 /*yield*/, connector.connect(device_1)];
|
|
362
|
-
case 4:
|
|
363
518
|
isConnected = _a.sent();
|
|
364
519
|
if (!isConnected) {
|
|
365
520
|
Logger.warn(SHOW_LOGS, TAG, "Failed to connect to device: ".concat(device_1.name));
|
|
366
521
|
return [2 /*return*/, existingDevices];
|
|
367
522
|
}
|
|
523
|
+
connector = warrantyConnManager.getConnector();
|
|
368
524
|
ricSystem = connector.getRaftSystemUtils();
|
|
369
525
|
return [4 /*yield*/, ricSystem.getSystemInfo()];
|
|
370
|
-
case
|
|
526
|
+
case 4:
|
|
371
527
|
systemInfo = _a.sent();
|
|
372
528
|
serialNumber = systemInfo.SerialNo || "";
|
|
373
529
|
raftType = systemInfo.SystemName;
|
|
374
|
-
return [4 /*yield*/, connector.disconnect()];
|
|
375
|
-
case 6:
|
|
376
|
-
_a.sent();
|
|
377
530
|
newDevice = { id: device_1.id, name: device_1.name || "", serialNumber: serialNumber, type: raftType };
|
|
378
531
|
existingDevices.push(newDevice);
|
|
379
532
|
Logger.info(SHOW_LOGS, TAG, "".concat(device_1.name, " added to the list of robots."));
|
|
380
533
|
return [2 /*return*/, existingDevices];
|
|
381
|
-
case
|
|
534
|
+
case 5:
|
|
382
535
|
Logger.warn(SHOW_LOGS, TAG, "".concat(device_1.name, " is already in the list of robots."));
|
|
383
|
-
_a.label =
|
|
384
|
-
case
|
|
385
|
-
case
|
|
386
|
-
|
|
387
|
-
Logger.error(SHOW_LOGS, TAG, JSON.stringify(
|
|
536
|
+
_a.label = 6;
|
|
537
|
+
case 6: return [3 /*break*/, 14];
|
|
538
|
+
case 7:
|
|
539
|
+
error_2 = _a.sent();
|
|
540
|
+
Logger.error(SHOW_LOGS, TAG, JSON.stringify(error_2));
|
|
388
541
|
return [2 /*return*/, existingDevices];
|
|
389
|
-
case
|
|
542
|
+
case 8:
|
|
543
|
+
if (!ownsTemporaryConnection) return [3 /*break*/, 13];
|
|
544
|
+
_a.label = 9;
|
|
545
|
+
case 9:
|
|
546
|
+
_a.trys.push([9, 11, 12, 13]);
|
|
547
|
+
return [4 /*yield*/, warrantyConnManager.disconnect()];
|
|
548
|
+
case 10:
|
|
549
|
+
_a.sent();
|
|
550
|
+
return [3 /*break*/, 13];
|
|
551
|
+
case 11:
|
|
552
|
+
error_3 = _a.sent();
|
|
553
|
+
Logger.warn(SHOW_LOGS, TAG, "Failed warranty connection cleanup: ".concat(error_3));
|
|
554
|
+
return [3 /*break*/, 13];
|
|
555
|
+
case 12:
|
|
556
|
+
this._pendingConnManagers.delete(warrantyConnManager);
|
|
557
|
+
return [7 /*endfinally*/];
|
|
558
|
+
case 13: return [7 /*endfinally*/];
|
|
559
|
+
case 14: return [2 /*return*/, existingDevices];
|
|
390
560
|
}
|
|
391
561
|
});
|
|
392
562
|
});
|
|
@@ -396,7 +566,7 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
396
566
|
*/
|
|
397
567
|
WrapperAppManager.prototype.sendAtomicReadOperationToMarty = function (raftId) {
|
|
398
568
|
return __awaiter(this, void 0, void 0, function () {
|
|
399
|
-
var raftConnector, systemType,
|
|
569
|
+
var raftConnector, systemType, error_4;
|
|
400
570
|
return __generator(this, function (_a) {
|
|
401
571
|
switch (_a.label) {
|
|
402
572
|
case 0:
|
|
@@ -412,8 +582,8 @@ var WrapperAppManager = /** @class */ (function () {
|
|
|
412
582
|
_a.sent();
|
|
413
583
|
return [2 /*return*/, true];
|
|
414
584
|
case 3:
|
|
415
|
-
|
|
416
|
-
Logger.error(SHOW_LOGS, TAG, "Failed to send atomic read operation to Marty: ".concat(
|
|
585
|
+
error_4 = _a.sent();
|
|
586
|
+
Logger.error(SHOW_LOGS, TAG, "Failed to send atomic read operation to Marty: ".concat(error_4));
|
|
417
587
|
return [3 /*break*/, 4];
|
|
418
588
|
case 4: return [3 /*break*/, 6];
|
|
419
589
|
case 5:
|
|
@@ -116,7 +116,7 @@ var WebAppCommunicator = /** @class */ (function () {
|
|
|
116
116
|
}());
|
|
117
117
|
export default WebAppCommunicator;
|
|
118
118
|
var receivedMessageHandler = function (receivedMessage, data, messagePromiseId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
119
|
-
var _a, connectionResults, error_1, ricName, error_2, verifyResults, error_3, confirmVerifiedResults, error_4, stopVerifyResults, error_5, disconnectResults, error_6, restResults, error_7, missedConnEventResults, streamAudioResults, commsStats, calibrateColourSensorResults, error_8, resetColourSensorResults, error_9, deviceInfoResults, wasSaved, wasSaved, fileContents, existingDevices, devices, error_10, wasSent, error_11;
|
|
119
|
+
var _a, isConnected, connectionResults, error_1, ricName, error_2, verifyResults, error_3, confirmVerifiedResults, error_4, stopVerifyResults, error_5, disconnectResults, error_6, restResults, error_7, missedConnEventResults, streamAudioResults, commsStats, calibrateColourSensorResults, error_8, resetColourSensorResults, error_9, deviceInfoResults, wasSaved, wasSaved, fileContents, existingDevices, devices, error_10, wasSent, error_11;
|
|
120
120
|
return __generator(this, function (_b) {
|
|
121
121
|
switch (_b.label) {
|
|
122
122
|
case 0:
|
|
@@ -146,11 +146,8 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
|
|
|
146
146
|
return [3 /*break*/, 54];
|
|
147
147
|
case 1:
|
|
148
148
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
console.log("12");
|
|
152
|
-
// console.log("raft is connected results", connectionResults);
|
|
153
|
-
window.wrapperCommunicator.onMessageResponse({ success: true, error: "", results: { log: "13" }, messagePromiseId: messagePromiseId });
|
|
149
|
+
isConnected = wrapperAppManager.isConnected(data.raftId);
|
|
150
|
+
window.wrapperCommunicator.onMessageResponse({ success: true, error: "", results: isConnected, messagePromiseId: messagePromiseId });
|
|
154
151
|
}
|
|
155
152
|
catch (error) {
|
|
156
153
|
window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
|
|
@@ -2,7 +2,7 @@ import { RaftInfoEvents } from "../../../types/events/raft-info";
|
|
|
2
2
|
import { ConnectionAttemptResults, RaftTypeE } from "../../../types/raft";
|
|
3
3
|
import Connector from "../Connector";
|
|
4
4
|
import ConnectorInterface from "../ConnectorInterface";
|
|
5
|
-
import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@
|
|
5
|
+
import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robdobsn/raftjs";
|
|
6
6
|
import { ConnManager } from "@robotical/roboticaljs";
|
|
7
7
|
declare class CogConnector extends Connector implements ConnectorInterface {
|
|
8
8
|
type: RaftTypeE;
|
|
@@ -53,7 +53,7 @@ import { RaftInfoEvents } from "../../../types/events/raft-info";
|
|
|
53
53
|
import Logger from "../../../services/logger/Logger";
|
|
54
54
|
import { RaftTypeE } from "../../../types/raft";
|
|
55
55
|
import Connector from "../Connector";
|
|
56
|
-
import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@
|
|
56
|
+
import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robdobsn/raftjs";
|
|
57
57
|
import { CogPublishedDataGetter } from "@robotical/roboticaljs";
|
|
58
58
|
import { WrapperSentMessage } from "../../../types/communication-between-apps/wrapper-communication";
|
|
59
59
|
var SHOW_LOGS = true;
|
|
@@ -4,13 +4,14 @@ import { ConnectionAttemptResults, RaftTypeE } from "../../types/raft";
|
|
|
4
4
|
import { RaftObserver } from "../../application/RAFTs/RaftObserver";
|
|
5
5
|
import ConnectorInterface from "./ConnectorInterface";
|
|
6
6
|
import { ConnManager, RICLedLcdColours } from "@robotical/roboticaljs";
|
|
7
|
-
import { RaftOKFail, RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@
|
|
7
|
+
import { RaftOKFail, RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@robdobsn/raftjs";
|
|
8
8
|
declare class Connector implements ConnectorInterface {
|
|
9
9
|
id: string;
|
|
10
10
|
type: RaftTypeE;
|
|
11
11
|
protected _observers: {
|
|
12
12
|
[key: string]: Array<RaftObserver>;
|
|
13
13
|
};
|
|
14
|
+
private _onDisconnected?;
|
|
14
15
|
connManager: ConnManager;
|
|
15
16
|
constructor(id: string, connManager: ConnManager);
|
|
16
17
|
/**
|
|
@@ -20,7 +21,7 @@ declare class Connector implements ConnectorInterface {
|
|
|
20
21
|
/**
|
|
21
22
|
* Get connected raft info
|
|
22
23
|
*/
|
|
23
|
-
getSystemInfo(): Promise<import("@
|
|
24
|
+
getSystemInfo(): Promise<import("@robdobsn/raftjs").RaftSystemInfo>;
|
|
24
25
|
/**
|
|
25
26
|
* Gets the RAFT name
|
|
26
27
|
*/
|
|
@@ -37,6 +38,17 @@ declare class Connector implements ConnectorInterface {
|
|
|
37
38
|
* Disconnect from a RAFT
|
|
38
39
|
*/
|
|
39
40
|
disconnect(): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Register the manager-owned cleanup callback for a terminal disconnect event.
|
|
43
|
+
*/
|
|
44
|
+
setOnDisconnected(onDisconnected: () => void): void;
|
|
45
|
+
/**
|
|
46
|
+
* Best-effort synchronous cleanup for page navigation/unload. Prefer the
|
|
47
|
+
* ConnManager boundary so its connection generation and Web BLE lease are
|
|
48
|
+
* finalized as well. The fallback keeps this app compatible with an older
|
|
49
|
+
* RoboticalJS package while the new ConnManager API is being released.
|
|
50
|
+
*/
|
|
51
|
+
disconnectForPageUnload(): void;
|
|
40
52
|
/**
|
|
41
53
|
* Stop verifying RAFT
|
|
42
54
|
* @param confirmCorrectRIC - indicates if the correct RAFT was selected (user input)
|
|
@@ -38,7 +38,7 @@ import { RaftInfoEvents } from "../../types/events/raft-info";
|
|
|
38
38
|
import { WrapperSentMessage } from "../../types/communication-between-apps/wrapper-communication";
|
|
39
39
|
import Logger from "../../services/logger/Logger";
|
|
40
40
|
import { RaftTypeE } from "../../types/raft";
|
|
41
|
-
import { RaftConnEvent, RaftUpdateEvent, RICRESTElemCode, } from "@
|
|
41
|
+
import { RaftConnEvent, RaftUpdateEvent, RICRESTElemCode, } from "@robdobsn/raftjs";
|
|
42
42
|
var SHOW_LOGS = true;
|
|
43
43
|
var TAG = "Connector";
|
|
44
44
|
var formatRestCommand = function (msg, params) {
|
|
@@ -64,6 +64,7 @@ var Connector = /** @class */ (function () {
|
|
|
64
64
|
// Set the listener function
|
|
65
65
|
// Subscribe to connManager events
|
|
66
66
|
this.connManager.setConnectionEventListener(function (eventType, eventEnum, eventName, eventData) {
|
|
67
|
+
var _a;
|
|
67
68
|
if (eventType === "pub") {
|
|
68
69
|
// if it's a pub event, we are publishing it from _pubEventHandler method (in child classes)
|
|
69
70
|
}
|
|
@@ -72,6 +73,9 @@ var Connector = /** @class */ (function () {
|
|
|
72
73
|
_this.publish(eventType, eventEnum, eventName, eventData);
|
|
73
74
|
}
|
|
74
75
|
_this.eventHandler(eventType, eventEnum, eventName, eventData);
|
|
76
|
+
if (eventType === "conn" && eventEnum === RaftConnEvent.CONN_DISCONNECTED) {
|
|
77
|
+
(_a = _this._onDisconnected) === null || _a === void 0 ? void 0 : _a.call(_this);
|
|
78
|
+
}
|
|
75
79
|
});
|
|
76
80
|
}
|
|
77
81
|
/**
|
|
@@ -158,6 +162,26 @@ var Connector = /** @class */ (function () {
|
|
|
158
162
|
});
|
|
159
163
|
});
|
|
160
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* Register the manager-owned cleanup callback for a terminal disconnect event.
|
|
167
|
+
*/
|
|
168
|
+
Connector.prototype.setOnDisconnected = function (onDisconnected) {
|
|
169
|
+
this._onDisconnected = onDisconnected;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Best-effort synchronous cleanup for page navigation/unload. Prefer the
|
|
173
|
+
* ConnManager boundary so its connection generation and Web BLE lease are
|
|
174
|
+
* finalized as well. The fallback keeps this app compatible with an older
|
|
175
|
+
* RoboticalJS package while the new ConnManager API is being released.
|
|
176
|
+
*/
|
|
177
|
+
Connector.prototype.disconnectForPageUnload = function () {
|
|
178
|
+
var connManagerWithPageUnload = this.connManager;
|
|
179
|
+
if (typeof connManagerWithPageUnload.disconnectForPageUnload === "function") {
|
|
180
|
+
connManagerWithPageUnload.disconnectForPageUnload();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.connManager.getConnector().disconnectForPageUnload();
|
|
184
|
+
};
|
|
161
185
|
/**
|
|
162
186
|
* Stop verifying RAFT
|
|
163
187
|
* @param confirmCorrectRIC - indicates if the correct RAFT was selected (user input)
|
|
@@ -10,6 +10,6 @@ export default class ConnectorFactory {
|
|
|
10
10
|
* @returns Promise<ConnectionAttemptResults>
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
|
-
static connectToRaftHelper(method: RaftConnectionMethod, uuids: string[]): Promise<Connector | null>;
|
|
13
|
+
static connectToRaftHelper(method: RaftConnectionMethod, uuids: string[], onConnManagerCreated?: (connManager: ConnManager) => void): Promise<Connector | null>;
|
|
14
14
|
static createConnector(raftType: string | undefined, connManager: ConnManager): Connector;
|
|
15
15
|
}
|
|
@@ -52,25 +52,56 @@ var ConnectorFactory = /** @class */ (function () {
|
|
|
52
52
|
* @returns Promise<ConnectionAttemptResults>
|
|
53
53
|
*
|
|
54
54
|
*/
|
|
55
|
-
ConnectorFactory.connectToRaftHelper = function (method, uuids) {
|
|
55
|
+
ConnectorFactory.connectToRaftHelper = function (method, uuids, onConnManagerCreated) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
-
var connManager,
|
|
57
|
+
var connManager, connectorWasCreated, lowLevelConnectionSucceeded, connectionResult, systemInfo, raftType, connector, error_1;
|
|
58
58
|
return __generator(this, function (_a) {
|
|
59
59
|
switch (_a.label) {
|
|
60
60
|
case 0:
|
|
61
61
|
connManager = new ConnManager();
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
connectorWasCreated = false;
|
|
63
|
+
lowLevelConnectionSucceeded = false;
|
|
64
|
+
_a.label = 1;
|
|
64
65
|
case 1:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
_a.trys.push([1, , 3, 8]);
|
|
67
|
+
onConnManagerCreated === null || onConnManagerCreated === void 0 ? void 0 : onConnManagerCreated(connManager);
|
|
68
|
+
Logger.info(SHOW_LOGS, TAG, "Connecting to RAFT with method: ".concat(method));
|
|
69
|
+
return [4 /*yield*/, connManager.connectDetailed(method, "", uuids)];
|
|
70
|
+
case 2:
|
|
71
|
+
connectionResult = _a.sent();
|
|
72
|
+
lowLevelConnectionSucceeded = connectionResult.status === "success";
|
|
73
|
+
Logger.info(SHOW_LOGS, TAG, "Connection result: ".concat(connectionResult.status));
|
|
74
|
+
if (!lowLevelConnectionSucceeded) {
|
|
68
75
|
return [2 /*return*/, null];
|
|
69
76
|
}
|
|
70
77
|
systemInfo = connManager.getConnector().getRaftSystemUtils().getCachedSystemInfo();
|
|
71
78
|
raftType = systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.SystemName;
|
|
72
79
|
connector = this.createConnector(raftType, connManager);
|
|
80
|
+
connectorWasCreated = true;
|
|
73
81
|
return [2 /*return*/, connector];
|
|
82
|
+
case 3:
|
|
83
|
+
if (!!connectorWasCreated) return [3 /*break*/, 7];
|
|
84
|
+
if (!!lowLevelConnectionSucceeded) return [3 /*break*/, 4];
|
|
85
|
+
// Before connectDetailed reports success there is no established
|
|
86
|
+
// RAFT session to notify. Use immediate transport teardown for
|
|
87
|
+
// chooser cancellation, generic failure, and thrown cancellation.
|
|
88
|
+
// The graceful path sends `bledisconnect` retries and can otherwise
|
|
89
|
+
// keep the UI pending for several seconds for a connection that
|
|
90
|
+
// never existed.
|
|
91
|
+
connManager.disconnectForPageUnload();
|
|
92
|
+
return [3 /*break*/, 7];
|
|
93
|
+
case 4:
|
|
94
|
+
_a.trys.push([4, 6, , 7]);
|
|
95
|
+
return [4 /*yield*/, connManager.disconnect()];
|
|
96
|
+
case 5:
|
|
97
|
+
_a.sent();
|
|
98
|
+
return [3 /*break*/, 7];
|
|
99
|
+
case 6:
|
|
100
|
+
error_1 = _a.sent();
|
|
101
|
+
Logger.warn(SHOW_LOGS, TAG, "Failed to clean up uncommitted RAFT connection: ".concat(error_1));
|
|
102
|
+
return [3 /*break*/, 7];
|
|
103
|
+
case 7: return [7 /*endfinally*/];
|
|
104
|
+
case 8: return [2 /*return*/];
|
|
74
105
|
}
|
|
75
106
|
});
|
|
76
107
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@
|
|
1
|
+
import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robdobsn/raftjs";
|
|
2
2
|
import { ConnectionAttemptResults, RaftTypeE } from "../../types/raft";
|
|
3
3
|
import { RaftInfoEvents } from "../../types/events/raft-info";
|
|
4
4
|
import { RICLedLcdColours } from "@robotical/roboticaljs";
|
|
@@ -2,7 +2,7 @@ import { RaftInfoEvents } from "../../../types/events/raft-info";
|
|
|
2
2
|
import { ConnectionAttemptResults, RaftTypeE } from "../../../types/raft";
|
|
3
3
|
import Connector from "../Connector";
|
|
4
4
|
import ConnectorInterface from "../ConnectorInterface";
|
|
5
|
-
import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@
|
|
5
|
+
import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@robdobsn/raftjs";
|
|
6
6
|
import { ConnManager } from "@robotical/roboticaljs";
|
|
7
7
|
declare class MartyConnector extends Connector implements ConnectorInterface {
|
|
8
8
|
type: RaftTypeE;
|