@robotical/webapp-types 1.0.0
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.
- package/application-manager.ts +20 -0
- package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +91 -0
- package/dist-types/src/application/ApplicationManager/ApplicationManager.js +448 -0
- package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +39 -0
- package/dist-types/src/application/RAFTs/Cog/Cog.js +171 -0
- package/dist-types/src/application/RAFTs/Marty/Marty.d.ts +40 -0
- package/dist-types/src/application/RAFTs/Marty/Marty.js +179 -0
- package/dist-types/src/application/RAFTs/RAFT.d.ts +109 -0
- package/dist-types/src/application/RAFTs/RAFT.js +313 -0
- package/dist-types/src/application/RAFTs/RAFTInterface.d.ts +13 -0
- package/dist-types/src/application/RAFTs/RAFTInterface.js +6 -0
- package/dist-types/src/application/RAFTs/RaftObserver.d.ts +10 -0
- package/dist-types/src/application/RAFTs/RaftObserver.js +1 -0
- package/dist-types/src/application/RAFTs/raft-subscription-helpers.d.ts +59 -0
- package/dist-types/src/application/RAFTs/raft-subscription-helpers.js +324 -0
- package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.d.ts +10 -0
- package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.js +31 -0
- package/dist-types/src/application/communicators/WrapperCommunicator.d.ts +24 -0
- package/dist-types/src/application/communicators/WrapperCommunicator.js +137 -0
- package/dist-types/src/components/disposables/LoadingSpinner/index.d.ts +7 -0
- package/dist-types/src/components/disposables/LoadingSpinner/index.js +29 -0
- package/dist-types/src/components/disposables/buttons/SVGImageButton/index.d.ts +14 -0
- package/dist-types/src/components/disposables/buttons/SVGImageButton/index.js +19 -0
- package/dist-types/src/components/disposables/buttons/SimpleButton/index.d.ts +14 -0
- package/dist-types/src/components/disposables/buttons/SimpleButton/index.js +18 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/index.d.ts +6 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/index.js +63 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/styles.d.ts +1 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/styles.js +7 -0
- package/dist-types/src/components/modals/InUnplugged/index.d.ts +1 -0
- package/dist-types/src/components/modals/InUnplugged/index.js +12 -0
- package/dist-types/src/components/modals/InUnplugged/styles.d.ts +5 -0
- package/dist-types/src/components/modals/InUnplugged/styles.js +11 -0
- package/dist-types/src/components/modals/VerificationModal/index.d.ts +6 -0
- package/dist-types/src/components/modals/VerificationModal/index.js +124 -0
- package/dist-types/src/components/modals/VerificationModalPhoneApp/index.d.ts +6 -0
- package/dist-types/src/components/modals/VerificationModalPhoneApp/index.js +190 -0
- package/dist-types/src/components/oneoffs/LEDs/index.d.ts +8 -0
- package/dist-types/src/components/oneoffs/LEDs/index.js +39 -0
- package/dist-types/src/components/oneoffs/RICSignal/index.d.ts +7 -0
- package/dist-types/src/components/oneoffs/RICSignal/index.js +29 -0
- package/dist-types/src/services/logger/Logger.d.ts +7 -0
- package/dist-types/src/services/logger/Logger.js +19 -0
- package/dist-types/src/state-observables/modal/ModalObserver.d.ts +17 -0
- package/dist-types/src/state-observables/modal/ModalObserver.js +1 -0
- package/dist-types/src/state-observables/modal/ModalState.d.ts +24 -0
- package/dist-types/src/state-observables/modal/ModalState.js +69 -0
- package/dist-types/src/store/SelectedRaftContext.d.ts +17 -0
- package/dist-types/src/store/SelectedRaftContext.js +80 -0
- package/dist-types/src/styles/colors.d.ts +35 -0
- package/dist-types/src/styles/colors.js +42 -0
- package/dist-types/src/types/communication-between-apps/wrapper-communication.d.ts +45 -0
- package/dist-types/src/types/communication-between-apps/wrapper-communication.js +25 -0
- package/dist-types/src/types/events/raft-info.d.ts +10 -0
- package/dist-types/src/types/events/raft-info.js +11 -0
- package/dist-types/src/types/phone-app-communicator.d.ts +20 -0
- package/dist-types/src/types/phone-app-communicator.js +5 -0
- package/dist-types/src/types/raft.d.ts +18 -0
- package/dist-types/src/types/raft.js +14 -0
- package/dist-types/src/utils/Toaster.d.ts +13 -0
- package/dist-types/src/utils/Toaster.js +38 -0
- package/dist-types/src/utils/helpers/compare-version.d.ts +2 -0
- package/dist-types/src/utils/helpers/compare-version.js +19 -0
- package/dist-types/src/utils/helpers/randomHashGenerator.d.ts +1 -0
- package/dist-types/src/utils/helpers/randomHashGenerator.js +10 -0
- package/dist-types/src/utils/helpers/rescale-range.d.ts +2 -0
- package/dist-types/src/utils/helpers/rescale-range.js +4 -0
- package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.d.ts +3 -0
- package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.js +34 -0
- package/dist-types/src/utils/phone-app-communication/is-phone-app.d.ts +5 -0
- package/dist-types/src/utils/phone-app-communication/is-phone-app.js +7 -0
- package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +58 -0
- package/dist-types/src/wrapper-app/WrapperAppManager.js +176 -0
- package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.d.ts +24 -0
- package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +243 -0
- package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.d.ts +35 -0
- package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.js +177 -0
- package/dist-types/src/wrapper-app/connectors/Connector.d.ts +69 -0
- package/dist-types/src/wrapper-app/connectors/Connector.js +315 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorFactory.d.ts +15 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorFactory.js +99 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorInterface.d.ts +10 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorInterface.js +6 -0
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.d.ts +35 -0
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +219 -0
- package/dist-types/types-package/application-manager.d.ts +17 -0
- package/dist-types/types-package/application-manager.js +5 -0
- package/package.json +13 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { RaftConnEvent } from "@robdobsn/raftjs";
|
|
2
|
+
/**
|
|
3
|
+
* Connection Verifying Subscription Helper
|
|
4
|
+
*/
|
|
5
|
+
export var raftConnectingSubscriptionHelper = function (raft) {
|
|
6
|
+
var observer = null;
|
|
7
|
+
return {
|
|
8
|
+
subscribe: function (callback) {
|
|
9
|
+
observer = raftConnectingSubscriptionObserver_(callback);
|
|
10
|
+
raft.subscribe(observer, ["conn"]);
|
|
11
|
+
},
|
|
12
|
+
unsubscribe: function () {
|
|
13
|
+
if (observer) {
|
|
14
|
+
raft.unsubscribe(observer);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
var raftConnectingSubscriptionObserver_ = function (callback) {
|
|
20
|
+
return {
|
|
21
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
22
|
+
switch (eventType) {
|
|
23
|
+
// case "conn":
|
|
24
|
+
// switch (eventEnum) {
|
|
25
|
+
// case RaftConnEvent.BLE_VERIFYING_CORRECT:
|
|
26
|
+
// callback(eventData.bondingColors);
|
|
27
|
+
// break;
|
|
28
|
+
// default:
|
|
29
|
+
// break;
|
|
30
|
+
// }
|
|
31
|
+
// break;
|
|
32
|
+
case "conn":
|
|
33
|
+
switch (eventEnum) {
|
|
34
|
+
case RaftConnEvent.CONN_VERIFYING_CORRECT:
|
|
35
|
+
callback(eventData);
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* RAFT Connected Subscription Helper
|
|
47
|
+
*/
|
|
48
|
+
export var raftConnectedSubscriptionHelper = function (raft) {
|
|
49
|
+
var observer = null;
|
|
50
|
+
return {
|
|
51
|
+
subscribe: function (callback) {
|
|
52
|
+
observer = raftConnectedSubscriptionObserver_(callback);
|
|
53
|
+
raft.subscribe(observer, ["conn"]);
|
|
54
|
+
},
|
|
55
|
+
unsubscribe: function () {
|
|
56
|
+
if (observer) {
|
|
57
|
+
raft.unsubscribe(observer);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var raftConnectedSubscriptionObserver_ = function (callback) {
|
|
63
|
+
return {
|
|
64
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
65
|
+
switch (eventType) {
|
|
66
|
+
// case "conn":
|
|
67
|
+
// switch (eventEnum) {
|
|
68
|
+
// case RaftConnEvent.BLE_CONNECTED:
|
|
69
|
+
// console.log("Marty Connected!!!!!!!!!");
|
|
70
|
+
// callback();
|
|
71
|
+
// break;
|
|
72
|
+
// default:
|
|
73
|
+
// break;
|
|
74
|
+
// }
|
|
75
|
+
// break;
|
|
76
|
+
case "conn":
|
|
77
|
+
switch (eventEnum) {
|
|
78
|
+
case RaftConnEvent.CONN_CONNECTED:
|
|
79
|
+
console.log("Marty Connected!!!!!!!!!");
|
|
80
|
+
callback();
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* RAFT Disconnected Subscription Helper
|
|
92
|
+
*/
|
|
93
|
+
export var raftDisconnectedSubscriptionHelper = function (raft) {
|
|
94
|
+
var observer = null;
|
|
95
|
+
return {
|
|
96
|
+
subscribe: function (callback) {
|
|
97
|
+
observer = raftDisconnectedSubscriptionObserver_(callback);
|
|
98
|
+
raft.subscribe(observer, ["conn"]);
|
|
99
|
+
},
|
|
100
|
+
unsubscribe: function () {
|
|
101
|
+
if (observer) {
|
|
102
|
+
raft.unsubscribe(observer);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
var raftDisconnectedSubscriptionObserver_ = function (callback) {
|
|
108
|
+
return {
|
|
109
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
110
|
+
switch (eventType) {
|
|
111
|
+
// case "conn":
|
|
112
|
+
// switch (eventEnum) {
|
|
113
|
+
// case RaftConnEvent.BLE_DISCONNECTED:
|
|
114
|
+
// console.log("Marty Disconnected!!!!!!!!!");
|
|
115
|
+
// callback();
|
|
116
|
+
// break;
|
|
117
|
+
// default:
|
|
118
|
+
// break;
|
|
119
|
+
// }
|
|
120
|
+
// break;
|
|
121
|
+
case "conn":
|
|
122
|
+
switch (eventEnum) {
|
|
123
|
+
case RaftConnEvent.CONN_DISCONNECTED:
|
|
124
|
+
console.log("Marty Disconnected!!!!!!!!!");
|
|
125
|
+
callback();
|
|
126
|
+
break;
|
|
127
|
+
default:
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* RAFT Verified Subscription Helper
|
|
137
|
+
*/
|
|
138
|
+
export var raftVerifiedSubscriptionHelper = function (raft) {
|
|
139
|
+
var observer = null;
|
|
140
|
+
return {
|
|
141
|
+
subscribe: function (callback) {
|
|
142
|
+
observer = raftVerifiedSubscriptionObserver_(callback);
|
|
143
|
+
raft.subscribe(observer, ["conn"]);
|
|
144
|
+
},
|
|
145
|
+
unsubscribe: function () {
|
|
146
|
+
if (observer) {
|
|
147
|
+
raft.unsubscribe(observer);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
var raftVerifiedSubscriptionObserver_ = function (callback) {
|
|
153
|
+
return {
|
|
154
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
155
|
+
switch (eventType) {
|
|
156
|
+
// case "conn":
|
|
157
|
+
// switch (eventEnum) {
|
|
158
|
+
// case RaftConnEvent.BLE_VERIFIED_CORRECT:
|
|
159
|
+
// callback();
|
|
160
|
+
// break;
|
|
161
|
+
// default:
|
|
162
|
+
// break;
|
|
163
|
+
// }
|
|
164
|
+
// break;
|
|
165
|
+
case "conn":
|
|
166
|
+
switch (eventEnum) {
|
|
167
|
+
case RaftConnEvent.CONN_VERIFIED_CORRECT:
|
|
168
|
+
callback();
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Subscription Helper for raftFound event
|
|
180
|
+
* ApplicationManager
|
|
181
|
+
*/
|
|
182
|
+
export var raftFoundSubscriptionHelper = function () {
|
|
183
|
+
var observer = null;
|
|
184
|
+
return {
|
|
185
|
+
subscribe: function (callback) {
|
|
186
|
+
observer = raftFoundSubscriptionObserver_(callback);
|
|
187
|
+
window.applicationManager.subscribe(observer, ["conn"]);
|
|
188
|
+
},
|
|
189
|
+
unsubscribe: function () {
|
|
190
|
+
if (observer) {
|
|
191
|
+
window.applicationManager.unsubscribe(observer);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
var raftFoundSubscriptionObserver_ = function (callback) {
|
|
197
|
+
return {
|
|
198
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
199
|
+
switch (eventType) {
|
|
200
|
+
case "conn":
|
|
201
|
+
switch (eventEnum) {
|
|
202
|
+
case RaftConnEvent.BLE_DEVICE_FOUND:
|
|
203
|
+
callback(eventData);
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Subscription Helper for raftDiscoveryFinished event
|
|
215
|
+
*/
|
|
216
|
+
export var raftDiscoveryFinishedSubscriptionHelper = function () {
|
|
217
|
+
var observer = null;
|
|
218
|
+
return {
|
|
219
|
+
subscribe: function (callback) {
|
|
220
|
+
observer = raftDiscoveryFinishedSubscriptionObserver_(callback);
|
|
221
|
+
window.applicationManager.subscribe(observer, ["conn"]);
|
|
222
|
+
},
|
|
223
|
+
unsubscribe: function () {
|
|
224
|
+
if (observer) {
|
|
225
|
+
window.applicationManager.unsubscribe(observer);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
var raftDiscoveryFinishedSubscriptionObserver_ = function (callback) {
|
|
231
|
+
return {
|
|
232
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
233
|
+
switch (eventType) {
|
|
234
|
+
case "conn":
|
|
235
|
+
switch (eventEnum) {
|
|
236
|
+
case RaftConnEvent.BLE_SCANNING_FINISHED:
|
|
237
|
+
callback(eventData);
|
|
238
|
+
break;
|
|
239
|
+
default:
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Subscription Helper for raftDiscoveryStarted event
|
|
249
|
+
*/
|
|
250
|
+
export var raftDiscoveryStartedSubscriptionHelper = function () {
|
|
251
|
+
var observer = null;
|
|
252
|
+
return {
|
|
253
|
+
subscribe: function (callback) {
|
|
254
|
+
observer = raftDiscoveryStartedSubscriptionObserver_(callback);
|
|
255
|
+
window.applicationManager.subscribe(observer, ["conn"]);
|
|
256
|
+
},
|
|
257
|
+
unsubscribe: function () {
|
|
258
|
+
if (observer) {
|
|
259
|
+
window.applicationManager.unsubscribe(observer);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
var raftDiscoveryStartedSubscriptionObserver_ = function (callback) {
|
|
265
|
+
return {
|
|
266
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
267
|
+
switch (eventType) {
|
|
268
|
+
case "conn":
|
|
269
|
+
switch (eventEnum) {
|
|
270
|
+
case RaftConnEvent.BLE_SCANNING_STARTED:
|
|
271
|
+
callback(eventData);
|
|
272
|
+
break;
|
|
273
|
+
default:
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Subscription Helper for raftRejected event
|
|
283
|
+
* This event is triggered when the RAFT is rejected during the verification process
|
|
284
|
+
*/
|
|
285
|
+
export var raftRejectedSubscriptionHelper = function (raft) {
|
|
286
|
+
var observer = null;
|
|
287
|
+
return {
|
|
288
|
+
subscribe: function (callback) {
|
|
289
|
+
observer = raftRejectedSubscriptionObserver_(callback);
|
|
290
|
+
raft.subscribe(observer, ["conn"]);
|
|
291
|
+
},
|
|
292
|
+
unsubscribe: function () {
|
|
293
|
+
if (observer) {
|
|
294
|
+
raft.unsubscribe(observer);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
var raftRejectedSubscriptionObserver_ = function (callback) {
|
|
300
|
+
return {
|
|
301
|
+
notify: function (eventType, eventEnum, eventName, eventData) {
|
|
302
|
+
switch (eventType) {
|
|
303
|
+
case "conn":
|
|
304
|
+
switch (eventEnum) {
|
|
305
|
+
case RaftConnEvent.CONN_REJECTED:
|
|
306
|
+
callback();
|
|
307
|
+
break;
|
|
308
|
+
default:
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
break;
|
|
312
|
+
case "conn":
|
|
313
|
+
switch (eventEnum) {
|
|
314
|
+
case RaftConnEvent.CONN_REJECTED:
|
|
315
|
+
callback();
|
|
316
|
+
break;
|
|
317
|
+
default:
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export default class SelfdestructiveMessagePromise {
|
|
3
|
+
resolve: (value?: any) => void;
|
|
4
|
+
reject: (reason?: any) => void;
|
|
5
|
+
timeout: NodeJS.Timeout;
|
|
6
|
+
TIMEOUT_PERIOD: number;
|
|
7
|
+
constructor(resolve: (value?: any) => void, reject: (reason?: any) => void, id: string, messagePromises: {
|
|
8
|
+
[key: string]: SelfdestructiveMessagePromise | undefined;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Logger from "../../services/logger/Logger";
|
|
2
|
+
var SHOW_LOGS = true;
|
|
3
|
+
var TAG = "SelfdestructiveMessagePromise";
|
|
4
|
+
var SelfdestructiveMessagePromise = /** @class */ (function () {
|
|
5
|
+
function SelfdestructiveMessagePromise(resolve, reject, id, messagePromises) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
this.resolve = function () { };
|
|
8
|
+
this.reject = function () { };
|
|
9
|
+
this.TIMEOUT_PERIOD = 30000;
|
|
10
|
+
this.resolve = function (value) {
|
|
11
|
+
resolve(value);
|
|
12
|
+
clearTimeout(_this.timeout);
|
|
13
|
+
delete messagePromises[id];
|
|
14
|
+
};
|
|
15
|
+
this.reject = function (reason) {
|
|
16
|
+
reject(reason);
|
|
17
|
+
clearTimeout(_this.timeout);
|
|
18
|
+
delete messagePromises[id];
|
|
19
|
+
};
|
|
20
|
+
this.timeout = setTimeout(function () {
|
|
21
|
+
if (_this.reject) {
|
|
22
|
+
Logger.warn(SHOW_LOGS, TAG, "Timeout for message promise with id: ".concat(id));
|
|
23
|
+
_this.reject({ error: "Timeout" });
|
|
24
|
+
delete messagePromises[id];
|
|
25
|
+
}
|
|
26
|
+
clearTimeout(_this.timeout);
|
|
27
|
+
}, this.TIMEOUT_PERIOD);
|
|
28
|
+
}
|
|
29
|
+
return SelfdestructiveMessagePromise;
|
|
30
|
+
}());
|
|
31
|
+
export default SelfdestructiveMessagePromise;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AppSentMessage, IWrapperSentMessage, WRAPPER_RESPONSE_BASE } from "../../types/communication-between-apps/wrapper-communication";
|
|
2
|
+
export declare class WrapperCommunicator {
|
|
3
|
+
private messagePromises;
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Receives a message from the wrapper app
|
|
7
|
+
*/
|
|
8
|
+
receiveMessage(receivedMessage: IWrapperSentMessage): void;
|
|
9
|
+
/**
|
|
10
|
+
* It sends a message to the phone app
|
|
11
|
+
* The client can await the response to that message
|
|
12
|
+
*/
|
|
13
|
+
sendMessageAndWait<R>(message: AppSentMessage, data?: any): Promise<R>;
|
|
14
|
+
/**
|
|
15
|
+
* It sends a message to the wrapper app
|
|
16
|
+
* The wrapper cannot await the response to that message
|
|
17
|
+
*/
|
|
18
|
+
sendMessageNoWait(message: AppSentMessage, data?: any): void;
|
|
19
|
+
/**
|
|
20
|
+
* Called by the react-native code to respond to sendMessage
|
|
21
|
+
*/
|
|
22
|
+
onMessageResponse(response: WRAPPER_RESPONSE_BASE): void;
|
|
23
|
+
}
|
|
24
|
+
export default WrapperCommunicator;
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
import Logger from "../../services/logger/Logger";
|
|
38
|
+
import { WrapperSentMessage } from "../../types/communication-between-apps/wrapper-communication";
|
|
39
|
+
import randomHashGenerator from "../../utils/helpers/randomHashGenerator";
|
|
40
|
+
import isPhoneApp from "../../utils/phone-app-communication/is-phone-app";
|
|
41
|
+
import SelfdestructiveMessagePromise from "./SelfdestructiveMessagePromise";
|
|
42
|
+
var SHOW_LOGS = true;
|
|
43
|
+
var TAG = "WrapperAppCommunicator";
|
|
44
|
+
var WrapperCommunicator = /** @class */ (function () {
|
|
45
|
+
function WrapperCommunicator() {
|
|
46
|
+
this.messagePromises = {};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Receives a message from the wrapper app
|
|
50
|
+
*/
|
|
51
|
+
WrapperCommunicator.prototype.receiveMessage = function (receivedMessage) {
|
|
52
|
+
receivedMessageHandler(receivedMessage.message, receivedMessage.data, receivedMessage.messagePromiseId);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* It sends a message to the phone app
|
|
56
|
+
* The client can await the response to that message
|
|
57
|
+
*/
|
|
58
|
+
WrapperCommunicator.prototype.sendMessageAndWait = function (message, data) {
|
|
59
|
+
var _this = this;
|
|
60
|
+
var messagePromiseId = randomHashGenerator();
|
|
61
|
+
var promise = new Promise(function (resolve, reject) {
|
|
62
|
+
_this.messagePromises[messagePromiseId] = new SelfdestructiveMessagePromise(resolve, reject, messagePromiseId, _this.messagePromises);
|
|
63
|
+
});
|
|
64
|
+
var messageObject = {
|
|
65
|
+
message: message,
|
|
66
|
+
data: data,
|
|
67
|
+
messagePromiseId: messagePromiseId
|
|
68
|
+
};
|
|
69
|
+
var stringifiedMessage = JSON.stringify(messageObject);
|
|
70
|
+
if (isPhoneApp()) {
|
|
71
|
+
window.ReactNativeWebView.postMessage(stringifiedMessage);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
window.WebAppCommunicator.receiveMessage(stringifiedMessage);
|
|
75
|
+
}
|
|
76
|
+
return promise;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* It sends a message to the wrapper app
|
|
80
|
+
* The wrapper cannot await the response to that message
|
|
81
|
+
*/
|
|
82
|
+
WrapperCommunicator.prototype.sendMessageNoWait = function (message, data) {
|
|
83
|
+
// Logger.info(SHOW_LOGS, TAG, "Sending message without waiting: " + message);
|
|
84
|
+
var messagePromiseId = randomHashGenerator();
|
|
85
|
+
var messageObject = {
|
|
86
|
+
message: message,
|
|
87
|
+
data: data,
|
|
88
|
+
messagePromiseId: messagePromiseId
|
|
89
|
+
};
|
|
90
|
+
var stringifiedMessage = JSON.stringify(messageObject);
|
|
91
|
+
if (isPhoneApp()) {
|
|
92
|
+
window.ReactNativeWebView.postMessage(stringifiedMessage);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
window.WebAppCommunicator.receiveMessage(stringifiedMessage);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Called by the react-native code to respond to sendMessage
|
|
100
|
+
*/
|
|
101
|
+
WrapperCommunicator.prototype.onMessageResponse = function (response) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
Logger.info(SHOW_LOGS, TAG, "Received message reply: " + JSON.stringify(response));
|
|
104
|
+
if (this.messagePromises[response.messagePromiseId]) {
|
|
105
|
+
if (response.success) {
|
|
106
|
+
(_a = this.messagePromises[response.messagePromiseId]) === null || _a === void 0 ? void 0 : _a.resolve(response.results);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
(_b = this.messagePromises[response.messagePromiseId]) === null || _b === void 0 ? void 0 : _b.reject(response.error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
Logger.warn(SHOW_LOGS, TAG, "Unhandled message reply with id: ".concat(response.messagePromiseId));
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return WrapperCommunicator;
|
|
117
|
+
}());
|
|
118
|
+
export { WrapperCommunicator };
|
|
119
|
+
export default WrapperCommunicator;
|
|
120
|
+
var receivedMessageHandler = function (receivedMessage, data, messagePromiseId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
if (data.eventName !== "StateInfo" && data.eventType !== "pub") {
|
|
123
|
+
Logger.info(SHOW_LOGS, TAG, "RAFT published event: ".concat(JSON.stringify(data)));
|
|
124
|
+
}
|
|
125
|
+
switch (receivedMessage) {
|
|
126
|
+
case WrapperSentMessage.RAFT_CONNECTED_RESULTS:
|
|
127
|
+
console.log("RAFT connected results");
|
|
128
|
+
break;
|
|
129
|
+
case WrapperSentMessage.RAFT_PUBLISHED_EVENT:
|
|
130
|
+
window.applicationManager.receivedRICEvent(data.raftId, data.eventType, data.eventEnum, data.eventName, data.eventData);
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
console.log("Unhandled message");
|
|
134
|
+
}
|
|
135
|
+
return [2 /*return*/];
|
|
136
|
+
});
|
|
137
|
+
}); };
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { useEffect, useRef } from "react";
|
|
14
|
+
import "./styles.css";
|
|
15
|
+
export default function LoadingSpinner(_a) {
|
|
16
|
+
var colourA = _a.colourA, colourB = _a.colourB;
|
|
17
|
+
var spinnerRef = useRef(null);
|
|
18
|
+
useEffect(function () {
|
|
19
|
+
if (spinnerRef.current) {
|
|
20
|
+
if (colourA) {
|
|
21
|
+
spinnerRef.current.style.setProperty("--border-colour", colourA);
|
|
22
|
+
}
|
|
23
|
+
if (colourB) {
|
|
24
|
+
spinnerRef.current.style.setProperty("--border-colour", colourB);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, [spinnerRef.current]);
|
|
28
|
+
return (_jsx("div", __assign({ className: "loading-spinner-container" }, { children: _jsx("div", { className: "loading-spinner", ref: spinnerRef }) })));
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FunctionComponent, SVGProps } from "react";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
type SVGImageButtonProps = {
|
|
4
|
+
onClick: () => void;
|
|
5
|
+
title: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
SVGImage: FunctionComponent<SVGProps<SVGSVGElement>>;
|
|
8
|
+
backgroundColour?: string;
|
|
9
|
+
titleColour?: string;
|
|
10
|
+
SVGColour?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export default function SVGImageButton({ onClick, title, subtitle, SVGImage, backgroundColour, titleColour, SVGColour, disabled, }: SVGImageButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import "./styles.css";
|
|
14
|
+
export default function SVGImageButton(_a) {
|
|
15
|
+
var onClick = _a.onClick, title = _a.title, subtitle = _a.subtitle, SVGImage = _a.SVGImage, backgroundColour = _a.backgroundColour, titleColour = _a.titleColour, SVGColour = _a.SVGColour, disabled = _a.disabled;
|
|
16
|
+
return (_jsxs("div", __assign({ className: subtitle
|
|
17
|
+
? "svg-image-button-container"
|
|
18
|
+
: "svg-image-button-container-no-sub", onClick: disabled ? function () { } : onClick, style: { backgroundColor: disabled ? "#f0f0f0" : backgroundColour, cursor: disabled ? "not-allowed" : "pointer" } }, { children: [_jsx("p", __assign({ className: subtitle ? "svg-image-button-title" : "svg-image-button-title-no-sub", style: { color: titleColour } }, { children: title })), subtitle && _jsx("p", __assign({ className: "svg-image-button-subtitle" }, { children: subtitle })), _jsx("div", __assign({ className: "svg-image-button-image-container" }, { children: _jsx(SVGImage, { fill: SVGColour }) }))] })));
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
type SimpleButtonProps = {
|
|
4
|
+
onClick: () => void;
|
|
5
|
+
title: string;
|
|
6
|
+
titleSize?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
colour?: string;
|
|
9
|
+
otherStyles?: React.CSSProperties;
|
|
10
|
+
borderColour?: string;
|
|
11
|
+
textColour?: string;
|
|
12
|
+
};
|
|
13
|
+
export default function SimpleButton({ onClick, title, titleSize, disabled, colour, otherStyles, borderColour, textColour }: SimpleButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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.css";
|
|
14
|
+
export default function SimpleButton(_a) {
|
|
15
|
+
var onClick = _a.onClick, title = _a.title, titleSize = _a.titleSize, disabled = _a.disabled, colour = _a.colour, otherStyles = _a.otherStyles, borderColour = _a.borderColour, textColour = _a.textColour;
|
|
16
|
+
return (_jsx("div", __assign({ className: "simple-button-component " +
|
|
17
|
+
(disabled ? "simple-button-component-disabled" : ""), style: __assign(__assign({}, otherStyles), { fontSize: titleSize, backgroundColor: colour, border: borderColour && "1px solid ".concat(borderColour), color: textColour }), onClick: disabled ? function () { } : onClick }, { children: title })));
|
|
18
|
+
}
|