Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Using socket.io ... #175

Open
codevin opened this issue Dec 8, 2012 · 0 comments
Open

Using socket.io ... #175

codevin opened this issue Dec 8, 2012 · 0 comments

Comments

@codevin
Copy link

codevin commented Dec 8, 2012

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant