Storing users with ES6 classes – Part I

We don't have access to the data (username and room name) that is inside join, but we do have access to one common thing, and that is the socket ID. We have access to the socket variable, socket.id, and we also have access to it inside our other event listeners. And this is going to be what we use inside of a data structure we're about to create. We're going to create an array of users where we can store this information, when we want to look up a user like we might want to do in createMessage and createLocationMessage. We'll simply pass the ID to some function, get back the name and the room name, and emit the event as we want.

Now in order to get that done, we are going to make a brand new file in ...

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.