From 25d8a59d6c594209409c9f70ac517c4bfeb53a83 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 3 Oct 2013 12:41:30 +0100 Subject: [PATCH] Fix some layout issues in the config popup and made the rate limit mode shut down the timer and make sure it sends the first message straight away when the buffer is empty. --- nodes/core/89-delay.html | 29 +++++++++++++++-------------- nodes/core/89-delay.js | 32 ++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/nodes/core/89-delay.html b/nodes/core/89-delay.html index 82a443c4a..39f28a6a9 100644 --- a/nodes/core/89-delay.html +++ b/nodes/core/89-delay.html @@ -18,17 +18,16 @@ @@ -93,6 +91,9 @@ return this.name?"node_label_italic":""; }, oneditprepare: function() { + $( "#node-input-timeout" ).spinner(); + $( "#node-input-rate" ).spinner(); + if (this.pauseType == "delay") { $("#delay-details").show(); $("#rate-details").hide(); @@ -114,7 +115,7 @@ } else if (this.value == "rate") { $("#delay-details").hide(); $("#rate-details").show(); - } + } }); } }); diff --git a/nodes/core/89-delay.js b/nodes/core/89-delay.js index e2f819e5a..b0fae5b0a 100644 --- a/nodes/core/89-delay.js +++ b/nodes/core/89-delay.js @@ -48,13 +48,11 @@ function DelayNode(n) { } else if (n.rateUnits == "day") { this.rate = (24 * 60 * 60 * 1000)/n.rate; } - - console.log(this.timeoutUnits + " - " + n.timeout + " = " + this.timeout); - console.log(this.rateUnits + " - " + n.rate + " = " + this.rate); this.name = n.name; this.idList = []; this.buffer = []; + this.intervalID = -1; var node= this; if (this.pauseType == "delay") { @@ -69,21 +67,31 @@ function DelayNode(n) { }); } else if (this.pauseType == "rate") { - this.intervalID = setInterval(function() { - if (node.buffer.length > 0) { - node.send(node.buffer.shift()); - } - },this.rate); - this.on("input", function(msg) { - this.buffer.push(msg); - if (this.buffer.length > 1000) { - this.warn(this.name + " buffer exceeded 1000 messages"); + if ( node.intervalID != -1) { + node.buffer.push(msg); + if (node.buffer.length > 1000) { + node.warn(this.name + " buffer exceeded 1000 messages"); + } + } else { + node.send(msg); + node.intervalID = setInterval(function() { + if (node.buffer.length == 0) { + clearInterval(node.intervalID); + node.intervalID = -1; + } + + if (node.buffer.length > 0) { + node.send(node.buffer.shift()); + } + },node.rate); } }); } } + + // register node RED.nodes.registerType("delay",DelayNode);