-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathping.js
63 lines (63 loc) · 1.6 KB
/
ping.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
55
56
57
58
59
60
61
62
63
/* global Module */
/* Magic Mirror
* Module: ping
*
* By Christopher Fenner https://github.com/CFenner
* MIT Licensed.
*/
Module.register('ping', {
defaults: {
animationSpeed: 1,
updateInterval: 10,
showAlways: false
},
payload: {},
start: function() {
Log.info('Starting module: ' + this.name);
this.update();
// refresh every x minutes
setInterval(
this.update.bind(this),
this.config.updateInterval * 60 * 1000);
},
update: function() {
this.sendSocketNotification('PING_REQUEST');
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'PING_RESPONSE') {
Log.info('received' + notification);
if(payload){
this.payload = payload;
this.updateDom(this.config.animationSpeed * 1000);
}
}
},
getStyles: function() {
return [];
},
getScripts: function() {
return ["moment.js"];
},
getTranslations: function() {
return {
en: "i18n/en.json",
es: "i18n/es.json",
de: "i18n/de.json",
fr: "i18n/fr.json"
};
},
getDom: function() {
var wrapper = document.createElement("div");
if(this.config.showAlways || this.payload.status === "ERROR"){
var span = document.createElement("div");
span.innerHTML = this.translate("LAST_ACTIVE_CONNECTION");
span.className = "small";
wrapper.appendChild(span);
span = document.createElement("div");
span.className = "bright";
span.innerHTML = moment(this.payload.lastConnection).fromNow();
wrapper.appendChild(span);
}
return wrapper;
}
});