* Executes the middleware for an incoming client. * * @param socket - the socket that will get added * @param fn - last fn call in the middleware * @private
(
socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>,
fn: (err: ExtendedError | null) => void
)
| 215 | * @private |
| 216 | */ |
| 217 | private run( |
| 218 | socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, |
| 219 | fn: (err: ExtendedError | null) => void |
| 220 | ) { |
| 221 | const fns = this._fns.slice(0); |
| 222 | if (!fns.length) return fn(null); |
| 223 | |
| 224 | function run(i: number) { |
| 225 | fns[i](socket, function (err) { |
| 226 | // upon error, short-circuit |
| 227 | if (err) return fn(err); |
| 228 | |
| 229 | // if no middleware left, summon callback |
| 230 | if (!fns[i + 1]) return fn(null); |
| 231 | |
| 232 | // go on to next |
| 233 | run(i + 1); |
| 234 | }); |
| 235 | } |
| 236 | |
| 237 | run(0); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Targets a room when emitting. |