Do not set websocket to null if in error state.
This commit is contained in:
parent
9addff6c13
commit
d27bfbf481
1 changed files with 5 additions and 1 deletions
|
@ -25,6 +25,7 @@ const useSocket = (
|
||||||
url: string,
|
url: string,
|
||||||
setIsWSReady: (ready: boolean) => void,
|
setIsWSReady: (ready: boolean) => void,
|
||||||
setError: (error: boolean) => void,
|
setError: (error: boolean) => void,
|
||||||
|
hasError: boolean
|
||||||
) => {
|
) => {
|
||||||
const [ws, setWs] = useState<WebSocket | null>(null);
|
const [ws, setWs] = useState<WebSocket | null>(null);
|
||||||
|
|
||||||
|
@ -183,7 +184,9 @@ const useSocket = (
|
||||||
|
|
||||||
ws.onclose = () => {
|
ws.onclose = () => {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
setWs(null);
|
if (!hasError) {
|
||||||
|
setWs(null); // forces websocket to reopen when needed.
|
||||||
|
}
|
||||||
console.log('[DEBUG] closed');
|
console.log('[DEBUG] closed');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -274,6 +277,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
||||||
process.env.NEXT_PUBLIC_WS_URL!,
|
process.env.NEXT_PUBLIC_WS_URL!,
|
||||||
setIsWSReady,
|
setIsWSReady,
|
||||||
setHasError,
|
setHasError,
|
||||||
|
hasError
|
||||||
);
|
);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue