From 2d82a6e5838d3a5418016f8dc4ab5db726a899a0 Mon Sep 17 00:00:00 2001 From: Eivind Dalholt Date: Sun, 1 Oct 2023 14:41:32 +0200 Subject: [PATCH] feat: enable reconnect on frontend --- frontend/src/components/EditAssembly.tsx | 9 ++++++++- frontend/src/pages/AssemblyPage.tsx | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/EditAssembly.tsx b/frontend/src/components/EditAssembly.tsx index c869b39..86467ad 100644 --- a/frontend/src/components/EditAssembly.tsx +++ b/frontend/src/components/EditAssembly.tsx @@ -40,7 +40,14 @@ export function EditAssembly(state: { group: UserDataGroupType }) { const [accordionActiveTabs, setAccordionActiveTabs] = useState([]); const { lastMessage, sendJsonMessage } = useWebSocket( - import.meta.env.VITE_SOCKET_URL + "/organizer" + import.meta.env.VITE_SOCKET_URL + "/organizer", + { + //Will attempt to reconnect on all close events, such as server shutting down + shouldReconnect: () => true, + // Try to reconnect 300 times before giving up. + // Also possible to change interval (default is 5000ms) + reconnectAttempts: 300, + } ); // Request access to live assembly data for the given group when component is mounted. diff --git a/frontend/src/pages/AssemblyPage.tsx b/frontend/src/pages/AssemblyPage.tsx index 588c704..6251a1a 100644 --- a/frontend/src/pages/AssemblyPage.tsx +++ b/frontend/src/pages/AssemblyPage.tsx @@ -13,7 +13,7 @@ import { LimitedVoteType } from "../types/votes"; import { getUserData } from "../services/organizer"; import { NotFound } from "./NotFound"; -export function AssemblyLobby() { +export function AssemblyLobxby() { let navigate = useNavigate(); const { groupSlug } = useParams() as { groupSlug: string }; const [groupName, setGroupName] = useState(undefined); @@ -26,7 +26,14 @@ export function AssemblyLobby() { >(undefined); const [voted, setVoted] = useState(false); const { lastMessage } = useWebSocket( - import.meta.env.VITE_SOCKET_URL + "/lobby" + import.meta.env.VITE_SOCKET_URL + "/lobby", + { + //Will attempt to reconnect on all close events, such as server shutting down + shouldReconnect: () => true, + // Try to reconnect 300 times before giving up. + // Also possible to change interval (default is 5000ms) + reconnectAttempts: 300, + } ); const { checkedIn, setCheckedIn } = useContext( checkedInState