socket.io with compoundJS

20 views
Skip to first unread message

didier ernotte

unread,
Jun 2, 2014, 9:39:38 PM6/2/14
to compo...@googlegroups.com
I'm trying to use socket.io with compoundjs, but without success. There is plenty of sample code for the initializer/socketio.js, but not a work on the router.js, and I have the feeling that the routing mechanism is not working properly. 
First, all HTML code refers to "/socket.io/socket.io.js", this means that this route must be handled by the socket.io module, but I have in the router.js the following line : map.all(':controller/:action'); and the app complains that there is no controller for socket.io#socket.io.js
What should I put in the router.js to make socket.io handle the /socket.io path ?

Ondreian

unread,
Jun 3, 2014, 2:22:39 PM6/3/14
to compo...@googlegroups.com
You can use the co-socket module and it should handle this stuff for you: https://www.npmjs.org/package/co-socket

Jef Harkay

unread,
Jun 5, 2014, 11:19:33 AM6/5/14
to compo...@googlegroups.com
What I do is use Node JS as a reverse proxy in nginx, which then allows me to serve up my socket.io through an nginx config.

However, I tried to get socket.io working with a test project, and all I did was add in socket.io to the package.json file, then added this code into initializers/socketio.js

var sio = require('socket.io');

module.exports = function (compound) {
 
var io = compound.io = sio.listen(compound.server, {resource: '/socket.io'});
  io
.set('transports', [
   
'websocket',
   
'xhr-polling',
   
'jsonp-polling'
 
]);

 
return io;
};

And I was able to access 0.0.0.0:3000/socket.io, which gave me the message "Welcome to socket.io."

Hope that helps.

didier ernotte

unread,
Jun 5, 2014, 11:26:47 AM6/5/14
to compo...@googlegroups.com

Thanks ! my initializer recreated a new http server. I think that was the cause of the prb. I remove that line and now it is working fine. At least with Firefox and Chrome. IE, as usual, has an error and does not seems to support socket.io on the client side.

Jef Harkay

unread,
Jun 5, 2014, 11:33:50 AM6/5/14
to compo...@googlegroups.com
Try using the io.set that I have listed in my code above... IE8- should default to xhr-polling because websocket is not a valid transport.  I believe IE9 is when they implemented sockets.
Reply all
Reply to author
Forward
0 new messages