O'Reilly logo

Socket.IO Cookbook by Tyson Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating private rooms

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required