forked from steffenmllr/node-red-contrib-speedtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speedtest.js
35 lines (32 loc) · 1.11 KB
/
speedtest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"use strict";
var speedTest = require("speedtest-net");
module.exports = exports = function (RED) {
function SpeedTest(config) {
RED.nodes.createNode(this, config);
this.on("input", function (msg) {
const node = this;
const { acceptLicense, serverId, acceptGdpr, maxTime } = config;
node.status({ fill: "yellow", shape: "dot", text: "Requesting" });
speedTest({
acceptLicense,
acceptGdpr,
serverId,
maxTime,
})
.then((result) => {
msg.payload = Object.assign({}, result, { config: config });
node.status({ fill: "green", shape: "dot" });
node.send(msg);
})
.catch((err) => {
node.status({
fill: "red",
shape: "dot",
text: err.message,
});
node.error(err, msg);
});
});
}
RED.nodes.registerType("speedtest", SpeedTest);
};