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

Listing rooms the socket is in

Socket.IO provides a dynamic list of the rooms that each socket is a member of. We can retrieve this list and use it as needed.

In this recipe, we will create a list of the rooms that our socket is in. The list will be dynamically updated if the socket leaves any of its rooms.

Listing rooms the socket is in

Getting ready

As usual, this recipe will use jQuery for the DOM manipulation and event delegation.

How to do it…

To list the rooms that your socket is in, follow these steps:

  1. On the server, we will add our socket to three distinct groups by default. We will add an event listener that will request to list the rooms for us. When this event is sent, we ...

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