0

I'm using socket.io and passport.js to authenticate people with their Steam accounts. I want to be able to send data to specific Steam's ID. I'am alredy using

io.use(function(socket, next) {
     session(socket.handshake, {}, next);
});

to access passport data of passport inside socket.io. I've thought of of storing active sockets in array, then just find one with a proper Steam ID. Is there some better solution?

irqize
  • 97
  • 1
  • 10

1 Answers1

2
var steamUsers= {};

io.sockets.on("connection",function(socket){
   //from passport
   socket.steamid= steamid;

   //store socket for every user
   steamUsers[socket.steamid] = socket;

   //emit from their socket
   steamUsers[steamid].emit('private',{msg:"private message"});
});

you shoude use this inside express routes. Getting data and emitting within express routes is tricky. Follow this link to setup socket.io inside express routes How to use socket.io in express routes?

Community
  • 1
  • 1