Skip to content

Commit

Permalink
✨ Add Conduit.Socket#is_connected property
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Oct 5, 2023
1 parent 9195bdf commit 2e529c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 13 additions & 0 deletions lib/app/conduit/socket_conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ SocketConduit.setProperty(function ip() {
return handshake.address || null;
});

/**
* Is this client still connected?
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @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
*
Expand Down
12 changes: 6 additions & 6 deletions lib/class/conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ Conduit.setMethod(function shouldBePostponed() {
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.3.0
* @version 0.4.0
* @version 1.3.16
*
* @param {String} type
* @param {Object} data
Expand All @@ -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);
});
});
});
Expand Down

0 comments on commit 2e529c8

Please sign in to comment.