const _debug = require('debug');
const debug = _debug('server:modules:mirror');

/**
 * Configure pluginManager.callbackFunction to use publish from nes
 *
 * @param server HAPI server
 */
var configurePluginManagerCallback = (server) => {
    require('../pluginManager').callbackFunction = function (pluginName) {
        return (response) => {
            server.publish(`/plugin/${pluginName}`, response);
        }
    };
};

/**
 * Filter the mirrors that will receive the intent based on the message owner
 *
 * @param path
 * @param message
 * @param options
 * @param next
 */
var recipientMirrorFilter = (path, message, options, next) => {
    next(/*options.credentials.id === message.owner*/ true);
};

/**
 * Send the plugin list to a newly subscribing mirror
 *
 * @param socket
 * @param path
 * @param params
 * @param next
 */
const sendPluginList = (socket, path, params, next) => {
    const pluginManifest = require('../../plugin/manifest').map(p => p.channel = `/plugin/${p.name}`);
    socket.publish(path, pluginManifest, (err) => err && console.warn(err));
};

exports.register = function (server, options, next) {
    debug('Registering mirror module.');
    server.subscription('/system',
        {
            onSubscribe: sendPluginList
        });

    //allow any subscription following this syntax
    server.subscription('/plugin/{name}',
        {
            filter: recipientMirrorFilter
            //auth:TODO
        });

    configurePluginManagerCallback(server);

    next();
};

exports.register.attributes = {
    pkg: require('./package.json')
};

@@ -966,19 +966,35 @@
  =%3E 
-p.
+Object.assign(p, %7B 
 channel
- =
+:
  %60/p
@@ -1009,16 +1009,18 @@
 p.name%7D%60
+%7D)
 );%0A    s

Fix channel in plugin list