twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

parent-namespace.js (917B)


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