March 2018
Intermediate to advanced
592 pages
13h 44m
English
Inside the disconnect listener, we want to remove the user and then we want to update the list once again. I'm going to do that by doing a few separate things. First up, we're going to make a variable called user, storing any potentially removed users, remember the removeUser method does return the user removed, users.removeUser passing in the ID, socket.id:
socket.io('disconnect', () => { var user = users.removeUser(socket.id);});
Now we only want to do something if we actually removed a user, if the person hadn't joined a room, there's no reason to actually do anything. If a user was removed we are going to emit two events, and we're going to emit them to every single person connected to the chatroom, ...