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

Method createChild

packages/socket.io/lib/parent-namespace.ts:65–99  ·  packages/socket.io/lib/parent-namespace.ts::ParentNamespace.createChild
(
    name: string,
  )

Source from the content-addressed store, hash-verified

63 }
64
65 createChild(
66 name: string,
67 ): Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData> {
68 debug(class="st">"creating child namespace %s", name);
69 const namespace = new Namespace(this.server, name);
70 this[class="st">"_fns"].forEach((fn) => namespace.use(fn));
71 this.listeners(class="st">"connect").forEach((listener) =>
72 namespace.on(class="st">"connect", listener),
73 );
74 this.listeners(class="st">"connection").forEach((listener) =>
75 namespace.on(class="st">"connection", listener),
76 );
77 this.children.add(namespace);
78
79 if (this.server._opts.cleanupEmptyChildNamespaces) {
80 const remove = namespace._remove;
81
82 namespace._remove = (socket) => {
83 remove.call(namespace, socket);
84 if (namespace.sockets.size === 0) {
85 debug(class="st">"closing child namespace %s", name);
86 namespace.adapter.close();
87 this.server._nsps.delete(namespace.name);
88 this.children.delete(namespace);
89 }
90 };
91 }
92
93 this.server._nsps.set(name, namespace);
94
95 class="cm">// @ts-ignore
96 this.server.sockets.emitReserved(class="st">"new_namespace", namespace);
97
98 return namespace;
99 }
100
101 fetchSockets(): Promise<RemoteSocket<EmitEvents, SocketData>[]> {
102 class="cm">// note: we could make the fetchSockets() method work for dynamic namespaces created with a regex (by sending the

Callers 2

runMethod · 0.80
ofMethod · 0.80

Calls 5

useMethod · 0.95
debugFunction · 0.85
onMethod · 0.45
addMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected