@robotical/webapp-types 1.1.0 → 1.1.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 (35) hide show
  1. package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +13 -3
  2. package/dist-types/src/application/ApplicationManager/ApplicationManager.js +59 -26
  3. package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +7 -2
  4. package/dist-types/src/application/RAFTs/Cog/Cog.js +28 -13
  5. package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.d.ts +64 -4
  6. package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.js +94 -33
  7. package/dist-types/src/application/RAFTs/Marty/Marty.js +1 -1
  8. package/dist-types/src/application/RAFTs/RAFT.d.ts +5 -4
  9. package/dist-types/src/application/RAFTs/RAFT.js +5 -5
  10. package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.js +1 -1
  11. package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.d.ts +3 -0
  12. package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.js +16 -0
  13. package/dist-types/src/components/modals/DisconnectConfirmation/index.d.ts +1 -6
  14. package/dist-types/src/components/modals/DisconnectConfirmation/index.js +2 -59
  15. package/dist-types/src/components/modals/VerificationModal/index.js +1 -1
  16. package/dist-types/src/components/modals/VerificationModalPhoneApp/index.js +11 -6
  17. package/dist-types/src/services/logger/Logger.d.ts +1 -0
  18. package/dist-types/src/services/logger/Logger.js +10 -4
  19. package/dist-types/src/state-observables/modal/ModalObserver.d.ts +1 -0
  20. package/dist-types/src/state-observables/modal/ModalState.d.ts +1 -1
  21. package/dist-types/src/state-observables/modal/ModalState.js +3 -2
  22. package/dist-types/src/types/communication-between-apps/wrapper-communication.d.ts +4 -1
  23. package/dist-types/src/types/communication-between-apps/wrapper-communication.js +3 -0
  24. package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +1 -1
  25. package/dist-types/src/wrapper-app/WrapperAppManager.js +2 -2
  26. package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +1 -1
  27. package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.d.ts +5 -0
  28. package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.js +33 -1
  29. package/dist-types/src/wrapper-app/connectors/Connector.d.ts +4 -1
  30. package/dist-types/src/wrapper-app/connectors/Connector.js +10 -11
  31. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.d.ts +1 -1
  32. package/dist-types/src/wrapper-app/connectors/ConnectorFactory.js +2 -2
  33. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.d.ts +5 -0
  34. package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +24 -0
  35. package/package.json +1 -1
@@ -102,7 +102,7 @@ var Marty = /** @class */ (function (_super) {
102
102
  }
103
103
  this.rssiValues.push(newRssi);
104
104
  var rssiAverage = this.rssiValues.reduce(function (sum, val) { return sum + val; }, 0) / this.rssiValues.length;
105
- return this.rssiValues.reduce(function (sum, val) { return sum + val; }, 0) / this.rssiValues.length;
105
+ return rssiAverage;
106
106
  };
107
107
  /**
108
108
  * Gets the battery strength of the RAFT
@@ -4,7 +4,8 @@ import { FOUND_RAFT_ON_DISCOVERY_RESPONSE } from "../../types/phone-app-communic
4
4
  import RICInterface from "./RAFTInterface";
5
5
  import { RaftObserver } from "./RaftObserver";
6
6
  import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, RaftOKFail, RaftSystemInfo } from "@robotical/raftjs";
7
- import { CogStateInfo, RICLedLcdColours, RICStateInfo } from "@robotical/roboticaljs";
7
+ import { RICLedLcdColours, RICStateInfo } from "@robotical/roboticaljs";
8
+ import { SimplifiedCogStateInfo } from "@robotical/roboticaljs/dist/SystemTypeCog/CogTypes";
8
9
  export default class RAFT implements RICInterface {
9
10
  id: string;
10
11
  type: RaftTypeE;
@@ -14,7 +15,7 @@ export default class RAFT implements RICInterface {
14
15
  };
15
16
  isSerialNoRegisteredInWarranty: boolean | null;
16
17
  systemInfo: RaftSystemInfo | null;
17
- raftStateInfo: RICStateInfo | CogStateInfo | null;
18
+ raftStateInfo: RICStateInfo | SimplifiedCogStateInfo | null;
18
19
  /**
19
20
  * Method to get ledLcdColours, to be implemented in child classes.
20
21
  */
@@ -29,7 +30,7 @@ export default class RAFT implements RICInterface {
29
30
  * Connect to a RAFT
30
31
  * We first connect, then we discover the raft type, and then we create the appopriate raft instance
31
32
  */
32
- static connect(method: RaftConnectionMethod, uuid: string): Promise<ConnectionAttemptResults>;
33
+ static connect(method: RaftConnectionMethod, uuids: string[]): Promise<ConnectionAttemptResults>;
33
34
  /**
34
35
  * Disconnect from a RAFT
35
36
  */
@@ -41,7 +42,7 @@ export default class RAFT implements RICInterface {
41
42
  /**
42
43
  * Verify correct RAFT is selected for phone app
43
44
  */
44
- verifyRaftPhoneApp(discoveredRIC: FOUND_RAFT_ON_DISCOVERY_RESPONSE['foundRIC']): Promise<boolean>;
45
+ verifyRaftPhoneApp(discoveredDevice: FOUND_RAFT_ON_DISCOVERY_RESPONSE['foundRIC']): Promise<boolean>;
45
46
  /**
46
47
  * Verify correct RAFT is selected
47
48
  */
@@ -84,12 +84,12 @@ var RAFT = /** @class */ (function () {
84
84
  * Connect to a RAFT
85
85
  * We first connect, then we discover the raft type, and then we create the appopriate raft instance
86
86
  */
87
- RAFT.connect = function (method, uuid) {
87
+ RAFT.connect = function (method, uuids) {
88
88
  return __awaiter(this, void 0, void 0, function () {
89
89
  var connectResults;
90
90
  return __generator(this, function (_a) {
91
91
  switch (_a.label) {
92
- case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_CONNECT, { method: method, uuid: uuid })];
92
+ case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_CONNECT, { method: method, uuids: uuids })];
93
93
  case 1:
94
94
  connectResults = _a.sent();
95
95
  return [2 /*return*/, connectResults];
@@ -126,10 +126,10 @@ var RAFT = /** @class */ (function () {
126
126
  /**
127
127
  * Verify correct RAFT is selected for phone app
128
128
  */
129
- RAFT.prototype.verifyRaftPhoneApp = function (discoveredRIC) {
129
+ RAFT.prototype.verifyRaftPhoneApp = function (discoveredDevice) {
130
130
  return __awaiter(this, void 0, void 0, function () {
131
131
  return __generator(this, function (_a) {
132
- return [2 /*return*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_VERIFY_PHONE, { ledLcdColours: this.ledLcdColours, discoveredRIC: discoveredRIC, raftId: this.id })];
132
+ return [2 /*return*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_VERIFY_PHONE, { ledLcdColours: this.ledLcdColours, discoveredDevice: discoveredDevice, raftId: this.id })];
133
133
  });
134
134
  });
135
135
  };
@@ -324,7 +324,7 @@ var RAFT = /** @class */ (function () {
324
324
  return __generator(this, function (_a) {
325
325
  switch (eventEnum) {
326
326
  case RaftInfoEvents.STATE_INFO:
327
- this.raftStateInfo = data.stateInfo;
327
+ this.raftStateInfo = data;
328
328
  break;
329
329
  case RaftInfoEvents.SYSTEM_INFO:
330
330
  this.systemInfo = data.systemInfo;
@@ -13,7 +13,7 @@ var SelfdestructiveMessagePromise = /** @class */ (function () {
13
13
  delete messagePromises[id];
14
14
  };
15
15
  this.reject = function (reason) {
16
- reject(reason);
16
+ resolve(reason); // on purpose resolving instead of rejecting
17
17
  clearTimeout(_this.timeout);
18
18
  delete messagePromises[id];
19
19
  };
@@ -0,0 +1,3 @@
1
+ type Props = {};
2
+ export default function ConnectingLoadingSpinnerModal({}: Props): import("react/jsx-runtime").JSX.Element;
3
+ export {};
@@ -0,0 +1,16 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import styles from "./styles.module.css";
14
+ export default function ConnectingLoadingSpinnerModal(_a) {
15
+ return (_jsx("div", __assign({ className: styles.container }, { children: "This shouldn't take long!" })));
16
+ }
@@ -1,6 +1 @@
1
- import RAFT from "../../../application/RAFTs/RAFT";
2
- type Props = {
3
- connectedRaft?: RAFT;
4
- };
5
- export default function DisconnectConfirmationModal({ connectedRaft }: Props): import("react/jsx-runtime").JSX.Element;
6
- export {};
1
+ export default function DisconnectConfirmationModal(): import("react/jsx-runtime").JSX.Element;
@@ -1,65 +1,8 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
38
2
  import modalState from "../../../state-observables/modal/ModalState";
39
- import { useConnectedRafts } from "../../../store/SelectedRaftContext";
40
3
  import { RED } from "../../../styles/colors";
41
4
  import SimpleButton from "../../disposables/buttons/SimpleButton";
42
5
  import { Container } from "./styles";
43
- export default function DisconnectConfirmationModal(_a) {
44
- var _this = this;
45
- var connectedRaft = _a.connectedRaft;
46
- var removeConnectedRaft = useConnectedRafts().removeConnectedRaft;
47
- var disconnectHandler = function () { return __awaiter(_this, void 0, void 0, function () {
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0:
51
- if (!connectedRaft) {
52
- console.warn("No connected raft found", connectedRaft);
53
- return [2 /*return*/];
54
- }
55
- return [4 /*yield*/, window.applicationManager.disconnectFromRaft(connectedRaft.id)];
56
- case 1:
57
- _a.sent();
58
- removeConnectedRaft(connectedRaft.id);
59
- modalState.closeModal();
60
- return [2 /*return*/];
61
- }
62
- });
63
- }); };
64
- return (_jsxs(Container, { children: [_jsx(SimpleButton, { onClick: function () { return modalState.closeModal(); }, title: "Cancel" }), _jsx(SimpleButton, { onClick: disconnectHandler, title: "Disconnect", colour: RED })] }));
6
+ export default function DisconnectConfirmationModal() {
7
+ return (_jsxs(Container, { children: [_jsx(SimpleButton, { onClick: function () { return modalState.closeModal(false); }, title: "Cancel" }), _jsx(SimpleButton, { onClick: function () { return modalState.closeModal(true); }, title: "Disconnect", colour: RED })] }));
65
8
  }
@@ -71,7 +71,7 @@ function VerificationModal(_a) {
71
71
  return;
72
72
  var signalUpdateTimout = setInterval(function () {
73
73
  setRSSI(connectedRaft.getRSSI());
74
- }, 200);
74
+ }, 1000);
75
75
  return function () { return clearInterval(signalUpdateTimout); };
76
76
  }, [connectedRaft]);
77
77
  var onCancel = function () { return __awaiter(_this, void 0, void 0, function () {
@@ -61,6 +61,7 @@ import isPhoneApp from "../../../utils/phone-app-communication/is-phone-app";
61
61
  import LoadingSpinner from "../../disposables/LoadingSpinner";
62
62
  import { RaftConnectionMethod } from "../../../types/raft";
63
63
  import { useConnectedRafts } from "../../../store/SelectedRaftContext";
64
+ import { ConnManager } from "@robotical/roboticaljs";
64
65
  var SHOW_LOGS = true;
65
66
  var TAG = "VerificationModalPhone";
66
67
  function VerificationModalPhoneApp(_a) {
@@ -92,8 +93,12 @@ function VerificationModalPhoneApp(_a) {
92
93
  case 2:
93
94
  _a.sent();
94
95
  removeConnectedRaft(connectedRaft.id);
95
- _a.label = 3;
96
- case 3:
96
+ return [3 /*break*/, 5];
97
+ case 3: return [4 /*yield*/, window.applicationManager.stopDiscovery()];
98
+ case 4:
99
+ _a.sent();
100
+ _a.label = 5;
101
+ case 5:
97
102
  modalState.closeModal();
98
103
  return [2 /*return*/];
99
104
  }
@@ -115,7 +120,7 @@ function VerificationModalPhoneApp(_a) {
115
120
  setSelectedRICIdx(-1);
116
121
  setConnectedRaft(undefined);
117
122
  if (!window.applicationManager.ricSelectedCb) return [3 /*break*/, 5];
118
- return [4 /*yield*/, window.applicationManager.startDiscovery(window.applicationManager.ricSelectedCb)];
123
+ return [4 /*yield*/, window.applicationManager.startDiscovery(window.applicationManager.ricSelectedCb, [ConnManager.COGUUID, ConnManager.RICUUID])];
119
124
  case 4:
120
125
  _a.sent();
121
126
  _a.label = 5;
@@ -144,7 +149,7 @@ function VerificationModalPhoneApp(_a) {
144
149
  raftConnectingSubscriptionHelper(connectedRaft).unsubscribe();
145
150
  };
146
151
  }, [connectedRaft]);
147
- var onselectRaft = function (raftIdx) { return __awaiter(_this, void 0, void 0, function () {
152
+ var onSelectRaft = function (raftIdx) { return __awaiter(_this, void 0, void 0, function () {
148
153
  var foundRaft, newRaft;
149
154
  return __generator(this, function (_a) {
150
155
  switch (_a.label) {
@@ -178,11 +183,11 @@ function VerificationModalPhoneApp(_a) {
178
183
  }); };
179
184
  var contentJSX = null;
180
185
  if (foundRICs.length === 0) {
181
- contentJSX = _jsxs("div", __assign({ className: "verification-modal-container" }, { children: [!isScanning && _jsx("p", __assign({ style: { alignSelf: 'center' } }, { children: "No Martys 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" })] }))] }));
186
+ 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" })] }))] }));
182
187
  }
183
188
  else {
184
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) {
185
- 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);
190
+ 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);
186
191
  })] })), _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" })] }))] }));
187
192
  }
188
193
  return contentJSX;
@@ -3,5 +3,6 @@ declare class Logger {
3
3
  static error(SHOW_LOGS: boolean, tag: string, message: string): void;
4
4
  static debug(SHOW_LOGS: boolean, tag: string, message: string): void;
5
5
  static warn(SHOW_LOGS: boolean, tag: string, message: string): void;
6
+ static phoneAppLog(SHOW_LOGS: boolean, tag: string, message: string): void;
6
7
  }
7
8
  export default Logger;
@@ -1,17 +1,23 @@
1
+ import { AppSentMessage } from "../../types/communication-between-apps/wrapper-communication";
2
+ var SHOW_LOGS_GLOBAL = true;
1
3
  var Logger = /** @class */ (function () {
2
4
  function Logger() {
3
5
  }
4
6
  Logger.info = function (SHOW_LOGS, tag, message) {
5
- SHOW_LOGS && console.log('\x1b[34m%s\x1b[0m', "INFO: ".concat(tag), message); // Blue color for info logs
7
+ SHOW_LOGS_GLOBAL && SHOW_LOGS && console.log('\x1b[34m%s\x1b[0m', "INFO: ".concat(tag), message); // Blue color for info logs
6
8
  };
7
9
  Logger.error = function (SHOW_LOGS, tag, message) {
8
- SHOW_LOGS && console.error('\x1b[31m%s\x1b[0m', "ERROR: ".concat(tag), message); // Red color for error logs
10
+ SHOW_LOGS_GLOBAL && SHOW_LOGS && console.error('\x1b[31m%s\x1b[0m', "ERROR: ".concat(tag), message); // Red color for error logs
9
11
  };
10
12
  Logger.debug = function (SHOW_LOGS, tag, message) {
11
- SHOW_LOGS && console.debug('\x1b[35m%s\x1b[0m', "DEBUG: ".concat(tag), message); // Magenta color for debug logs
13
+ SHOW_LOGS_GLOBAL && SHOW_LOGS && console.debug('\x1b[35m%s\x1b[0m', "DEBUG: ".concat(tag), message); // Magenta color for debug logs
12
14
  };
13
15
  Logger.warn = function (SHOW_LOGS, tag, message) {
14
- SHOW_LOGS && console.warn('\x1b[33m%s\x1b[0m', "WARN: ".concat(tag), message); // Yellow color for warning logs
16
+ SHOW_LOGS_GLOBAL && SHOW_LOGS && console.warn('\x1b[33m%s\x1b[0m', "WARN: ".concat(tag), message); // Yellow color for warning logs
17
+ };
18
+ Logger.phoneAppLog = function (SHOW_LOGS, tag, message) {
19
+ SHOW_LOGS_GLOBAL && SHOW_LOGS && console.log('\x1b[32m%s\x1b[0m', "PHONE APP: ".concat(tag), message); // Green color for phone app logs
20
+ SHOW_LOGS_GLOBAL && window.wrapperCommunicator.sendMessageNoWait(AppSentMessage.LOG, { showLogs: SHOW_LOGS, tag: tag, message: message });
15
21
  };
16
22
  return Logger;
17
23
  }());
@@ -6,6 +6,7 @@ export type ModalStateData = {
6
6
  modalTitle?: string;
7
7
  newWindowLink?: string;
8
8
  withCloseButton?: boolean;
9
+ withLogo?: boolean;
9
10
  };
10
11
  export interface ModalObservable {
11
12
  subscribe(observer: ModalObserver, topics: Array<ModalEventTopics>): void;
@@ -8,7 +8,7 @@ declare class ModalState implements ModalObservable {
8
8
  private _modalResolve;
9
9
  private _modalReject;
10
10
  constructor();
11
- setModal(modalContent: ModalContentType, modalTitle: string): Promise<ModalReturnValue>;
11
+ setModal(modalContent: ModalContentType, modalTitle: string, withLogo?: boolean): Promise<ModalReturnValue>;
12
12
  closeModal(modalReturnValue?: ModalReturnValue, onCloseCb?: () => void): void;
13
13
  updateModalProps(updatedProps: {
14
14
  modalTitle?: string;
@@ -5,14 +5,15 @@ var ModalState = /** @class */ (function () {
5
5
  this._modalResolve = function () { };
6
6
  this._modalReject = function () { };
7
7
  }
8
- ModalState.prototype.setModal = function (modalContent, modalTitle) {
8
+ ModalState.prototype.setModal = function (modalContent, modalTitle, withLogo) {
9
9
  var _this = this;
10
+ if (withLogo === void 0) { withLogo = true; }
10
11
  this._modalPromise = new Promise(function (resolve, reject) {
11
12
  _this._modalResolve = resolve;
12
13
  _this._modalReject = reject;
13
14
  _this.modalContent = modalContent;
14
15
  _this.modalTitle = modalTitle;
15
- _this.publish("SetModal", { modalContent: modalContent, modalTitle: modalTitle });
16
+ _this.publish("SetModal", { modalContent: modalContent, modalTitle: modalTitle, withLogo: withLogo });
16
17
  });
17
18
  return this._modalPromise;
18
19
  };
@@ -17,6 +17,7 @@ export declare enum AppSentMessage {
17
17
  RAFT_STOP_VERIFY = "RAFT_STOP_VERIFY",
18
18
  RAFT_DISCONNECT = "RAFT_DISCONNECT",
19
19
  RAFT_START_DISCOVERY = "RAFT_START_DISCOVERY",
20
+ RAFT_STOP_DISCOVERY = "RAFT_STOP_DISCOVERY",
20
21
  RAFT_SELECT = "RAFT_SELECT",
21
22
  RAFT_SEND_REST = "RAFT_SEND_REST",
22
23
  GET_MISSED_CONN_EVENT = "GET_MISSED_CONN_EVENT",
@@ -25,7 +26,9 @@ export declare enum AppSentMessage {
25
26
  SAVE_FILE_ON_DEVICE_LOCAL_STORAGE = "SAVE_FILE_ON_DEVICE_LOCAL_STORAGE",
26
27
  LOAD_FILE_FROM_DEVICE_LOCAL_STORAGE = "LOAD_FILE_FROM_DEVICE_LOCAL_STORAGE",
27
28
  DELETE_FILE_FROM_DEVICE_LOCAL_STORAGE = "DELETE_FILE_FROM_DEVICE_LOCAL_STORAGE",
28
- LIST_FILES_FROM_DEVICE_LOCAL_STORAGE = "LIST_FILES_FROM_DEVICE_LOCAL_STORAGE"
29
+ LIST_FILES_FROM_DEVICE_LOCAL_STORAGE = "LIST_FILES_FROM_DEVICE_LOCAL_STORAGE",
30
+ LOG = "LOG",
31
+ INJECT_JS = "INJECT_JS"
29
32
  }
30
33
  export declare enum WrapperSentMessage {
31
34
  RAFT_PUBLISHED_EVENT = "RAFT_PUBLISHED_EVENT",
@@ -8,6 +8,7 @@ export var AppSentMessage;
8
8
  AppSentMessage["RAFT_STOP_VERIFY"] = "RAFT_STOP_VERIFY";
9
9
  AppSentMessage["RAFT_DISCONNECT"] = "RAFT_DISCONNECT";
10
10
  AppSentMessage["RAFT_START_DISCOVERY"] = "RAFT_START_DISCOVERY";
11
+ AppSentMessage["RAFT_STOP_DISCOVERY"] = "RAFT_STOP_DISCOVERY";
11
12
  AppSentMessage["RAFT_SELECT"] = "RAFT_SELECT";
12
13
  AppSentMessage["RAFT_SEND_REST"] = "RAFT_SEND_REST";
13
14
  AppSentMessage["GET_MISSED_CONN_EVENT"] = "GET_MISSED_CONN_EVENT";
@@ -17,6 +18,8 @@ export var AppSentMessage;
17
18
  AppSentMessage["LOAD_FILE_FROM_DEVICE_LOCAL_STORAGE"] = "LOAD_FILE_FROM_DEVICE_LOCAL_STORAGE";
18
19
  AppSentMessage["DELETE_FILE_FROM_DEVICE_LOCAL_STORAGE"] = "DELETE_FILE_FROM_DEVICE_LOCAL_STORAGE";
19
20
  AppSentMessage["LIST_FILES_FROM_DEVICE_LOCAL_STORAGE"] = "LIST_FILES_FROM_DEVICE_LOCAL_STORAGE";
21
+ AppSentMessage["LOG"] = "LOG";
22
+ AppSentMessage["INJECT_JS"] = "INJECT_JS";
20
23
  })(AppSentMessage || (AppSentMessage = {}));
21
24
  export var WrapperSentMessage;
22
25
  (function (WrapperSentMessage) {
@@ -14,7 +14,7 @@ export declare class WrapperAppManager {
14
14
  * @returns Promise<ConnectionAttemptResults>
15
15
  *
16
16
  */
17
- connect(method: RaftConnectionMethod, uuid: string): Promise<ConnectionAttemptResults>;
17
+ connect(method: RaftConnectionMethod, uuids: string[]): Promise<ConnectionAttemptResults>;
18
18
  /**
19
19
  * Re-triggers the connect event which was missed due to the connection logic
20
20
  */
@@ -55,12 +55,12 @@ var WrapperAppManager = /** @class */ (function () {
55
55
  * @returns Promise<ConnectionAttemptResults>
56
56
  *
57
57
  */
58
- WrapperAppManager.prototype.connect = function (method, uuid) {
58
+ WrapperAppManager.prototype.connect = function (method, uuids) {
59
59
  return __awaiter(this, void 0, void 0, function () {
60
60
  var connector, connectionResults;
61
61
  return __generator(this, function (_a) {
62
62
  switch (_a.label) {
63
- case 0: return [4 /*yield*/, ConnectorFactory.connectToRaftHelper(method, uuid)];
63
+ case 0: return [4 /*yield*/, ConnectorFactory.connectToRaftHelper(method, uuids)];
64
64
  case 1:
65
65
  connector = _a.sent();
66
66
  if (!connector) {
@@ -146,7 +146,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
146
146
  return [3 /*break*/, 29];
147
147
  case 2:
148
148
  _b.trys.push([2, 4, , 5]);
149
- return [4 /*yield*/, wrapperAppManager.connect(data.method, data.uuid)];
149
+ return [4 /*yield*/, wrapperAppManager.connect(data.method, data.uuids)];
150
150
  case 3:
151
151
  connectionResults = _b.sent();
152
152
  window.wrapperCommunicator.onMessageResponse({ success: true, error: "", results: connectionResults, messagePromiseId: messagePromiseId });
@@ -7,6 +7,11 @@ import { ConnManager } from "@robotical/roboticaljs";
7
7
  declare class CogConnector extends Connector implements ConnectorInterface {
8
8
  type: RaftTypeE;
9
9
  constructor(raftId: string, connManager: ConnManager);
10
+ /**
11
+ * Publish an event to all observers
12
+ * Set in RICConnector as an event listener callback
13
+ */
14
+ publish(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent | RaftInfoEvents, eventName: string, eventData: any): void;
10
15
  /**
11
16
  * Connect to a RAFT
12
17
  */
@@ -49,10 +49,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
50
  }
51
51
  };
52
+ import { RaftInfoEvents } from "../../../types/events/raft-info";
52
53
  import Logger from "../../../services/logger/Logger";
53
54
  import { RaftTypeE } from "../../../types/raft";
54
55
  import Connector from "../Connector";
55
- import { RaftConnEvent, RaftUpdateEvent } from "@robotical/raftjs";
56
+ import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robotical/raftjs";
57
+ import { CogPublishedDataGetter } from "@robotical/roboticaljs";
58
+ import { WrapperSentMessage } from "../../../types/communication-between-apps/wrapper-communication";
56
59
  var SHOW_LOGS = true;
57
60
  var TAG = "CogConnector";
58
61
  var CogConnector = /** @class */ (function (_super) {
@@ -62,6 +65,19 @@ var CogConnector = /** @class */ (function (_super) {
62
65
  _this.type = RaftTypeE.COG;
63
66
  return _this;
64
67
  }
68
+ /**
69
+ * Publish an event to all observers
70
+ * Set in RICConnector as an event listener callback
71
+ */
72
+ CogConnector.prototype.publish = function (eventType, eventEnum, eventName, eventData) {
73
+ window.WebAppCommunicator.sendMessageNoWait(WrapperSentMessage.RAFT_PUBLISHED_EVENT, { raftId: this.id, eventType: eventType, eventEnum: eventEnum, eventName: eventName, eventData: eventData });
74
+ if (this._observers.hasOwnProperty(eventType)) {
75
+ for (var _i = 0, _a = this._observers[eventType]; _i < _a.length; _i++) {
76
+ var observer = _a[_i];
77
+ observer.notify(eventType, eventEnum, eventName, eventData);
78
+ }
79
+ }
80
+ };
65
81
  /**
66
82
  * Connect to a RAFT
67
83
  */
@@ -163,8 +179,24 @@ var CogConnector = /** @class */ (function (_super) {
163
179
  */
164
180
  CogConnector.prototype.pubEventHandler = function (eventEnum, eventName, data) {
165
181
  return __awaiter(this, void 0, void 0, function () {
182
+ var systemType, stateInfo, simplifiedInfo;
166
183
  return __generator(this, function (_a) {
167
184
  switch (eventEnum) {
185
+ case RaftPublishEvent.PUBLISH_EVENT_DATA:
186
+ systemType = this.connManager.getConnector().getSystemType();
187
+ if (systemType) {
188
+ stateInfo = systemType.getStateInfo();
189
+ if (stateInfo.deviceManager) {
190
+ simplifiedInfo = {
191
+ power: CogPublishedDataGetter.getPowerData(stateInfo.deviceManager),
192
+ accelerometer: CogPublishedDataGetter.getAccelerometerData(stateInfo.deviceManager),
193
+ light: CogPublishedDataGetter.getLightData(stateInfo.deviceManager),
194
+ gyroscope: CogPublishedDataGetter.getGyroscopeData(stateInfo.deviceManager)
195
+ };
196
+ this.publish("raftinfo", RaftInfoEvents.STATE_INFO, "StateInfo", simplifiedInfo);
197
+ }
198
+ }
199
+ break;
168
200
  default:
169
201
  break;
170
202
  }
@@ -1,12 +1,15 @@
1
1
  import { RaftInfoEvents } from "../../types/events/raft-info";
2
2
  import { ConnectionAttemptResults, RaftTypeE } from "../../types/raft";
3
+ import { RaftObserver } from "../../application/RAFTs/RaftObserver";
3
4
  import ConnectorInterface from "./ConnectorInterface";
4
5
  import { ConnManager, RICLedLcdColours } from "@robotical/roboticaljs";
5
6
  import { RaftOKFail, RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@robotical/raftjs";
6
7
  declare class Connector implements ConnectorInterface {
7
8
  id: string;
8
9
  type: RaftTypeE;
9
- private _observers;
10
+ protected _observers: {
11
+ [key: string]: Array<RaftObserver>;
12
+ };
10
13
  connManager: ConnManager;
11
14
  constructor(id: string, connManager: ConnManager);
12
15
  /**
@@ -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, RaftPublishEvent } from "@robotical/raftjs";
41
+ import { RaftConnEvent, RaftUpdateEvent, } from "@robotical/raftjs";
42
42
  var SHOW_LOGS = true;
43
43
  var TAG = "Connector";
44
44
  var Connector = /** @class */ (function () {
@@ -53,11 +53,14 @@ var Connector = /** @class */ (function () {
53
53
  // Set the listener function
54
54
  // Subscribe to connManager events
55
55
  this.connManager.setConnectionEventListener(function (eventType, eventEnum, eventName, eventData) {
56
- if (eventType !== "pub") {
56
+ if (eventType === "pub") {
57
+ // if it's a pub event, we are publishing it from _pubEventHandler method (in child classes)
58
+ }
59
+ else {
57
60
  Logger.info(SHOW_LOGS, TAG, "eventType: ".concat(eventType, " eventEnum: ").concat(eventEnum, " eventName: ").concat(eventName, " eventData: ").concat(eventData));
61
+ _this.publish(eventType, eventEnum, eventName, eventData);
58
62
  }
59
63
  _this.eventHandler(eventType, eventEnum, eventName, eventData);
60
- _this.publish(eventType, eventEnum, eventName, eventData);
61
64
  });
62
65
  }
63
66
  /**
@@ -192,6 +195,10 @@ var Connector = /** @class */ (function () {
192
195
  * Set in RICConnector as an event listener callback
193
196
  */
194
197
  Connector.prototype.publish = function (eventType, eventEnum, eventName, eventData) {
198
+ if (eventType === "raftinfo") {
199
+ // should be handled from child class
200
+ return;
201
+ }
195
202
  window.WebAppCommunicator.sendMessageNoWait(WrapperSentMessage.RAFT_PUBLISHED_EVENT, { raftId: this.id, eventType: eventType, eventEnum: eventEnum, eventName: eventName, eventData: eventData });
196
203
  if (this._observers.hasOwnProperty(eventType)) {
197
204
  for (var _i = 0, _a = this._observers[eventType]; _i < _a.length; _i++) {
@@ -293,16 +300,8 @@ var Connector = /** @class */ (function () {
293
300
  */
294
301
  Connector.prototype._pubEventHandler = function (eventEnum, eventName, data) {
295
302
  return __awaiter(this, void 0, void 0, function () {
296
- var systemType, stateInfo;
297
303
  return __generator(this, function (_a) {
298
304
  switch (eventEnum) {
299
- case RaftPublishEvent.PUBLISH_EVENT_DATA:
300
- systemType = this.connManager.getConnector().getSystemType();
301
- if (systemType) {
302
- stateInfo = systemType.getStateInfo();
303
- this.publish("raftinfo", RaftInfoEvents.STATE_INFO, "StateInfo", { stateInfo: stateInfo });
304
- }
305
- break;
306
305
  default:
307
306
  break;
308
307
  }
@@ -10,6 +10,6 @@ export default class ConnectorFactory {
10
10
  * @returns Promise<ConnectionAttemptResults>
11
11
  *
12
12
  */
13
- static connectToRaftHelper(method: RaftConnectionMethod, uuid: string): Promise<Connector | null>;
13
+ static connectToRaftHelper(method: RaftConnectionMethod, uuids: string[]): Promise<Connector | null>;
14
14
  static createConnector(raftType: string | undefined, connManager: ConnManager): Connector;
15
15
  }
@@ -52,7 +52,7 @@ var ConnectorFactory = /** @class */ (function () {
52
52
  * @returns Promise<ConnectionAttemptResults>
53
53
  *
54
54
  */
55
- ConnectorFactory.connectToRaftHelper = function (method, uuid) {
55
+ ConnectorFactory.connectToRaftHelper = function (method, uuids) {
56
56
  return __awaiter(this, void 0, void 0, function () {
57
57
  var connManager, wasConnected, systemInfo, raftType, connector;
58
58
  return __generator(this, function (_a) {
@@ -60,7 +60,7 @@ var ConnectorFactory = /** @class */ (function () {
60
60
  case 0:
61
61
  connManager = new ConnManager();
62
62
  Logger.info(SHOW_LOGS, TAG, "Connecting to RAFT with method: ".concat(method));
63
- return [4 /*yield*/, connManager.connect(method, "", uuid)];
63
+ return [4 /*yield*/, connManager.connect(method, "", uuids)];
64
64
  case 1:
65
65
  wasConnected = _a.sent();
66
66
  Logger.info(SHOW_LOGS, TAG, "Was connected to RAFT: ".concat(wasConnected));
@@ -7,6 +7,11 @@ import { ConnManager } from "@robotical/roboticaljs";
7
7
  declare class MartyConnector extends Connector implements ConnectorInterface {
8
8
  type: RaftTypeE;
9
9
  constructor(raftId: string, connManager: ConnManager);
10
+ /**
11
+ * Publish an event to all observers
12
+ * Set in RICConnector as an event listener callback
13
+ */
14
+ publish(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent | RaftInfoEvents, eventName: string, eventData: any): void;
10
15
  /**
11
16
  * Connect to a RAFT
12
17
  */