node-connection-manager
Store and retreive active connections from multiple locations in your code-base, keep connection alive as long as there are references to it. One all references are lost, the connection is terminated using the provided callback.
This module was designed to be used in a situation where a single connection might need to be shared amongst several places in the code, and should be automatically destroyed once there are no more references.
var xmpp_client = ;var cm = 'MY_APPS_CONNECTIONS' id: 'unique_to_this_object_instance' foo: 'bar' // always added to the scope of the callbacks defined below hello: 'country' 'world' 'universe'; cm;
Elsewhere in the code:
var connectionManager = ; var cm = ;; var credentials = nick: 'user' host: 'irc.freenode.net'; var client = cm; // listeners for this scope are added with the above object console; // 2 // if a `join` event happens, the listener callback will be called with the above scope// so 'goodbye' will be printed clientconnection;