Session middleware for socket.io v1.x;
varsocketSessions=require('socket.io-handshake');vario=require('socket.io')(3000);io.use(socketSessions());Using connect-redis for our session store.
varsession=require('express-session');varRedisStore=require('connect-redis')(session);varsessionStore=newRedisStore();varcookieParser=require('cookie-parser');varsocketHandshake=require('socket.io-handshake');vario=require('socket.io')(3000);io.use(socketHandshake({store: sessionStore,key:'sid',secret:'secret',parser:cookieParser()}));To access the session data.
io.on('connection'function(sock){if(!sock.handshake.session.name){sock.emit('get name');};sock.on('set nama',function(name){sock.handhsake.session.name=name;sock.handshake.session.save();});});Install node.js (See download and install instructions here: http://nodejs.org/).
Clone this repository
> git clone git@github.com:turbonetix/socket.io-handshake.git
cd into the directory and install the dependencies
> cd socket.io-handshake
> npm install && npm shrinkwrap --dev
Install coffee-script
> npm install coffee-script -g
Tests are run using grunt. You must first globally install the grunt-cli with npm.
> sudo npm install -g grunt-cli
To run the tests, just run grunt
> grunt spec
