Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ihavener-deprecate-socketio-clie…
Browse files Browse the repository at this point in the history
…nts'
  • Loading branch information
ivolucien committed Apr 20, 2017
2 parents 4e81607 + a75f5b0 commit 5e1e60d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
0.4.0 / 2017-03-19
==================

* Support disconnect for more socket.io versions

0.3.2 / 2016-08/05
==================

Expand Down
27 changes: 23 additions & 4 deletions lib/graceful-exit.js
Expand Up @@ -80,10 +80,29 @@ exports.gracefulExitHandler = function(app, server, _options) {

// Disconnect all the socket.io clients
if (options.socketio) {
options.socketio.sockets.clients().forEach(function(socket) {
logger('Killing socketio socket');
socket.disconnect();
});
var sockets = options.socketio.sockets;
var connectedSockets;
if (typeof sockets.sockets === 'object' && !Array.isArray(sockets.sockets)) {
// socket.io 1.4+
connectedSockets = _.values(sockets.sockets);
}
else if (sockets.sockets && sockets.sockets.length) {
// socket.io 1.0-1.3
connectedSockets = sockets.sockets;
}
else if (typeof sockets.clients === 'function') {
// socket.io 0.x
connectedSockets = sockets.clients();
}
if (typeof options.socketio.close === 'function') {
options.socketio.close();
}
if (connectedSockets && connectedSockets.length) {
logger('Killing ' + connectedSockets.length + ' socket.io sockets');
connectedSockets.forEach(function(socket) {
socket.disconnect();
});
}
}

// If after an acceptable time limit is reached and we still have some
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "express-graceful-exit",
"version": "0.3.3",
"version": "0.4.0",
"description": "Allow graceful exits for express apps, supporting zero downtime deploys",
"keywords": [
"express",
Expand Down

0 comments on commit 5e1e60d

Please sign in to comment.