Skip to content

Commit

Permalink
chore: update socket
Browse files Browse the repository at this point in the history
  • Loading branch information
ynwd committed Nov 16, 2024
1 parent d00c48f commit 045249a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions modules/hook/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ const useWebSocket = (url: string, room: string, user: string) => {
setIsConnected(true);
return clearInterval(i);
}
socketRef.current?.send(
JSON.stringify({ ...{ type: "ping", room, user }, ...data }),
);
countRef.current++;

if (socketRef.current?.readyState === WebSocket.OPEN) {
socketRef.current?.send(
JSON.stringify({
...{ type: "ping", room, user },
...data,
}),
);
countRef.current++;
}
}, 1000);

console.log(`WebSocket connection established: ${room}`);
Expand Down

0 comments on commit 045249a

Please sign in to comment.