react-use-websocket icon indicating copy to clipboard operation
react-use-websocket copied to clipboard

[Heartbeat question] is a ping/pong cycle skipped if a 'standard' message is received on the websocket?

Open 1nfm1k3 opened this issue 9 months ago • 2 comments

I configured a websocket with a pretty standard heartbeat configuration:

heartbeat: {
      message: 'ping',
      returnMessage: 'pong',
      interval: 10000,
      timeout: 60000
    }

However, I noticed that no ping/pong exchanges were happening in my use case. So, I lowered down the interval to something like 1000, and at that point I could see the ping/pong messages being sent.

Finally, I realized the backend sends a message on this websocket roughly every ~5 seconds. Is this what is preventing the ping messages from being sent by the client? Or, more generally: receiving a 'standard' message on the websocket clears up a ping/pong cycle or am I misunderstanding something?

Using ^4.13.0.

1nfm1k3 avatar Feb 12 '25 10:02 1nfm1k3