"use strict";

/**
 * Configure pluginManager.callbackFunction to use publish from nes
 *
 * @param server HAPI server
 */
var configurePluginManagerCallback = (server) => {
    require('../pluginManager').callbackFunction = function (intentObject) {
        return (response) => {
            server.publish('/intent/' + intentObject.name, 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
 */
var sendPluginList = (socket, path, params, next) => {
    var pluginManifest = require('../../plugin/manifest');

    for (var i = 0; i < pluginManifest.length; i++)
    {
        pluginManifest[i].channel = `/plugin/${pluginManifest.name}`;
    }

    socket.publish(path, pluginManifest, (err) => { if (err) console.warn(err); });
};

exports.register = function (server, options, next) {

    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')
};
@@ -779,19 +779,21 @@
 ext%0A */%0A
-var
+const
  sendPlu
@@ -840,19 +840,21 @@
 %3E %7B%0A    
-var
+const
  pluginM
@@ -899,94 +899,19 @@
 st')
-;%0A%0A    for (var i = 0; i %3C pluginManifest.length; i++)%0A    %7B%0A        pluginManifest%5Bi%5D
+.map(p =%3E p
 .cha
@@ -933,37 +933,18 @@
 /$%7Bp
-luginManifest
 .name%7D%60
+)
 ;%0A
-    %7D%0A%0A
     
@@ -993,18 +993,14 @@
  =%3E 
-%7B if (err)
+err &&
  con
@@ -1017,11 +1017,8 @@
 err)
-; %7D
 );%0A%7D
@@ -1485,8 +1485,9 @@
 son')%0A%7D;
+%0A

Fix plugin list