Chapter 4. Building a Room with a View

In this chapter, we will cover the following recipes:

  • Creating chat channels with namespaces
  • Joining rooms
  • Leaving rooms
  • Listing the rooms that the socket is in
  • Creating private rooms
  • Setting up a default room

Introduction

Socket.IO uses namespaces to keep separate types of messages from colliding with each other. With namespaces, we can be sure that our applications are listening for the correct events.

We can also define arbitrary rooms that our sockets can join or leave. These rooms restrict someone from receiving messages and send them only to interested parties.

In this chapter, you will also learn how to harness namespaces and rooms to create richer real-time experiences.

Get Socket.IO Cookbook 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.