Skip to content

Commit

Permalink
feat: add health
Browse files Browse the repository at this point in the history
  • Loading branch information
ynwd committed Nov 30, 2024
1 parent eee5d69 commit a3bd912
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions modules/hook/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const useWebSocket = (url: string, room: string, user: string) => {
...data,
}),
);
return countRef.current++;
countRef.current++;
console.log("ws ping:", room);
} else {
console.log("ws close:", room);
}

console.log(`WebSocket connection closed: ${room}`);
}, 300);
}, 500);
}

useEffect(() => {
Expand All @@ -52,12 +53,14 @@ const useWebSocket = (url: string, room: string, user: string) => {
};

socketRef.current.onclose = () => {
console.error("WebSocket close");
setIsConnected(false);
};

socketRef.current.onerror = (error) => {
console.error("WebSocket error:", error);
// Close the socket on error
setIsConnected(false);
socketRef.current?.close();
};

Expand Down

0 comments on commit a3bd912

Please sign in to comment.