Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
dynamic.io is a subclass of the socket.io server that knows how to deal with multiple hostnames and dynamically created namespaces that delete themselves when idle. It works with the standard socket.io client.
It also provides an optional socket.io/status page for debugging.
This subclass is perfectly usable as a standard socket.io server, in the ordinary way (it passes socket.io unit tests, for example). But it supports a few more options as well as the "setupNamespace" method for handling namespace callbacks.
Dynamic namespaces can be set up using "setupNamespace", which accepts a namespace name (or /.*/ for any-namespace, or any other regexp to match regexps) and a callback that can initialize a (passed) namespace instance when it is dynamically created. (Or, if it's pre-existing at setupNamespace time.) Return false from this callback to reject the namespace.
New options include:
If you find this useful, please contribute test, documentation, and fixes.
A usage example:
// Specify host in options if you want to handle virtual hosts. // Then only connections with a Host header matching host will // map to "/". (The default is /.*/, which maps all hosts to '/'; // host can be a string or a RegExp). All other host namespaces // will get a prefix of "//otherhost.com". The Namespace method // nsp.fullname() gets the fully qualified namespace name, while // and nsp.name still // returns just '/' (or '/mynamespace') // without the host; nsp.host returns the host. io = require('dynamic.io')({host: 'myhost.com'}); // By the way, you can override gethost if you need to normalize. io.getHost = function(conn) { return conn.request.headers.host.replace(/^www\./, ''); } // Namespaces other than '/' are created and deleted dynamically. // You can register namespaces with specific names, or with // the '*' wildcard, and your setup function will be called whenever // that namespace is created (or re-created after expiration). io.setupNamespace('*', function(nsp) { // Set retirement to set up the number of milliseconds this // namespace should hang around after its last socket disconnects. // Default is 10 seconds. nsp.retirement = Math.max(nsp.retirement, 30 * 1000); // Set up the namespace as normal in socket.io. nsp.on('connect', function(socket) { console.log('got a socket connect on', nsp.fullname()); socket.on('disconnect', function() { console.log('somebody disconnected from', nsp.fullname()); }); }); // Return false from the setupNamespace callback if // you want to ignore this namespace. return true; }); // Just use the server as normal. io.listen(process.env.PORT);
FAQs
socket.io server subclass for dynamic hosts and namespaces
We found that dynamic.io demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.