Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/controllers/ChatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -44,4 +44,4 @@ module.exports = {

}

};
};
4 changes: 2 additions & 2 deletions api/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,4 +51,4 @@ module.exports = {

}

};
};
6 changes: 3 additions & 3 deletions config/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

};

Expand All @@ -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
};
9 changes: 7 additions & 2 deletions config/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

});
Expand All @@ -40,4 +45,4 @@ module.exports.sockets = {

}

};
};