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?
所以我使用带有socket.io的express有这个问题。我认为这是非常自我解释;我只需要获取会话并向socket.io请求参数数据。这不能在客户端进行,因为有些房间是私人的。有解决方案?
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
})
1 个解决方案
#1
5
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.
Socket.IO 0.7.7~在套接字上引入了一个名为handshake的新属性,这是我们在客户端执行初始握手请求时收集的数据。它包含标题,IP和其他一些东西。
This wiki https://github.com/LearnBoost/socket.io/wiki/Authorizing touches the subject lightly.
这个wiki https://github.com/LearnBoost/socket.io/wiki/Authorizing轻轻触及主题。
#1
5
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.
Socket.IO 0.7.7~在套接字上引入了一个名为handshake的新属性,这是我们在客户端执行初始握手请求时收集的数据。它包含标题,IP和其他一些东西。
This wiki https://github.com/LearnBoost/socket.io/wiki/Authorizing touches the subject lightly.
这个wiki https://github.com/LearnBoost/socket.io/wiki/Authorizing轻轻触及主题。