mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
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.
41 lines
988 B
TypeScript
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;
|
|
}
|
|
}
|