* Registers a middleware, which is a function that gets executed for every incoming {@link Socket}. * * @example * const myNamespace = io.of("/my-namespace"); * * myNamespace.use((socket, next) => { * // ... * next(); * }); * * @param fn - the middleware function
(
fn: (
socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>,
next: (err?: ExtendedError) => void,
) => void,
)
| 217 | * @param fn - the middleware function |
| 218 | */ |
| 219 | public use( |
| 220 | fn: ( |
| 221 | socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, |
| 222 | next: (err?: ExtendedError) => void, |
| 223 | ) => void, |
| 224 | ): this { |
| 225 | this._fns.push(fn); |
| 226 | return this; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Executes the middleware for an incoming client. |