@robotical/webapp-types 3.7.11 → 3.7.13

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.
@@ -9,8 +9,10 @@ import { RaftInfoEvents } from "../../types/events/raft-info";
9
9
  import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, RaftWifiScanResults, RaftWifiConnStatus, RaftOKFail } from "@robotical/raftjs";
10
10
  import { ConnectedRaftItem } from "../../store/SelectedRaftContext";
11
11
  import Toaster from "../../utils/Toaster";
12
- import { AnalyticsManager } from "../../analytics/AnalyticsManager";
12
+ import AnalyticsFacade from "@robotical/appv2-analytics-gatherer";
13
13
  export default class ApplicationManager {
14
+ AnalyticsFacade: typeof AnalyticsFacade;
15
+ analyticsSessionId: string | undefined;
14
16
  private _observers;
15
17
  static wrapperAppCommunicator: WebAppCommunicator;
16
18
  connectedRafts: {
@@ -23,7 +25,6 @@ export default class ApplicationManager {
23
25
  navigateTo(path: string): void;
24
26
  ricSelectedCb: ((raft: RAFT) => void) | null;
25
27
  toaster: typeof Toaster;
26
- analyticsManager: AnalyticsManager;
27
28
  showBackHomeButton: () => void;
28
29
  hideBackHomeButton: () => void;
29
30
  connectedRaftContextMethods: {
@@ -49,7 +49,7 @@ import Logger from "../../services/logger/Logger";
49
49
  import isPhoneApp from "../../utils/phone-app-communication/is-phone-app";
50
50
  import DisconnectConfirmationModal from "../../components/modals/DisconnectConfirmation";
51
51
  import Toaster from "../../utils/Toaster";
52
- import { AnalyticsManager } from "../../analytics/AnalyticsManager";
52
+ import AnalyticsFacade from "@robotical/appv2-analytics-gatherer";
53
53
  import { ConnManager } from "@robotical/roboticaljs";
54
54
  import ConnectingLoadingSpinnerModal from "../../components/modals/ConnectingLoadingSpinnerModal";
55
55
  import draggableModalState from "../../state-observables/modal/DraggableModalState";
@@ -59,6 +59,8 @@ var SHOW_LOGS = true;
59
59
  var TAG = "ApplicationManager";
60
60
  var ApplicationManager = /** @class */ (function () {
61
61
  function ApplicationManager() {
62
+ // Analytics
63
+ this.AnalyticsFacade = AnalyticsFacade;
62
64
  // Observers
63
65
  this._observers = {};
64
66
  // Connected RICs
@@ -81,8 +83,6 @@ var ApplicationManager = /** @class */ (function () {
81
83
  // public sessionDbs = new SessionsDBManager();
82
84
  // toaster
83
85
  this.toaster = Toaster;
84
- // Analytics Manager
85
- this.analyticsManager = AnalyticsManager.getInstance();
86
86
  this.showBackHomeButton = function () { };
87
87
  this.hideBackHomeButton = function () { };
88
88
  // connected raft context methods
@@ -39,6 +39,7 @@ import { RaftTypeE } from "../../types/raft";
39
39
  import { RaftInfoEvents } from "../../types/events/raft-info";
40
40
  import { RaftConnEvent, RaftPublishEvent, } from "@robotical/raftjs";
41
41
  import Logger from "../../services/logger/Logger";
42
+ import randomHashGenerator from "../../utils/helpers/randomHashGenerator";
42
43
  var SHOW_LOGS = true;
43
44
  var TAG = "RAFT";
44
45
  var RAFT = /** @class */ (function () {
@@ -323,20 +324,41 @@ var RAFT = /** @class */ (function () {
323
324
  */
324
325
  RAFT.prototype._connectionEventHandler = function (eventEnum, eventName, data) {
325
326
  return __awaiter(this, void 0, void 0, function () {
327
+ var _this = this;
326
328
  return __generator(this, function (_a) {
327
329
  switch (eventEnum) {
328
330
  case RaftConnEvent.CONN_VERIFIED_CORRECT:
329
- window.applicationManager.analyticsManager.logEvent("connection", { raftType: this.type, systemInfo: this.systemInfo });
331
+ new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
332
+ var robotId, raftType, deviceInfo, sessionId, deviceId;
333
+ return __generator(this, function (_a) {
334
+ switch (_a.label) {
335
+ case 0:
336
+ robotId = this.id;
337
+ raftType = this.type;
338
+ window.applicationManager.AnalyticsFacade.setRaftType(raftType);
339
+ window.applicationManager.AnalyticsFacade.setRobotId(robotId);
340
+ if (!!window.applicationManager.analyticsSessionId) return [3 /*break*/, 2];
341
+ return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.GET_DEVICE_INFO, {})];
342
+ case 1:
343
+ deviceInfo = _a.sent();
344
+ console.log("deviceInfo", deviceInfo);
345
+ sessionId = randomHashGenerator();
346
+ deviceId = deviceInfo.deviceId;
347
+ window.applicationManager.AnalyticsFacade.startSession(sessionId, deviceId, robotId, raftType);
348
+ _a.label = 2;
349
+ case 2:
350
+ resolve(void 0);
351
+ return [2 /*return*/];
352
+ }
353
+ });
354
+ }); });
330
355
  break;
331
356
  case RaftConnEvent.CONN_DISCONNECTED: // this runs when the RAFT is disconnected on its own (due to a timeout or other reasons)
332
357
  window.applicationManager.disconnectGeneric(this, function () { }, true); // disconnects the RAFT and removes it from the connectedRafts list
333
- window.applicationManager.analyticsManager.logEvent("disconnection", { raftType: this.type });
334
358
  break;
335
359
  case RaftConnEvent.CONN_ISSUE_DETECTED:
336
- window.applicationManager.analyticsManager.logEvent("connection_issue", { data: data });
337
360
  break;
338
361
  case RaftConnEvent.CONN_ISSUE_RESOLVED:
339
- window.applicationManager.analyticsManager.logEvent("connection_issue_resolved", { data: data });
340
362
  break;
341
363
  default:
342
364
  break;
@@ -28,7 +28,7 @@ export default function DetailedFeedbackModal(_a) {
28
28
  return;
29
29
  }
30
30
  var reportWithContact = { text: "".concat(email ? email : "Anonymous", ": ").concat(report) };
31
- window.applicationManager.analyticsManager.logEvent("textfeedback", __assign(__assign({}, reportWithContact), otherInfoObject));
31
+ // window.applicationManager.analyticsManager.logEvent("textfeedback", { ...reportWithContact, ...otherInfoObject });
32
32
  setReportSent(true);
33
33
  modalState.updateModalProps({ modalTitle: "🚀" });
34
34
  setTimeout(function () { return modalState.closeModal(); }, 1500);
@@ -30,7 +30,8 @@ export declare enum AppSentMessage {
30
30
  LOG = "LOG",
31
31
  INJECT_JS = "INJECT_JS",
32
32
  MARTY_GET_COMMS_STATS = "MARTY_GET_COMMS_STATS",
33
- MARTY_CALIBRATE_COLOUR_SENSOR = "MARTY_CALIBRATE_COLOUR_SENSOR"
33
+ MARTY_CALIBRATE_COLOUR_SENSOR = "MARTY_CALIBRATE_COLOUR_SENSOR",
34
+ GET_DEVICE_INFO = "GET_DEVICE_INFO"
34
35
  }
35
36
  export declare enum WrapperSentMessage {
36
37
  RAFT_PUBLISHED_EVENT = "RAFT_PUBLISHED_EVENT",
@@ -22,6 +22,7 @@ export var AppSentMessage;
22
22
  AppSentMessage["INJECT_JS"] = "INJECT_JS";
23
23
  AppSentMessage["MARTY_GET_COMMS_STATS"] = "MARTY_GET_COMMS_STATS";
24
24
  AppSentMessage["MARTY_CALIBRATE_COLOUR_SENSOR"] = "MARTY_CALIBRATE_COLOUR_SENSOR";
25
+ AppSentMessage["GET_DEVICE_INFO"] = "GET_DEVICE_INFO";
25
26
  })(AppSentMessage || (AppSentMessage = {}));
26
27
  export var WrapperSentMessage;
27
28
  (function (WrapperSentMessage) {
@@ -0,0 +1,13 @@
1
+ export type UserDeviceInfo = {
2
+ deviceId: string;
3
+ deviceName: string;
4
+ manufacturer: string;
5
+ model: string;
6
+ systemName: string;
7
+ systemVersion: string;
8
+ version: string;
9
+ buildNumber: string;
10
+ bundleId: string;
11
+ isEmulator: boolean;
12
+ isTablet: boolean;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -3,6 +3,7 @@ import { ConnectionAttemptResults, RaftConnectionMethod } from "../types/raft";
3
3
  import Connector from "./connectors/Connector";
4
4
  import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robotical/raftjs";
5
5
  import { RICLedLcdColours } from "@robotical/roboticaljs";
6
+ import { UserDeviceInfo } from "../types/userDeviceInfo";
6
7
  export declare class WrapperAppManager {
7
8
  private connectors;
8
9
  private _observers;
@@ -20,6 +21,10 @@ export declare class WrapperAppManager {
20
21
  *
21
22
  */
22
23
  connect(method: RaftConnectionMethod, uuids: string[]): Promise<ConnectionAttemptResults>;
24
+ /**
25
+ * Gets user's device info
26
+ */
27
+ getDeviceInfo(): UserDeviceInfo;
23
28
  /**
24
29
  * Get Marty Comms stats
25
30
  */
@@ -30,6 +35,9 @@ export declare class WrapperAppManager {
30
35
  msgRoundtripBestMs: number;
31
36
  msgRetries: number;
32
37
  } | undefined;
38
+ aveFileOnDevice(fileName: string, base64: string): boolean;
39
+ deleteFiles(fileName: string, _: string): boolean;
40
+ loadFile(fileName: string, _: string): string | false;
33
41
  /**
34
42
  * Re-triggers the connect event which was missed due to the connection logic
35
43
  */
@@ -39,6 +39,7 @@ import Logger from "../services/logger/Logger";
39
39
  import { RaftConnEvent } from "@robotical/raftjs";
40
40
  import ConnectorFactory from "./connectors/ConnectorFactory";
41
41
  import ColourSensorManualCalibratorMarty from "./utils/ColourSensorManualCalibratorMarty";
42
+ import { getBrowserVersion, getOrGenerateDeviceId, getOSName, isTablet } from "./utils/device-info";
42
43
  var SHOW_LOGS = true;
43
44
  var TAG = "WrapperAppManager";
44
45
  var WrapperAppManager = /** @class */ (function () {
@@ -90,6 +91,25 @@ var WrapperAppManager = /** @class */ (function () {
90
91
  });
91
92
  });
92
93
  };
94
+ /**
95
+ * Gets user's device info
96
+ */
97
+ WrapperAppManager.prototype.getDeviceInfo = function () {
98
+ var info = {
99
+ deviceId: getOrGenerateDeviceId(),
100
+ deviceName: navigator.userAgent,
101
+ manufacturer: "Webapp",
102
+ model: "N/A",
103
+ systemName: getOSName(),
104
+ systemVersion: navigator.userAgent,
105
+ version: getBrowserVersion(),
106
+ buildNumber: "N/A",
107
+ bundleId: window.location.hostname,
108
+ isEmulator: false,
109
+ isTablet: isTablet(),
110
+ };
111
+ return info;
112
+ };
93
113
  /**
94
114
  * Get Marty Comms stats
95
115
  */
@@ -107,6 +127,42 @@ var WrapperAppManager = /** @class */ (function () {
107
127
  }
108
128
  return undefined;
109
129
  };
130
+ WrapperAppManager.prototype.aveFileOnDevice = function (fileName, base64) {
131
+ Logger.info(SHOW_LOGS, TAG, "Saving file on device: ".concat(fileName));
132
+ try {
133
+ window.localStorage.setItem(fileName, base64);
134
+ return true;
135
+ }
136
+ catch (error) {
137
+ Logger.error(SHOW_LOGS, TAG, "Failed to save file on device: ".concat(error));
138
+ return false;
139
+ }
140
+ };
141
+ WrapperAppManager.prototype.deleteFiles = function (fileName, _) {
142
+ Logger.info(SHOW_LOGS, TAG, "Deleting file: ".concat(fileName));
143
+ try {
144
+ window.localStorage.removeItem("".concat(fileName));
145
+ return true;
146
+ }
147
+ catch (error) {
148
+ Logger.error(SHOW_LOGS, TAG, "Failed to delete file: ".concat(error));
149
+ return false;
150
+ }
151
+ };
152
+ WrapperAppManager.prototype.loadFile = function (fileName, _) {
153
+ Logger.info(SHOW_LOGS, TAG, "Loading file: ".concat(fileName));
154
+ try {
155
+ var file = window.localStorage.getItem("".concat(fileName));
156
+ if (file) {
157
+ return file;
158
+ }
159
+ return false;
160
+ }
161
+ catch (error) {
162
+ Logger.error(SHOW_LOGS, TAG, "Failed to load file: ".concat(error));
163
+ return false;
164
+ }
165
+ };
110
166
  /**
111
167
  * Re-triggers the connect event which was missed due to the connection logic
112
168
  */
@@ -38,6 +38,7 @@ import SelfdestructiveMessagePromise from "../../application/communicators/Selfd
38
38
  import Logger from "../../services/logger/Logger";
39
39
  import { AppSentMessage } from "../../types/communication-between-apps/wrapper-communication";
40
40
  import randomHashGenerator from "../../utils/helpers/randomHashGenerator";
41
+ import { loadItem, saveItemOnDevice } from "../utils/localStorageUtils";
41
42
  import wrapperAppManager from "../WrapperAppManager";
42
43
  var SHOW_LOGS = true;
43
44
  var TAG = "WebAppCommunicator";
@@ -115,7 +116,7 @@ var WebAppCommunicator = /** @class */ (function () {
115
116
  }());
116
117
  export default WebAppCommunicator;
117
118
  var receivedMessageHandler = function (receivedMessage, data, messagePromiseId) { return __awaiter(void 0, void 0, void 0, function () {
118
- var _a, connectionResults, error_1, ricName, error_2, verifyResults, error_3, stopVerifyResults, error_4, disconnectResults, error_5, restResults, error_6, missedConnEventResults, streamAudioResults, commsStats, calibrateColourSensorResults, error_7;
119
+ var _a, connectionResults, error_1, ricName, error_2, verifyResults, error_3, stopVerifyResults, error_4, disconnectResults, error_5, restResults, error_6, missedConnEventResults, streamAudioResults, commsStats, calibrateColourSensorResults, error_7, deviceInfoResults, wasSaved, wasSaved, fileContents;
119
120
  return __generator(this, function (_b) {
120
121
  switch (_b.label) {
121
122
  case 0:
@@ -132,8 +133,12 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
132
133
  case AppSentMessage.RAFT_STREAM_AUDIO: return [3 /*break*/, 27];
133
134
  case AppSentMessage.MARTY_GET_COMMS_STATS: return [3 /*break*/, 28];
134
135
  case AppSentMessage.MARTY_CALIBRATE_COLOUR_SENSOR: return [3 /*break*/, 29];
136
+ case AppSentMessage.GET_DEVICE_INFO: return [3 /*break*/, 33];
137
+ case AppSentMessage.SAVE_FILE_ON_DEVICE: return [3 /*break*/, 34];
138
+ case AppSentMessage.SAVE_FILE_ON_DEVICE_LOCAL_STORAGE: return [3 /*break*/, 35];
139
+ case AppSentMessage.LOAD_FILE_FROM_DEVICE_LOCAL_STORAGE: return [3 /*break*/, 36];
135
140
  }
136
- return [3 /*break*/, 33];
141
+ return [3 /*break*/, 37];
137
142
  case 1:
138
143
  try {
139
144
  console.log("3");
@@ -145,7 +150,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
145
150
  catch (error) {
146
151
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
147
152
  }
148
- return [3 /*break*/, 34];
153
+ return [3 /*break*/, 38];
149
154
  case 2:
150
155
  _b.trys.push([2, 4, , 5]);
151
156
  return [4 /*yield*/, wrapperAppManager.connect(data.method, data.uuids)];
@@ -157,7 +162,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
157
162
  error_1 = _b.sent();
158
163
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error_1.message, messagePromiseId: messagePromiseId });
159
164
  return [3 /*break*/, 5];
160
- case 5: return [3 /*break*/, 34];
165
+ case 5: return [3 /*break*/, 38];
161
166
  case 6:
162
167
  _b.trys.push([6, 8, , 9]);
163
168
  return [4 /*yield*/, wrapperAppManager.getRaftName(data.raftId)];
@@ -169,7 +174,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
169
174
  error_2 = _b.sent();
170
175
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error_2.message, messagePromiseId: messagePromiseId });
171
176
  return [3 /*break*/, 9];
172
- case 9: return [3 /*break*/, 34];
177
+ case 9: return [3 /*break*/, 38];
173
178
  case 10:
174
179
  _b.trys.push([10, 12, , 13]);
175
180
  return [4 /*yield*/, wrapperAppManager.verifyRaft(data.ledLcdColours, data.raftId)];
@@ -181,7 +186,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
181
186
  error_3 = _b.sent();
182
187
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error_3.message, messagePromiseId: messagePromiseId });
183
188
  return [3 /*break*/, 13];
184
- case 13: return [3 /*break*/, 34];
189
+ case 13: return [3 /*break*/, 38];
185
190
  case 14:
186
191
  _b.trys.push([14, 16, , 17]);
187
192
  return [4 /*yield*/, wrapperAppManager.stopVerifyingRaft(data.isCorrectRIC, data.raftId)];
@@ -193,7 +198,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
193
198
  error_4 = _b.sent();
194
199
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error_4.message, messagePromiseId: messagePromiseId });
195
200
  return [3 /*break*/, 17];
196
- case 17: return [3 /*break*/, 34];
201
+ case 17: return [3 /*break*/, 38];
197
202
  case 18:
198
203
  _b.trys.push([18, 20, , 21]);
199
204
  return [4 /*yield*/, wrapperAppManager.disconnect(data.raftId)];
@@ -205,7 +210,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
205
210
  error_5 = _b.sent();
206
211
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error_5.message, messagePromiseId: messagePromiseId });
207
212
  return [3 /*break*/, 21];
208
- case 21: return [3 /*break*/, 34];
213
+ case 21: return [3 /*break*/, 38];
209
214
  case 22:
210
215
  _b.trys.push([22, 24, , 25]);
211
216
  return [4 /*yield*/, wrapperAppManager.sendRestMessage(data.msg, data.params, data.raftId)];
@@ -217,7 +222,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
217
222
  error_6 = _b.sent();
218
223
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error_6.message, messagePromiseId: messagePromiseId });
219
224
  return [3 /*break*/, 25];
220
- case 25: return [3 /*break*/, 34];
225
+ case 25: return [3 /*break*/, 38];
221
226
  case 26:
222
227
  try {
223
228
  missedConnEventResults = wrapperAppManager.getMissedConnEvent(data.raftId);
@@ -226,7 +231,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
226
231
  catch (error) {
227
232
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
228
233
  }
229
- return [3 /*break*/, 34];
234
+ return [3 /*break*/, 38];
230
235
  case 27:
231
236
  try {
232
237
  streamAudioResults = wrapperAppManager.streamAudio(data.raftId, data.streamContents, data.clearExisting, data.duration);
@@ -235,7 +240,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
235
240
  catch (error) {
236
241
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
237
242
  }
238
- return [3 /*break*/, 34];
243
+ return [3 /*break*/, 38];
239
244
  case 28:
240
245
  try {
241
246
  commsStats = wrapperAppManager.getCommsStatsMarty(data.raftId);
@@ -244,7 +249,7 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
244
249
  catch (error) {
245
250
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
246
251
  }
247
- return [3 /*break*/, 34];
252
+ return [3 /*break*/, 38];
248
253
  case 29:
249
254
  _b.trys.push([29, 31, , 32]);
250
255
  return [4 /*yield*/, wrapperAppManager.calibrateColourSensorMarty(data.raftId)];
@@ -256,11 +261,52 @@ var receivedMessageHandler = function (receivedMessage, data, messagePromiseId)
256
261
  error_7 = _b.sent();
257
262
  window.wrapperCommunicator.onMessageResponse({ success: false, error: error_7.message, messagePromiseId: messagePromiseId });
258
263
  return [3 /*break*/, 32];
259
- case 32: return [3 /*break*/, 34];
264
+ case 32: return [3 /*break*/, 38];
260
265
  case 33:
266
+ try {
267
+ deviceInfoResults = wrapperAppManager.getDeviceInfo();
268
+ window.wrapperCommunicator.onMessageResponse({ success: true, error: "", results: deviceInfoResults, messagePromiseId: messagePromiseId });
269
+ }
270
+ catch (error) {
271
+ window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
272
+ }
273
+ return [3 /*break*/, 38];
274
+ case 34:
275
+ try {
276
+ wasSaved = saveItemOnDevice(data.fileName, data.base64);
277
+ window.wrapperCommunicator.onMessageResponse({ success: wasSaved, error: "", results: "", messagePromiseId: messagePromiseId });
278
+ }
279
+ catch (error) {
280
+ window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
281
+ }
282
+ return [3 /*break*/, 38];
283
+ case 35:
284
+ try {
285
+ wasSaved = saveItemOnDevice(data.fileName, data.base64);
286
+ window.wrapperCommunicator.onMessageResponse({ success: wasSaved, error: "", results: "", messagePromiseId: messagePromiseId });
287
+ }
288
+ catch (error) {
289
+ window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
290
+ }
291
+ return [3 /*break*/, 38];
292
+ case 36:
293
+ try {
294
+ fileContents = loadItem(data.fileName);
295
+ if (fileContents) {
296
+ window.wrapperCommunicator.onMessageResponse({ success: true, error: "", results: fileContents, messagePromiseId: messagePromiseId });
297
+ }
298
+ else {
299
+ window.wrapperCommunicator.onMessageResponse({ success: false, error: "File not found", messagePromiseId: messagePromiseId });
300
+ }
301
+ }
302
+ catch (error) {
303
+ window.wrapperCommunicator.onMessageResponse({ success: false, error: error.message, messagePromiseId: messagePromiseId });
304
+ }
305
+ return [3 /*break*/, 38];
306
+ case 37:
261
307
  Logger.warn(SHOW_LOGS, TAG, "Unhandled message: ".concat(receivedMessage));
262
- _b.label = 34;
263
- case 34: return [2 /*return*/];
308
+ _b.label = 38;
309
+ case 38: return [2 /*return*/];
264
310
  }
265
311
  });
266
312
  }); };
@@ -0,0 +1,4 @@
1
+ export declare const getOrGenerateDeviceId: () => string;
2
+ export declare const getOSName: () => "Windows" | "MacOS" | "Linux" | "Android" | "iOS" | "Unknown OS";
3
+ export declare const getBrowserVersion: () => string;
4
+ export declare const isTablet: () => boolean;
@@ -0,0 +1,35 @@
1
+ import randomHashGenerator from "../../utils/helpers/randomHashGenerator";
2
+ var DEVICE_ID_KEY = '@robotica/appv2/deviceId';
3
+ export var getOrGenerateDeviceId = function () {
4
+ var deviceId = localStorage.getItem(DEVICE_ID_KEY);
5
+ if (deviceId) {
6
+ return deviceId;
7
+ }
8
+ else {
9
+ var deviceId_1 = randomHashGenerator();
10
+ localStorage.setItem(DEVICE_ID_KEY, deviceId_1);
11
+ return deviceId_1;
12
+ }
13
+ };
14
+ export var getOSName = function () {
15
+ var userAgent = navigator.userAgent;
16
+ if (userAgent.includes("Windows"))
17
+ return "Windows";
18
+ if (userAgent.includes("Mac"))
19
+ return "MacOS";
20
+ if (userAgent.includes("Linux"))
21
+ return "Linux";
22
+ if (userAgent.includes("Android"))
23
+ return "Android";
24
+ if (userAgent.includes("like Mac"))
25
+ return "iOS";
26
+ return "Unknown OS";
27
+ };
28
+ export var getBrowserVersion = function () {
29
+ var userAgent = navigator.userAgent;
30
+ var match = userAgent.match(/(chrome|firefox|safari|opera|edge|msie|trident)\/?\s*(\d+)/i) || [];
31
+ return match[1] ? "".concat(match[1], " ").concat(match[2]) : "Unknown Browser";
32
+ };
33
+ export var isTablet = function () {
34
+ return /iPad|Tablet|Android(?!.*Mobile)/i.test(navigator.userAgent);
35
+ };
@@ -0,0 +1,3 @@
1
+ export declare function saveItemOnDevice(itemName: string, base64: string): boolean;
2
+ export declare function deleteItem(itemName: string): boolean;
3
+ export declare function loadItem(itemName: string): string | false;
@@ -0,0 +1,39 @@
1
+ import Logger from "../../services/logger/Logger";
2
+ var SHOW_LOGS = true;
3
+ var TAG = "LocalStorageUtils";
4
+ export function saveItemOnDevice(itemName, base64) {
5
+ Logger.info(SHOW_LOGS, TAG, "Saving item on device: ".concat(itemName));
6
+ try {
7
+ window.localStorage.setItem(itemName, base64);
8
+ return true;
9
+ }
10
+ catch (error) {
11
+ Logger.error(SHOW_LOGS, TAG, "Failed to save item on device: ".concat(error));
12
+ return false;
13
+ }
14
+ }
15
+ export function deleteItem(itemName) {
16
+ Logger.info(SHOW_LOGS, TAG, "Deleting item: ".concat(itemName));
17
+ try {
18
+ window.localStorage.removeItem(itemName);
19
+ return true;
20
+ }
21
+ catch (error) {
22
+ Logger.error(SHOW_LOGS, TAG, "Failed to delete item: ".concat(error));
23
+ return false;
24
+ }
25
+ }
26
+ export function loadItem(itemName) {
27
+ Logger.info(SHOW_LOGS, TAG, "Loading item: ".concat(itemName));
28
+ try {
29
+ var item = window.localStorage.getItem(itemName);
30
+ if (item) {
31
+ return item;
32
+ }
33
+ return false;
34
+ }
35
+ catch (error) {
36
+ Logger.error(SHOW_LOGS, TAG, "Failed to load item: ".concat(error));
37
+ return false;
38
+ }
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "3.7.11",
3
+ "version": "3.7.13",
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",
@@ -1,28 +0,0 @@
1
- /**
2
- * AnalyticsManager
3
- *
4
- * This class is responsible for managing the analytics services for the testing phase.
5
- * Analytics gathered:
6
- * - Connections
7
- * - Disconnections
8
- * - Visited pages
9
- * - emoji feedback
10
- * - text feedback
11
- *
12
- * Each of them will be stored as an event. They will stored in the order they were received so we can track the user's journey.
13
- * There will be a timestamp for each event.
14
- *
15
- * We store client's id in a cookie so we can track the user's journey.
16
- */
17
- type EventType = "connection" | "disconnection" | "page" | "emojifeedback" | "textfeedback" | "connection_issue" | "connection_issue_resolved";
18
- export declare class AnalyticsManager {
19
- private static instance;
20
- private clientId;
21
- private eventsStorer;
22
- private constructor();
23
- static getInstance(): AnalyticsManager;
24
- private getClientId;
25
- private generateClientId;
26
- logEvent(eventType: EventType, data: any): void;
27
- }
28
- export {};
@@ -1,171 +0,0 @@
1
- /**
2
- * AnalyticsManager
3
- *
4
- * This class is responsible for managing the analytics services for the testing phase.
5
- * Analytics gathered:
6
- * - Connections
7
- * - Disconnections
8
- * - Visited pages
9
- * - emoji feedback
10
- * - text feedback
11
- *
12
- * Each of them will be stored as an event. They will stored in the order they were received so we can track the user's journey.
13
- * There will be a timestamp for each event.
14
- *
15
- * We store client's id in a cookie so we can track the user's journey.
16
- */
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
- 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;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var AnalyticsManager = /** @class */ (function () {
65
- function AnalyticsManager() {
66
- this.clientId = this.getClientId();
67
- this.eventsStorer = new EventsStorer(this.clientId);
68
- }
69
- AnalyticsManager.getInstance = function () {
70
- if (!AnalyticsManager.instance) {
71
- AnalyticsManager.instance = new AnalyticsManager();
72
- }
73
- return AnalyticsManager.instance;
74
- };
75
- AnalyticsManager.prototype.getClientId = function () {
76
- var clientId = localStorage.getItem('@robotical/webapp/analytics/clientId');
77
- if (!clientId) {
78
- clientId = this.generateClientId();
79
- localStorage.setItem('@robotical/webapp/analytics/clientId', clientId);
80
- }
81
- return clientId;
82
- };
83
- AnalyticsManager.prototype.generateClientId = function () {
84
- return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
85
- };
86
- AnalyticsManager.prototype.logEvent = function (eventType, data) {
87
- var event = new AnalyticsEvent(eventType, data);
88
- this.eventsStorer.addEvent(event);
89
- };
90
- return AnalyticsManager;
91
- }());
92
- export { AnalyticsManager };
93
- var AnalyticsEvent = /** @class */ (function () {
94
- function AnalyticsEvent(type, data) {
95
- this.type = type;
96
- this.data = data;
97
- this.isProcessed = false;
98
- this.timestamp = new Date().toString();
99
- this.urlSafeTimestamp = new Date().toISOString().replaceAll("T", "_").replaceAll(":", "-").replaceAll("/", "-").replaceAll(".", "_");
100
- }
101
- AnalyticsEvent.prototype.process = function () {
102
- this.isProcessed = true;
103
- };
104
- return AnalyticsEvent;
105
- }());
106
- var EventsStorer = /** @class */ (function () {
107
- function EventsStorer(clientId) {
108
- this.clientId = clientId;
109
- this.events = [];
110
- this.processing = false;
111
- }
112
- EventsStorer.prototype.addEvent = function (event) {
113
- this.events.push(event);
114
- this._processEvents();
115
- };
116
- EventsStorer.prototype._processEvents = function () {
117
- return __awaiter(this, void 0, void 0, function () {
118
- var _i, _a, event_1;
119
- return __generator(this, function (_b) {
120
- switch (_b.label) {
121
- case 0:
122
- if (this.processing)
123
- return [2 /*return*/];
124
- this.processing = true;
125
- _i = 0, _a = this.events;
126
- _b.label = 1;
127
- case 1:
128
- if (!(_i < _a.length)) return [3 /*break*/, 4];
129
- event_1 = _a[_i];
130
- if (!!event_1.isProcessed) return [3 /*break*/, 3];
131
- this._processEvent(event_1);
132
- return [4 /*yield*/, this._delay(1000)];
133
- case 2:
134
- _b.sent(); // 1 second debounce time
135
- _b.label = 3;
136
- case 3:
137
- _i++;
138
- return [3 /*break*/, 1];
139
- case 4:
140
- this.processing = false;
141
- return [2 /*return*/];
142
- }
143
- });
144
- });
145
- };
146
- EventsStorer.prototype._delay = function (ms) {
147
- return new Promise(function (resolve) { return setTimeout(resolve, ms); });
148
- };
149
- EventsStorer.prototype._processEvent = function (event) {
150
- event.process();
151
- var data = __assign(__assign(__assign({}, event), event.data), { data: undefined, isProcessed: undefined, urlSafeTimestamp: undefined });
152
- var path = "".concat(this.clientId, "/").concat(event.urlSafeTimestamp, "-").concat(event.type);
153
- FirebaseInteractor.put(path, data);
154
- };
155
- return EventsStorer;
156
- }());
157
- var FirebaseInteractor = /** @class */ (function () {
158
- function FirebaseInteractor() {
159
- }
160
- FirebaseInteractor.put = function (path, data) {
161
- fetch("".concat(this.db_href, "/").concat(path, ".json"), {
162
- method: 'PUT',
163
- body: JSON.stringify(data),
164
- headers: {
165
- 'Content-Type': 'application/json'
166
- }
167
- });
168
- };
169
- FirebaseInteractor.db_href = "https://app-v2-analytics-default-rtdb.firebaseio.com";
170
- return FirebaseInteractor;
171
- }());