It can often be useful to provide privacy for certain rooms. This allows you to send messages to a small group of sockets without worrying about the messages being received by sockets that should not be allowed to see them.
Although Socket.IO doesn't have any inbuilt way to consider a room private or public, we can add some logic around joining a room so that only sockets that validate against a password check are allowed to be members of the room.
In this recipe, we will create a simple login page. Sockets can log in with the static password:
pass123, but we could easily make it use a dynamic password that comes from our database or an environmental variable. When the socket joins a group, it will be able to see all the messages ...