module.exports = function (RED) { "use strict"; function XMPPServerNode(n) { RED.nodes.createNode(this, n); this.delay_msec = n.delay; //this.by_value = n.by_value; this.recv = new Map(); this.on("input", msg => { let msg_json = JSON.stringify(msg.payload); let now = new Date(); for (let [key, val] of this.recv) { if ((now.getTime() - val.getTime()) > this.delay_msec) { this.recv.delete(key); } } if (!this.recv.has(msg_json)) { this.send(msg); this.recv.set(msg_json, now); } }); } RED.nodes.registerType("my-debounce", XMPPServerNode); }