diff --git a/package.json b/package.json index 92cad068..0581c9d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "0.23.3", + "version": "0.23.4", "private": true, "scripts": { "dev": "react-scripts start", diff --git a/src/components/Connections/Connections.tsx b/src/components/Connections/Connections.tsx index 44df2d4a..9ff866f7 100644 --- a/src/components/Connections/Connections.tsx +++ b/src/components/Connections/Connections.tsx @@ -3,12 +3,48 @@ import StateCell from "../TableInformationCells/StateCell"; import { envApplication } from "../../helpers/envProvider"; import { useKeycloak } from "@react-keycloak/web"; import useRobot from "../../hooks/useRobot"; -import { ReactElement } from "react"; +import { ReactElement, useEffect, useState } from "react"; +import ROSLIB from "roslib"; export default function Connections(): ReactElement { - const { responseRobot, isSettedCookie } = useRobot(); + const { responseRobot, isSettedCookie, isRobotReady } = useRobot(); const { keycloak } = useKeycloak(); + const [isRosConnected, setIsRosConnected] = useState(null); + + useEffect(() => { + const rosClient: ROSLIB.Ros = new ROSLIB.Ros({ + url: responseRobot?.bridgeIngressEndpoint, + }); + + if (isRosConnected === null) { + if ( + isRobotReady && + isSettedCookie && + responseRobot?.bridgeIngressEndpoint + ) { + rosClient?.on("connection", function () { + setIsRosConnected(true); + }); + + rosClient?.on("error", function (error) { + setIsRosConnected(false); + }); + } + } else { + rosClient?.close(); + } + }, [ + isRobotReady, + isSettedCookie, + isRosConnected, + responseRobot?.bridgeIngressEndpoint, + ]); + + useEffect(() => { + console.log("isRosConnected", isRosConnected); + }, [isRosConnected]); + return (
{!envApplication && ( diff --git a/src/contexts/RobotContext.tsx b/src/contexts/RobotContext.tsx index a6378804..a1de99c6 100644 --- a/src/contexts/RobotContext.tsx +++ b/src/contexts/RobotContext.tsx @@ -42,10 +42,6 @@ export default ({ children }: any) => { undefined, ); - useEffect(() => { - console.log("pagesState", pagesState); - }, [pagesState]); - // Main Functions useEffect(() => { if ( @@ -148,8 +144,6 @@ export default ({ children }: any) => { ? true : false; - console.log("isWorkspaceReady", isWorkspaceReady); - if (isWorkspaceReady || isBuildManagerReady || isLaunchManagerReady) { setIsRobotReady(true); } else {