Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Using socket.io ... #175

Open
codevin opened this Issue · 0 comments

1 participant

@codevin

I am exploring use of socket.io directly from a module. This seems to work, and these are instructions if you want to try.

(However, the sessions need to play well with socket.io, as given here: http://www.danielbaulig.de/socket-ioexpress/. This needs some exploration. )

First change app.js (in root of calipso) as follows:

var socket_io=require("socket.io");
...
// within express.boot() function
     if (app) {
          var server=http.createServer(app);  // socket.io requires access to http.Server object.
          var io=socket_io.listen(server);
          app.socketIO=io;  // You need to access this object from modules as calipso.app.socketIO
          var out = server.listen(port, function () {
             ...
          }
          ...
     }

And within the module, use this code. I presume this should be in the route handler code (as opposed to init).

calipso.app.socketIO.sockets.on('connection',  function(socket) {
     socket.emit('news', <<data object>>); // send something to client.
     socket.on('flag', function(data){...} ); // receive something from client.
}

And you will also need to put in the usual socket.io client code in one of the module templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.