Create e.g. assets/js/dependencies/app.io.js
with:
io.socket.on(\'connect\', function socketConnected() {
console.debug(\"This is from the connect
we need more informations such as:
Above all i can show you how i configured my Sails backend:
in my .sailsrc
i have the hooks configured as follows
"hooks": {
"csrf": false,
"grunt": false,
"i18n": false,
"pubsub": false,
"session": false,
"sockets": true,
"views": false}
then in my UserController.js
i have this simple method that enables the socket communication
enableNtofications: function(req, res){
// checking if the request comes from
// a socket request
if(req.isSocket){
// getting the current logged user
var user = req.user;
// subuscribing the client to model changes
User.subscribe(req, [user.id]);
return res.ok();
} else {
return res.badRequest();
}
},
my frontend uses Angular and a the ngSails module that is a sort of wrapper of 'sails.io' for Angular
and in my 'UserService.js' i can do something like
// waiting for notifications on User
$sails.on('user', function(event) {
if (event) {
// manage the message here...
}
});
and then call the server method in order to enable the sockets
// calling the service
return $sails.post('/user/enableNtofications').then(
// ok
function() {},
// ko
function(data) {
console.log("enable notifications KO");
console.log(data.error);
});
(you need also to inject the '$sails' module and configure it properly...)
Hope this could help you