Intial Commit

This commit is contained in:
valki
2020-10-17 18:42:50 +02:00
commit 664c6d8ca3
5892 changed files with 759183 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
Copyright 2016 Daniel 'Eisbehr' Kern', http://eisbehr.de
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,55 @@
{
"_from": "node-red-contrib-throttle@0.1.6",
"_id": "node-red-contrib-throttle@0.1.6",
"_inBundle": false,
"_integrity": "sha1-jo/gxEYJViMqkK5y3jy5xCG6hmk=",
"_location": "/node-red-contrib-throttle",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "node-red-contrib-throttle@0.1.6",
"name": "node-red-contrib-throttle",
"escapedName": "node-red-contrib-throttle",
"rawSpec": "0.1.6",
"saveSpec": null,
"fetchSpec": "0.1.6"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/node-red-contrib-throttle/-/node-red-contrib-throttle-0.1.6.tgz",
"_shasum": "8e8fe0c4460956232a90ae72de3cb9c421ba8669",
"_spec": "node-red-contrib-throttle@0.1.6",
"_where": "/data",
"author": {
"name": "Daniel 'Eisbehr' Kern",
"email": "jquery@eisbehr.de",
"url": "http://eisbehr.de"
},
"bugs": {
"url": "http://github.com/eisbehr-/node-red-throttle/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "A Node-RED node to throttle down passed through message amount.",
"homepage": "http://github.com/eisbehr-/node-red-throttle",
"keywords": [
"node-red",
"throttle",
"limit"
],
"license": "Apache-2.0",
"name": "node-red-contrib-throttle",
"node-red": {
"nodes": {
"throttle": "throttle.js"
}
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/eisbehr-/node-red-throttle.git"
},
"version": "0.1.6"
}

View File

@@ -0,0 +1,124 @@
node-red-contrib-throttle
=========================
[![GitHub version](https://badge.fury.io/gh/eisbehr-%2Fnode-red-throttle.svg)](http://github.com/eisbehr-/node-red-throttle)
[![NPM version](https://badge.fury.io/js/node-red-contrib-throttle.svg)](http://www.npmjs.org/package/node-red-contrib-throttle)
[![Dependencies Status](https://david-dm.org/eisbehr-/node-red-throttle/status.svg)](https://david-dm.org/eisbehr-/node-red-throttle)
A <a href="http://nodered.org" target="_new">Node-RED</a> node to throttle down outgoing messages.
---
## Table of Contents
* [Install](#install)
* [Usage](#usage)
* [By Time](#by-time)
* [By Count](#by-count)
* [By Block Size](#by-block-size)
* [By Reset](#by-reset)
* [Example Flows](#example-flows)
* [Example by Time](#example-by-time)
* [Example by Count](#example-by-count)
* [Example by Block Size](#example-by-block-size)
* [Example by Reset](#example-by-reset)
* [Bugs / Feature request](#bugs--feature-request)
* [License](#license)
* [Donation](#donation)
---
## Install
Run the following command in your Node-RED user directory - typically `~/.node-red`:
```
npm install node-red-contrib-throttle
```
## Usage
A simple node to throttle down passed through message amount.
Just insert the throttle node in between two others, and the passed through message amount can be limited by different parameters.
Every other messages will be dropped.
### By Time
Limits the passed through messages by a given amount of time.
**For example:** setting the node to `10 seconds` means, that only one message in ten seconds will be forwarded.
### By Count
Limits the passed through messages by a given count.
**For example:** setting the node to a count of `5` means, that only every fifth message will be forwarded.
### By Block Size
Limits the passed through messages by a given block size.
The counter will be reset when a message with `msg.reset` was received.
**For example:** setting the node to a block size of `5` means, that only the first five messages will be forwarded.
### By Reset
Will only pass through a single message, when a message with `msg.reset` was received before.
## Example Flows
Simple examples showing how to use the throttle and it's output.
### Example by Time
![example1.png](./doc/example1.png)
```JSON
[{"id":"81be4802.e74478","type":"function","z":"8a25646f.9d541","name":"info msg","func":"msg.payload = \"injected\";\nreturn msg;","outputs":1,"noerr":0,"x":800,"y":60,"wires":[["789ee5ac.32e214"]]},{"id":"789ee5ac.32e214","type":"debug","z":"8a25646f.9d541","name":"output","active":true,"console":"false","complete":"payload","x":950,"y":80,"wires":[]},{"id":"99fbadf5.9b42e8","type":"throttle","z":"8a25646f.9d541","name":"","throttleType":"time","timeLimit":"3","timeLimitType":"seconds","countLimit":"3","blockSize":0,"locked":false,"x":800,"y":100,"wires":[["789ee5ac.32e214"]]},{"id":"681f30ee.8f3598","type":"inject","z":"8a25646f.9d541","name":"inject","topic":"","payload":"!!! PASSED THROUGH !!!","payloadType":"str","repeat":"","crontab":"","once":false,"x":650,"y":80,"wires":[["99fbadf5.9b42e8","81be4802.e74478"]]}]
```
### Example by Count
![example2.png](./doc/example2.png)
```JSON
[{"id":"a3d7f710.99f97","type":"debug","z":"8a25646f.9d541","name":"output","active":true,"console":"false","complete":"payload","x":950,"y":200,"wires":[]},{"id":"e2c6599a.0b5c98","type":"function","z":"8a25646f.9d541","name":"info msg","func":"msg.payload = \"injected\";\nreturn msg;","outputs":1,"noerr":0,"x":800,"y":180,"wires":[["a3d7f710.99f97"]]},{"id":"8a2c177f.24e0c8","type":"throttle","z":"8a25646f.9d541","name":"","throttleType":"count","timeLimit":"10","timeLimitType":"seconds","countLimit":"3","blockSize":0,"locked":false,"x":800,"y":220,"wires":[["a3d7f710.99f97"]]},{"id":"836ebd21.ad25","type":"inject","z":"8a25646f.9d541","name":"inject","topic":"","payload":"!!! PASSED THROUGH !!!","payloadType":"str","repeat":"","crontab":"","once":false,"x":650,"y":200,"wires":[["8a2c177f.24e0c8","e2c6599a.0b5c98"]]}]
```
### Example by Block Size
![example3.png](./doc/example3.png)
```JSON
[{"id":"32aac7a2.1c4d2","type":"function","z":"8a25646f.9d541","name":"info msg","func":"msg.payload = \"injected\";\nreturn msg;","outputs":1,"noerr":0,"x":800,"y":300,"wires":[["cc05fc6b.4e2598"]]},{"id":"ad1cf860.9c085","type":"throttle","z":"8a25646f.9d541","name":"","throttleType":"block","timeLimit":"10","timeLimitType":"seconds","countLimit":"3","blockSize":"3","locked":false,"x":800,"y":340,"wires":[["cc05fc6b.4e2598"]]},{"id":"8925c66d.9381d8","type":"inject","z":"8a25646f.9d541","name":"inject","topic":"","payload":"!!! PASSED THROUGH !!!","payloadType":"str","repeat":"","crontab":"","once":false,"x":490,"y":320,"wires":[["ad1cf860.9c085","32aac7a2.1c4d2"]]},{"id":"8a84f4e3.491f18","type":"inject","z":"8a25646f.9d541","name":"reset","topic":"","payload":"reset","payloadType":"str","repeat":"","crontab":"","once":false,"x":490,"y":380,"wires":[["c83fa727.0f0b3"]]},{"id":"c83fa727.0f0b3","type":"function","z":"8a25646f.9d541","name":"reset msg","func":"msg.reset = true;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":380,"wires":[["ad1cf860.9c085","cc05fc6b.4e2598"]]},{"id":"cc05fc6b.4e2598","type":"debug","z":"8a25646f.9d541","name":"output","active":true,"console":"false","complete":"payload","x":970,"y":380,"wires":[]}]
```
### Example by Reset
![example4.png](./doc/example4.png)
```JSON
[{"id":"4e11480f.2fad28","type":"function","z":"8a25646f.9d541","name":"info msg","func":"msg.payload = \"injected\";\nreturn msg;","outputs":1,"noerr":0,"x":800,"y":460,"wires":[["c1d324bd.d2feb8"]]},{"id":"50915215.704714","type":"throttle","z":"8a25646f.9d541","name":"","throttleType":"reset","timeLimit":"10","timeLimitType":"seconds","countLimit":"3","blockSize":0,"locked":false,"x":800,"y":500,"wires":[["c1d324bd.d2feb8"]]},{"id":"4ba961e0.c018c8","type":"inject","z":"8a25646f.9d541","name":"inject","topic":"","payload":"!!! PASSED THROUGH !!!","payloadType":"str","repeat":"","crontab":"","once":false,"x":490,"y":480,"wires":[["50915215.704714","4e11480f.2fad28"]]},{"id":"f786e09d.1cdfa","type":"inject","z":"8a25646f.9d541","name":"reset","topic":"","payload":"reset","payloadType":"str","repeat":"","crontab":"","once":false,"x":490,"y":540,"wires":[["bbf770bd.df0768"]]},{"id":"bbf770bd.df0768","type":"function","z":"8a25646f.9d541","name":"reset msg","func":"msg.reset = true;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":540,"wires":[["50915215.704714","c1d324bd.d2feb8"]]},{"id":"c1d324bd.d2feb8","type":"debug","z":"8a25646f.9d541","name":"output","active":true,"console":"false","complete":"payload","x":970,"y":540,"wires":[]}]
```
## Bugs / Feature request
Please [report](http://github.com/eisbehr-/node-red-throttle/issues) bugs and feel free to [ask](http://github.com/eisbehr-/node-red-throttle/issues) for new features directly on GitHub.
## License
This project is licensed under [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0) license.
## Donation
_You like to support me?_
_You appreciate my work?_
_You use it in commercial projects?_
Feel free to make a little [donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FFL6VQJCUZMXC)! :wink:

View File

@@ -0,0 +1,102 @@
<script type="text/x-red" data-template-name="throttle">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for=""><i class="fa fa-filter"></i> Throttle</label>
<select id="node-input-throttleType" style="width: 70%">
<option value="time">by time</option>
<option value="count">by count</option>
<option value="block">by block size</option>
<option value="reset">by reset</option>
</select>
</div>
<div class="form-row throttle-limit-row" id="throttle-limit-row-time">
<label for="node-input-timeLimit"><i class="fa fa-clock-o"></i> Time Limit</label>
<input type="text" id="node-input-timeLimit" placeholder="0" style="padding-left: 5px; width: 70%">
<input type="hidden" id="node-input-timeLimitType">
</div>
<div class="form-row throttle-limit-row hidden" id="throttle-limit-row-count">
<label for="node-input-countLimit"><i class="fa fa-hashtag"></i> Count Limit</label>
<input type="text" id="node-input-countLimit" placeholder="0">
</div>
<div class="form-row throttle-limit-row hidden" id="throttle-limit-row-block">
<label for="node-input-blockSize"><i class="fa fa-hashtag"></i> Block Size</label>
<input type="text" id="node-input-blockSize" placeholder="0">
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-locked" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-locked" style="width: 70%;">Locked by default?</label>
</div>
</script>
<script type="text/x-red" data-help-name="throttle">
<p>A simple node to throttle down passed through message amount.</p>
<p>Just insert the throttle node in between two others, and the passed through message amount can be limited by different parameters.</p>
<p><strong>By Time:</strong><br/>
Limits the passed through messages by a given amount of time.
For example: setting the node to <code>10 seconds</code> means, that only one message in ten seconds will be forwarded.</p>
<p><strong>By Count:</strong><br/>
Limits the passed through messages by a given count.
For example: setting the node to a count of <code>5</code> means, that only every fifth message will be forwarded.</p>
<p><strong>By Block Size:</strong><br/>
Limits the passed through messages by a given block size.
The counter will be reset when a message with <code>msg.reset</code> was received.
For example: setting the node to a block size of <code>5</code> means, that only the first five messages will be forwarded.</p>
<p><strong>By Reset:</strong><br/>
Will only pass through a single message, when a message with <code>msg.reset</code> was received before.</p>
<p>Every other messages will be dropped!</p>
</script>
<script type="text/javascript">
RED.nodes.registerType("throttle", {
category: "function",
defaults: {
name: {value:""},
throttleType: {value:"time"},
timeLimit: {value:0,validate:RED.validators.number()},
timeLimitType: {value:"seconds"},
countLimit: {value:0,validate:RED.validators.number()},
blockSize: {value:0,validate:RED.validators.number()},
locked: {value:false}
},
color:"#e6e0f8",
inputs: 1,
outputs: 1,
icon: "throttle.png",
label: function() {
return this.name || "throttle";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
// defaults
this.throttleType = !this.throttleType ? "time" : this.throttleType;
this.countLimit = !this.countLimit ? 0 : this.countLimit;
this.blockSize = !this.blockSize ? 0 : this.blockSize;
this.timeLimit = !this.timeLimit ? 0 : this.timeLimit;
this.timeLimitType = !this.timeLimitType ? "seconds" : this.timeLimitType;
// change listener for type select
$("#node-input-throttleType").change(function() {
$(".throttle-limit-row").hide();
$("#throttle-limit-row-" + $(this).val()).show();
});
// typed input for time throttle
$("#node-input-timeLimit").typedInput({
default: "seconds",
typeField: $("#node-input-timeLimitType"),
types: [
{value: "milliseconds", label: "milliseconds", hasValue: true},
{value: "seconds", label: "seconds", hasValue: true},
{value: "minutes", label: "minutes", hasValue: true},
{value: "hours", label: "hours", hasValue: true}
]
});
}
});
</script>

View File

@@ -0,0 +1,101 @@
module.exports = function(RED) {
"use strict";
function throttle(config) {
RED.nodes.createNode(this, config);
var node = this;
// config
this.throttleType = config.throttleType || "time";
this.timeLimitType = config.timeLimitType || "seconds";
this.timeLimit = Number(config.timeLimit || 0);
this.countLimit = Number(config.countLimit || 0);
this.blockSize = Number(config.blockSize || 0);
this.locked = config.locked || false;
// helpers
this.time = this.locked ? Math.floor(Date.now()) : 0;
this.count = this.locked ? 1 : 0;
this.block = this.locked ? this.blockSize + 1 : 0;
this.reset = !!this.locked;
// calculate time limit in milliseconds
if( this.timeLimitType === "hours" ) {
this.timeLimit *= 60 * 60 * 1000;
}
else if( this.timeLimitType === "minutes" ) {
this.timeLimit *= 60 * 1000;
}
else if( this.timeLimitType === "seconds" ) {
this.timeLimit *= 1000;
}
this.on("input", function(msg) {
// throttle by time
if( node.throttleType === "time" ) {
if( isNaN(node.timeLimit) || !isFinite(node.timeLimit) ) {
return this.error("time limit is not numeric", msg);
}
var now = Math.floor(Date.now());
if( node.time + node.timeLimit < now ) {
node.time = now;
node.send(msg);
}
}
// throttle by count
else if( node.throttleType === "count" ) {
if( isNaN(node.countLimit) || !isFinite(node.countLimit) ) {
return this.error("count limit is not numeric", msg);
}
++node.count;
if( node.count >= node.countLimit ) {
node.count = 0;
}
if( node.countLimit === 0 || node.countLimit === 1 || node.count === 1 ) {
node.send(msg);
}
}
// throttle by block size
else if( node.throttleType === "block" ) {
if( isNaN(node.blockSize) || !isFinite(node.blockSize) ) {
return this.error("block size is not numeric", msg);
}
++node.block;
if( node.block <= node.blockSize ) {
node.send(msg);
}
else if( msg.reset ) {
node.block = 0;
}
}
// throttle by reset
else if( node.throttleType === "reset" ) {
if( !node.reset ) {
node.reset = true;
node.send(msg);
}
else if( msg.reset ) {
node.reset = false;
}
}
// unknown throttle type
else {
this.error("unknown throttle type '" + node.throttleType + "'", msg);
}
});
}
RED.nodes.registerType("throttle", throttle);
};