-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Add support for dynamic namespaces
- Loading branch information
1 parent
e241fd0
commit 9cead1e
Showing
5 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const Namespace = require('./namespace'); | ||
|
||
let count = 0; | ||
|
||
class ParentNamespace extends Namespace { | ||
|
||
constructor(server) { | ||
super(server, '/_' + (count++)); | ||
this.children = new Set(); | ||
} | ||
|
||
initAdapter() {} | ||
|
||
emit() { | ||
const args = Array.prototype.slice.call(arguments); | ||
|
||
this.children.forEach(nsp => { | ||
nsp.rooms = this.rooms; | ||
nsp.flags = this.flags; | ||
nsp.emit.apply(nsp, args); | ||
}); | ||
this.rooms = []; | ||
this.flags = {}; | ||
} | ||
|
||
createChild(name) { | ||
const namespace = new Namespace(this.server, name); | ||
namespace.fns = this.fns.slice(0); | ||
this.listeners('connect').forEach(listener => namespace.on('connect', listener)); | ||
this.listeners('connection').forEach(listener => namespace.on('connection', listener)); | ||
this.children.add(namespace); | ||
this.server.nsps[name] = namespace; | ||
return namespace; | ||
} | ||
} | ||
|
||
module.exports = ParentNamespace; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters