Skip to content

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

Description

@thernstig

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions