From 2a2d18f9d91aad6d8bdcda0332051656948224eb Mon Sep 17 00:00:00 2001 From: Umang-Rajkarnikar Date: Wed, 27 Mar 2024 18:32:00 -0400 Subject: [PATCH 1/2] Added endpoint to send test command --- src/leo-server-app/src/routes/forwarder.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/leo-server-app/src/routes/forwarder.ts b/src/leo-server-app/src/routes/forwarder.ts index 8debbeb..94a9065 100644 --- a/src/leo-server-app/src/routes/forwarder.ts +++ b/src/leo-server-app/src/routes/forwarder.ts @@ -88,4 +88,16 @@ router.post("/sendCommand", async (req: SendCommandProp, res: any) => { res.status(201).json({ output: response.toString() }); }); + +router.post("/sendTestCommand", async (req: SendCommandProp, res: any) => { + const { body } = req; + + // Forward through socket + const response = await messageHandler.sendDataToClientAndAwaitResponse( + body.command, + 5000 + ); + + res.status(201).json({ output: response.toString() }); +}); module.exports = router; From b35c75ed20c00ca1850f38c699a4f36209461c8d Mon Sep 17 00:00:00 2001 From: Umang-Rajkarnikar Date: Wed, 27 Mar 2024 18:32:22 -0400 Subject: [PATCH 2/2] Added page to send test command --- src/leo-client-app/src/constants/api.ts | 11 +++ .../src/pages/test-playground/index.tsx | 86 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/leo-client-app/src/pages/test-playground/index.tsx diff --git a/src/leo-client-app/src/constants/api.ts b/src/leo-client-app/src/constants/api.ts index 620d33e..3d8efec 100644 --- a/src/leo-client-app/src/constants/api.ts +++ b/src/leo-client-app/src/constants/api.ts @@ -158,6 +158,17 @@ export const sendCommandToForwarder = async ( return res.data; }; +export const sendCommandToTestForwarder = async (command: string) => { + const body = { + command, + }; + const res = await axios.post( + `${BACKEND_URL}/forwarder/sendTestCommand`, + body + ); + return res.data; +}; + export const executeSchedule = async ( scheduleId: string, satelliteId: string diff --git a/src/leo-client-app/src/pages/test-playground/index.tsx b/src/leo-client-app/src/pages/test-playground/index.tsx new file mode 100644 index 0000000..803dde7 --- /dev/null +++ b/src/leo-client-app/src/pages/test-playground/index.tsx @@ -0,0 +1,86 @@ +"use client"; +import { withPageAuthRequired } from "@auth0/nextjs-auth0/client"; +import Navbar from "@/components/navbar/Navbar"; +import EditScheduler from "@/components/EditSchedules"; +import { Box, Stack } from "@mui/material"; +import { useRouter } from "next/router"; +import ExecuteScheduleCard from "@/components/ExecuteScheduleCard"; +import SchedulerTerminal from "@/components/SchedulerTerminal"; +import { ReactTerminal } from "react-terminal"; +import { sendCommandToTestForwarder } from "@/constants/api"; +import { useState } from "react"; +import SocketConnection from "@/components/SocketConnection"; +import { useGetPingSocket } from "@/constants/hooks"; + +function TestPlayground() { + const router = useRouter(); + const { satId, scheduleId } = router.query as { + satId: string; + scheduleId: string; + }; + + const pingSocket = useGetPingSocket(); + + // -------- Constants -------- + const isSocketActive = + pingSocket.data?.output && + pingSocket.data.output !== "WEBSOCKET_NOT_CONNECT"; + + const [isSubmitting, setIsSubmitting] = useState(false); + + const sendCommand = async (command: string) => { + setIsSubmitting(true); + try { + const res = await sendCommandToTestForwarder(command); + setIsSubmitting(false); + return res; + } catch (error) {} + setIsSubmitting(false); + + return null; + }; + return ( +
+ + + + + + + { + const res = await sendCommand(request); + return res?.output ?? "Error"; + }} + /> + + + +
+ ); +} + +export default withPageAuthRequired(TestPlayground);