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

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.