From a3bd9120bf0584cd6e827acb6f4dd2e1455b4676 Mon Sep 17 00:00:00 2001 From: ynwd <10122431+ynwd@users.noreply.github.com> Date: Sat, 30 Nov 2024 10:21:59 +0700 Subject: [PATCH] feat: add health --- modules/hook/socket.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/hook/socket.ts b/modules/hook/socket.ts index 73956d19..622ccde8 100644 --- a/modules/hook/socket.ts +++ b/modules/hook/socket.ts @@ -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(() => { @@ -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(); };