-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnode_helper.js
40 lines (36 loc) · 1.22 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
/* Magic Mirror
* Module: iFrame-Ping
*
* By AgP42
*
* This is a modified version from MMM-ping by Christopher Fenner https://github.com/CFenner
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function () {
console.log(this.name + ' helper started ...');
this.lastConnection = new Date(); //on considere un ping ok au start-up...
},
socketNotificationReceived: function(notification, payload) {
//console.log(notification);
if (notification === 'PING_REQUEST') {
var that = this;
request({
url: payload,
method: 'GET'
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
that.lastConnection = new Date(); //success, we record the new date
}
//whatever the answer, we send the answer back to main file with status and lastConnection timestamp
that.sendSocketNotification('PING_RESPONSE', {
status: !error && response.statusCode == 200?"OK":"ERROR",
lastConnection: that.lastConnection
});
}
);
}
}
});