On every new socket object(new connection) I set up custom attribute to socket object like this :
io.on('connection', function(socket){
socket.username = "some-custom-username";
console.log(socket.id); //Output : unique ID from socket object
console.log(socket.username); //Output : some-custom-username
socket.on('disconnect',function(reason){
console.log(socket.id); //Output : Same unique ID like earlier
console.log(socket.username); //Output : undefined
});
}
Can anyone explain why does this happen?
It is same object, the id attribute stays the same but every custom attribute gets deleted on disconnect event therefore I am unable to easily detect which user has disconnected.