UNPKG

@halsystems/red-bacnet

Version:
49 lines (40 loc) 1.53 kB
'use strict'; require('./_alias.js'); // ---------------------------- functions ---------------------------- // ---------------------------- module ---------------------------- module.exports = function (RED) { class Play { constructor(config) { RED.nodes.createNode(this, config); this.name = config.name; this.client = RED.nodes.getNode(config.client); // events this.#subscribeListeners(); } #subscribeListeners() { /** * @param {Object} msg - The message object. * @param {any} msg.payload - The payload of the message. */ // @ts-ignore this.on('input', function (msg) { // msg.payload = msg.payload.toUpperCase(); let count = 0 const loopWithTimeout = () => { if (count < 10) { this.status({ fill: "yellow", shape: "dot", text: `count: ${count}` }); count++; setTimeout(loopWithTimeout, 1000); // Schedule the next iteration after 1 second } else { this.status({ fill: "green", shape: "dot", text: "completed" }); } msg.payload = count; this.send(msg); }; loopWithTimeout(); }); } } // ----- register node ----- RED.nodes.registerType("play", Play); }