I would like to create a chat application in my sailjs based project, How and where can i configure the socket and related setting in the server ? I got a sample project from this repository but it is using sails v0.10 and i need to use sails v0.11.3, but v0.11.3 having many changes while using socket in Nodejs script, for example, We can't use onConnect since it is deprecated.
I have tried this example, but not working this with sail v0.11.3 https://github.com/sgress454/sailsChat
This is the code i have done, but i don't know where should i put , it is not working when i put this in sockets.js file with in the config directory
// Set some options:
// (you have to specify the host and port of the Sails backend when using this library from Node.js)
io.sails.url = 'http://localhost:9002';
// ...
io.socket.on('connect', function socketConnected() {
console.log('connect..');
});
// Send a GET request to `http://localhost:1337/hello`:
io.socket.get('/hello', function serverResponded (body, JWR) {
// body === JWR.body
console.log('Sails responded with: ', body);
console.log('with headers: ', JWR.headers);
console.log('and with status code: ', JWR.statusCode);
// When you are finished with `io.socket`, or any other sockets you connect manually,
// you should make sure and disconnect them, e.g.:
io.socket.disconnect();
// (note that there is no callback argument to the `.disconnect` method)
});
Please guide me on this.