forked from PoOwAa/MMM-network-signal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
33 lines (31 loc) · 1.04 KB
/
node_helper.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
const NodeHelper = require("node_helper");
const ping = require("ping");
module.exports = NodeHelper.create({
start: function() {
console.log(this.name + " helper started ...");
},
socketNotificationReceived: function(notification, payload) {
const config = payload.config;
if (notification === "MMM_NETWORKSIGNAL_CHECK_SIGNAL") {
const self = this;
ping.promise
.probe(config.server, {
timeout: config.maxTimeout,
})
.then(pong => {
// console.log(pong);
self.sendSocketNotification(
"MMM_NETWORKSIGNAL_RESULT_PING",
pong.time,
);
})
.catch(err => {
// console.log(err);
self.sendSocketNotification(
"MMM_NETWORKSIGNAL_RESULT_PING",
9999,
);
});
}
},
});