-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnode_helper.js
54 lines (48 loc) · 1.28 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @file node_helper.js
*
* @author fewieden
* @license MIT
*
* @see https://github.com/fewieden/MMM-ping
*/
/**
* @external node_helper
* @see https://github.com/MichMich/MagicMirror/blob/master/modules/node_modules/node_helper/index.js
*/
const NodeHelper = require('node_helper');
/**
* @external ping
* @see https://www.npmjs.com/package/ping
*/
const ping = require('ping');
/**
* @module node_helper
* @description Backend for the module to ping hosts.
*
* @requires external:ping
* @requires external:node_helper
*/
module.exports = NodeHelper.create({
/**
* @function socketNotificationReceived
* @description Receives socket notifications from the module.
* @async
* @override
*
* @param {string} notification - Notification name
* @param {*} payload - Detailed payload of the notification.
*
* @returns {void}
*/
async socketNotificationReceived(notification, payload) {
if (notification === 'CHECK_HOSTS') {
const status = [];
for (const host of payload) {
const { alive } = await ping.promise.probe(host);
status.push({ host, online: alive });
}
this.sendSocketNotification('STATUS_UPDATE', status);
}
}
});