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.
As usual, this recipe will use jQuery for the DOM manipulation and event delegation.
To list the rooms that your socket is in, follow these steps: