Do not set websocket to null if in error state.

This commit is contained in:
projectmoon 2024-07-30 19:45:20 +02:00
parent f03f665e08
commit 84821d289c

View file

@ -25,6 +25,7 @@ const useSocket = (
url: string,
setIsWSReady: (ready: boolean) => void,
setError: (error: boolean) => void,
hasError: boolean
) => {
const [ws, setWs] = useState<WebSocket | null>(null);
@ -194,7 +195,9 @@ const useSocket = (
ws.onclose = () => {
clearTimeout(timeoutId);
setWs(null);
if (!hasError) {
setWs(null); // forces websocket to reopen when needed.
}
console.log('[DEBUG] closed');
};
@ -285,6 +288,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
process.env.NEXT_PUBLIC_WS_URL!,
setIsWSReady,
setHasError,
hasError
);
const [loading, setLoading] = useState(false);