Add setupNamespace and dynamic namespace support #1865
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull requests adds dynamic namespace support, virtual host support, and an optional /socket.io/status page to help monitor dynamic (and regular) namespaces.
It addresses #1854
From the library user's point of view, it doesn't change any existing behavior. Passes current unit tests, but adds some functionality.
Three new options.
host: true - enables hostname qualification on namespaces
host: 'roothost.com' - enables hostnames, but matching hosts (may be a regexp) are still unqualified
host: '*' - the default - all hosts are unqualified
retirement: 10000 (default) - the number of ms to wait before cleaning up an empty dynamic namespace
serveStatus: false (default) - set to true to enable socket.io/status
One main new public API
server.setupNamespace(pattern, fn) - call to set up all namespaces matching "pattern" (which may be a string or regexp).
The rules are: each namespace instance is called with at most one setup function. When a new dynamic namespace is connected by a client, the best-matching setup function is found and called. Exact string matches are preferred over regexps, and within those groups, the last registered name/pattern gets precedence. If no pattern matches a client's requested namespace name, an error is sent to the client.
Other public functions
server.getHost(conn) - override to normalize hostnames
namespace.host - has the hostname
namespace.fullname() - '//host/name'
namespace.retriement - set to milliseconds to persist after going empty (defaulted)
namespace.expire(fn) - register an expiration callback for when a stale namespace is deleted