socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Docs: Document `io.on`, `io.use` etc in the Server API docs

Open thernstig opened this issue 2 years ago • 0 comments

https://socket.io/docs/v4/server-api/ shows some examples of .e.g io.use(), but it never explains what they are.

https://socket.io/docs/v4/namespaces/#main-namespace explains that all those versions are interacting with the main namespace:

io.on("connection", (socket) => {});
io.use((socket, next) => { next() });
io.emit("hello");
// are actually equivalent to
io.of("/").on("connection", (socket) => {});
io.of("/").use((socket, next) => { next() });
io.of("/").emit("hello");

A section in the Server API docs should preferably document all these, as they are part of the API of io but never explained there.

(If I could chose, I would in version 5 actually remove the direct usage of those and only allow io.of() as I believe explicit-over-implicit is good in this case and also simplifies a lot of documentation and explanation around this. But that is highly subjective and I am sure others like the shortcuts).

thernstig avatar Jan 24 '23 11:01 thernstig