I have made a simple realtime visitor counter.
You can download it from this repository.
What happens is that disconnect event (even after browser closing) on se
Put your on disconnect code inside your on connect block and edit it a bit like so:
io.sockets.on('connection', function (socket) {
count++;
io.sockets.emit('count', {
number: count
});
socket.on('disconnect', function () {
console.log('DISCONNESSO!!! ');
count--;
io.sockets.emit('count', {
number: count
});
});
});
This way you're detecting when a specific socket (specifically the socket you pass to your anonymous function that is run on connection) is disconnected.