diff --git a/api/controllers/ChatController.js b/api/controllers/ChatController.js index 7d561a7..a88665f 100644 --- a/api/controllers/ChatController.js +++ b/api/controllers/ChatController.js @@ -3,7 +3,7 @@ module.exports = { // Send a private message from one user to another private: function(req, res) { // Get the ID of the currently connected socket - var socketId = sails.sockets.id(req.socket); + var socketId = sails.sockets.getId(req.socket); // Use that ID to look up the user in the session // We need to do this because we can have more than one user // per session, since we're creating one user per socket @@ -23,7 +23,7 @@ module.exports = { // Post a message in a public chat room public: function(req, res) { // Get the ID of the currently connected socket - var socketId = sails.sockets.id(req.socket); + var socketId = sails.sockets.getId(req.socket); // Use that ID to look up the user in the session // We need to do this because we can have more than one user // per session, since we're creating one user per socket @@ -44,4 +44,4 @@ module.exports = { } -}; \ No newline at end of file +}; diff --git a/api/controllers/UserController.js b/api/controllers/UserController.js index 249b4de..58e0483 100644 --- a/api/controllers/UserController.js +++ b/api/controllers/UserController.js @@ -8,7 +8,7 @@ module.exports = { announce: function(req, res) { // Get the socket ID from the reauest - var socketId = sails.sockets.id(req); + var socketId = sails.sockets.getId(req); // Get the session from the request var session = req.session; @@ -51,4 +51,4 @@ module.exports = { } -}; \ No newline at end of file +}; diff --git a/config/http.js b/config/http.js index a4d4f01..c3a1f0a 100644 --- a/config/http.js +++ b/config/http.js @@ -6,6 +6,9 @@ */ module.exports.http = { + // The number of seconds to cache files being served from disk + // (only works in production mode) + cache: 31557600000 }; @@ -31,7 +34,4 @@ module.exports.http = { */ module.exports.cache = { - // The number of seconds to cache files being served from disk - // (only works in production mode) - maxAge: 31557600000 }; diff --git a/config/sockets.js b/config/sockets.js index af62b74..1a6750f 100644 --- a/config/sockets.js +++ b/config/sockets.js @@ -14,8 +14,10 @@ module.exports.sockets = { afterDisconnect: function(session, socket, cb) { console.log("DISCONNECT SESSION", session); try { + if (!session.users) return cb(); + // Look up the user ID using the connected socket - var userId = session.users[sails.sockets.id(socket)].id; + var userId = session.users[sails.sockets.getId(socket)].id; // Get the user instance User.findOne(userId).populate('rooms').exec(function(err, user) { @@ -28,6 +30,9 @@ module.exports.sockets = { // Publish the destroy event to every socket subscribed to this user instance User.publishDestroy(user.id, null, {previous: user}); + // clean up users list in session + delete session.users[sails.sockets.getId(socket)]; + return cb(); }); @@ -40,4 +45,4 @@ module.exports.sockets = { } -}; \ No newline at end of file +};