@robotical/webapp-types 0.6.58
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/analytics/AnalyticsManager.d.ts +28 -0
- package/dist-types/src/analytics/AnalyticsManager.js +171 -0
- package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +117 -0
- package/dist-types/src/application/ApplicationManager/ApplicationManager.js +567 -0
- package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +50 -0
- package/dist-types/src/application/RAFTs/Cog/Cog.js +223 -0
- package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.d.ts +120 -0
- package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.js +533 -0
- package/dist-types/src/application/RAFTs/Marty/Marty.d.ts +42 -0
- package/dist-types/src/application/RAFTs/Marty/Marty.js +187 -0
- package/dist-types/src/application/RAFTs/RAFT.d.ts +114 -0
- package/dist-types/src/application/RAFTs/RAFT.js +341 -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 +63 -0
- package/dist-types/src/application/RAFTs/raft-subscription-helpers.js +355 -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/ SensorsDashboardModal/index.d.ts +2 -0
- package/dist-types/src/components/modals/ SensorsDashboardModal/index.js +61 -0
- package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.d.ts +3 -0
- package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.js +16 -0
- package/dist-types/src/components/modals/DetailedFeedbackModal/index.d.ts +5 -0
- package/dist-types/src/components/modals/DetailedFeedbackModal/index.js +37 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/index.d.ts +1 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/index.js +8 -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 +195 -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/RaftSignal/index.d.ts +7 -0
- package/dist-types/src/components/oneoffs/RaftSignal/index.js +29 -0
- package/dist-types/src/services/logger/Logger.d.ts +8 -0
- package/dist-types/src/services/logger/Logger.js +25 -0
- package/dist-types/src/state-observables/modal/DraggableModalState.d.ts +16 -0
- package/dist-types/src/state-observables/modal/DraggableModalState.js +52 -0
- package/dist-types/src/state-observables/modal/ModalObserver.d.ts +18 -0
- package/dist-types/src/state-observables/modal/ModalObserver.js +1 -0
- package/dist-types/src/state-observables/modal/ModalState.d.ts +25 -0
- package/dist-types/src/state-observables/modal/ModalState.js +71 -0
- package/dist-types/src/store/SelectedRaftContext.d.ts +19 -0
- package/dist-types/src/store/SelectedRaftContext.js +84 -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 +48 -0
- package/dist-types/src/types/communication-between-apps/wrapper-communication.js +28 -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 +40 -0
- package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.js +209 -0
- package/dist-types/src/wrapper-app/connectors/Connector.d.ts +72 -0
- package/dist-types/src/wrapper-app/connectors/Connector.js +314 -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 +40 -0
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +243 -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,18 @@
|
|
|
1
|
+
export declare enum RaftConnectionMethod {
|
|
2
|
+
WEB_SOCKET = "WebSocket",
|
|
3
|
+
WEB_BLE = "WebBLE",
|
|
4
|
+
PHONE_BLE = "PhoneBLE"
|
|
5
|
+
}
|
|
6
|
+
export type ConnectionAttemptResults = {
|
|
7
|
+
success: boolean;
|
|
8
|
+
reason: 'failed' | 'unplugged' | 'success' | 'no_sys_info' | 'invalid_raft_type';
|
|
9
|
+
data?: {
|
|
10
|
+
raftId: string;
|
|
11
|
+
raftType: RaftTypeE;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare enum RaftTypeE {
|
|
15
|
+
MARTY = "Marty",
|
|
16
|
+
COG = "Cog",
|
|
17
|
+
undefined = "undefined"
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var RaftConnectionMethod;
|
|
2
|
+
(function (RaftConnectionMethod) {
|
|
3
|
+
RaftConnectionMethod["WEB_SOCKET"] = "WebSocket";
|
|
4
|
+
RaftConnectionMethod["WEB_BLE"] = "WebBLE";
|
|
5
|
+
RaftConnectionMethod["PHONE_BLE"] = "PhoneBLE";
|
|
6
|
+
})(RaftConnectionMethod || (RaftConnectionMethod = {}));
|
|
7
|
+
;
|
|
8
|
+
export var RaftTypeE;
|
|
9
|
+
(function (RaftTypeE) {
|
|
10
|
+
RaftTypeE["MARTY"] = "Marty";
|
|
11
|
+
RaftTypeE["COG"] = "Cog";
|
|
12
|
+
RaftTypeE["undefined"] = "undefined";
|
|
13
|
+
})(RaftTypeE || (RaftTypeE = {}));
|
|
14
|
+
;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ToastOptions } from 'react-toastify';
|
|
2
|
+
import 'react-toastify/dist/ReactToastify.css';
|
|
3
|
+
declare class Toaster {
|
|
4
|
+
private static lastToastTime;
|
|
5
|
+
private static debounceTime;
|
|
6
|
+
private static shouldShowToast;
|
|
7
|
+
static warn(message: string, options?: ToastOptions): void;
|
|
8
|
+
static error(message: string, options?: ToastOptions): void;
|
|
9
|
+
static info(message: string, options?: ToastOptions): void;
|
|
10
|
+
static success(message: string, options?: ToastOptions): void;
|
|
11
|
+
static clearAll(): void;
|
|
12
|
+
}
|
|
13
|
+
export default Toaster;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { toast } from 'react-toastify';
|
|
2
|
+
import 'react-toastify/dist/ReactToastify.css';
|
|
3
|
+
var Toaster = /** @class */ (function () {
|
|
4
|
+
function Toaster() {
|
|
5
|
+
}
|
|
6
|
+
Toaster.shouldShowToast = function (message) {
|
|
7
|
+
var currentTime = Date.now();
|
|
8
|
+
var lastTimeShown = this.lastToastTime.get(message) || 0;
|
|
9
|
+
var shouldBeShown = currentTime - lastTimeShown > this.debounceTime;
|
|
10
|
+
if (shouldBeShown) {
|
|
11
|
+
this.lastToastTime.set(message, currentTime);
|
|
12
|
+
}
|
|
13
|
+
return shouldBeShown;
|
|
14
|
+
};
|
|
15
|
+
Toaster.warn = function (message, options) {
|
|
16
|
+
if (this.shouldShowToast(message))
|
|
17
|
+
toast.warn(message, options);
|
|
18
|
+
};
|
|
19
|
+
Toaster.error = function (message, options) {
|
|
20
|
+
if (this.shouldShowToast(message))
|
|
21
|
+
toast.error(message, options);
|
|
22
|
+
};
|
|
23
|
+
Toaster.info = function (message, options) {
|
|
24
|
+
if (this.shouldShowToast(message))
|
|
25
|
+
toast.info(message, options);
|
|
26
|
+
};
|
|
27
|
+
Toaster.success = function (message, options) {
|
|
28
|
+
if (this.shouldShowToast(message))
|
|
29
|
+
toast.success(message, options);
|
|
30
|
+
};
|
|
31
|
+
Toaster.clearAll = function () {
|
|
32
|
+
toast.dismiss();
|
|
33
|
+
};
|
|
34
|
+
Toaster.lastToastTime = new Map();
|
|
35
|
+
Toaster.debounceTime = 5000;
|
|
36
|
+
return Toaster;
|
|
37
|
+
}());
|
|
38
|
+
export default Toaster;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import semverGt from "semver/functions/gt";
|
|
2
|
+
export default function isVersionGreater(v1, v2) {
|
|
3
|
+
try {
|
|
4
|
+
return semverGt(v1, v2);
|
|
5
|
+
}
|
|
6
|
+
catch (e) {
|
|
7
|
+
console.log(e, v1, v2);
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function isVersionGreater_errorCatching(v1, v2) {
|
|
12
|
+
try {
|
|
13
|
+
return semverGt(v1, v2);
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
console.log(e, v1, v2);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (length?: number): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default function (length) {
|
|
2
|
+
if (length === void 0) { length = 10; }
|
|
3
|
+
var result = "";
|
|
4
|
+
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
5
|
+
var charactersLength = characters.length;
|
|
6
|
+
for (var i = 0; i < length; i++) {
|
|
7
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import isVersionGreater from "./compare-version";
|
|
2
|
+
export var FW_VERSION_RSSI_WIFI = "1.2.0"; // greater versions than this (1.1.17) have the wifi rssi logic
|
|
3
|
+
export default function wifiConfigSub(raft) {
|
|
4
|
+
if (!isVersionGreater(raft.getRaftVersion(), FW_VERSION_RSSI_WIFI)) {
|
|
5
|
+
return "Currently, wifi configuration only works in the phone application.";
|
|
6
|
+
}
|
|
7
|
+
return "";
|
|
8
|
+
// const isPaused = window.marty.getCachedWifiStatus().ssid ? true : false;
|
|
9
|
+
// const conInfo =
|
|
10
|
+
// window.marty.getCachedWifiStatus().connState ===
|
|
11
|
+
// RICWifiConnState.WIFI_CONN_CONNECTED ||
|
|
12
|
+
// window.marty.getCachedWifiStatus().ssid
|
|
13
|
+
// ? window.marty.getCachedWifiStatus().ipAddress +
|
|
14
|
+
// " on " +
|
|
15
|
+
// window.marty.getCachedWifiStatus().ssid
|
|
16
|
+
// : null;
|
|
17
|
+
// const isConnected =
|
|
18
|
+
// window.marty.getCachedWifiStatus().connState ===
|
|
19
|
+
// RICWifiConnState.WIFI_CONN_CONNECTED;
|
|
20
|
+
// let subtitle;
|
|
21
|
+
// if (isConnected) {
|
|
22
|
+
// subtitle = "Connected";
|
|
23
|
+
// }
|
|
24
|
+
// if (isPaused) {
|
|
25
|
+
// subtitle = "Connected (Paused for BLE)";
|
|
26
|
+
// }
|
|
27
|
+
// if (!isConnected && !isPaused) {
|
|
28
|
+
// subtitle = "Not Connected";
|
|
29
|
+
// }
|
|
30
|
+
// if (conInfo) {
|
|
31
|
+
// subtitle += " | " + conInfo;
|
|
32
|
+
// }
|
|
33
|
+
// return subtitle;
|
|
34
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RaftInfoEvents } from "../types/events/raft-info";
|
|
2
|
+
import { ConnectionAttemptResults, RaftConnectionMethod } from "../types/raft";
|
|
3
|
+
import { RaftConnEvent, RaftPublishEvent, RaftUpdateEvent } from "@robotical/raftjs";
|
|
4
|
+
import { RICLedLcdColours } from "@robotical/roboticaljs";
|
|
5
|
+
export declare class WrapperAppManager {
|
|
6
|
+
private connectors;
|
|
7
|
+
private _observers;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Connect to a RAFT
|
|
11
|
+
*
|
|
12
|
+
* @param {string} method - can be "WebBLE" or "WebSocket"
|
|
13
|
+
* @param {string | object} locator - either a string (WebSocket URL) or an object (WebBLE)
|
|
14
|
+
* @returns Promise<ConnectionAttemptResults>
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
connect(method: RaftConnectionMethod, uuids: string[]): Promise<ConnectionAttemptResults>;
|
|
18
|
+
/**
|
|
19
|
+
* Re-triggers the connect event which was missed due to the connection logic
|
|
20
|
+
*/
|
|
21
|
+
getMissedConnEvent(raftId: any): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get the RAFT Name
|
|
24
|
+
*/
|
|
25
|
+
getRaftName(raftId: string): "" | Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Verify RAFT
|
|
28
|
+
*/
|
|
29
|
+
verifyRaft(ledLcdColours: RICLedLcdColours, raftId: string): false | Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Stop verifying RAFT
|
|
32
|
+
*/
|
|
33
|
+
stopVerifyingRaft(isCorrectRIC: boolean, raftId: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Disconnect from a RAFT
|
|
36
|
+
*/
|
|
37
|
+
disconnect(raftId: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Audio streaming
|
|
40
|
+
*/
|
|
41
|
+
streamAudio(raftId: string, streamContents: Uint8Array, clearExisting: boolean, duration: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Publish an event to all observers
|
|
44
|
+
* Set in RICConnector as an event listener callback
|
|
45
|
+
*/
|
|
46
|
+
publish(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent | RaftInfoEvents, eventName: string, eventData: any): void;
|
|
47
|
+
/**
|
|
48
|
+
* Send a REST message to the RAFT
|
|
49
|
+
*/
|
|
50
|
+
sendRestMessage(msg: string, params: object | undefined, raftId: string): Promise<import("@robotical/raftjs").RaftOKFail>;
|
|
51
|
+
/**
|
|
52
|
+
* Removes marty after a certain time
|
|
53
|
+
* Removes from the martys list after x seconds so that we can still get the last event
|
|
54
|
+
*/
|
|
55
|
+
_removeRICConnector(connectorId: string, timeout: number): void;
|
|
56
|
+
}
|
|
57
|
+
declare const wrapperAppManager: WrapperAppManager;
|
|
58
|
+
export default wrapperAppManager;
|
|
@@ -0,0 +1,176 @@
|
|
|
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 { WrapperSentMessage } from "../types/communication-between-apps/wrapper-communication";
|
|
38
|
+
import Logger from "../services/logger/Logger";
|
|
39
|
+
import { RaftConnEvent } from "@robotical/raftjs";
|
|
40
|
+
import ConnectorFactory from "./connectors/ConnectorFactory";
|
|
41
|
+
var SHOW_LOGS = true;
|
|
42
|
+
var TAG = "WrapperAppManager";
|
|
43
|
+
var WrapperAppManager = /** @class */ (function () {
|
|
44
|
+
function WrapperAppManager() {
|
|
45
|
+
// Connectors
|
|
46
|
+
this.connectors = {};
|
|
47
|
+
// Observers
|
|
48
|
+
this._observers = {};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Connect to a RAFT
|
|
52
|
+
*
|
|
53
|
+
* @param {string} method - can be "WebBLE" or "WebSocket"
|
|
54
|
+
* @param {string | object} locator - either a string (WebSocket URL) or an object (WebBLE)
|
|
55
|
+
* @returns Promise<ConnectionAttemptResults>
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
WrapperAppManager.prototype.connect = function (method, uuids) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
var connector, connectionResults;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0: return [4 /*yield*/, ConnectorFactory.connectToRaftHelper(method, uuids)];
|
|
64
|
+
case 1:
|
|
65
|
+
connector = _a.sent();
|
|
66
|
+
if (!connector) {
|
|
67
|
+
Logger.warn(SHOW_LOGS, TAG, "Failed to connect to RAFT with method: ".concat(method));
|
|
68
|
+
return [2 /*return*/, { success: false, reason: "failed" }];
|
|
69
|
+
}
|
|
70
|
+
return [4 /*yield*/, connector.connect()];
|
|
71
|
+
case 2:
|
|
72
|
+
connectionResults = _a.sent();
|
|
73
|
+
if (connectionResults.success) {
|
|
74
|
+
this.connectors[connector.id] = connector;
|
|
75
|
+
connectionResults.data = { raftId: connector.id, raftType: connector.type };
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
Logger.warn(SHOW_LOGS, TAG, "Failed to connect to RAFT with id: ".concat(connector.id, " and type: ").concat(connector.type));
|
|
79
|
+
}
|
|
80
|
+
Logger.info(SHOW_LOGS, TAG, "Connected to RAFT with id: ".concat(connector.id, " and type: ").concat(connector.type));
|
|
81
|
+
return [2 /*return*/, connectionResults];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Re-triggers the connect event which was missed due to the connection logic
|
|
88
|
+
*/
|
|
89
|
+
WrapperAppManager.prototype.getMissedConnEvent = function (raftId) {
|
|
90
|
+
if (this.connectors[raftId]) {
|
|
91
|
+
this.connectors[raftId].eventHandler("conn", RaftConnEvent.CONN_CONNECTED, "connect", {});
|
|
92
|
+
this.connectors[raftId].publish("conn", RaftConnEvent.CONN_CONNECTED, "connect", {});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Get the RAFT Name
|
|
97
|
+
*/
|
|
98
|
+
WrapperAppManager.prototype.getRaftName = function (raftId) {
|
|
99
|
+
if (this.connectors[raftId]) {
|
|
100
|
+
return this.connectors[raftId].getRaftName();
|
|
101
|
+
}
|
|
102
|
+
return "";
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Verify RAFT
|
|
106
|
+
*/
|
|
107
|
+
WrapperAppManager.prototype.verifyRaft = function (ledLcdColours, raftId) {
|
|
108
|
+
if (!this.connectors[raftId]) {
|
|
109
|
+
Logger.warn(SHOW_LOGS, TAG, "verifyRaft: No connector found for raftId: ".concat(raftId));
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return this.connectors[raftId].verifyRaft(ledLcdColours);
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Stop verifying RAFT
|
|
116
|
+
*/
|
|
117
|
+
WrapperAppManager.prototype.stopVerifyingRaft = function (isCorrectRIC, raftId) {
|
|
118
|
+
if (!isCorrectRIC) {
|
|
119
|
+
this._removeRICConnector(raftId, 3000);
|
|
120
|
+
}
|
|
121
|
+
return this.connectors[raftId].stopVerifyingRaft(isCorrectRIC);
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Disconnect from a RAFT
|
|
125
|
+
*/
|
|
126
|
+
WrapperAppManager.prototype.disconnect = function (raftId) {
|
|
127
|
+
this._removeRICConnector(raftId, 3000);
|
|
128
|
+
return this.connectors[raftId].disconnect();
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Audio streaming
|
|
132
|
+
*/
|
|
133
|
+
WrapperAppManager.prototype.streamAudio = function (raftId, streamContents, clearExisting, duration) {
|
|
134
|
+
return this.connectors[raftId].streamAudio(streamContents, clearExisting, duration);
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Publish an event to all observers
|
|
138
|
+
* Set in RICConnector as an event listener callback
|
|
139
|
+
*/
|
|
140
|
+
WrapperAppManager.prototype.publish = function (eventType, eventEnum, eventName, eventData) {
|
|
141
|
+
window.WebAppCommunicator.sendMessageNoWait(WrapperSentMessage.RAFT_PUBLISHED_EVENT, { eventType: eventType, eventEnum: eventEnum, eventName: eventName, eventData: eventData });
|
|
142
|
+
if (this._observers.hasOwnProperty(eventType)) {
|
|
143
|
+
for (var _i = 0, _a = this._observers[eventType]; _i < _a.length; _i++) {
|
|
144
|
+
var observer = _a[_i];
|
|
145
|
+
observer.notify(eventType, eventEnum, eventName, eventData);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Send a REST message to the RAFT
|
|
151
|
+
*/
|
|
152
|
+
WrapperAppManager.prototype.sendRestMessage = function (msg, params, raftId) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
+
return __generator(this, function (_a) {
|
|
155
|
+
return [2 /*return*/, this.connectors[raftId].sendRestMessage(msg, params)];
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Removes marty after a certain time
|
|
161
|
+
* Removes from the martys list after x seconds so that we can still get the last event
|
|
162
|
+
*/
|
|
163
|
+
WrapperAppManager.prototype._removeRICConnector = function (connectorId, timeout) {
|
|
164
|
+
var _this = this;
|
|
165
|
+
var martyRemovalTimeout = setTimeout(function () {
|
|
166
|
+
delete _this.connectors[connectorId];
|
|
167
|
+
clearTimeout(martyRemovalTimeout);
|
|
168
|
+
}, timeout);
|
|
169
|
+
};
|
|
170
|
+
return WrapperAppManager;
|
|
171
|
+
}());
|
|
172
|
+
export { WrapperAppManager };
|
|
173
|
+
var wrapperAppManager = new WrapperAppManager();
|
|
174
|
+
// @ts-ignore : just for debugging
|
|
175
|
+
window.wrapperAppManager = wrapperAppManager;
|
|
176
|
+
export default wrapperAppManager;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WEB_APP_MESSAGE_BASE, WrapperSentMessage } from "../../types/communication-between-apps/wrapper-communication";
|
|
2
|
+
/**
|
|
3
|
+
* This file is responsible for the communication between the web app and the Wrapper Web App
|
|
4
|
+
*/
|
|
5
|
+
declare class WebAppCommunicator {
|
|
6
|
+
private messagePromises;
|
|
7
|
+
constructor();
|
|
8
|
+
receiveMessage(receivedMessageStringified: string): Promise<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: WrapperSentMessage, data?: any): Promise<R>;
|
|
14
|
+
/**
|
|
15
|
+
* It sends a message to the phone app
|
|
16
|
+
* The client cannot await the response to that message
|
|
17
|
+
*/
|
|
18
|
+
sendMessageNoWait(message: WrapperSentMessage, data?: any): void;
|
|
19
|
+
/**
|
|
20
|
+
* Called by the react-native code to respond to sendMessage
|
|
21
|
+
*/
|
|
22
|
+
onMessageResponse(response: WEB_APP_MESSAGE_BASE): void;
|
|
23
|
+
}
|
|
24
|
+
export default WebAppCommunicator;
|