subscribe and interval nodes added
This commit is contained in:
33
nodes/xilica-interval.js
Normal file
33
nodes/xilica-interval.js
Normal file
@@ -0,0 +1,33 @@
|
||||
module.exports = function (RED) {
|
||||
function XilicaInterval(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
const node = this;
|
||||
|
||||
node.interval = parseInt(config.interval, 10) || 100;
|
||||
|
||||
node.on("input", (msg, send, done) => {
|
||||
send =
|
||||
send ||
|
||||
function () {
|
||||
node.send.apply(node, arguments);
|
||||
};
|
||||
done = done || function () {};
|
||||
|
||||
let interval = node.interval;
|
||||
if (Object.prototype.hasOwnProperty.call(msg, "interval")) {
|
||||
const v = parseInt(msg.interval, 10);
|
||||
if (!Number.isNaN(v) && v > 0) {
|
||||
interval = v;
|
||||
}
|
||||
}
|
||||
|
||||
msg.payload = "INTERVAL " + interval;
|
||||
|
||||
send(msg);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("xilica-interval", XilicaInterval);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user