forked from socketio/socket.io
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (socketio#3195)
This follows socketio#3187, with a slightly different API. A dynamic namespace can be created with: ```js io.of(/^\/dynamic-\d+$/).on('connect', (socket) => { /* ... */ }); ```
- Loading branch information
1 parent
62ae65c
commit dd3a901
Showing
5 changed files
with
147 additions
and
117 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