Files
socket.io/lib/parent-namespace.ts
Damien Arrachequesne 58b66f8089 refactor: hide internal methods and properties
There is no concept of package-private methods in TypeScript, so we'll
just prefix them with "_" and mark them as private in the JSDoc.
2020-10-15 11:54:06 +02:00

41 lines
988 B
TypeScript

import { Namespace } from "./namespace";
export class ParentNamespace extends Namespace {
private static count: number = 0;
private children: Set<Namespace> = new Set();
constructor(server) {
super(server, "/_" + ParentNamespace.count++);
}
_initAdapter() {}
public emit(...args): Namespace {
this.children.forEach(nsp => {
nsp._rooms = this._rooms;
nsp._flags = this._flags;
nsp.emit.apply(nsp, args);
});
this._rooms.clear();
this._flags = {};
return this;
}
createChild(name) {
const namespace = new Namespace(this.server, name);
namespace._fns = this._fns.slice(0);
this.listeners("connect").forEach(listener =>
// @ts-ignore
namespace.on("connect", listener)
);
this.listeners("connection").forEach(listener =>
// @ts-ignore
namespace.on("connection", listener)
);
this.children.add(namespace);
this.server._nsps.set(name, namespace);
return namespace;
}
}