jdev - 2024-12-11


  1. Guus

    web devs, is there a recommended approach to close a websocket when an end-user closes a browser window?

  2. edhelas

    Guus I do it like this in Movim

  3. edhelas

    https://github.com/movim/movim/blob/master/public/scripts/movim_websocket.js#L242

  4. leke

    window.addEventListener('beforeunload',() => { }) I think

  5. leke

    ``` window.onbeforeunload = function () { if (MovimWebsocket.connection !== null) { MovimWebsocket.connection.onclose = function () { }; // disable onclose handler first MovimWebsocket.connection.close() } }; ``` I guessed it right

  6. Guus

    Thanks!