Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the request data with socket.io with node.js and express?

So I have this problem using express with socket.io. I think it is pretty self explanitory; I simply need to get the session and request parameter data to socket.io. This cannot be done on the client side as some rooms are going to be private. Any solutions?

io.sockets.on('connection', function (socket) {
  socket.join(ROOM ID)

  socket.on('send message', function(data) {
    NEED USER ID STORED IN session.user
  }
})

app.get('/:roomid', function (req, res) {
  //req.session.user = THE USER ID
  //req.params.roomid = THE ROOM ID
})
like image 434
Guy guy Avatar asked Jul 25 '11 19:07

Guy guy


1 Answers

Socket.IO 0.7.7~ introduces a new property on the socket called handshake this is the data that we gather when the client does it's initial handshake request. It contains the headers, ip and some other stuff.

This wiki https://github.com/LearnBoost/socket.io/wiki/Authorizing touches the subject lightly.

like image 140
3rdEden Avatar answered Sep 19 '22 15:09

3rdEden