-
Guus
web devs, is there a recommended approach to close a websocket when an end-user closes a browser window?
-
edhelas
Guus I do it like this in Movim
-
edhelas
https://github.com/movim/movim/blob/master/public/scripts/movim_websocket.js#L242
-
leke
window.addEventListener('beforeunload',() => { }) I think
-
leke
``` window.onbeforeunload = function () { if (MovimWebsocket.connection !== null) { MovimWebsocket.connection.onclose = function () { }; // disable onclose handler first MovimWebsocket.connection.close() } }; ``` I guessed it right
-
Guus
Thanks!