Skip to content

Commit

Permalink
refactor(connections): 🎉 add ros connection control functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangunduz committed Dec 20, 2023
1 parent 2a8c145 commit 2806011
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui",
"version": "0.23.3",
"version": "0.23.4",
"private": true,
"scripts": {
"dev": "react-scripts start",
Expand Down
40 changes: 38 additions & 2 deletions src/components/Connections/Connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean | null>(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 (
<div className="flex gap-4">
{!envApplication && (
Expand Down
6 changes: 0 additions & 6 deletions src/contexts/RobotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export default ({ children }: any) => {
undefined,
);

useEffect(() => {
console.log("pagesState", pagesState);
}, [pagesState]);

// Main Functions
useEffect(() => {
if (
Expand Down Expand Up @@ -148,8 +144,6 @@ export default ({ children }: any) => {
? true
: false;

console.log("isWorkspaceReady", isWorkspaceReady);

if (isWorkspaceReady || isBuildManagerReady || isLaunchManagerReady) {
setIsRobotReady(true);
} else {
Expand Down

0 comments on commit 2806011

Please sign in to comment.