Socket.io授权function没有更新会话数据

我试图使用Socket.IO的授权function获取会话数据。 问题是,即使我注销并销毁会话,Socket.IO仍然具有旧的会话信息,这显然不理想。 任何想法我在做什么错在下面的代码?

io.set('authorization', function (data, accept) { if(data.headers.cookie) { data.cookie = parseCookie(data.headers.cookie); data.sessionID = data.cookie['express.sid']; app.set('mongo-store').get(data.sessionID, function (err, session) { console.log(err, session); if (err || !session) { // if we cannot grab a session, turn down the connection accept('Error', false); } else { // save the session data and accept the connection data.session = session; accept(null, true); } }); } else { return accept('No cookie transmitted.', false); } accept(null, true); }); 

这里是连接代码:

 io.sockets.on('connection', function(socket) { var hs = socket.handshake; console.log('A socket with sessionID ' + hs.sessionID + ' connected!'); // setup an inteval that will keep our session fresh var intervalID = setInterval(function () { // reload the session (just in case something changed, // we don't want to override anything, but the age) // reloading will also ensure we keep an up2date copy // of the session with our connection. hs.session.reload( function () { // "touch" it (resetting maxAge and lastAccess) // and save it back again. hs.session.touch().save(); }); }, 60 * 1000); socket.on('disconnect', function () { console.log('A socket with sessionID ' + hs.sessionID + ' disconnected!'); // clear the socket interval to stop refreshing the session clearInterval(intervalID); }); }); 

来自http://www.danielbaulig.de/socket-ioexpress/

 sio.sockets.on('connection', function (socket) { var hs = socket.handshake; console.log('A socket with sessionID ' + hs.sessionID + ' connected!'); // setup an inteval that will keep our session fresh var intervalID = setInterval(function () { // reload the session (just in case something changed, // we don't want to override anything, but the age) // reloading will also ensure we keep an up2date copy // of the session with our connection. hs.session.reload( function () { // "touch" it (resetting maxAge and lastAccess) // and save it back again. hs.session.touch().save(); }); }, 60 * 1000); socket.on('disconnect', function () { console.log('A socket with sessionID ' + hs.sessionID + ' disconnected!'); // clear the socket interval to stop refreshing the session clearInterval(intervalID); }); }); 

编辑:授权码

 io.set('authorization', function (handshakeData, callback) { var cookie; // console.log(handshakeData.headers); if (handshakeData.headers && handshakeData.headers.cookie) { cookie = parseCookie(handshakeData.headers.cookie); // where SessionStore is an instance of your mongo store SessionStore.load(cookie['sioapp.sid'], function (err, session) { if (err) { // if we cannot grab a session, turn down the connection console.log(err); } else { // console.log('Successfully decoded the session: ', session); handshakeData.session = session; } }); } callback(null, true); // error first callback style }); 

每60秒一次,会话被触摸(因此刷新)。 当用户断开连接时,会话被破坏。

我不确定60 * 1000是指60分钟。 我会说这是1百万。