If you have n different tabs, there are actually the number n of different sockets. One way to achieve what you want is to make all sockets from a specific user attached to the same room .
io.on('connection', function (socket) {
socket.join(socket.handshake.user.id);
}
And in the exit code, output the "logout" event to this particular room.
io.sockets.in(socket.handshake.user.id).emit('logout')
Now on the client side you can write an event listener in "logout", which redirects you to the right place.
source
share