Once a user has selected their screen name, the next step is selecting a room. This is a bit more complex than choosing a name because they can either choose from a list of existing rooms, or they can start a new room by typing in a new name. If the user types in the name of an existing room, they'll go to the existing rooms because we obviously can't have multiple rooms with the same name. The tricky part in all this is that while we're calling them rooms, they're actually more like tags. The only place they exist is as a property on the chat messages; they aren't stored on their own. When a user creates a new room, there's no actual record of the room until they write the first message in that room. If they create a room and then close the page, the room doesn't exist. All this will make it a bit trickier to keep track of the rooms, but we love a good challenge, right?
Open a new file, rooms.js
, in public
. Just like our user.js
file, this will have a model, collection, model...