You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
917 B

4 years ago
  1. 'use strict';
  2. const Namespace = require('./namespace');
  3. let count = 0;
  4. class ParentNamespace extends Namespace {
  5. constructor(server) {
  6. super(server, '/_' + (count++));
  7. this.children = new Set();
  8. }
  9. initAdapter() {}
  10. emit() {
  11. const args = Array.prototype.slice.call(arguments);
  12. this.children.forEach(nsp => {
  13. nsp.rooms = this.rooms;
  14. nsp.flags = this.flags;
  15. nsp.emit.apply(nsp, args);
  16. });
  17. this.rooms = [];
  18. this.flags = {};
  19. }
  20. createChild(name) {
  21. const namespace = new Namespace(this.server, name);
  22. namespace.fns = this.fns.slice(0);
  23. this.listeners('connect').forEach(listener => namespace.on('connect', listener));
  24. this.listeners('connection').forEach(listener => namespace.on('connection', listener));
  25. this.children.add(namespace);
  26. this.server.nsps[name] = namespace;
  27. return namespace;
  28. }
  29. }
  30. module.exports = ParentNamespace;