fix websocket connection
This commit is contained in:
@@ -21,7 +21,25 @@ function App() {
|
|||||||
const [reqError, setReqError] = useState<undefined|string>()
|
const [reqError, setReqError] = useState<undefined|string>()
|
||||||
const [error, setError] = useState<string|null>()
|
const [error, setError] = useState<string|null>()
|
||||||
const [loadinBtn, setLoadingBtn] = useState(false);
|
const [loadinBtn, setLoadingBtn] = useState(false);
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
socketio.auth = { token: localStorage.getItem("access_token") }
|
||||||
|
socketio.connect()
|
||||||
|
getStatus()
|
||||||
|
socketio.on("update", (data) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: data })
|
||||||
|
})
|
||||||
|
socketio.on("connect_error", (err) => {
|
||||||
|
errorNotify("Socket.Io connection failed! ",`Error message: [${err.message}]`)
|
||||||
|
getStatus()
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
socketio.off("update")
|
||||||
|
socketio.off("connect_error")
|
||||||
|
socketio.disconnect()
|
||||||
|
}
|
||||||
|
},[])
|
||||||
|
|
||||||
const getStatus = () =>{
|
const getStatus = () =>{
|
||||||
getstatus().then( res =>{
|
getstatus().then( res =>{
|
||||||
@@ -140,26 +158,6 @@ function App() {
|
|||||||
|
|
||||||
const PageRouting = ({ getStatus }:{ getStatus:()=>void }) => {
|
const PageRouting = ({ getStatus }:{ getStatus:()=>void }) => {
|
||||||
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
socketio.auth = { token: localStorage.getItem("access_token") }
|
|
||||||
socketio.connect()
|
|
||||||
getStatus()
|
|
||||||
socketio.on("update", (data) => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: data })
|
|
||||||
})
|
|
||||||
socketio.on("connect_error", (err) => {
|
|
||||||
errorNotify("Socket.Io connection failed! ",`Error message: [${err.message}]`)
|
|
||||||
getStatus()
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
socketio.off("update")
|
|
||||||
socketio.off("connect_error")
|
|
||||||
socketio.disconnect()
|
|
||||||
}
|
|
||||||
},[])
|
|
||||||
|
|
||||||
return <Routes>
|
return <Routes>
|
||||||
<Route element={<MainLayout><Outlet /></MainLayout>}>
|
<Route element={<MainLayout><Outlet /></MainLayout>}>
|
||||||
<Route path="nfregex" element={<NFRegex><Outlet /></NFRegex>} >
|
<Route path="nfregex" element={<NFRegex><Outlet /></NFRegex>} >
|
||||||
|
|||||||
Reference in New Issue
Block a user