More information can be found .
- (String)
The namespace identifier property.
namespace.sockets
- (Map<SocketId, Socket>)
A map of instances that are connected to this namespace.
namespace.adapter
- (Adapter)
The used for the namespace. Useful when using the Adapter
based on Redis, as it exposes methods to manage sockets and rooms across your cluster.
Note: the adapter of the main namespace can be accessed with io.of("/").adapter
.
namespace.to(room)
room
(String)- Returns
Namespace
for chaining
Sets a modifier for a subsequent event emission that the event will only be broadcasted to clients that have joined the given room
.
To emit to multiple rooms, you can call several times.
Synonym of namespace.to(room).
namespace.emit(eventName[, …args])
eventName
(String)args
- Returns
true
Emits an event to all connected clients. The following two are equivalent:
Note: acknowledgements are not supported when emitting from namespace.
namespace.allSockets()
- Returns
Promise<Set<SocketId>>
namespace.use(fn)
fn
(Function)
Registers a middleware, which is a function that gets executed for every incoming Socket
, and receives as parameters the socket and a function to optionally defer execution to the next registered middleware.
Errors passed to middleware callbacks are sent as special connect_error
packets to clients.
socket
(Socket) socket connection with client
Fired upon a connection from client.
io.on("connection", (socket) => {
// ...
});
io.of("/admin").on("connection", (socket) => {
// ...
});
Event: ‘connect’
Synonym of .
Flag: ‘volatile’
Sets a modifier for a subsequent event emission that the event data may be lost if the clients are not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).