Giter Club home page Giter Club logo

socket-io.sessions's Introduction

Access Express session from socket.io.

Build Status

Installation

npm install socket-io.sessions

Usage

  //configure passport and express

  var socketIo = require("socket.io"),
    socketIoSessions = require("socket-io.sessions");

  var sio = socketIo.listen(webServer);


  //same attribute than the session middleware http://www.senchalabs.org/connect/middleware-session.html

  sio.set("authorization", socketIoSessions({
    key:    'express.sid',       //the cookie where express (or connect) stores its session id.
    secret: 'my session secret', //the session secret to parse the cookie
    store:   mySessionStore      //the session store that express uses
  }));

  sio.sockets.on("connection", function(socket){
    
    socket.handshake.getSession(function (err, session) {
      socket.emit('aaa!', session.someSessionProperty);
    });

  });

Change the session

socket.handshake.getSession(function (err, session) {
  session.something = 123;
  socket.handshake.saveSession(session, function (err) {
    //whatever
  });
});
  var sessionOptions = {
    key:    'express.sid',      
    secret: 'my session secret',
    store:   mySessionStore     
  };
  //chain the two this way:
  sio.set("authorization", socketIoSessions(sessionOptions, passportSocketIo.authorize(sessionOptions)));

Develop

npm install npm test

License

MIT - José F. Romaniello 2012.

socket-io.sessions's People

Contributors

baoist avatar faceleg avatar jfromaniello avatar karneyli avatar kcaffrey avatar willfe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.