0.0.5 • Published 11 years ago

socket.io-session v0.0.5

Weekly downloads
11
License
-
Repository
github
Last release
11 years ago

socket.io-session

Unobtrusive Socket.io middleware to add Express session capability.

npm install socket.io-session

This module uses io.set('authorization') to add a session property to socket.handshake.

var express = require('express')
  , MongoStore = require('connect-mongo')(express)
  , ioSession = require('socket.io-session');

var app = express();

var sessionKey = 'secret key'
var memoryStore = new MongoStore({ db: 'name', url: MONGO_URI + '/name' });
app.use(express.cookieParser());
app.use(express.session({ secret: sessionKey, store: memoryStore }));

var io = require('socket.io').listen(server);
io.set('authorization', ioSession(express.cookieParser(sessionKey), memoryStore));

io.on('connection', function (socket) {
  console.log(socket.handshake.session);
})

Invocation

You can use your own authorization function as the last argument after the session is added:

ioSession(cookieParser, memoryStore, [session sid key], [authorization(data, accept)])

License

miT

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago