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 order. Then, we can turn it off for a few seconds and finally turn it back on and see the notification number resume after skipping the numbers it would have emitted when it was off.