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

Leaving rooms

A socket can not only join a room but also leave any room that it is a member of.

This is important if you're building a real-time application. Here, users may want to disable certain notifications. By leaving a room entirely, the client-side socket will never receive the events that are broadcasted to the room that it has left.

In this recipe, we will expose a single room to the client-side sockets. We will allow the room to be joined or remain separate by simply toggling a checkbox.

The server side will emit a message every two seconds with an ongoing count of how many times the notification has been sent. Therefore, we will be able to turn the notifications on and see the notification numbers logged one after another in a particular ...

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