var fs = require("fs");
let moduleConfiguration = JSON.parse(fs.readFileSync('moduleConfiguration.json', 'utf8'));
// code for connecting to pubsub
let vfosMessagingPubsub = require("../pubsub/index.js");
// this parameters are read from some external json
let broker = moduleConfiguration.broker;
let userName = moduleConfiguration.userName;
let platformDomain = moduleConfiguration.platformDomain;
let routingKeys = moduleConfiguration.routingKeys;
let pubsub = moduleConfiguration.activation;
let communications;
if (pubsub){
communications = new vfosMessagingPubsub(broker, userName, platformDomain, routingKeys);
}
module.exports = function (log) {
/**
* Log listing (Subscribe)
* @param {subscriptionData} subscriptionData device object to subscribe the platform to the log
* @callback {Function} callback Callback function
* @param {Error|string} err Error object
* @param {referenceResult} result Result object
*/
log.subscribe = function (subscriptionData, callback) {
let prefixMessagingPrivateDestination1 = platformDomain;
let componentMessagingPrivateDestination1 = "platform";
callback(null, "{msg: \"registered logger on platform with" + platformDomain + ":" + componentMessagingPrivateDestination1 + "\"}");
// communications.sendPrivateMessage(prefixMessagingPrivateDestination1, componentMessagingPrivateDestination1, privateMessage1);
}
/**
* Log UnSubscribe
* @param {string} reference reference to unsubscribe a component as listener of logs
* @callback {Function} callback Callback function
* @param {Error|string} err Error object
* @param {any} result Result object
*/
log.unsubscribe = function (reference, callback) {
// Replace the code below with your implementation.
// Please make sure the callback is invoked.
process.nextTick(function () {
var err = new Error('Not implemented');
callback(err);
});
/*
var err0 = new Error('Invalid ID supplied');
err0.statusCode = 400;
return cb(err0);
*/
/*
var err1 = new Error('device not found');
err1.statusCode = 404;
return cb(err1);
*/
}
log.remoteMethod('subscribe', {
isStatic: true,
consumes: ['application/json'],
produces: ['application/json'],
accepts: [{
arg: 'subscriptionData',
type: 'subscriptionData',
description: 'device object to subscribe the platform to the log',
required: true,
http: {
source: 'body'
}
}],
returns: [{
description: 'id of the device created',
type: 'referenceResult',
arg: 'data',
root: true
}],
http: {
verb: 'post',
path: '/logs'
},
description: 'Log listing (Subscribe)'
});
log.remoteMethod('unsubscribe', {
isStatic: true,
produces: ['application/json'],
accepts: [{
arg: 'reference',
type: 'string',
description: 'reference to unsubscribe a component as listener of logs',
required: true,
http: {
source: 'path'
}
}],
returns: [],
http: {
verb: 'delete',
path: '/logs/:reference'
},
description: 'Log UnSubscribe'
});
}