Fix error connection
This commit is contained in:
parent
22913be04e
commit
a4bf5b4579
1 changed files with 14 additions and 7 deletions
|
@ -160,7 +160,11 @@ const useSocket = (
|
|||
wsURL.search = searchParams.toString();
|
||||
|
||||
const ws = new WebSocket(wsURL.toString());
|
||||
|
||||
const keepAliveInterval = setInterval(() => {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'ping' }));
|
||||
}
|
||||
}, 50000);
|
||||
const timeoutId = setTimeout(() => {
|
||||
if (ws.readyState !== 1) {
|
||||
toast.error(
|
||||
|
@ -176,16 +180,20 @@ const useSocket = (
|
|||
};
|
||||
|
||||
ws.onerror = () => {
|
||||
clearInterval(keepAliveInterval);
|
||||
clearTimeout(timeoutId);
|
||||
setError(true);
|
||||
toast.error('WebSocket connection error.');
|
||||
};
|
||||
|
||||
// ws.onclose = () => {
|
||||
// clearTimeout(timeoutId);
|
||||
// setError(true);
|
||||
// console.log('[DEBUG] closed');
|
||||
// };
|
||||
ws.onclose = () => {
|
||||
clearTimeout(timeoutId);
|
||||
setError(true);
|
||||
console.log('[DEBUG] closed');
|
||||
setTimeout(() => {
|
||||
connectWs();
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
ws.addEventListener('message', (e) => {
|
||||
const data = JSON.parse(e.data);
|
||||
|
@ -529,7 +537,6 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [messages]);
|
||||
console.log(hasError);
|
||||
|
||||
// if (hasError) {
|
||||
// return (
|
||||
|
|
Loading…
Add table
Reference in a new issue