Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

parent-namespace.js 917B

123456789101112131415161718192021222324252627282930313233343536373839
  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;