This commit is contained in:
Benjamin Toby 2025-02-06 09:48:23 +01:00
parent c90843bbd1
commit fcd69e55d4
2 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,7 @@ import React from "react";
export type UseWebsocketHookParams = { export type UseWebsocketHookParams = {
debounce?: number; debounce?: number;
url: string; url: string;
disableReconnect?: boolean;
}; };
let reconnectInterval: any; let reconnectInterval: any;
@ -27,7 +28,7 @@ export const WebSocketEventNames = ["wsDataEvent", "wsMessageEvent"] as const;
*/ */
export default function useWebSocket< export default function useWebSocket<
T extends { [key: string]: any } = { [key: string]: any } T extends { [key: string]: any } = { [key: string]: any }
>({ url, debounce }: UseWebsocketHookParams) { >({ url, debounce, disableReconnect }: UseWebsocketHookParams) {
const DEBOUNCE = debounce || 200; const DEBOUNCE = debounce || 200;
const [socket, setSocket] = React.useState<WebSocket | undefined>( const [socket, setSocket] = React.useState<WebSocket | undefined>(
@ -73,6 +74,8 @@ export default function useWebSocket<
}; };
ws.onclose = (ev) => { ws.onclose = (ev) => {
if (disableReconnect) return;
console.log("Websocket closed ... Attempting to reconnect ..."); console.log("Websocket closed ... Attempting to reconnect ...");
console.log("URL:", url); console.log("URL:", url);

View File

@ -25,7 +25,7 @@ export default function Main() {
> >
Contact Me Contact Me
</Button> </Button>
<Button {/* <Button
beforeIcon={ beforeIcon={
<ScrollText size={17} className="font-normal" /> <ScrollText size={17} className="font-normal" />
} }
@ -34,7 +34,7 @@ export default function Main() {
className="grow w-full" className="grow w-full"
> >
Resume Resume
</Button> </Button> */}
</Row> </Row>
</Stack> </Stack>
</Section> </Section>