I have a nodejs websocket server and I have the following problem.
When my clients connect to the server and terminate gracefully the onclose
method is
To detect a disconnect, you need to have some traffic. If your application produces constant traffic, then you could do something like reset a counter each time something is received, and consider the connection failed when the counter runs out.
Otherwise you should be able to use the pings that WebSocket offers. These are not exposed in the browser, but your WebSocket library for Node.js may allow you to turn them on and get a notification if a ping fails.