resend request on lost ws connection
parent
730eee9751
commit
f56a4235e7
|
@ -1,5 +1,10 @@
|
||||||
import { createContext, useContext, useEffect, useRef } from "react";
|
import { createContext, useContext, useEffect, useRef } from "react";
|
||||||
import { BrowserTabSession, Constants, myFetch } from "../utils";
|
import {
|
||||||
|
BrowserTabSession,
|
||||||
|
Constants,
|
||||||
|
myFetch,
|
||||||
|
wsConnectionCustomEventName,
|
||||||
|
} from "../utils";
|
||||||
import { useSideBarContext } from "./SideBarContext";
|
import { useSideBarContext } from "./SideBarContext";
|
||||||
import { useAppContext } from "./AppContext";
|
import { useAppContext } from "./AppContext";
|
||||||
import { handleWebSocketMessage } from "../Handlers/WebSocketMessageHandler";
|
import { handleWebSocketMessage } from "../Handlers/WebSocketMessageHandler";
|
||||||
|
@ -15,6 +20,8 @@ const WebSocketContext = createContext(null);
|
||||||
|
|
||||||
export const useWebSocketContext = () => useContext(WebSocketContext);
|
export const useWebSocketContext = () => useContext(WebSocketContext);
|
||||||
|
|
||||||
|
let wsConnectionEvent = null;
|
||||||
|
|
||||||
export default function WebSocketProvider({
|
export default function WebSocketProvider({
|
||||||
children,
|
children,
|
||||||
userSession,
|
userSession,
|
||||||
|
@ -35,6 +42,12 @@ export default function WebSocketProvider({
|
||||||
const usersContext = useUsersContext();
|
const usersContext = useUsersContext();
|
||||||
const consolesContext = useConsolesContext();
|
const consolesContext = useConsolesContext();
|
||||||
|
|
||||||
|
if (wsConnectionEvent === null) {
|
||||||
|
wsConnectionEvent = new CustomEvent(wsConnectionCustomEventName, {
|
||||||
|
detail: "wsReconnect",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
ws.current = new WebSocket(
|
ws.current = new WebSocket(
|
||||||
`${Constants.WS_ADDRESS}?auth=${userSession}&bts=${BrowserTabSession}`
|
`${Constants.WS_ADDRESS}?auth=${userSession}&bts=${BrowserTabSession}`
|
||||||
|
@ -45,6 +58,9 @@ export default function WebSocketProvider({
|
||||||
sideBarContext.setConnectionBadgeStatus("success");
|
sideBarContext.setConnectionBadgeStatus("success");
|
||||||
setIsWebSocketReady(true);
|
setIsWebSocketReady(true);
|
||||||
|
|
||||||
|
console.log("dispatchEvent");
|
||||||
|
document.dispatchEvent(wsConnectionEvent);
|
||||||
|
|
||||||
myFetch("/user/", "GET").then((data) => {
|
myFetch("/user/", "GET").then((data) => {
|
||||||
appContext.userId.current = data.UserId;
|
appContext.userId.current = data.UserId;
|
||||||
appContext.setUserPermissions(
|
appContext.setUserPermissions(
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
FormatDatetime,
|
FormatDatetime,
|
||||||
hasPermission,
|
hasPermission,
|
||||||
myFetch,
|
myFetch,
|
||||||
|
wsConnectionCustomEventName,
|
||||||
} from "../../../utils";
|
} from "../../../utils";
|
||||||
import { useAppContext } from "../../../Contexts/AppContext";
|
import { useAppContext } from "../../../Contexts/AppContext";
|
||||||
import { useConsolesContext } from "../../../Contexts/ConsolesContext";
|
import { useConsolesContext } from "../../../Contexts/ConsolesContext";
|
||||||
|
@ -136,9 +137,14 @@ function LogManagerServersTable({ t, webSocketContext, appContext }) {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const lmscRequest = () =>
|
||||||
myFetch("/lmsc", "GET").then((data) =>
|
myFetch("/lmsc", "GET").then((data) =>
|
||||||
consolesContext.setConnectedLogManagerServers(data)
|
consolesContext.setConnectedLogManagerServers(data)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
lmscRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () => lmscRequest());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -12,7 +12,12 @@ import {
|
||||||
Typography,
|
Typography,
|
||||||
notification,
|
notification,
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import { Constants, hasPermission, myFetch } from "../../../utils";
|
import {
|
||||||
|
Constants,
|
||||||
|
hasPermission,
|
||||||
|
myFetch,
|
||||||
|
wsConnectionCustomEventName,
|
||||||
|
} from "../../../utils";
|
||||||
import {
|
import {
|
||||||
ArrowDownOutlined,
|
ArrowDownOutlined,
|
||||||
ArrowUpOutlined,
|
ArrowUpOutlined,
|
||||||
|
@ -118,11 +123,18 @@ export default function AdminAreaRoles() {
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const rolesRequest = () =>
|
||||||
myFetch("/adminarea/roles", "GET").then((data) => {
|
myFetch("/adminarea/roles", "GET").then((data) => {
|
||||||
adminAreaRolesContext.setRoles(data.Roles);
|
adminAreaRolesContext.setRoles(data.Roles);
|
||||||
adminAreaRolesContext.setRolesPermissions(data.RolesPermissions);
|
adminAreaRolesContext.setRolesPermissions(data.RolesPermissions);
|
||||||
adminAreaRolesContext.setUsers(data.Users);
|
adminAreaRolesContext.setUsers(data.Users);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rolesRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () =>
|
||||||
|
rolesRequest()
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
hasOnePermission,
|
hasOnePermission,
|
||||||
hasPermission,
|
hasPermission,
|
||||||
myFetch,
|
myFetch,
|
||||||
|
wsConnectionCustomEventName,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
@ -331,11 +332,18 @@ export default function AllUsers() {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const usersRequest = () =>
|
||||||
myFetch("/users", "GET").then((data) => {
|
myFetch("/users", "GET").then((data) => {
|
||||||
usersContext.setRoleId(data.RoleId);
|
usersContext.setRoleId(data.RoleId);
|
||||||
usersContext.setUsers(data.Users);
|
usersContext.setUsers(data.Users);
|
||||||
usersContext.setRoles(data.Roles);
|
usersContext.setRoles(data.Roles);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
usersRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () =>
|
||||||
|
usersRequest()
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Col, Result, Row, Select, Space } from "antd";
|
import { Col, Result, Row, Select, Space } from "antd";
|
||||||
import LogCard from "../../Components/LogCard";
|
import LogCard from "../../Components/LogCard";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { AppStyle, myFetch } from "../../utils";
|
import { AppStyle, myFetch, wsConnectionCustomEventName } from "../../utils";
|
||||||
import { useConsolesContext } from "../../Contexts/ConsolesContext";
|
import { useConsolesContext } from "../../Contexts/ConsolesContext";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
@ -15,11 +15,16 @@ export default function Consoles() {
|
||||||
const [result, setResult] = useState();
|
const [result, setResult] = useState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const lmscRequest = () =>
|
||||||
myFetch("/lmsc", "GET").then((data) => {
|
myFetch("/lmsc", "GET").then((data) => {
|
||||||
consolesContext.setConnectedLogManagerServers(data);
|
consolesContext.setConnectedLogManagerServers(data);
|
||||||
|
|
||||||
setSelectedLogServer(data.length > 0 ? data[0].Address : "");
|
setSelectedLogServer(data.length > 0 ? data[0].Address : "");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
lmscRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () => lmscRequest());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -3,7 +3,12 @@ import { useEffect, useState } from "react";
|
||||||
import GroupTasksViewModal from "./GroupTasksViewModal";
|
import GroupTasksViewModal from "./GroupTasksViewModal";
|
||||||
import GroupTypeSelectionModal from "./GroupTypeSelectionModal";
|
import GroupTypeSelectionModal from "./GroupTypeSelectionModal";
|
||||||
import GroupTaskTableList from "./GroupTasksTableList";
|
import GroupTaskTableList from "./GroupTasksTableList";
|
||||||
import { Constants, hasPermission, myFetch } from "../../../utils";
|
import {
|
||||||
|
Constants,
|
||||||
|
hasPermission,
|
||||||
|
myFetch,
|
||||||
|
wsConnectionCustomEventName,
|
||||||
|
} from "../../../utils";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ReloadOutlined } from "@ant-design/icons";
|
import { ReloadOutlined } from "@ant-design/icons";
|
||||||
import { useGroupTasksContext } from "../../../Contexts/GroupTasksContext";
|
import { useGroupTasksContext } from "../../../Contexts/GroupTasksContext";
|
||||||
|
@ -75,10 +80,16 @@ export default function GroupTasks({ isGroupTasksViewModalOpen }) {
|
||||||
}
|
}
|
||||||
}, [paramCategory]);
|
}, [paramCategory]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(() => {
|
||||||
() => fetchGroupTasks(groupTasksContext.paginationPage),
|
const groupTasksRequest = () =>
|
||||||
[groupTasksContext.paginationPage]
|
fetchGroupTasks(groupTasksContext.paginationPage);
|
||||||
|
|
||||||
|
groupTasksRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () =>
|
||||||
|
groupTasksRequest()
|
||||||
);
|
);
|
||||||
|
}, [groupTasksContext.paginationPage]);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => groupTasksContext.setSelectInputs({}),
|
() => groupTasksContext.setSelectInputs({}),
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
hasPermission,
|
hasPermission,
|
||||||
myFetch,
|
myFetch,
|
||||||
myFetchContentType,
|
myFetchContentType,
|
||||||
|
wsConnectionCustomEventName,
|
||||||
} from "../../../utils";
|
} from "../../../utils";
|
||||||
import MyPagination from "../../../Components/MyPagination";
|
import MyPagination from "../../../Components/MyPagination";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
@ -508,14 +509,26 @@ export default function Robots() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => fetchRobots(0, robotsPaginationPage), [robotsPaginationPage]);
|
const initRequest = () => fetchRobots(0, robotsPaginationPage);
|
||||||
|
|
||||||
useEffect(
|
|
||||||
() => fetchRobots(1, unauthorizedRobotsPaginationPage),
|
|
||||||
[unauthorizedRobotsPaginationPage]
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
initRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () => initRequest());
|
||||||
|
}, [robotsPaginationPage]);
|
||||||
|
|
||||||
|
const initRequest2 = () => fetchRobots(1, unauthorizedRobotsPaginationPage);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
initRequest2();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () =>
|
||||||
|
initRequest2()
|
||||||
|
);
|
||||||
|
}, [unauthorizedRobotsPaginationPage]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const permitJoinRequest = () =>
|
||||||
myFetch(
|
myFetch(
|
||||||
"/permitjoin",
|
"/permitjoin",
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -525,6 +538,12 @@ export default function Robots() {
|
||||||
Constants.ROBOTICS_API_ADDRESS
|
Constants.ROBOTICS_API_ADDRESS
|
||||||
).then((data) => setPermitJoinEnabled(data.Enabled));
|
).then((data) => setPermitJoinEnabled(data.Enabled));
|
||||||
|
|
||||||
|
permitJoinRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () =>
|
||||||
|
permitJoinRequest()
|
||||||
|
);
|
||||||
|
|
||||||
sseEventSource.current = new EventSource(
|
sseEventSource.current = new EventSource(
|
||||||
`${Constants.ROBOTICS_API_ADDRESS}/sse`
|
`${Constants.ROBOTICS_API_ADDRESS}/sse`
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import {
|
||||||
hasPermission,
|
hasPermission,
|
||||||
isEmailValid,
|
isEmailValid,
|
||||||
myFetch,
|
myFetch,
|
||||||
|
wsConnectionCustomEventName,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
@ -271,6 +272,7 @@ export default function UserProfile() {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const userProfileRequest = () =>
|
||||||
myFetch("/user/profile", "GET").then((data) => {
|
myFetch("/user/profile", "GET").then((data) => {
|
||||||
userProfileContext.setEmail(data.Email);
|
userProfileContext.setEmail(data.Email);
|
||||||
userProfileContext.setSessions(data.Sessions);
|
userProfileContext.setSessions(data.Sessions);
|
||||||
|
@ -278,6 +280,12 @@ export default function UserProfile() {
|
||||||
|
|
||||||
setEmail(data.Email);
|
setEmail(data.Email);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
userProfileRequest();
|
||||||
|
|
||||||
|
document.addEventListener(wsConnectionCustomEventName, () =>
|
||||||
|
userProfileRequest()
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
|
|
|
@ -261,6 +261,8 @@ export function setUserSessionToLocalStorage(session) {
|
||||||
// not receive any messages
|
// not receive any messages
|
||||||
export const BrowserTabSession = GetUuid();
|
export const BrowserTabSession = GetUuid();
|
||||||
|
|
||||||
|
export const wsConnectionCustomEventName = "wsConnection";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* websocket
|
* websocket
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue