@robotical/webapp-types 3.7.6 → 3.7.7

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.
@@ -155,49 +155,55 @@ var ApplicationManager = /** @class */ (function () {
155
155
  uuids = [ConnManager.COGUUID, ConnManager.RICUUID];
156
156
  }
157
157
  }
158
- if (!isPhoneApp()) return [3 /*break*/, 9];
158
+ if (!isPhoneApp()) return [3 /*break*/, 10];
159
159
  _a.label = 2;
160
160
  case 2:
161
- _a.trys.push([2, 7, , 8]);
162
- if (!isQRVerification) return [3 /*break*/, 4];
161
+ _a.trys.push([2, 8, , 9]);
162
+ if (!isQRVerification) return [3 /*break*/, 5];
163
+ secondaryModalState.setModal(createElement(ConnectingLoadingSpinnerModal, {}), "Connecting...", false);
164
+ this.ricSelectedCb = null;
163
165
  return [4 /*yield*/, window.applicationManager.startDiscoveryWithoutVerification(uuids, afterRaftConnectedCb)];
164
166
  case 3:
165
167
  _a.sent();
166
- return [3 /*break*/, 6];
167
- case 4: return [4 /*yield*/, window.applicationManager.startDiscovery(function (newRaft) {
168
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
169
+ case 4:
170
+ _a.sent(); // make sure the device has shown up in the connection area
171
+ secondaryModalState.closeModal();
172
+ return [3 /*break*/, 7];
173
+ case 5: return [4 /*yield*/, window.applicationManager.startDiscovery(function (newRaft) {
168
174
  _this.connectedRaftContextMethods.addConnectedRaft({ id: newRaft.id, type: newRaft.type, name: newRaft.getFriendlyName() || "", isSelected: true });
169
175
  afterRaftConnectedCb(newRaft);
170
176
  }, uuids)];
171
- case 5:
177
+ case 6:
172
178
  _a.sent();
173
- _a.label = 6;
174
- case 6: return [3 /*break*/, 8];
175
- case 7:
179
+ _a.label = 7;
180
+ case 7: return [3 /*break*/, 9];
181
+ case 8:
176
182
  e_1 = _a.sent();
177
183
  Logger.error(SHOW_LOGS, TAG, "Failed to start discovery: ".concat(e_1));
178
- return [3 /*break*/, 8];
179
- case 8: return [3 /*break*/, 14];
180
- case 9:
181
- secondaryModalState.setModal(createElement(ConnectingLoadingSpinnerModal, {}), "Connecting...", false);
182
- _a.label = 10;
184
+ return [3 /*break*/, 9];
185
+ case 9: return [3 /*break*/, 15];
183
186
  case 10:
184
- _a.trys.push([10, 12, , 13]);
185
- return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuids, isQRVerification)];
187
+ secondaryModalState.setModal(createElement(ConnectingLoadingSpinnerModal, {}), "Connecting...", false);
188
+ _a.label = 11;
186
189
  case 11:
190
+ _a.trys.push([11, 13, , 14]);
191
+ return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuids, isQRVerification)];
192
+ case 12:
187
193
  newRaft = _a.sent();
188
194
  if (newRaft) {
189
195
  this.connectedRaftContextMethods.addConnectedRaft({ id: newRaft.id, type: newRaft.type, name: newRaft.getFriendlyName() || "", isSelected: true });
190
196
  afterRaftConnectedCb(newRaft);
191
197
  }
192
- return [3 /*break*/, 13];
193
- case 12:
198
+ return [3 /*break*/, 14];
199
+ case 13:
194
200
  e_2 = _a.sent();
195
201
  Logger.error(SHOW_LOGS, TAG, "Failed to connect to new robot: ".concat(e_2));
196
- return [3 /*break*/, 13];
197
- case 13:
202
+ return [3 /*break*/, 14];
203
+ case 14:
198
204
  secondaryModalState.closeModal();
199
- _a.label = 14;
200
- case 14: return [2 /*return*/];
205
+ _a.label = 15;
206
+ case 15: return [2 /*return*/];
201
207
  }
202
208
  });
203
209
  });
@@ -381,26 +387,11 @@ var ApplicationManager = /** @class */ (function () {
381
387
  */
382
388
  ApplicationManager.prototype.startDiscovery = function (ricSelectedCb, uuids) {
383
389
  return __awaiter(this, void 0, void 0, function () {
384
- var foundRICs, wasDiscoveryStarted;
390
+ var wasDiscoveryStarted;
385
391
  return __generator(this, function (_a) {
386
392
  switch (_a.label) {
387
393
  case 0:
388
394
  this.ricSelectedCb = ricSelectedCb;
389
- foundRICs = [];
390
- raftFoundSubscriptionHelper().subscribe(function (_a) {
391
- var discoveredDevice = _a.discoveredDevice;
392
- // if the discovered RAFT is already in the list, don't add it, just update the rssi
393
- var foundRICIdx = foundRICs.findIndex(function (ric_) { return ric_._id === discoveredDevice._id; });
394
- if (foundRICIdx !== -1) {
395
- foundRICs[foundRICIdx] = discoveredDevice;
396
- }
397
- else {
398
- foundRICs.push(discoveredDevice);
399
- }
400
- // foundRICs.sort((a, b) => b._rssi - a._rssi);
401
- modalState.setModal(createElement(VerificationModalPhoneApp, { foundRICs: foundRICs }), "Looking for RAFT");
402
- });
403
- modalState.setModal(createElement(VerificationModalPhoneApp, { foundRICs: [] }), "Looking for RAFT");
404
395
  return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_START_DISCOVERY, { uuids: uuids })];
405
396
  case 1:
406
397
  wasDiscoveryStarted = _a.sent();
@@ -435,10 +426,11 @@ var ApplicationManager = /** @class */ (function () {
435
426
  return __generator(this, function (_b) {
436
427
  switch (_b.label) {
437
428
  case 0:
438
- // connect to the first device found, block the rest
429
+ // connect to the first device found if it has the correct service UUID
439
430
  if (foundRICs.length > 0) {
440
431
  return [2 /*return*/];
441
432
  }
433
+ if (!discoveredDevice._serviceUUIDs.includes(uuids[0])) return [3 /*break*/, 2];
442
434
  foundRICs.push(discoveredDevice);
443
435
  return [4 /*yield*/, this.selectRaft(discoveredDevice, RaftConnectionMethod.PHONE_BLE)];
444
436
  case 1:
@@ -446,11 +438,13 @@ var ApplicationManager = /** @class */ (function () {
446
438
  if (newRaft) {
447
439
  this.connectedRaftContextMethods.addConnectedRaft({ id: newRaft.id, type: newRaft.type, name: newRaft.getFriendlyName() || "", isSelected: true });
448
440
  afterRaftConnectedCb(newRaft);
441
+ raftFoundSubscriptionHelper().unsubscribe();
449
442
  }
450
443
  else {
451
444
  foundRICs = [];
452
445
  }
453
- return [2 /*return*/];
446
+ _b.label = 2;
447
+ case 2: return [2 /*return*/];
454
448
  }
455
449
  });
456
450
  });
@@ -70,7 +70,7 @@ var options = [
70
70
  ];
71
71
  export default function LEDLightsOrQRVerificationModal() {
72
72
  var _this = this;
73
- var _a = useState(true), qrSelected = _a[0], setQRSelected = _a[1];
73
+ var _a = useState(false), qrSelected = _a[0], setQRSelected = _a[1];
74
74
  var _b = useState(undefined), serialNoFromQR = _b[0], setSerialNoFromQR = _b[1];
75
75
  var _c = useState(false), isButtonToConnectVisible = _c[0], setIsButtonToConnectVisible = _c[1];
76
76
  useEffect(function () {
@@ -78,8 +78,8 @@ export default function LEDLightsOrQRVerificationModal() {
78
78
  // 00000000202502200000000000000239
79
79
  console.log("serialNoFromQR", serialNoFromQR);
80
80
  console.log("ConnManager.generateServiceFilterUUID(serialNoFromQR)", ConnManager.generateServiceFilterUUID(serialNoFromQR));
81
- // modalState.closeModal([ConnManager.generateServiceFilterUUID(serialNoFromQR)]);
82
- // modalState.closeModal([ConnManager.generateServiceFilterUUID('00000000202302111d28b4dc5f0d46d5')]);
81
+ // modalState.closeModalWithoutAnimation([ConnManager.generateServiceFilterUUID(serialNoFromQR)]);
82
+ // modalState.closeModalWithoutAnimation([ConnManager.generateServiceFilterUUID('00000000202302111d28b4dc5f0d46d5')]);
83
83
  setIsButtonToConnectVisible(true);
84
84
  setQRSelected(false);
85
85
  }
@@ -88,15 +88,17 @@ export default function LEDLightsOrQRVerificationModal() {
88
88
  if (id === 'qr') {
89
89
  setSerialNoFromQR(undefined);
90
90
  setQRSelected(function (prev) { return !prev; });
91
+ // modalState.closeModalWithoutAnimation([ConnManager.generateServiceFilterUUID('00000000202502200000000000000239')]);
91
92
  }
92
93
  else {
93
- modalState.closeModal([]);
94
+ console.log("LED Lights Verification");
95
+ modalState.closeModalWithoutAnimation([]);
94
96
  }
95
97
  };
96
98
  var handleConnect = function () { return __awaiter(_this, void 0, void 0, function () {
97
99
  return __generator(this, function (_a) {
98
100
  if (serialNoFromQR) {
99
- modalState.closeModal([ConnManager.generateServiceFilterUUID(serialNoFromQR)]);
101
+ modalState.closeModalWithoutAnimation([ConnManager.generateServiceFilterUUID(serialNoFromQR)]);
100
102
  }
101
103
  return [2 /*return*/];
102
104
  });
@@ -124,7 +126,7 @@ function QRContent(_a) {
124
126
  return [2 /*return*/];
125
127
  });
126
128
  }); };
127
- return (_jsx("div", __assign({ className: styles.QRcontainer }, { children: _jsx("div", __assign({ className: styles.QRscannerContainer }, { children: _jsx(Scanner, { formats: [
129
+ return (_jsx("div", __assign({ className: styles.QRcontainer }, { children: _jsx("div", __assign({ className: styles.QRscannerContainer }, { children: _jsx(Scanner, { onError: function (err) { return console.error(err); }, formats: [
128
130
  "qr_code",
129
131
  "micro_qr_code",
130
132
  "rm_qr_code",
@@ -45,6 +45,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
48
57
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
49
58
  import { Fragment, useEffect, useState } from "react";
50
59
  import "./styles.css";
@@ -56,7 +65,7 @@ import RICSignal from "../../oneoffs/RaftSignal";
56
65
  import SimpleButton from "../../disposables/buttons/SimpleButton";
57
66
  import LEDs from "../../oneoffs/LEDs";
58
67
  import SVGImageButton from "../../disposables/buttons/SVGImageButton";
59
- import { raftConnectingSubscriptionHelper, raftDiscoveryFinishedSubscriptionHelper, raftDiscoveryStartedSubscriptionHelper } from "../../../application/RAFTs/raft-subscription-helpers";
68
+ import { raftConnectingSubscriptionHelper, raftDiscoveryFinishedSubscriptionHelper, raftDiscoveryStartedSubscriptionHelper, raftFoundSubscriptionHelper } from "../../../application/RAFTs/raft-subscription-helpers";
60
69
  import isPhoneApp from "../../../utils/phone-app-communication/is-phone-app";
61
70
  import LoadingSpinner from "../../disposables/LoadingSpinner";
62
71
  import { RaftConnectionMethod } from "../../../types/raft";
@@ -68,10 +77,11 @@ function VerificationModalPhoneApp(_a) {
68
77
  var _this = this;
69
78
  var foundRICs = _a.foundRICs;
70
79
  var _b = useState([]), randomColours = _b[0], setRandomColours = _b[1];
71
- var _c = useState(-1), selectedRICIdx = _c[0], setSelectedRICIdx = _c[1];
72
- var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
73
- var _e = useState(isPhoneApp()), isScanning = _e[0], setIsScanning = _e[1];
74
- var _f = useState(), connectedRaft = _f[0], setConnectedRaft = _f[1];
80
+ var _c = useState(foundRICs), foundRICsState = _c[0], setFoundRICsState = _c[1];
81
+ var _d = useState(-1), selectedRICIdx = _d[0], setSelectedRICIdx = _d[1];
82
+ var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
83
+ var _f = useState(isPhoneApp()), isScanning = _f[0], setIsScanning = _f[1];
84
+ var _g = useState(), connectedRaft = _g[0], setConnectedRaft = _g[1];
75
85
  var removeConnectedRaft = useConnectedRafts().removeConnectedRaft;
76
86
  useEffect(function () {
77
87
  raftDiscoveryFinishedSubscriptionHelper().subscribe(function () { return setIsScanning(false); });
@@ -81,6 +91,21 @@ function VerificationModalPhoneApp(_a) {
81
91
  raftDiscoveryStartedSubscriptionHelper().unsubscribe();
82
92
  };
83
93
  }, []);
94
+ useEffect(function () {
95
+ raftFoundSubscriptionHelper().subscribe(function (_a) {
96
+ var discoveredDevice = _a.discoveredDevice;
97
+ setFoundRICsState(function (prevState) {
98
+ var foundRICIdx = prevState.findIndex(function (ric_) { return ric_._id === discoveredDevice._id; });
99
+ if (foundRICIdx !== -1) {
100
+ prevState[foundRICIdx] = discoveredDevice;
101
+ return __spreadArray([], prevState, true);
102
+ }
103
+ else {
104
+ return __spreadArray(__spreadArray([], prevState, true), [discoveredDevice], false);
105
+ }
106
+ });
107
+ });
108
+ }, []);
84
109
  var onCancel = function () { return __awaiter(_this, void 0, void 0, function () {
85
110
  return __generator(this, function (_a) {
86
111
  switch (_a.label) {
@@ -99,6 +124,7 @@ function VerificationModalPhoneApp(_a) {
99
124
  _a.sent();
100
125
  _a.label = 5;
101
126
  case 5:
127
+ raftFoundSubscriptionHelper().unsubscribe();
102
128
  modalState.closeModal();
103
129
  return [2 /*return*/];
104
130
  }
@@ -108,6 +134,7 @@ function VerificationModalPhoneApp(_a) {
108
134
  return __generator(this, function (_a) {
109
135
  switch (_a.label) {
110
136
  case 0:
137
+ modalState.closeModalWithoutAnimation();
111
138
  if (!connectedRaft) return [3 /*break*/, 3];
112
139
  return [4 /*yield*/, window.applicationManager.stopVerifyingRaft(connectedRaft.id, false)];
113
140
  case 1:
@@ -144,7 +171,7 @@ function VerificationModalPhoneApp(_a) {
144
171
  if (!connectedRaft)
145
172
  return;
146
173
  raftConnectingSubscriptionHelper(connectedRaft).subscribe(setRandomColours);
147
- connectedRaft === null || connectedRaft === void 0 ? void 0 : connectedRaft.verifyRaftPhoneApp(foundRICs[selectedRICIdx]);
174
+ connectedRaft === null || connectedRaft === void 0 ? void 0 : connectedRaft.verifyRaftPhoneApp(foundRICsState[selectedRICIdx]);
148
175
  return function () {
149
176
  raftConnectingSubscriptionHelper(connectedRaft).unsubscribe();
150
177
  };
@@ -166,8 +193,9 @@ function VerificationModalPhoneApp(_a) {
166
193
  _a.label = 3;
167
194
  case 3:
168
195
  setSelectedRICIdx(raftIdx);
169
- if (!foundRICs) return [3 /*break*/, 5];
170
- foundRaft = foundRICs[raftIdx];
196
+ raftFoundSubscriptionHelper().unsubscribe();
197
+ if (!foundRICsState) return [3 /*break*/, 5];
198
+ foundRaft = foundRICsState[raftIdx];
171
199
  return [4 /*yield*/, window.applicationManager.selectRaft(foundRaft, RaftConnectionMethod.PHONE_BLE)];
172
200
  case 4:
173
201
  newRaft = _a.sent();
@@ -182,11 +210,11 @@ function VerificationModalPhoneApp(_a) {
182
210
  });
183
211
  }); };
184
212
  var contentJSX = null;
185
- if (foundRICs.length === 0) {
213
+ if (foundRICsState.length === 0) {
186
214
  contentJSX = _jsxs("div", __assign({ className: "verification-modal-container" }, { children: [!isScanning && _jsx("p", __assign({ style: { alignSelf: 'center' } }, { children: "No Robots Found" })), _jsx("div", __assign({ className: "verification-modal-martys-container" }, { children: isScanning && _jsxs("div", __assign({ style: { margin: "auto", width: "50px", height: "50px" } }, { children: [" ", _jsx(LoadingSpinner, {}), " "] })) })), _jsxs("div", __assign({ className: "verification-modal-bottom-btns-container" }, { children: [_jsx(SVGImageButton, { onClick: onScanAgain, title: "SCAN AGAIN", SVGImage: RefreshSVG, backgroundColour: MAIN_BLUE, titleColour: WHITE, SVGColour: WHITE }), _jsx("div", { className: "dummy-gap" }), _jsx(SimpleButton, { onClick: onCancel, title: "CANCEL" })] }))] }));
187
215
  }
188
216
  else {
189
- contentJSX = _jsxs("div", __assign({ className: "verification-modal-container" }, { children: [_jsxs("div", __assign({ className: "verification-modal-martys-container" }, { children: [isScanning && _jsxs("div", __assign({ style: { margin: "auto", width: "50px", height: "50px" } }, { children: [" ", _jsx(LoadingSpinner, {}), " "] })), foundRICs.map(function (raftObj, raftIdx) {
217
+ contentJSX = _jsxs("div", __assign({ className: "verification-modal-container" }, { children: [_jsxs("div", __assign({ className: "verification-modal-martys-container" }, { children: [isScanning && _jsxs("div", __assign({ style: { margin: "auto", width: "50px", height: "50px" } }, { children: [" ", _jsx(LoadingSpinner, {}), " "] })), foundRICsState.map(function (raftObj, raftIdx) {
190
218
  return _jsxs(Fragment, { children: [_jsxs("div", __assign({ className: "verification-modal-marty-name-row-container", onClick: function () { return onSelectRaft(raftIdx); } }, { children: [_jsx("p", __assign({ className: "verification-modal-marty-name" }, { children: raftObj._localName })), _jsx("div", __assign({ className: "verification-modal-marty-signal-container" }, { children: _jsx(RICSignal, { signalStrength: raftObj._rssi }) })), _jsx(BluetoothSVG, { fill: MAIN_BLUE })] })), selectedRICIdx === raftIdx && _jsxs("div", { children: [_jsx("p", __assign({ className: "verification-modal-martys-back-hint" }, { children: isLoading ? "Loading..." : "Look on ".concat(connectedRaft === null || connectedRaft === void 0 ? void 0 : connectedRaft.type, "'s back, is it displaying these lights?") })), _jsxs("div", __assign({ className: "verification-modal-led-row-container" }, { children: [_jsx(LEDs, { coloursArr: randomColours, connectedRaft: connectedRaft }), !isLoading && _jsx(SimpleButton, { onClick: onCancel, title: "No", borderColour: "red", colour: "white", textColour: "red" }), !isLoading && _jsx(SimpleButton, { onClick: onYes, title: "YES" })] }))] })] }, raftIdx);
191
219
  })] })), _jsxs("div", __assign({ className: "verification-modal-bottom-btns-container" }, { children: [_jsx(SVGImageButton, { onClick: onScanAgain, title: "SCAN AGAIN", SVGImage: RefreshSVG, backgroundColour: MAIN_BLUE, titleColour: WHITE, SVGColour: WHITE, disabled: isScanning }), _jsx("div", { className: "dummy-gap" }), _jsx(SimpleButton, { onClick: onCancel, title: "CANCEL" })] }))] }));
192
220
  }
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from "react";
2
2
  export type ModalContentType = ReactNode;
3
- export type ModalEventTopics = "SetModal" | "CloseModal" | "UpdateModalProps";
3
+ export type ModalEventTopics = "SetModal" | "CloseModal" | "CloseModalWithoutAnimation" | "UpdateModalProps";
4
4
  export type ModalStateData = {
5
5
  modalContent?: ModalContentType;
6
6
  modalTitle?: string;
@@ -10,6 +10,7 @@ declare class ModalState implements ModalObservable {
10
10
  constructor();
11
11
  setModal(modalContent: ModalContentType, modalTitle: string, withLogo?: boolean): Promise<ModalReturnValue>;
12
12
  closeModal(modalReturnValue?: ModalReturnValue, onCloseCb?: () => void): void;
13
+ closeModalWithoutAnimation(modalReturnValue?: ModalReturnValue, onCloseCb?: () => void): void;
13
14
  updateModalProps(updatedProps: {
14
15
  modalTitle?: string;
15
16
  withCloseButton?: boolean;
@@ -25,6 +25,14 @@ var ModalState = /** @class */ (function () {
25
25
  this.clearPromise();
26
26
  onCloseCb && onCloseCb();
27
27
  };
28
+ ModalState.prototype.closeModalWithoutAnimation = function (modalReturnValue, onCloseCb) {
29
+ this.modalContent = null;
30
+ this.modalTitle = "";
31
+ this.publish("CloseModalWithoutAnimation");
32
+ this._modalResolve(modalReturnValue);
33
+ this.clearPromise();
34
+ onCloseCb && onCloseCb();
35
+ };
28
36
  ModalState.prototype.updateModalProps = function (updatedProps) {
29
37
  this.modalTitle = updatedProps.modalTitle || this.modalTitle;
30
38
  this.publish("UpdateModalProps", updatedProps);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "3.7.6",
3
+ "version": "3.7.7",
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",