From 0c03a3115e761d9259b52003a7ab5a88bee7f0fe Mon Sep 17 00:00:00 2001 From: Nedas Date: Fri, 11 May 2018 10:46:48 +0000 Subject: [PATCH] Service update (#42) * lesley service update: *Added new fields (notification method and port/interval). * Service now supports both notification receiving methods (Callback register and notification pulling) * *Changed interval from miliseconds to seconds. *Added default values for method value. * Added Information of "lesley-service" node. * service html replaced spaces with tabs. * Service object creation after options has been handled * Replaced tabs with spaces * Created options object to configure restAPI service. --- v1/lesley-service.html | 46 ++++++++++++++++++++++++++++++++++++++++-- v1/lesley-service.js | 19 +++++++++++++---- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/v1/lesley-service.html b/v1/lesley-service.html index 6eb8b90..278d0e8 100644 --- a/v1/lesley-service.html +++ b/v1/lesley-service.html @@ -3,7 +3,9 @@ category: "config", defaults: { name: {value:"lesley-service", required:true}, - url: {value:"http://localhost:8888", required:true} + url: {value:"http://localhost:8888", required:true}, + notificationMethod: {value:'callback', required:true}, + methodValue: {value:5728, required:true} }, inputs: 0, outputs: 0, @@ -12,6 +14,25 @@ return this.name; }, }); + + function methodHandler(selectionId, methodValueId) { + const selectionElement = document.getElementById(selectionId); + var methodValue = document.getElementById(methodValueId); + + switch (selectionElement.value) { + case 'polling': { + methodValue.labels[0].innerHTML = 'Interval (s)'; + methodValue.value = 1; + break; + } + + case 'callback': { + methodValue.labels[0].innerHTML = 'Port'; + methodValue.value = 5728; + break; + } + } + } diff --git a/v1/lesley-service.js b/v1/lesley-service.js index 5be02d6..fa81a82 100644 --- a/v1/lesley-service.js +++ b/v1/lesley-service.js @@ -5,10 +5,21 @@ const restAPI = require('restserver-api'); module.exports = function (RED) { function LesleyService(config) { RED.nodes.createNode(this, config); - this.options = {}; - this.options.name = config.name; - this.options.url = config.url; - this.service = new restAPI.Service({ host: this.options.url }); + const options = { + host: 'http://localhost:8888', + interval: 1234, + polling: false, + port: 5728, + }; + options.host = config.url; + if (config.notificationMethod === 'callback') { + options.polling = false; + options.port = config.methodValue; + } else if (config.notificationMethod === 'polling') { + options.polling = true; + options.interval = config.methodValue * 1000; + } + this.service = new restAPI.Service(options); this.service.start(); } RED.nodes.registerType('lesley-service', LesleyService);