#769·peerjs

Handling broken connections

Author: NiksacCreated Dec 14, 2020Updated Feb 6, 2026
Labelsclient

I'm testing with latest peerjs and two latest version chrome browsers.

When i connect two peers using peerjs and then shutdown the network, the connection "close" event does not fire.

The connection's readyState stays OPEN and I do not notice the disconnect in code. The connection will not recover when I restore the network. I get a "close event" after something like 10 minutes and only as a result of using send() on the connection.

The peerjs control connection fires its handlers much faster.

My question is: how to handle such disconnects. Do I need to implement my own kind of heartbeat between the clients? Can i utilize the websocket's "ping" functionality for that or is there an even better way?