The first step in the process is going to be to add a user to the list when they join a chatroom. We can do that right after our call to socket.join. I'm going to remove the old comments, although you can choose to keep yours around if you find they are a good reference. Just below socket.join, we're going to call users.addUser, adding our brand new user, and we need to pass in those three pieces of information, the socket ID, socket.id is where that's stored, the name, that's on params.name, and finally we're going to go ahead and pass in the room name, params.room:
socket.join(params.room);
users.addUser(socket.id, params.name, params.room);
Now as you notice this code is not supposed to run if there is a validation error, meaning that the name or the room name is not provided, but currently that's not the case. We don't actually stop the function execution, I'm going to use return to make sure none of the code down below ever fires if the data is not valid:
socket.on('join', (params, callback) => {
if(!isRealString(params.name) || !isRealString(params.room)){
return callback('Name and room name are required.');
}
});