MCPcopy
hub / github.com/socketio/socket.io / _checkNamespace

Method _checkNamespace

packages/socket.io/lib/index.ts:370–404  ·  view source on GitHub ↗

* Executes the middleware for an incoming namespace not already created on the server. * * @param name - name of incoming namespace * @param auth - the auth parameters * @param fn - callback * * @private

(
    name: string,
    auth: { [key: string]: any },
    fn: (
      nsp:
        | Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>
        | false,
    ) => void,
  )

Source from the content-addressed store, hash-verified

368 * @private
369 */
370 _checkNamespace(
371 name: string,
372 auth: { [key: string]: any },
373 fn: (
374 nsp:
375 | Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>
376 | false,
377 ) => void,
378 ): void {
379 if (this.parentNsps.size === 0) return fn(false);
380
381 const keysIterator = this.parentNsps.keys();
382
383 const run = () => {
384 const nextFn = keysIterator.next();
385 if (nextFn.done) {
386 return fn(false);
387 }
388 nextFn.value(name, auth, (err, allow) => {
389 if (err || !allow) {
390 return run();
391 }
392 if (this._nsps.has(name)) {
393 // the namespace was created in the meantime
394 debug("dynamic namespace %s already exists", name);
395 return fn(this._nsps.get(name) as Namespace);
396 }
397 const namespace = this.parentNsps.get(nextFn.value)!.createChild(name);
398 debug("dynamic namespace %s was created", name);
399 fn(namespace);
400 });
401 };
402
403 run();
404 }
405
406 /**
407 * Sets the client serving path.

Callers 1

connectMethod · 0.80

Calls 3

fnFunction · 0.85
runFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected