Working in rooms
In Socket.IO, we use rooms to segregate messages as a means to send them only to certain users. When a client joins a room, any messages sent to that room will be available. A useful way to think of this is to imagine the rooms as being like rooms in a house with the doors shut. When someone wants to tell you something, they have to be in the same room as you to tell you.
Both our general and secret links will tie into rooms. The general page will use a blank room name that equates to the default Socket.IO room. The secret link will join a room called secret so that any messages sent to secret will automatically appear to any user on that page. To make our life easy, we will provide a helper method to emit the joinRoom ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access