UNPKG

node-red-contrib-netvar-utils

Version:

Network Variable List utility nodes for node-red

27 lines 1.09 kB
"use strict"; const nodeInit = (RED) => { function NvlEmitterNodeConstructor(config) { var _a; RED.nodes.createNode(this, config); const nvl = (_a = RED.nodes.getNode(config.nvl)) === null || _a === void 0 ? void 0 : _a.nvl; let counter = 0; this.on('input', (msg, send, done) => { if (!nvl) return done(new TypeError('Network Variable List is not defined or invalid.')); const { payload } = msg; if (!nvl.validateJSON(payload)) { this.error(nvl.validateJSON.errors); return done(new TypeError('Bad JSON payload. See previous log for information.')); } const packets = nvl.emitPackets(payload, counter); counter += nvl.getExpectedPacketCount(); packets.forEach((packet) => { send({ payload: packet }); }); done(); }); } RED.nodes.registerType('nvl-emitter', NvlEmitterNodeConstructor); }; module.exports = nodeInit; //# sourceMappingURL=nvl-emitter.js.map