Setting up a default room

In Socket.IO, every socket that makes a connection is assigned a default room to emit messages. This default room could be used for a wide variety of purposes.

A practical use of the default room is to store friends or followers of the socket. When another socket joins the default room of a socket, we can assume that the socket is interested in receiving updates from the room that it has joined.

Other sockets are able to join the default room of any other socket. It isn't safe to assume that the default room of a socket only has one member unless the server-side architecture is set up in this way.

In this recipe, we will let our socket emit messages to the default room of any other connected socket. We will build a drop-down ...

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.