I am using sailsjs with socket io. The sail version is 0.10.5. I have the following socket client for testing:
var socketIOClient = require('socket.io-client');
var sailsIOClient = require('sails.io.js');
var io = sailsIOClient(socketIOClient);
io.sails.url = 'http://localhost:1337';
io.socket.get('/join', function serverResponded (body, JWR) {
console.log('Sails responded with: ', body);
console.log('with headers: ', JWR.headers);
console.log('and with status code: ', JWR.statusCode);
});
io.socket.on('myroom', function(response){
console.log(response);
});
In my config / routes.js, I have the following:
'get /join':'LayoutController.join'
In my api / controller / LayoutController, I have the following:
module.exports={
join: function(req, res) {
console.log('Inside Join');
sails.sockets.join(req.socket,'myroom');
res.json({message:'youve subscribed to a room'});
}
};
The problem that I encountered is that the connection function inside the controller never starts via the socket call io.socket.get ('/ join', ...). The .log console in the controller never prints, nor does it return a response to the client. If I do the same testing via http, it starts the connection function. This is the first time I'm working with a jack. Can anyone suggest what I am doing wrong here?
source
share