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

Connection persists on closed tab

Open poljsakerik opened this issue 2 years ago • 1 comments

Hey, thanks for the awesome lib. I have a question however, is the socket supposed to not close when I close the tab ?

poljsakerik avatar May 16 '22 20:05 poljsakerik

Hi @poljsakerik ,

When you say 'tab', do you mean browser tab? If so, the browser is supposed to handle this for you (afaik), but there is no reliable way to back this up on the client-side (this library only closes the websockets based on when your components unmount, which will not get triggered if the window is suddenly terminated). I'd recommend setting up a heartbeat/ping-pong system, which will close the connection on the server-side if the client doesn't respond in a timely manner.

robtaussig avatar May 17 '22 14:05 robtaussig