index.js
function installPlugin(nameOrPlugin, options) {
    assert(nameOrPlugin, 'name or plugin is required')

    var plugin,
        ctor,
        self   = this,
        parent = module.parent

    if (typeof nameOrPlugin === 'string')
        try {
            // local plugin
            if (nameOrPlugin.substring(0, 2) === './')
                ctor = parent.require(nameOrPlugin)
            // installed plugin with prefixed name 'hand-over-'
            else
                ctor = parent.require('hand-over-' + nameOrPlugin)
        }
        catch (ex) {
            // installed plugin without prefix
            ctor = parent.require(nameOrPlugin)
        }
    else
        ctor = nameOrPlugin

    // maybe we've got an already instantiated plugin
    if (ctor instanceof Plugin)
        plugin = ctor
    else {
        assert.equal(typeof ctor, 'function', 'plugin must provide a constructor')
        plugin = new ctor(options || {})
        assert(plugin instanceof Plugin, 'plugin must be a descendant of Handover.Plugin')
    }

    assert(plugin.name, 'plugin must expose a channel name')
    assert(!(plugin.name in this._plugins), 'plugin is already installed')
    assert.equal(typeof plugin.send, 'function', "'" + plugin.name + '" does not implements `send()`')
    assert(plugin.send.length >= 3, "'" + plugin.name + "' plugin's `send()` method must take at least three arguments")
    assert.equal(typeof plugin.destroy, 'function', "'" + plugin.name + '" does not implements `destroy()`')

    this._plugins[ plugin.name ] = plugin

    // delegate plugin errors for convenience
    plugin.on('error', function (err) {
        // decorate error object with channel name
        if (err && typeof err === 'object')
            err.channel = plugin.name

        self.emit('error', err)
    })

    // make it chainable
    return this
}
function installPlugin(nameOrPlugin, options) {
    assert(nameOrPlugin, 'name or plugin is required')

    var plugin,
        ctor,
        self   = this,
        parent = module.parent

    if (typeof nameOrPlugin === 'string')
        try {
            // local plugin
            if (nameOrPlugin.substring(0, 2) === './')
                ctor = parent.require(nameOrPlugin)
            // installed plugin with prefixed name 'hand-over-'
            else
                ctor = parent.require('hand-over-' + nameOrPlugin)
        }
        catch (ex) {
            // installed plugin without prefix
            ctor = parent.require(nameOrPlugin)
        }
    else
        ctor = nameOrPlugin

    // maybe we've got an already instantiated plugin
    if (ctor instanceof Plugin)
        plugin = ctor
    else {
        assert.equal(typeof ctor, 'function', 'plugin must provide a constructor')
        plugin = new ctor(options || {})
        assert(plugin instanceof Plugin, 'plugin must be a descendant of Handover.Plugin')
    }

    assert(plugin.name, 'plugin must expose a channel name')
    assert(!(plugin.name in this._plugins), 'plugin is already installed')
    assert.equal(typeof plugin.send, 'function', "'" + plugin.name + '" does not implements `send()`')
    assert(plugin.send.length >= 3, "'" + plugin.name + "' plugin's `send()` method must take at least three arguments")
    assert.equal(typeof plugin.destroy, 'function', "'" + plugin.name + '" does not implements `destroy()`')

    this._plugins[ plugin.name ] = plugin

    // delegate plugin errors for convenience
    plugin.on('error', function (err) {
        // decorate error object with channel name
        if (err && typeof err === 'object')
            err.channel = plugin.name

        self.emit('error', err)
    })

    // make it chainable
    return this
}
function installPlugin ( nameOrPlugin , options ) { assert ( nameOrPlugin , 'name or plugin is required' ) var plugin , ctor , self = this , parent = module . parent if ( typeof nameOrPlugin === 'string' ) try { // local plugin if ( nameOrPlugin . substring ( 0 , 2 ) === './' ) ctor = parent . require ( nameOrPlugin ) // installed plugin with prefixed name 'hand-over-' else ctor = parent . require ( 'hand-over-' + nameOrPlugin ) } catch ( ex ) { // installed plugin without prefix ctor = parent . require ( nameOrPlugin ) } else ctor = nameOrPlugin // maybe we've got an already instantiated plugin if ( ctor instanceof Plugin ) plugin = ctor else { assert . equal ( typeof ctor , 'function' , 'plugin must provide a constructor' ) plugin = new ctor ( options || { } ) assert ( plugin instanceof Plugin , 'plugin must be a descendant of Handover.Plugin' ) } assert ( plugin . name , 'plugin must expose a channel name' ) assert ( ! ( plugin . name in this . _plugins ) , 'plugin is already installed' ) assert . equal ( typeof plugin . send , 'function' , "'" + plugin . name + '" does not implements `send()`' ) assert ( plugin . send . length >= 3 , "'" + plugin . name + "' plugin's `send()` method must take at least three arguments" ) assert . equal ( typeof plugin . destroy , 'function' , "'" + plugin . name + '" does not implements `destroy()`' ) this . _plugins [ plugin . name ] = plugin // delegate plugin errors for convenience plugin . on ( 'error' , function ( err ) { // decorate error object with channel name if ( err && typeof err === 'object' ) err . channel = plugin . name self . emit ( 'error' , err ) } ) // make it chainable return this }
Include and initialize a plugin that handles a notification channel.

@param {string|function|object} nameOrPlugin - Plugin name, constructor or instance to install.
@param {*} [options] - Initialization settings for the plugin.
@returns {Handover}
Include and initialize a plugin that handles a notification channel .