user3134962 user3134962 - 17 days ago 5
Javascript Question

Logic on disconnect sails.js socket.io

I am using sails.js with the raw API of socket.io. Now when a user disconnects, I want to inform everyone else. Normally I would do something like:

socket.on('disconnect', function () {
//disconnect logic
});


But I am not sure how I would accomplish this inside of a sails.js controller. Any help would be appreciated.

Answer

Starting with Sails v0.9.8, your config/sockets.js file will have both onConnect and onDisconnect methods that give you access both to the connecting/disconnecting socket and the session.

Comments