@robotical/webapp-types 1.0.0 → 1.0.5

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.
@@ -1,4 +1,4 @@
1
- import { RaftConnectionMethod } from "../../types/raft";
1
+ import { RaftConnectionMethod, RaftTypeE } from "../../types/raft";
2
2
  import WebAppCommunicator from "../../wrapper-app/communicators/WebAppCommunicator";
3
3
  import RAFT from "../RAFTs/RAFT";
4
4
  import Marty from "../RAFTs/Marty/Marty";
@@ -15,8 +15,11 @@ export default class ApplicationManager {
15
15
  connectedRafts: {
16
16
  [key: string]: RAFT;
17
17
  };
18
+ connectedRaftsContext: ConnectedRaftItem[];
18
19
  ricSelectedCb: ((raft: RAFT) => void) | null;
19
20
  toaster: typeof Toaster;
21
+ showBackHomeButton: () => void;
22
+ hideBackHomeButton: () => void;
20
23
  connectedRaftContextMethods: {
21
24
  addConnectedRaft: (connectedRaft: ConnectedRaftItem) => void;
22
25
  removeConnectedRaft: (connectedRaftId: string) => void;
@@ -26,12 +29,14 @@ export default class ApplicationManager {
26
29
  constructor();
27
30
  createNewCog(id: string): Cog;
28
31
  createNewMarty(id: string): Marty;
32
+ connectGenericMarty(afterRaftConnectedCb: (raft: RAFT) => void): Promise<void>;
33
+ connectGenericCog(afterRaftConnectedCb: (raft: RAFT) => void): Promise<void>;
29
34
  /**
30
35
  * Generic Connect method
31
36
  * This method is called from various environments (connection button, blocksjr, blocks etc.)
32
37
  * Known issue: connecting to a raft from within a platform won't add the newly connected raft to the connectedRafts hook
33
38
  */
34
- connectGeneric(afterRaftConnectedCb: (raft: RAFT) => void): Promise<void>;
39
+ connectGeneric(afterRaftConnectedCb: (raft: RAFT) => void, uuid: string): Promise<void>;
35
40
  /**
36
41
  * Disconnect from RAFT generic
37
42
  * This method is called from various environments (connection button, blocksjr, blocks etc.)
@@ -41,7 +46,7 @@ export default class ApplicationManager {
41
46
  * Selects a RAFT in Phone's verification modal
42
47
  */
43
48
  selectRaft(ricToConnectTo: FOUND_RAFT_ON_DISCOVERY_RESPONSE['foundRIC'], method: RaftConnectionMethod): Promise<RAFT | null>;
44
- connectToRIC(method: RaftConnectionMethod): Promise<RAFT | null>;
49
+ connectToRIC(method: RaftConnectionMethod, uuid: string): Promise<RAFT | null>;
45
50
  /**
46
51
  * Disconnect from RAFT
47
52
  */
@@ -88,4 +93,5 @@ export default class ApplicationManager {
88
93
  * List the files from the device's local storage
89
94
  */
90
95
  listFilesFromDeviceLocalStorage(dirname: string): Promise<unknown>;
96
+ getTheCurrentlySelectedDeviceOrFirstOfItsKind(deviceType: RaftTypeE): RAFT | undefined;
91
97
  }
@@ -45,6 +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 { RaftChannelBLE, } from "@robdobsn/raftjs";
48
49
  import Logger from "../../services/logger/Logger";
49
50
  import isPhoneApp from "../../utils/phone-app-communication/is-phone-app";
50
51
  import DisconnectConfirmationModal from "../../components/modals/DisconnectConfirmation";
@@ -57,6 +58,7 @@ var ApplicationManager = /** @class */ (function () {
57
58
  this._observers = {};
58
59
  // Connected RICs
59
60
  this.connectedRafts = {};
61
+ this.connectedRaftsContext = [];
60
62
  // Callback to call when a RAFT is selected (Phone App only)
61
63
  // We need that to make sure the connection button gets the selected RAFT once the user selects one
62
64
  this.ricSelectedCb = null;
@@ -73,6 +75,8 @@ var ApplicationManager = /** @class */ (function () {
73
75
  // public sessionDbs = new SessionsDBManager();
74
76
  // toaster
75
77
  this.toaster = Toaster;
78
+ this.showBackHomeButton = function () { };
79
+ this.hideBackHomeButton = function () { };
76
80
  // connected raft context methods
77
81
  this.connectedRaftContextMethods = {
78
82
  addConnectedRaft: function (connectedRaft) { },
@@ -82,6 +86,8 @@ var ApplicationManager = /** @class */ (function () {
82
86
  this.isPhoneApp = isPhoneApp;
83
87
  // super();
84
88
  // AnalyticsManager.appStartSession();
89
+ this.connectGenericMarty = this.connectGenericMarty.bind(this);
90
+ this.connectGenericCog = this.connectGenericCog.bind(this);
85
91
  }
86
92
  ApplicationManager.prototype.createNewCog = function (id) {
87
93
  return new Cog(id);
@@ -89,12 +95,26 @@ var ApplicationManager = /** @class */ (function () {
89
95
  ApplicationManager.prototype.createNewMarty = function (id) {
90
96
  return new Marty(id);
91
97
  };
98
+ ApplicationManager.prototype.connectGenericMarty = function (afterRaftConnectedCb) {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, RaftChannelBLE.RICServiceUUID)];
102
+ });
103
+ });
104
+ };
105
+ ApplicationManager.prototype.connectGenericCog = function (afterRaftConnectedCb) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ return __generator(this, function (_a) {
108
+ return [2 /*return*/, this.connectGeneric(afterRaftConnectedCb, RaftChannelBLE.CogServiceUUID)];
109
+ });
110
+ });
111
+ };
92
112
  /**
93
113
  * Generic Connect method
94
114
  * This method is called from various environments (connection button, blocksjr, blocks etc.)
95
115
  * Known issue: connecting to a raft from within a platform won't add the newly connected raft to the connectedRafts hook
96
116
  */
97
- ApplicationManager.prototype.connectGeneric = function (afterRaftConnectedCb) {
117
+ ApplicationManager.prototype.connectGeneric = function (afterRaftConnectedCb, uuid) {
98
118
  return __awaiter(this, void 0, void 0, function () {
99
119
  var e_1, newRaft, e_2;
100
120
  var _this = this;
@@ -119,7 +139,7 @@ var ApplicationManager = /** @class */ (function () {
119
139
  case 4: return [3 /*break*/, 8];
120
140
  case 5:
121
141
  _a.trys.push([5, 7, , 8]);
122
- return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE)];
142
+ return [4 /*yield*/, window.applicationManager.connectToRIC(RaftConnectionMethod.WEB_BLE, uuid)];
123
143
  case 6:
124
144
  newRaft = _a.sent();
125
145
  if (newRaft) {
@@ -215,13 +235,13 @@ var ApplicationManager = /** @class */ (function () {
215
235
  });
216
236
  });
217
237
  };
218
- ApplicationManager.prototype.connectToRIC = function (method) {
238
+ ApplicationManager.prototype.connectToRIC = function (method, uuid) {
219
239
  var _a, _b;
220
240
  return __awaiter(this, void 0, void 0, function () {
221
241
  var wasConnectedObj, raftId, raftType, raft;
222
242
  return __generator(this, function (_c) {
223
243
  switch (_c.label) {
224
- case 0: return [4 /*yield*/, RAFT.connect(method)];
244
+ case 0: return [4 /*yield*/, RAFT.connect(method, uuid)];
225
245
  case 1:
226
246
  wasConnectedObj = _c.sent();
227
247
  if (!wasConnectedObj.success) return [3 /*break*/, 3];
@@ -441,6 +461,40 @@ var ApplicationManager = /** @class */ (function () {
441
461
  });
442
462
  });
443
463
  };
464
+ /*======== END OF NATIVE COMMANDS ONLY ========*/
465
+ //======================//
466
+ /* UI */
467
+ //======================//
468
+ //======================//
469
+ /* HELPERS */
470
+ //======================//
471
+ ApplicationManager.prototype.getTheCurrentlySelectedDeviceOrFirstOfItsKind = function (deviceType) {
472
+ var _a;
473
+ // checks if the currently selected device is a deviceType and returns it
474
+ // if not, returns the first deviceType in the list (if there is one)
475
+ var currentlySelectedId = (_a = this.connectedRaftsContext.find(function (connectedRaft) { return connectedRaft.isSelected; })) === null || _a === void 0 ? void 0 : _a.id;
476
+ if (currentlySelectedId) {
477
+ var selectedRaft = this.connectedRafts[currentlySelectedId];
478
+ if (!selectedRaft) {
479
+ return;
480
+ }
481
+ if (selectedRaft.type === deviceType) {
482
+ // the currently selected device is a cog, return it
483
+ return selectedRaft;
484
+ }
485
+ else {
486
+ // the currently selected device is not a cog, find the first cog in the list
487
+ var fistCog = void 0;
488
+ for (var raftId in this.connectedRafts) {
489
+ if (this.connectedRafts[raftId].type === deviceType) {
490
+ fistCog = this.connectedRafts[raftId];
491
+ break;
492
+ }
493
+ }
494
+ return fistCog;
495
+ }
496
+ }
497
+ };
444
498
  // Communicator to the wrapper app
445
499
  ApplicationManager.wrapperAppCommunicator = new WebAppCommunicator();
446
500
  return ApplicationManager;
@@ -90,7 +90,7 @@ var Cog = /** @class */ (function (_super) {
90
90
  */
91
91
  Cog.prototype.getBatteryStrength = function () {
92
92
  var _a;
93
- return ((_a = this.raftStateInfo) === null || _a === void 0 ? void 0 : _a.Power.battV) || 0;
93
+ return ((_a = this.raftStateInfo) === null || _a === void 0 ? void 0 : _a.Power.battV) ? Math.round(this.raftStateInfo.Power.battV * 100) : 0;
94
94
  };
95
95
  /**
96
96
  * This methods handles RAFT events coming from the RICConnector of the wrapper
@@ -131,7 +131,7 @@ var Cog = /** @class */ (function (_super) {
131
131
  return __awaiter(this, void 0, void 0, function () {
132
132
  return __generator(this, function (_a) {
133
133
  switch (_a.label) {
134
- case 0: return [4 /*yield*/, this.sendRestMessage('led//color/#ff8585')];
134
+ case 0: return [4 /*yield*/, this.sendRestMessage('led/ring/color/#ff8585')];
135
135
  case 1:
136
136
  _a.sent();
137
137
  return [4 /*yield*/, this.sendRestMessage('audio/rtttl/NoteASharp:d=4,o=6,b=600:a#')];
@@ -140,7 +140,7 @@ var Cog = /** @class */ (function (_super) {
140
140
  return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
141
141
  case 3:
142
142
  _a.sent();
143
- return [4 /*yield*/, this.sendRestMessage('led//color/#000000')];
143
+ return [4 /*yield*/, this.sendRestMessage('led/ring/color/#000000')];
144
144
  case 4:
145
145
  _a.sent();
146
146
  return [2 /*return*/];
@@ -29,7 +29,7 @@ export default class RAFT implements RICInterface {
29
29
  * Connect to a RAFT
30
30
  * We first connect, then we discover the raft type, and then we create the appopriate raft instance
31
31
  */
32
- static connect(method: RaftConnectionMethod): Promise<ConnectionAttemptResults>;
32
+ static connect(method: RaftConnectionMethod, uuid: string): Promise<ConnectionAttemptResults>;
33
33
  /**
34
34
  * Disconnect from a RAFT
35
35
  */
@@ -85,12 +85,12 @@ var RAFT = /** @class */ (function () {
85
85
  * Connect to a RAFT
86
86
  * We first connect, then we discover the raft type, and then we create the appopriate raft instance
87
87
  */
88
- RAFT.connect = function (method) {
88
+ RAFT.connect = function (method, uuid) {
89
89
  return __awaiter(this, void 0, void 0, function () {
90
90
  var connectResults;
91
91
  return __generator(this, function (_a) {
92
92
  switch (_a.label) {
93
- case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_CONNECT, { method: method })];
93
+ case 0: return [4 /*yield*/, window.wrapperCommunicator.sendMessageAndWait(AppSentMessage.RAFT_CONNECT, { method: method, uuid: uuid })];
94
94
  case 1:
95
95
  connectResults = _a.sent();
96
96
  return [2 /*return*/, connectResults];
@@ -49,6 +49,9 @@ export var ConnectedRaftContentProvider = function (_a) {
49
49
  };
50
50
  }
51
51
  }, []);
52
+ useEffect(function () {
53
+ window.applicationManager.connectedRaftsContext = connectedRafts;
54
+ }, [connectedRafts]);
52
55
  var addConnectedRaft = function (connectedRaft) {
53
56
  // if the new raft is already in the list, do not add it again, just select it
54
57
  var existingRaft = connectedRafts.find(function (connectedRaft_) { return connectedRaft_.id === connectedRaft.id; });
@@ -14,7 +14,7 @@ export declare class WrapperAppManager {
14
14
  * @returns Promise<ConnectionAttemptResults>
15
15
  *
16
16
  */
17
- connect(method: RaftConnectionMethod): Promise<ConnectionAttemptResults>;
17
+ connect(method: RaftConnectionMethod, uuid: 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) {
58
+ WrapperAppManager.prototype.connect = function (method, uuid) {
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)];
63
+ case 0: return [4 /*yield*/, ConnectorFactory.connectToRaftHelper(method, uuid)];
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)];
149
+ return [4 /*yield*/, wrapperAppManager.connect(data.method, data.uuid)];
150
150
  case 3:
151
151
  connectionResults = _b.sent();
152
152
  window.wrapperCommunicator.onMessageResponse({ success: true, error: "", results: connectionResults, messagePromiseId: messagePromiseId });
@@ -10,6 +10,6 @@ export default class ConnectorFactory {
10
10
  * @returns Promise<ConnectionAttemptResults>
11
11
  *
12
12
  */
13
- static connectToRaftHelper(method: RaftConnectionMethod): Promise<Connector | null>;
13
+ static connectToRaftHelper(method: RaftConnectionMethod, uuid: 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) {
55
+ ConnectorFactory.connectToRaftHelper = function (method, uuid) {
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, "")];
63
+ return [4 /*yield*/, connManager.connect(method, "", uuid)];
64
64
  case 1:
65
65
  wasConnected = _a.sent();
66
66
  Logger.info(SHOW_LOGS, TAG, "Was connected to RAFT: ".concat(wasConnected));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "1.0.0",
3
+ "version": "1.0.5",
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",