From efd370e79e20ea52cb67a7d2f5e36b5a7a623ad6 Mon Sep 17 00:00:00 2001 From: inmake Date: Mon, 23 Oct 2023 17:46:39 +0500 Subject: [PATCH] upd --- src/HistoryPage.tsx | 11 +++++----- src/MonitoringPage.tsx | 24 ++++++-------------- src/StreamPage.tsx | 21 +++++------------- src/components/modals/AFKTimerModal.tsx | 29 +++++++++++++++++++++++-- 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/HistoryPage.tsx b/src/HistoryPage.tsx index eac3bf0..fb4b56e 100644 --- a/src/HistoryPage.tsx +++ b/src/HistoryPage.tsx @@ -23,13 +23,14 @@ function HistoryPage() { {history.map((item: any) => (

- Дата и время запуска: {new Date(item.createdAt).toLocaleString()} + Дата и время: {new Date(item.createdAt).toLocaleString()}

-

Сборка: "{item.title}"

+

Сборка: "{item.build}"

+

Локация: "{item.location}"

Сервер: "{item.server}"

-

IP клиента: {item.headers["x-forwarded-for"]}

-

Город: {item.city}

-

Устройство: {item.headers["user-agent"]}

+

IP клиента: {item.ownerIp}

+ {/*

Город: {item.city}

*/} + {/*

Устройство: {item.headers["user-agent"]}

*/}
))} diff --git a/src/MonitoringPage.tsx b/src/MonitoringPage.tsx index ec1bb3d..d822d9a 100644 --- a/src/MonitoringPage.tsx +++ b/src/MonitoringPage.tsx @@ -34,19 +34,16 @@ function MonitoringPage() { }, 1000); } - async function endActiveSession( - location: string, - server: string, - uePort: number, - cirrusPort: number - ) { - await ky - .get( + async function endSession(activeSessionId: string) { + const result = await ky + .post( `${ import.meta.env.VITE_COORD_URL - }/end?location=${location}&server=${server}&uePort=${uePort}&cirrusPort=${cirrusPort}` + }/active_sessions/${activeSessionId}/end` ) .json(); + + console.log(result); } useEffect(() => { @@ -181,14 +178,7 @@ function MonitoringPage() { Открыть в новом окне - + */} diff --git a/src/components/modals/AFKTimerModal.tsx b/src/components/modals/AFKTimerModal.tsx index 888b181..c744c5f 100644 --- a/src/components/modals/AFKTimerModal.tsx +++ b/src/components/modals/AFKTimerModal.tsx @@ -1,13 +1,38 @@ -import { useEffect, useState } from "react"; +/* eslint-disable react-hooks/exhaustive-deps */ +import { useEffect, useRef, useState } from "react"; import useModalStore from "../../stores/useModalStore"; +import ky from "ky"; +import { useParams } from "react-router-dom"; function AFKTimerModal() { const setModal = useModalStore((state) => state.setModal); const [afkTimer, setAfkTimer] = useState(60); + const afkTimerRef = useRef(); + afkTimerRef.current = afkTimer; + const params = useParams(); + + async function endSession() { + await ky.post( + `${import.meta.env.VITE_COORD_URL}/active_sessions/${params.id}/end` + ); + } + + async function checkAFK(interval: number) { + console.log(afkTimerRef.current); + + if (afkTimerRef.current && afkTimerRef.current <= 1) { + clearInterval(interval); + await endSession(); + window.location.reload(); + return; + } + + setAfkTimer((prev) => prev - 1); + } useEffect(() => { const interval = setInterval(() => { - setAfkTimer((prev) => prev - 1); + checkAFK(interval); }, 1000); return () => {