engine.io-session

Read Connect sessions in engine.io

engine.io-session

An engine.io plugin that allows you to read sessions created by the Connect session middleware.

npm install engine.io-session
var connect = require('connect');
var eio = require('engine.io');
var eioSession = require('engine.io-session');
 
var cookieParser = connect.cookieParser();
var app = connect();
var sessionStore = new connect.session.MemoryStore();
var sessionKey = 'sid';
var sessionSecret = 'your secret here';
 
app.use(cookieParser);
app.use({ store: sessionStore, key: sessionKey, secret: sessionSecret });
 
var httpServer = http.createServer(app).listen(3000);
var server = eio.attach(httpServer);
 
server.on('connection', engineSession({
  cookieParser: cookieParser,
  store: sessionStore,
  key: sessionKey,
  secret: sessionSecret
});
 
server.on('session', function(socketsession) {
  // Output session data. 
  console.log(session);
});
var express = require('express');
var eio = require('engine.io');
var eioSession = require('engine.io-session');
 
var app = express();
var cookieParser = express.cookieParser();
var sessionStore = new express.session.MemoryStore();
var sessionKey = 'sid';
var sessionSecret = 'your secret here';
 
app.use(cookieParser);
app.use(express.session({ store: sessionStore, key: sessionKey, secret: sessionSecret }));
 
var httpServer = http.createServer(app).listen(3000);
var server = engine.attach(httpServer);
 
server.on('connection', eioSession({
  cookieParser: cookieParser,
  store: sessionStore,
  key: sessionKey,
  secret: sessionSecret
});
 
server.on('session', function(socketsession) {
  // Output session data. 
  console.log(session);
});
  • session
    • Called when a session for a socket is available.
    • Arguments
      • Socket: the Socket object
      • session: the session data
  • session
    • Called when a session for this socket is available.
    • Arguments
      • session: the session data