Socket.io在断开连接时设置会话变量

时间:2016-05-08 22:15:49

标签: javascript session events socket.io disconnect

我创建了一个socket.io服务器。当客户离开房间时,我想将socket.handshake.session.canal设置为" 0"值。但它没有用。

我使用存储在Redis服务器上的快速共享会话。有什么想法解决这个问题吗?

socket.on("disconnect", function() {
if (people[socket.id] != undefined)
{
    if (people[socket.id].inroom != false)
    {
        var room = rooms[people[socket.id].inroom];
        if (room)
        {
            if (_.contains((room.people), socket.id))
            {
                var personIndex = room.people.indexOf(socket.id);
                room.people.splice(personIndex, 1);
                room.peoples = room.peoples-1;
                socket.leave(room.id);
                if (socket.handshake.session.isLogged == true)
                {
                    io.to(room.id).emit('userleft', socket.handshake.session.pseudo);
                }
                socket.handshake.session.canal = 0;
            }
        }
        else
        {
            socket.leave(room.id);
            socket.handshake.session.canal = 0;
        }
    }
    delete people[socket.id];
    delete sockets[socket];
}

0 个答案:

没有答案