jfromaniello / passport.socketio

access passport.js authenticated user information from socket.io connection
655 stars 81 forks source link

Socket undefined (Cluster) #26

Open abdula opened 11 years ago

abdula commented 11 years ago

Hello, I try to use your library with cluster. Some times your function not founded socket by user. Looks like socket.io does't sync this list socketIo.sockets.manager.sockets.sockets between all process in cluster.

function filterSocketsByUser(socketIo, filter){
  var handshaken = socketIo.sockets.manager.handshaken;
  return Object.keys(handshaken || {})
    .filter(function(skey){
      return filter(handshaken[skey].user);
    })
    .map(function(skey){
      return socketIo.sockets.manager.sockets.sockets[skey];
    });
}

My IO initialization

var io = require('socket.io').listen(server, {
        //'log level': 1,
        'polling duration': '10',
        transports: ['websocket','xhr-polling'],
        store: new RedisStore({
            redis: redis,
            redisPub : redis.createClient(redisOptions.port, redisOptions.host, redisOptions),
            redisSub : redis.createClient(redisOptions.port, redisOptions.host, redisOptions),
            redisClient : redis.createClient(redisOptions.port, redisOptions.host, redisOptions)
        }),
        authorization: passportSocketIo.authorize({
            cookieParser: express.cookieParser,   //or connect.cookieParser
            key:          'express.sid',          //the cookie where express (or connect) stores its session id.
            secret:       'secret',               //the session secret to parse the cookie
            store:         sessionStore,          //the session store that express uses
        })
    });
jfromaniello commented 10 years ago

I don't know how this works in socket.io to be honest. It's clear for me that the handshake is done by one of the nodes in the socket.io cluster but from there I'm not sure how it works

@guille ? could you help us with this; how does handshake authorization works in socket.io clusters? https://github.com/LearnBoost/socket.io/wiki/Authorizing thanks!

abdula commented 10 years ago

Unfortunately I can't, because I do not know very well how it works