Adding users with unique ID

The next step in the process is going to be to make sure that there is already no user with the same ID. I'm going to call users.removeUser to get that done, passing in the only argument requires the socket.id just like this:

socket.join(params.room);users.removeUser(socket.id);users.addUser(socket.id, params.name, params.room);

That means that user joins the room, and we remove them from any potential previous rooms. Finally, we add them to the new one. Now that we have this in place we can actually go ahead and emit that event.

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.