Files
node-red-contrib-xilica/nodes/xilica-interval.js
2025-12-31 08:54:22 +01:00

34 lines
768 B
JavaScript

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);
};