Skip to content
Snippets Groups Projects
Unverified Commit 376011ea authored by GyDi's avatar GyDi
Browse files

fix: refresh websocket

parent 2ce7624c
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,8 @@ const LayoutTraffic = () => {
// setup log ws during layout
useLogSetup();
const [refresh, setRefresh] = useState({});
useEffect(() => {
if (!clashInfo) return;
......@@ -33,8 +35,12 @@ const LayoutTraffic = () => {
setTraffic(data);
});
ws.addEventListener("error", () => {
setTimeout(() => setRefresh({}), 1000);
});
return () => ws?.close();
}, [clashInfo]);
}, [clashInfo, refresh]);
const [up, upUnit] = parseTraffic(traffic.up);
const [down, downUnit] = parseTraffic(traffic.down);
......
import dayjs from "dayjs";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useRecoilValue, useSetRecoilState } from "recoil";
import { getClashLogs } from "@/services/cmds";
import { useClashInfo } from "@/hooks/use-clash";
......@@ -14,6 +14,8 @@ export const useLogSetup = () => {
const enableLog = useRecoilValue(atomEnableLog);
const setLogData = useSetRecoilState(atomLogData);
const [refresh, setRefresh] = useState({});
useEffect(() => {
if (!enableLog || !clashInfo) return;
......@@ -31,6 +33,10 @@ export const useLogSetup = () => {
});
});
ws.addEventListener("error", () => {
setTimeout(() => setRefresh({}), 1000);
});
return () => ws?.close();
}, [clashInfo, enableLog]);
}, [clashInfo, enableLog, refresh]);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment