MCPcopy Index your code
hub / github.com/socketio/socket.io / _checkNamespace

Method _checkNamespace

lib/index.ts:300–334  ·  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

298 * @private
299 */
300 _checkNamespace(
301 name: string,
302 auth: { [key: string]: any },
303 fn: (
304 nsp:
305 | Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>
306 | false
307 ) => void
308 ): void {
309 if (this.parentNsps.size === 0) return fn(false);
310
311 const keysIterator = this.parentNsps.keys();
312
313 const run = () => {
314 const nextFn = keysIterator.next();
315 if (nextFn.done) {
316 return fn(false);
317 }
318 nextFn.value(name, auth, (err, allow) => {
319 if (err || !allow) {
320 return run();
321 }
322 if (this._nsps.has(name)) {
323 // the namespace was created in the meantime
324 debug("dynamic namespace %s already exists", name);
325 return fn(this._nsps.get(name) as Namespace);
326 }
327 const namespace = this.parentNsps.get(nextFn.value)!.createChild(name);
328 debug("dynamic namespace %s was created", name);
329 fn(namespace);
330 });
331 };
332
333 run();
334 }
335
336 /**
337 * Sets the client serving path.

Callers 1

connectMethod · 0.80

Calls 2

fnFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected