diff --git a/CHANGELOG.md b/CHANGELOG.md index 57cddb7a..a73fa4b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Minimum node version is now also `v16.20.1` because of the mongodb upgrade * Upgrade all dependencies * Don't log `.js.map` 404 errors +* Add `Conduit.Socket#is_connected` property ## 1.3.15 (2023-07-03) diff --git a/lib/app/conduit/socket_conduit.js b/lib/app/conduit/socket_conduit.js index 03a53dce..e442ede2 100644 --- a/lib/app/conduit/socket_conduit.js +++ b/lib/app/conduit/socket_conduit.js @@ -132,6 +132,19 @@ SocketConduit.setProperty(function ip() { return handshake.address || null; }); +/** + * Is this client still connected? + * + * @author Jelle De Loecker + * @since 1.3.16 + * @version 1.3.16 + * + * @type {Boolean} + */ +SocketConduit.setProperty(function is_connected() { + return this.socket?.connected || false; +}); + /** * Parse the request, get information from the url * diff --git a/lib/class/conduit.js b/lib/class/conduit.js index 806a3ad1..3122942f 100644 --- a/lib/class/conduit.js +++ b/lib/class/conduit.js @@ -2693,7 +2693,7 @@ Conduit.setMethod(function shouldBePostponed() { * * @author Jelle De Loecker * @since 0.3.0 - * @version 0.4.0 + * @version 1.3.16 * * @param {String} type * @param {Object} data @@ -2702,18 +2702,18 @@ Alchemy.setMethod(function broadcast(type, data) { alchemy.sessions.forEach(function eachSession(session, key) { - // Go over every listening scene and submit the data - Object.each(session.connections, function eachScene(scene, scene_id) { + // Go over every listening socket and submit the data + Object.each(session.connections, function eachScene(socket_conduit, scene_id) { - if (!scene) { + if (!socket_conduit?.is_connected) { return; } if (alchemy.settings.debug) { - log.debug('Broadcasting', type, {data, scene}); + log.debug('Broadcasting', type, {data, scene: socket_conduit}); } - scene.submit(type, data); + socket_conduit.submit(type, data); }); }); });