@vention/machine-logic-ui-sdk 0.20.0 → 0.22.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/index.esm.js CHANGED
@@ -2856,8 +2856,9 @@ const isOnEdge = () => {
2856
2856
  const getExecutionEngineHttpUrl = () => {
2857
2857
  return isOnEdge() ? `http://${window.location.hostname}:3100` : getExecutionEngineUrlGivenUiIframeUrl(window.location.href);
2858
2858
  };
2859
- const getMqttWsUrl = () => __awaiter(void 0, void 0, void 0, function* () {
2860
- return isOnEdge() ? `ws://${window.location.hostname}:9001` : getMqttWsUrlGivenUiIframeUrl(window.location.href);
2859
+ const getMqttWsUrl = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (version = "v2") {
2860
+ const urlOnEdge = version === "v2" ? "ws://192.168.5.2:9001" : `ws://${window.location.hostname}:9001`;
2861
+ return isOnEdge() ? urlOnEdge : getMqttWsUrlGivenUiIframeUrl(window.location.href);
2861
2862
  });
2862
2863
  const connectToMqttAndGetClient = () => __awaiter(void 0, void 0, void 0, function* () {
2863
2864
  const websocketUrl = yield getMqttWsUrl();
@@ -2881,12 +2882,18 @@ const getMqttWsUrlGivenUiIframeUrl = uiIframeUrl => {
2881
2882
  const wssBaseUrl = baseUrl.replace("https:", "wss:");
2882
2883
  return `${wssBaseUrl}/${token}/mqtt`;
2883
2884
  };
2885
+ const closeCustomUi = () => {
2886
+ window.parent.postMessage("closeCustomUi", "*");
2887
+ };
2884
2888
 
2885
2889
  const defaultContext = {
2886
2890
  client: null,
2887
2891
  connectionStatus: "disconnected"
2888
2892
  };
2889
2893
  const mqttContext = /*#__PURE__*/createContext(defaultContext);
2894
+ const defaultProps = {
2895
+ version: "v2"
2896
+ };
2890
2897
  const MqttProvider = props => {
2891
2898
  const [connectionStatus, setConnectionStatus] = useState("disconnected");
2892
2899
  const [mqttClient, setMqttClient] = useState(null);
@@ -2897,8 +2904,9 @@ const MqttProvider = props => {
2897
2904
  useEffect(function mqttConnection() {
2898
2905
  function connectToMqtt() {
2899
2906
  return __awaiter(this, void 0, void 0, function* () {
2907
+ var _a;
2900
2908
  console.log("Connecting to MQTT");
2901
- const client = mqtt.connect(yield getMqttWsUrl());
2909
+ const client = mqtt.connect(yield getMqttWsUrl((_a = props.version) !== null && _a !== void 0 ? _a : defaultProps.version));
2902
2910
  client.on("connect", () => {
2903
2911
  setConnectionStatus("connected");
2904
2912
  console.log("Connected to MQTT");
@@ -2929,19 +2937,6 @@ const MqttProvider = props => {
2929
2937
  });
2930
2938
  };
2931
2939
 
2932
- var MqttSandingTopics;
2933
- (function (MqttSandingTopics) {
2934
- MqttSandingTopics["SET_APP_STATE"] = "sandingMachineApp/setAppState";
2935
- MqttSandingTopics["STATION_CALIBRATION_STATE"] = "sandingMachineApp/state/stationCalibration";
2936
- MqttSandingTopics["STATE_APP"] = "sandingMachineApp/state/app";
2937
- MqttSandingTopics["STATE_ROBOT"] = "sandingMachineApp/state/robot";
2938
- MqttSandingTopics["STATE_STATION"] = "sandingMachineApp/state/station";
2939
- MqttSandingTopics["CHANGE_SANDING_PAPER"] = "sandingMachineApp/state/changeSandingPaper";
2940
- MqttSandingTopics["SANDING_PAPER_CHANGED"] = "sandingMachineApp/sandingPaperChanged";
2941
- MqttSandingTopics["GET_INITIAL_STATE"] = "sandingMachineApp/getInitialState";
2942
- MqttSandingTopics["NOTIFICATION_MESSAGES"] = "sandingMachineApp/notification/messages";
2943
- })(MqttSandingTopics || (MqttSandingTopics = {}));
2944
-
2945
2940
  const useMqttSubscription = props => {
2946
2941
  const mqtt = useContext(mqttContext);
2947
2942
  const [message, setMessage] = useState();
@@ -2962,4 +2957,4 @@ const useMqttSubscription = props => {
2962
2957
  return message;
2963
2958
  };
2964
2959
 
2965
- export { MqttClient, MqttProvider, MqttSandingTopics, VirtualKeyboard, connectToMqttAndGetClient, getExecutionEngineHttpUrl, getMachineCodeProcessHttpUrl, getMqttWsUrl, getMqttWsUrlGivenUiIframeUrl, isOnEdge, isTouchScreenDevice, mqttContext, useMqttSubscription };
2960
+ export { MqttClient, MqttProvider, VirtualKeyboard, closeCustomUi, connectToMqttAndGetClient, getExecutionEngineHttpUrl, getMachineCodeProcessHttpUrl, getMqttWsUrl, getMqttWsUrlGivenUiIframeUrl, isOnEdge, isTouchScreenDevice, mqttContext, useMqttSubscription };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vention/machine-logic-ui-sdk",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/VentionCo/machine-cloud.git"
package/src/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export * from "./lib/components/virtual-keyboard/virtual-keyboard";
2
2
  export * from "./lib/utils/machine-logic-ui-sdk-utils";
3
3
  export * from "./lib/mqtt-browser/mqtt-client";
4
4
  export * from "./lib/mqtt/mqtt-context";
5
- export * from "./lib/mqtt/mqtt-types";
6
5
  export * from "./lib/mqtt/use-mqtt-subscription";
6
+ export * from "./lib/mqtt/generic-mqtt-mapping";
@@ -0,0 +1 @@
1
+ export type MqttPayloadByTopic<TMapping extends Record<string, unknown>, T extends keyof TMapping> = TMapping[T];
@@ -7,6 +7,7 @@ interface MqttContext {
7
7
  export declare const mqttContext: import("react").Context<MqttContext>;
8
8
  interface Props {
9
9
  children: ReactNode;
10
+ version?: "v2" | "v3";
10
11
  }
11
12
  export declare const MqttProvider: (props: Props) => import("react/jsx-runtime").JSX.Element;
12
13
  export {};
@@ -1,6 +1,5 @@
1
- import { MqttSandingTopics, MqttPayloadByTopic } from "./mqtt-types";
2
- interface Props<TMqttTopic> {
3
- topic: TMqttTopic;
1
+ interface Props {
2
+ topic: string;
4
3
  }
5
- export declare const useMqttSubscription: <TMqttTopic extends MqttSandingTopics>(props: Props<TMqttTopic>) => MqttPayloadByTopic<TMqttTopic>;
4
+ export declare const useMqttSubscription: <TMessage>(props: Props) => TMessage;
6
5
  export {};
@@ -2,7 +2,8 @@ import { MqttClient } from "../mqtt-browser/mqtt-client";
2
2
  export declare const isTouchScreenDevice: () => boolean;
3
3
  export declare const isOnEdge: () => boolean;
4
4
  export declare const getExecutionEngineHttpUrl: () => string;
5
- export declare const getMqttWsUrl: () => Promise<string>;
5
+ export declare const getMqttWsUrl: (version?: "v2" | "v3") => Promise<string>;
6
6
  export declare const connectToMqttAndGetClient: () => Promise<MqttClient>;
7
7
  export declare const getMachineCodeProcessHttpUrl: (processName: string) => string;
8
8
  export declare const getMqttWsUrlGivenUiIframeUrl: (uiIframeUrl: string) => string;
9
+ export declare const closeCustomUi: () => void;
@@ -1,64 +0,0 @@
1
- export declare enum MqttSandingTopics {
2
- SET_APP_STATE = "sandingMachineApp/setAppState",
3
- STATION_CALIBRATION_STATE = "sandingMachineApp/state/stationCalibration",
4
- STATE_APP = "sandingMachineApp/state/app",
5
- STATE_ROBOT = "sandingMachineApp/state/robot",
6
- STATE_STATION = "sandingMachineApp/state/station",
7
- CHANGE_SANDING_PAPER = "sandingMachineApp/state/changeSandingPaper",
8
- SANDING_PAPER_CHANGED = "sandingMachineApp/sandingPaperChanged",
9
- GET_INITIAL_STATE = "sandingMachineApp/getInitialState",
10
- NOTIFICATION_MESSAGES = "sandingMachineApp/notification/messages"
11
- }
12
- export type SandingApplicationState = "STOP" | "START" | "HOME" | "FREEDRIVE" | "STOPPING" | "FAULT" | "CALIBRATING_LASER" | "CALIBRATING_STATION";
13
- export type SandingRobotState = "FAULT" | "READY";
14
- type MqttSetAppStatePayload = {
15
- state: SandingApplicationState;
16
- data?: unknown;
17
- };
18
- export type StationCalibrationState = "completed" | "calibrating" | "incomplete";
19
- export type MqttStationCalibrationStatePayload = {
20
- station1: StationCalibrationState;
21
- station2: StationCalibrationState;
22
- station3: StationCalibrationState;
23
- station4: StationCalibrationState;
24
- };
25
- type MqttRobotStatePayload = {
26
- state: SandingRobotState;
27
- };
28
- export type StationState = {
29
- completedSteps: number;
30
- totalSteps: number;
31
- isActive: boolean;
32
- status: "waitingForPanel" | "inProgress" | "ready" | "complete";
33
- isVacuumActivated: boolean;
34
- isPanelInPlace: boolean;
35
- };
36
- export type MqttStationStatePayload = {
37
- station1: StationState;
38
- station2: StationState;
39
- station3: StationState;
40
- station4: StationState;
41
- };
42
- type MqttChangeSandingPaperPayload = object;
43
- type MqttSandingPaperChangedPayload = object;
44
- type MqttGetInitialStatePayload = object;
45
- export type MqttNotificationPayload = {
46
- id: string;
47
- message: string;
48
- type: "info" | "warn" | "error";
49
- timestamp: number;
50
- isRead?: boolean;
51
- };
52
- type MqttPayloadMapping = {
53
- [MqttSandingTopics.SET_APP_STATE]: MqttSetAppStatePayload;
54
- [MqttSandingTopics.STATION_CALIBRATION_STATE]: MqttStationCalibrationStatePayload;
55
- [MqttSandingTopics.STATE_APP]: MqttSetAppStatePayload;
56
- [MqttSandingTopics.STATE_ROBOT]: MqttRobotStatePayload;
57
- [MqttSandingTopics.STATE_STATION]: MqttStationStatePayload;
58
- [MqttSandingTopics.CHANGE_SANDING_PAPER]: MqttChangeSandingPaperPayload;
59
- [MqttSandingTopics.SANDING_PAPER_CHANGED]: MqttSandingPaperChangedPayload;
60
- [MqttSandingTopics.GET_INITIAL_STATE]: MqttGetInitialStatePayload;
61
- [MqttSandingTopics.NOTIFICATION_MESSAGES]: MqttNotificationPayload;
62
- };
63
- export type MqttPayloadByTopic<T extends MqttSandingTopics> = MqttPayloadMapping[T];
64
- export {};