Skip to content

Commit

Permalink
Service update (#42)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mrNedas authored May 11, 2018
1 parent cac8a50 commit 0c03a31
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
46 changes: 44 additions & 2 deletions v1/lesley-service.html
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}
}
</script>

<script type="text/x-red" data-template-name="lesley-service">
Expand All @@ -21,12 +42,33 @@
</div>
<div class="form-row">
<label for="node-config-input-url"> URL</label>
<input type="text" id="node-config-input-url" placeholder="Name">
<input type="text" id="node-config-input-url">
</div>
<div class="form-row">
<label for="node-config-input-notificationMethod">Notification receiving method</label>
<select id="node-config-input-notificationMethod" onchange="methodHandler('node-config-input-notificationMethod', 'node-config-input-methodValue')">
<option value='callback'>Register a callback</option>
<option value='polling'>Pulling</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-methodValue">Port</label>
<input type="text" id="node-config-input-methodValue">
</div>
</script>


<script type="text/x-red" data-help-name="lesley-service">
<p>Configuration node for Lesley nodes.</p>
<p>Settings:</p>
<ul>
<li>Name : Name of the node.</li>
<li>URL : REST server's URL.</li>
<li>Notification receiving method :
Technology which would be used to obtain notifications
(Registering a callback and create a server to listen for notificaions or pulling out every interval of time).</li>
<li>Port / Interval (s) : Server's port or time interval in seconds depending on what notification recieving method is chosen.</li>
</ul>
</script>


19 changes: 15 additions & 4 deletions v1/lesley-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0c03a31

Please sign in to comment.