@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.
Files changed (42) hide show
  1. package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +18 -10
  2. package/dist-types/src/application/ApplicationManager/ApplicationManager.js +177 -79
  3. package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +1 -1
  4. package/dist-types/src/application/RAFTs/Cog/Cog.js +1 -1
  5. package/dist-types/src/application/RAFTs/Marty/CalibrationManager.d.ts +1 -1
  6. package/dist-types/src/application/RAFTs/Marty/CalibrationManager.js +1 -1
  7. package/dist-types/src/application/RAFTs/Marty/Marty.d.ts +1 -1
  8. package/dist-types/src/application/RAFTs/Marty/Marty.js +1 -1
  9. package/dist-types/src/application/RAFTs/Marty/MartyWifiManager.d.ts +1 -1
  10. package/dist-types/src/application/RAFTs/Marty/MartyWifiManager.js +1 -1
  11. package/dist-types/src/application/RAFTs/Marty/notifications-manager/ReportedWarningsState.js +1 -1
  12. package/dist-types/src/application/RAFTs/RAFT.d.ts +1 -1
  13. package/dist-types/src/application/RAFTs/RAFT.js +2 -2
  14. package/dist-types/src/application/RAFTs/RAFTInterface.d.ts +1 -1
  15. package/dist-types/src/application/RAFTs/RaftObserver.d.ts +1 -1
  16. package/dist-types/src/application/RAFTs/raft-subscription-helpers.js +1 -1
  17. package/dist-types/src/components/disposables/SwitchableCameraScanner/index.d.ts +4 -0
  18. package/dist-types/src/components/disposables/SwitchableCameraScanner/index.js +47 -0
  19. package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.d.ts +4 -2
  20. package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.js +14 -7
  21. package/dist-types/src/components/modals/LEDLightsOrQRVerificationModal/index.js +4 -4
  22. package/dist-types/src/components/modals/VerificationModal/index.js +0 -8
  23. package/dist-types/src/components/modals/VerificationModalPhoneApp/index.js +17 -32
  24. package/dist-types/src/components/oneoffs/LEDs/index.js +1 -1
  25. package/dist-types/src/i18n.js +2 -0
  26. package/dist-types/src/types/raft.d.ts +1 -1
  27. package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.d.ts +1 -1
  28. package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.js +1 -1
  29. package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +16 -7
  30. package/dist-types/src/wrapper-app/WrapperAppManager.js +225 -55
  31. package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +3 -6
  32. package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.d.ts +1 -1
  33. package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.js +1 -1
  34. package/dist-types/src/wrapper-app/connectors/Connector.d.ts +14 -2
  35. package/dist-types/src/wrapper-app/connectors/Connector.js +25 -1
  36. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.d.ts +1 -1
  37. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.js +38 -7
  38. package/dist-types/src/wrapper-app/connectors/ConnectorInterface.d.ts +1 -1
  39. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.d.ts +1 -1
  40. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +9 -5
  41. package/dist-types/src/wrapper-app/utils/ColourSensorManualCalibratorMarty.d.ts +1 -1
  42. package/package.json +10 -1
@@ -7,7 +7,7 @@ import { FOUND_RAFT_ON_DISCOVERY_RESPONSE } from "../../types/phone-app-communic
7
7
  import { ColourSensorCalibrationStage } from "../../types/colour-sensor-calibration";
8
8
  import { RaftObserver } from "../RAFTs/RaftObserver";
9
9
  import { RaftInfoEvents } from "../../types/events/raft-info";
10
- import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, RaftWifiScanResults, RaftWifiConnStatus, RaftOKFail } from "@robotical/raftjs";
10
+ import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, RaftWifiScanResults, RaftWifiConnStatus, RaftOKFail } from "@robdobsn/raftjs";
11
11
  import { ConnectedRaftItem } from "../../store/SelectedRaftContext";
12
12
  import Toaster from "../../utils/Toaster";
13
13
  import AnalyticsFacade from "@robotical/appv2-analytics-gatherer";
@@ -23,6 +23,10 @@ export default class ApplicationManager {
23
23
  connectedRafts: {
24
24
  [key: string]: RAFT;
25
25
  };
26
+ private _connectPromise;
27
+ private _connectAttemptSequence;
28
+ private _activeConnectAttemptId;
29
+ private _disconnectPromises;
26
30
  connectedRaftsContext: ConnectedRaftItem[];
27
31
  returnToMainApp: () => void;
28
32
  carouselNavigatorManager: CarouselNavigatorManager;
@@ -54,6 +58,7 @@ export default class ApplicationManager {
54
58
  getDeviceInfo(): Promise<void>;
55
59
  updateRaftNameInAllStates(raftId: string, name: string): Promise<boolean>;
56
60
  private getConnectedRaftName;
61
+ private isRaftActive;
57
62
  private addConnectedRaftToContext;
58
63
  private publishLocalVerifiedConnection;
59
64
  private confirmQrVerifiedConnection;
@@ -89,6 +94,11 @@ export default class ApplicationManager {
89
94
  * Known issue: connecting to a raft from within a platform won't add the newly connected raft to the connectedRafts hook
90
95
  */
91
96
  connectGeneric(afterRaftConnectedCb: (raft: RAFT) => void, uuids?: string[], shouldShowQrModal?: boolean): Promise<void>;
97
+ private _clearConnectPromise;
98
+ private _dismissConnectAttempt;
99
+ private _isConnectAttemptActive;
100
+ private _createConnectingModal;
101
+ private _connectGeneric;
92
102
  /**
93
103
  * Disconnect from RAFT generic
94
104
  * This method is called from various environments (connection button, blocksjr, blocks etc.)
@@ -116,15 +126,13 @@ export default class ApplicationManager {
116
126
  */
117
127
  disconnectFromRaft(raftId: string): Promise<void>;
118
128
  /**
119
- * Removes raft from the connectedRafts list after a timeout without disconnecting as at this point
120
- * the device should already be disconnected
129
+ * Finalizes a RAFT which has already emitted its terminal disconnect event.
130
+ * Passing the source RAFT prevents a late event from deleting a replacement
131
+ * connection which happens to have the same serial/ID.
121
132
  */
122
- removeRaft(raftId: string): Promise<void>;
123
- /**
124
- * Removes raft after a certain time
125
- * Removes from the rics list after x seconds so that we can still get the last event
126
- */
127
- _removeRaft(raftId: string, timeout: number): void;
133
+ removeRaft(raftId: string, disconnectedRaft?: RAFT): Promise<void>;
134
+ private _disconnectRaft;
135
+ private _removeRaftIfCurrent;
128
136
  /**
129
137
  * Start looking for rics to connect to
130
138
  * This is used from the Phone App only
@@ -143,7 +151,7 @@ export default class ApplicationManager {
143
151
  /**
144
152
  * Stop verifying raft
145
153
  */
146
- stopVerifyingRaft(raftId: string, isCorrectRIC: boolean): Promise<void>;
154
+ stopVerifyingRaft(raftId: string, isCorrectRIC: boolean): Promise<boolean | undefined>;
147
155
  /**
148
156
  * Publishing events to observers
149
157
  * It could be either events we get from RAFT, or custom events related to the app
@@ -45,7 +45,7 @@ import VerificationModal from "../../components/modals/VerificationModal";
45
45
  import { raftFoundSubscriptionHelper } from "../RAFTs/raft-subscription-helpers";
46
46
  import { AppSentMessage } from "../../types/communication-between-apps/wrapper-communication";
47
47
  import VerificationModalPhoneApp from "../../components/modals/VerificationModalPhoneApp";
48
- import { RaftConnEvent, } from "@robotical/raftjs";
48
+ import { RaftConnEvent, } from "@robdobsn/raftjs";
49
49
  import Logger from "../../services/logger/Logger";
50
50
  import isPhoneApp from "../../utils/phone-app-communication/is-phone-app";
51
51
  import DisconnectConfirmationModal from "../../components/modals/DisconnectConfirmation";
@@ -90,6 +90,10 @@ var ApplicationManager = /** @class */ (function () {
90
90
  this._observers = {};
91
91
  // Connected RICs
92
92
  this.connectedRafts = {};
93
+ this._connectPromise = null;
94
+ this._connectAttemptSequence = 0;
95
+ this._activeConnectAttemptId = null;
96
+ this._disconnectPromises = new Map();
93
97
  this.connectedRaftsContext = [];
94
98
  this.returnToMainApp = function () { };
95
99
  // Carousel navigators
@@ -226,6 +230,9 @@ var ApplicationManager = /** @class */ (function () {
226
230
  });
227
231
  });
228
232
  };
233
+ ApplicationManager.prototype.isRaftActive = function (raft) {
234
+ return this.connectedRafts[raft.id] === raft && !this._disconnectPromises.has(raft);
235
+ };
229
236
  ApplicationManager.prototype.addConnectedRaftToContext = function (raft) {
230
237
  return __awaiter(this, void 0, void 0, function () {
231
238
  var name;
@@ -234,13 +241,16 @@ var ApplicationManager = /** @class */ (function () {
234
241
  case 0: return [4 /*yield*/, this.getConnectedRaftName(raft)];
235
242
  case 1:
236
243
  name = _a.sent();
244
+ if (!this.isRaftActive(raft)) {
245
+ return [2 /*return*/, false];
246
+ }
237
247
  this.connectedRaftContextMethods.addConnectedRaft({
238
248
  id: raft.id,
239
249
  type: raft.type,
240
250
  name: name,
241
251
  isSelected: true,
242
252
  });
243
- return [2 /*return*/];
253
+ return [2 /*return*/, true];
244
254
  }
245
255
  });
246
256
  });
@@ -489,18 +499,10 @@ var ApplicationManager = /** @class */ (function () {
489
499
  return new Marty(id);
490
500
  };
491
501
  ApplicationManager.prototype.connectGenericMarty = function (afterRaftConnectedCb) {
492
- return __awaiter(this, void 0, void 0, function () {
493
- return __generator(this, function (_a) {
494
- return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, [ConnManager.RICUUID], false)];
495
- });
496
- });
502
+ return this.connectGeneric(afterRaftConnectedCb, [ConnManager.RICUUID], false);
497
503
  };
498
504
  ApplicationManager.prototype.connectGenericCog = function (afterRaftConnectedCb) {
499
- return __awaiter(this, void 0, void 0, function () {
500
- return __generator(this, function (_a) {
501
- return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, [ConnManager.COGUUID])];
502
- });
503
- });
505
+ return this.connectGeneric(afterRaftConnectedCb, [ConnManager.COGUUID]);
504
506
  };
505
507
  /**
506
508
  * Generic Connect method
@@ -508,9 +510,51 @@ var ApplicationManager = /** @class */ (function () {
508
510
  * Known issue: connecting to a raft from within a platform won't add the newly connected raft to the connectedRafts hook
509
511
  */
510
512
  ApplicationManager.prototype.connectGeneric = function (afterRaftConnectedCb, uuids, shouldShowQrModal) {
513
+ var _this = this;
511
514
  if (shouldShowQrModal === void 0) { shouldShowQrModal = true; }
515
+ if (this._connectPromise) {
516
+ return this._connectPromise;
517
+ }
518
+ if (this._disconnectPromises.size > 0) {
519
+ this.toaster.info(i18n.t("connection.wait_for_bluetooth_disconnect", {
520
+ defaultValue: "Please wait for the current Bluetooth disconnect to finish.",
521
+ }));
522
+ return Promise.resolve();
523
+ }
524
+ var connectAttemptId = ++this._connectAttemptSequence;
525
+ this._activeConnectAttemptId = connectAttemptId;
526
+ var connectPromise = this._connectGeneric(afterRaftConnectedCb, uuids, shouldShowQrModal, connectAttemptId);
527
+ this._connectPromise = connectPromise;
528
+ void connectPromise.then(function () { return _this._clearConnectPromise(connectPromise, connectAttemptId); }, function () { return _this._clearConnectPromise(connectPromise, connectAttemptId); });
529
+ return connectPromise;
530
+ };
531
+ ApplicationManager.prototype._clearConnectPromise = function (connectPromise, connectAttemptId) {
532
+ if (this._connectPromise === connectPromise) {
533
+ this._connectPromise = null;
534
+ }
535
+ if (this._activeConnectAttemptId === connectAttemptId) {
536
+ this._activeConnectAttemptId = null;
537
+ }
538
+ };
539
+ ApplicationManager.prototype._dismissConnectAttempt = function (connectAttemptId) {
540
+ if (this._activeConnectAttemptId !== connectAttemptId) {
541
+ return;
542
+ }
543
+ this._activeConnectAttemptId = null;
544
+ this._connectPromise = null;
545
+ };
546
+ ApplicationManager.prototype._isConnectAttemptActive = function (connectAttemptId) {
547
+ return this._activeConnectAttemptId === connectAttemptId;
548
+ };
549
+ ApplicationManager.prototype._createConnectingModal = function (connectAttemptId) {
550
+ var _this = this;
551
+ return createElement(ConnectingLoadingSpinnerModal, {
552
+ onDismiss: function () { return _this._dismissConnectAttempt(connectAttemptId); },
553
+ });
554
+ };
555
+ ApplicationManager.prototype._connectGeneric = function (afterRaftConnectedCb, uuids, shouldShowQrModal, connectAttemptId) {
512
556
  return __awaiter(this, void 0, void 0, function () {
513
- var verificationMethod, cancelVerificationResult, isQRVerification, e_1, newRaft, e_2;
557
+ var verificationMethod, cancelVerificationResult, isQRVerification, e_1, newRaft, wasAdopted, e_2;
514
558
  var _this = this;
515
559
  return __generator(this, function (_a) {
516
560
  switch (_a.label) {
@@ -537,7 +581,7 @@ var ApplicationManager = /** @class */ (function () {
537
581
  return [2 /*return*/];
538
582
  }
539
583
  if (verificationMethod.action === "switch-to-marty") {
540
- return [2 /*return*/, this.connectGenericMarty(afterRaftConnectedCb)];
584
+ return [2 /*return*/, this._connectGeneric(afterRaftConnectedCb, [ConnManager.RICUUID], false, connectAttemptId)];
541
585
  }
542
586
  isQRVerification = false;
543
587
  if (verificationMethod.action === "qr") {
@@ -555,19 +599,22 @@ var ApplicationManager = /** @class */ (function () {
555
599
  case 3:
556
600
  _a.trys.push([3, 8, , 9]);
557
601
  if (!isQRVerification) return [3 /*break*/, 5];
558
- secondaryModalState.setModal(createElement(ConnectingLoadingSpinnerModal, {}), i18n.t("connection.connecting_msg"), false);
602
+ secondaryModalState.setModal(this._createConnectingModal(connectAttemptId), i18n.t("connection.connecting_msg"), false);
559
603
  this.ricSelectedCb = null;
560
604
  return [4 /*yield*/, window.applicationManager.startDiscoveryWithoutVerification(uuids, afterRaftConnectedCb)];
561
605
  case 4:
562
606
  _a.sent();
563
607
  return [3 /*break*/, 7];
564
608
  case 5: return [4 /*yield*/, window.applicationManager.startDiscovery(function (newRaft) { return __awaiter(_this, void 0, void 0, function () {
609
+ var wasAdopted;
565
610
  return __generator(this, function (_a) {
566
611
  switch (_a.label) {
567
612
  case 0: return [4 /*yield*/, this.addConnectedRaftToContext(newRaft)];
568
613
  case 1:
569
- _a.sent();
570
- afterRaftConnectedCb(newRaft);
614
+ wasAdopted = _a.sent();
615
+ if (wasAdopted && this.isRaftActive(newRaft)) {
616
+ afterRaftConnectedCb(newRaft);
617
+ }
571
618
  return [2 /*return*/];
572
619
  }
573
620
  });
@@ -582,19 +629,24 @@ var ApplicationManager = /** @class */ (function () {
582
629
  return [3 /*break*/, 9];
583
630
  case 9: return [3 /*break*/, 18];
584
631
  case 10:
585
- secondaryModalState.setModal(createElement(ConnectingLoadingSpinnerModal, {}), i18n.t("connection.connecting_msg"), false);
632
+ secondaryModalState.setModal(this._createConnectingModal(connectAttemptId), i18n.t("connection.connecting_msg"), false);
586
633
  _a.label = 11;
587
634
  case 11:
588
635
  _a.trys.push([11, 16, , 17]);
589
636
  return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuids, isQRVerification)];
590
637
  case 12:
591
638
  newRaft = _a.sent();
639
+ if (!this._isConnectAttemptActive(connectAttemptId)) {
640
+ return [2 /*return*/];
641
+ }
592
642
  if (!newRaft) return [3 /*break*/, 15];
593
643
  return [4 /*yield*/, this.addConnectedRaftToContext(newRaft)];
594
644
  case 13:
595
- _a.sent();
596
- afterRaftConnectedCb(newRaft);
597
- if (!isQRVerification) return [3 /*break*/, 15];
645
+ wasAdopted = _a.sent();
646
+ if (wasAdopted && this.isRaftActive(newRaft)) {
647
+ afterRaftConnectedCb(newRaft);
648
+ }
649
+ if (!(wasAdopted && this.isRaftActive(newRaft) && isQRVerification)) return [3 /*break*/, 15];
598
650
  return [4 /*yield*/, this.confirmQrVerifiedConnection(newRaft)];
599
651
  case 14:
600
652
  _a.sent();
@@ -605,7 +657,9 @@ var ApplicationManager = /** @class */ (function () {
605
657
  Logger.error(SHOW_LOGS, TAG, "Failed to connect to new robot: ".concat(e_2));
606
658
  return [3 /*break*/, 17];
607
659
  case 17:
608
- secondaryModalState.closeModalWithoutAnimation();
660
+ if (this._isConnectAttemptActive(connectAttemptId)) {
661
+ secondaryModalState.closeModalWithoutAnimation();
662
+ }
609
663
  _a.label = 18;
610
664
  case 18: return [2 /*return*/];
611
665
  }
@@ -623,27 +677,32 @@ var ApplicationManager = /** @class */ (function () {
623
677
  return __generator(this, function (_a) {
624
678
  switch (_a.label) {
625
679
  case 0:
626
- _a.trys.push([0, 4, , 5]);
627
- if (!!skipConfirmation) return [3 /*break*/, 2];
628
- return [4 /*yield*/, modalState.setModal(createElement(DisconnectConfirmationModal), "Are you sure you want to disconnect from your ".concat(raft.getFriendlyName(), "?"), getModalLogoForRaftType(raft.type))];
680
+ if (!raft) {
681
+ return [2 /*return*/];
682
+ }
683
+ _a.label = 1;
629
684
  case 1:
685
+ _a.trys.push([1, 5, , 6]);
686
+ if (!!skipConfirmation) return [3 /*break*/, 3];
687
+ return [4 /*yield*/, modalState.setModal(createElement(DisconnectConfirmationModal), "Are you sure you want to disconnect from your ".concat(raft.getFriendlyName(), "?"), getModalLogoForRaftType(raft.type))];
688
+ case 2:
630
689
  confirmDisconnect = _a.sent();
631
690
  if (!confirmDisconnect) {
632
691
  return [2 /*return*/];
633
692
  }
634
- _a.label = 2;
635
- case 2: return [4 /*yield*/, window.applicationManager.disconnectFromRaft(raft.id)];
636
- case 3:
693
+ _a.label = 3;
694
+ case 3: return [4 /*yield*/, window.applicationManager.disconnectFromRaft(raft.id)];
695
+ case 4:
637
696
  _a.sent();
638
697
  if (afterRaftDisconnectedCb) {
639
698
  afterRaftDisconnectedCb();
640
699
  }
641
- return [3 /*break*/, 5];
642
- case 4:
700
+ return [3 /*break*/, 6];
701
+ case 5:
643
702
  e_3 = _a.sent();
644
703
  Logger.error(SHOW_LOGS, TAG, "Failed to disconnect from robot: ".concat(e_3));
645
- return [3 /*break*/, 5];
646
- case 5: return [2 /*return*/];
704
+ return [3 /*break*/, 6];
705
+ case 6: return [2 /*return*/];
647
706
  }
648
707
  });
649
708
  });
@@ -788,59 +847,78 @@ var ApplicationManager = /** @class */ (function () {
788
847
  * Disconnect from RAFT
789
848
  */
790
849
  ApplicationManager.prototype.disconnectFromRaft = function (raftId) {
850
+ var raft = this.connectedRafts[raftId];
851
+ if (!raft) {
852
+ return Promise.resolve();
853
+ }
854
+ return this._disconnectRaft(raft);
855
+ };
856
+ /**
857
+ * Finalizes a RAFT which has already emitted its terminal disconnect event.
858
+ * Passing the source RAFT prevents a late event from deleting a replacement
859
+ * connection which happens to have the same serial/ID.
860
+ */
861
+ ApplicationManager.prototype.removeRaft = function (raftId, disconnectedRaft) {
791
862
  return __awaiter(this, void 0, void 0, function () {
792
- var raft;
863
+ var currentRaft;
793
864
  return __generator(this, function (_a) {
794
- switch (_a.label) {
795
- case 0:
796
- this.connectedRaftContextMethods.removeConnectedRaft(raftId);
797
- raft = this.connectedRafts[raftId];
798
- if (!raft) {
799
- return [2 /*return*/];
800
- }
801
- return [4 /*yield*/, raft.disconnect()];
802
- case 1:
803
- _a.sent();
804
- this._removeRaft(raftId, 3000);
805
- return [2 /*return*/];
865
+ currentRaft = this.connectedRafts[raftId];
866
+ if (!currentRaft || (disconnectedRaft && currentRaft !== disconnectedRaft)) {
867
+ return [2 /*return*/];
868
+ }
869
+ // A user-initiated disconnect is already waiting for RAFT_DISCONNECT.
870
+ // The event is only a notification in that case, not a second command.
871
+ if (this._disconnectPromises.has(currentRaft)) {
872
+ return [2 /*return*/];
806
873
  }
874
+ this._removeRaftIfCurrent(currentRaft);
875
+ return [2 /*return*/];
807
876
  });
808
877
  });
809
878
  };
810
- /**
811
- * Removes raft from the connectedRafts list after a timeout without disconnecting as at this point
812
- * the device should already be disconnected
813
- */
814
- ApplicationManager.prototype.removeRaft = function (raftId) {
815
- return __awaiter(this, void 0, void 0, function () {
816
- var raft;
879
+ ApplicationManager.prototype._disconnectRaft = function (raft, beforeDisconnect) {
880
+ var _this = this;
881
+ var inFlightDisconnect = this._disconnectPromises.get(raft);
882
+ if (inFlightDisconnect) {
883
+ return inFlightDisconnect;
884
+ }
885
+ var operation = Promise.resolve().then(function () { return __awaiter(_this, void 0, void 0, function () {
817
886
  return __generator(this, function (_a) {
818
887
  switch (_a.label) {
819
888
  case 0:
820
- this.connectedRaftContextMethods.removeConnectedRaft(raftId);
821
- raft = this.connectedRafts[raftId];
822
- if (!raft) {
823
- return [2 /*return*/];
824
- }
825
- return [4 /*yield*/, raft.disconnect()];
889
+ _a.trys.push([0, , 3, 5]);
890
+ if (!beforeDisconnect) return [3 /*break*/, 2];
891
+ return [4 /*yield*/, beforeDisconnect()];
826
892
  case 1:
827
893
  _a.sent();
828
- this._removeRaft(raftId, 10);
829
- return [2 /*return*/];
894
+ _a.label = 2;
895
+ case 2: return [3 /*break*/, 5];
896
+ case 3: return [4 /*yield*/, raft.disconnect()];
897
+ case 4:
898
+ _a.sent();
899
+ return [7 /*endfinally*/];
900
+ case 5: return [2 /*return*/];
830
901
  }
831
902
  });
903
+ }); });
904
+ var disconnectPromise;
905
+ disconnectPromise = operation.finally(function () {
906
+ _this._removeRaftIfCurrent(raft);
907
+ if (_this._disconnectPromises.get(raft) === disconnectPromise) {
908
+ _this._disconnectPromises.delete(raft);
909
+ }
832
910
  });
911
+ // Register ownership before connector code runs. A connector may emit a
912
+ // terminal event synchronously while disconnect() is being invoked.
913
+ this._disconnectPromises.set(raft, disconnectPromise);
914
+ return disconnectPromise;
833
915
  };
834
- /**
835
- * Removes raft after a certain time
836
- * Removes from the rics list after x seconds so that we can still get the last event
837
- */
838
- ApplicationManager.prototype._removeRaft = function (raftId, timeout) {
839
- var _this = this;
840
- var ricRemovalTimeout = setTimeout(function () {
841
- delete _this.connectedRafts[raftId];
842
- clearTimeout(ricRemovalTimeout);
843
- }, timeout);
916
+ ApplicationManager.prototype._removeRaftIfCurrent = function (raft) {
917
+ if (this.connectedRafts[raft.id] !== raft) {
918
+ return;
919
+ }
920
+ delete this.connectedRafts[raft.id];
921
+ this.connectedRaftContextMethods.removeConnectedRaft(raft.id);
844
922
  };
845
923
  /**
846
924
  * Start looking for rics to connect to
@@ -892,7 +970,7 @@ var ApplicationManager = /** @class */ (function () {
892
970
  raftFoundSubscriptionHelper().subscribe(function (_a) {
893
971
  var discoveredDevice = _a.discoveredDevice;
894
972
  return __awaiter(_this, void 0, void 0, function () {
895
- var newRaft, oldColours;
973
+ var newRaft, wasAdopted, oldColours;
896
974
  return __generator(this, function (_b) {
897
975
  switch (_b.label) {
898
976
  case 0:
@@ -909,7 +987,10 @@ var ApplicationManager = /** @class */ (function () {
909
987
  secondaryModalState.closeModalWithoutAnimation();
910
988
  return [4 /*yield*/, this.addConnectedRaftToContext(newRaft)];
911
989
  case 2:
912
- _b.sent();
990
+ wasAdopted = _b.sent();
991
+ if (!wasAdopted || !this.isRaftActive(newRaft)) {
992
+ return [2 /*return*/];
993
+ }
913
994
  afterRaftConnectedCb(newRaft);
914
995
  oldColours = newRaft._ledLcdColours;
915
996
  newRaft._ledLcdColours = [];
@@ -967,15 +1048,32 @@ var ApplicationManager = /** @class */ (function () {
967
1048
  * Stop verifying raft
968
1049
  */
969
1050
  ApplicationManager.prototype.stopVerifyingRaft = function (raftId, isCorrectRIC) {
970
- var _a;
971
1051
  return __awaiter(this, void 0, void 0, function () {
972
- return __generator(this, function (_b) {
973
- switch (_b.label) {
974
- case 0: return [4 /*yield*/, ((_a = this.connectedRafts[raftId]) === null || _a === void 0 ? void 0 : _a.stopVerifyingRaft(isCorrectRIC))];
1052
+ var raft, verificationResult;
1053
+ var _this = this;
1054
+ return __generator(this, function (_a) {
1055
+ switch (_a.label) {
1056
+ case 0:
1057
+ raft = this.connectedRafts[raftId];
1058
+ if (!raft) {
1059
+ return [2 /*return*/];
1060
+ }
1061
+ if (isCorrectRIC) {
1062
+ return [2 /*return*/, raft.stopVerifyingRaft(true)];
1063
+ }
1064
+ return [4 /*yield*/, this._disconnectRaft(raft, function () { return __awaiter(_this, void 0, void 0, function () {
1065
+ return __generator(this, function (_a) {
1066
+ switch (_a.label) {
1067
+ case 0: return [4 /*yield*/, raft.stopVerifyingRaft(false)];
1068
+ case 1:
1069
+ verificationResult = _a.sent();
1070
+ return [2 /*return*/];
1071
+ }
1072
+ });
1073
+ }); })];
975
1074
  case 1:
976
- _b.sent();
977
- this._removeRaft(raftId, 3000);
978
- return [2 /*return*/];
1075
+ _a.sent();
1076
+ return [2 /*return*/, verificationResult];
979
1077
  }
980
1078
  });
981
1079
  });
@@ -3,7 +3,7 @@ import RICInterface from "../RAFTInterface";
3
3
  import { RaftTypeE } from "../../../types/raft";
4
4
  import { RICLedLcdColours } from "@robotical/roboticaljs";
5
5
  import { SimplifiedCogStateInfo } from "@robotical/roboticaljs/dist/SystemTypeCog/CogTypes";
6
- import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robotical/raftjs";
6
+ import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robdobsn/raftjs";
7
7
  import { RaftInfoEvents } from "../../../types/events/raft-info";
8
8
  import PublishedDataAnalyser from "./PublishedDataAnalyser";
9
9
  export declare class Cog extends RAFT implements RICInterface {
@@ -51,7 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
51
51
  };
52
52
  import RAFT from "../RAFT";
53
53
  import { RaftTypeE } from "../../../types/raft";
54
- import { RaftConnEvent, RaftPublishEvent } from "@robotical/raftjs";
54
+ import { RaftConnEvent, RaftPublishEvent } from "@robdobsn/raftjs";
55
55
  import { RaftInfoEvents } from "../../../types/events/raft-info";
56
56
  import PublishedDataAnalyser, { setButtonThresholdsUtil } from "./PublishedDataAnalyser";
57
57
  var Cog = /** @class */ (function (_super) {
@@ -1,4 +1,4 @@
1
- import { RaftOKFail } from "@robotical/raftjs";
1
+ import { RaftOKFail } from "@robdobsn/raftjs";
2
2
  import Marty from "./Marty";
3
3
  export default class CalibrationManager {
4
4
  marty: Marty;
@@ -34,7 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import { RaftOKFail } from "@robotical/raftjs";
37
+ import { RaftOKFail } from "@robdobsn/raftjs";
38
38
  import Logger from "../../../services/logger/Logger";
39
39
  var SHOW_LOGS = true;
40
40
  var TAG = "CalibrationManager";
@@ -1,7 +1,7 @@
1
1
  import RICInterface from "../RAFTInterface";
2
2
  import { RaftTypeE } from "../../../types/raft";
3
3
  import RAFT from "../RAFT";
4
- import { RaftConnEvent, RaftPublishEvent, RaftSystemInfo, RaftUpdateEvent } from "@robotical/raftjs";
4
+ import { RaftConnEvent, RaftPublishEvent, RaftSystemInfo, RaftUpdateEvent } from "@robdobsn/raftjs";
5
5
  import { RaftInfoEvents } from "../../../types/events/raft-info";
6
6
  import { RICLedLcdColours, RICStateInfo } from "@robotical/roboticaljs";
7
7
  import { MartyWifiManager } from "./MartyWifiManager";
@@ -51,7 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
51
51
  };
52
52
  import { RaftTypeE } from "../../../types/raft";
53
53
  import RAFT from "../RAFT";
54
- import { RaftConnEvent, RaftPublishEvent } from "@robotical/raftjs";
54
+ import { RaftConnEvent, RaftPublishEvent } from "@robdobsn/raftjs";
55
55
  import { MartyWifiManager } from "./MartyWifiManager";
56
56
  import MartyAddonsManager from "./MartyAddonsManager";
57
57
  import CalibrationManager from "./CalibrationManager";
@@ -1,4 +1,4 @@
1
- import { RaftOKFail, RaftWifiConnStatus, RaftWifiScanResults } from "@robotical/raftjs";
1
+ import { RaftOKFail, RaftWifiConnStatus, RaftWifiScanResults } from "@robdobsn/raftjs";
2
2
  import Marty from "./Marty";
3
3
  export declare class MartyWifiManager {
4
4
  marty: Marty;
@@ -34,7 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import { RaftWifiConnState, RaftWifiConnStatus } from "@robotical/raftjs";
37
+ import { RaftWifiConnState, RaftWifiConnStatus } from "@robdobsn/raftjs";
38
38
  import Logger from "../../../services/logger/Logger";
39
39
  var SHOW_LOGS = true;
40
40
  var TAG = "MartyWifiManager";
@@ -3,7 +3,7 @@
3
3
  * One of the main purposes of this class is to prevent duplicate warnings from being
4
4
  * displayed to the user.
5
5
  */
6
- import { RaftLog } from "@robotical/raftjs";
6
+ import { RaftLog } from "@robdobsn/raftjs";
7
7
  // we won't store these warnings in the cached warnings state, and so they won't be displayed or stored to the warranty service db, only to the general db
8
8
  var ERRORS_TO_IGNORE = [
9
9
  // eyes faulty connection
@@ -4,7 +4,7 @@ import { RaftInfoEvents } from "../../types/events/raft-info";
4
4
  import { FOUND_RAFT_ON_DISCOVERY_RESPONSE } from "../../types/phone-app-communicator";
5
5
  import RICInterface from "./RAFTInterface";
6
6
  import { RaftObserver } from "./RaftObserver";
7
- import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, RaftOKFail, RaftSystemInfo } from "@robotical/raftjs";
7
+ import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, RaftOKFail, RaftSystemInfo } from "@robdobsn/raftjs";
8
8
  import { RICLedLcdColours, RICStateInfo } from "@robotical/roboticaljs";
9
9
  import { SimplifiedCogStateInfo } from "@robotical/roboticaljs/dist/SystemTypeCog/CogTypes";
10
10
  export default class RAFT implements RICInterface {
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  import { AppSentMessage } from "../../types/communication-between-apps/wrapper-communication";
38
38
  import { RaftTypeE } from "../../types/raft";
39
39
  import { RaftInfoEvents } from "../../types/events/raft-info";
40
- import { RaftConnEvent, RaftPublishEvent, } from "@robotical/raftjs";
40
+ import { RaftConnEvent, RaftPublishEvent, } from "@robdobsn/raftjs";
41
41
  import Logger from "../../services/logger/Logger";
42
42
  import randomHashGenerator from "../../utils/helpers/randomHashGenerator";
43
43
  import { addRobotNameToSerialNumber, isSerialNumberRegistered } from "../../utils/warranty-service/warranty-service-utils";
@@ -400,7 +400,7 @@ var RAFT = /** @class */ (function () {
400
400
  // this runs when the RAFT is disconnected either on its own (due to a timeout or other reasons), or by the user
401
401
  // if it's by the user, we don't really need to do anything as the applicationManager will handle the disconnection
402
402
  // if the RAFT is disconnected on its own, however, we need to remove it from the connectedRafts list
403
- return [4 /*yield*/, window.applicationManager.removeRaft(this.id)];
403
+ return [4 /*yield*/, window.applicationManager.removeRaft(this.id, this)];
404
404
  case 3:
405
405
  // this runs when the RAFT is disconnected either on its own (due to a timeout or other reasons), or by the user
406
406
  // if it's by the user, we don't really need to do anything as the applicationManager will handle the disconnection
@@ -1,5 +1,5 @@
1
1
  import { RaftTypeE } from "../../types/raft";
2
- import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robotical/raftjs";
2
+ import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robdobsn/raftjs";
3
3
  import { RaftInfoEvents } from "../../types/events/raft-info";
4
4
  import { RICLedLcdColours } from "@robotical/roboticaljs";
5
5
  export default abstract class RICInterface {
@@ -1,5 +1,5 @@
1
1
  import { RaftInfoEvents } from "../../types/events/raft-info";
2
- import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@robotical/raftjs";
2
+ import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@robdobsn/raftjs";
3
3
  export interface MartyObservable {
4
4
  subscribe(observer: RaftObserver, topics: Array<string>): void;
5
5
  unsubscribe(observer: RaftObserver): void;
@@ -1,4 +1,4 @@
1
- import { RaftConnEvent } from "@robotical/raftjs";
1
+ import { RaftConnEvent } from "@robdobsn/raftjs";
2
2
  var subHelpersObject = {};
3
3
  /**
4
4
  * Connection Verifying Subscription Helper
@@ -0,0 +1,4 @@
1
+ import { type IScannerProps } from "@yudiel/react-qr-scanner";
2
+ type Props = IScannerProps;
3
+ export default function SwitchableCameraScanner({ constraints, ...scannerProps }: Props): import("react/jsx-runtime").JSX.Element;
4
+ export {};