This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMMM-Callmonitor-Current-Call.js
99 lines (82 loc) · 2.31 KB
/
MMM-Callmonitor-Current-Call.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* global Module */
/* Magic Mirror
* Module: MMM-Callmonitor-Current-Call
*
* By Paul-Vincent Roll http://paulvincentroll.com
* MIT Licensed.
*/
Module.register("MMM-Callmonitor-Current-Call", {
// Default module config.
defaults: {
},
// Define required translations.
getTranslations: function() {
return {
en: "translations/en.json",
de: "translations/de.json"
};
},
getScripts: function() {
return ["moment.js"];
},
notificationReceived: function(notification, payload, sender) {
if (notification === "CALL_CONNECTED") {
this.active_calls[payload] = moment();
if (!this.timer) {
console.log("timer set");
var self = this;
this.timer = setInterval(function() {self.updateDom();}, 1000);
this.updateDom(300);
}
console.log(this.active_calls);
} else if (notification === "CALL_DISCONNECTED") {
delete this.active_calls[payload];
if (Object.keys(this.active_calls).length == 0) {
clearInterval(this.timer);
this.timer = false;
console.log("timer cleared");
}
this.updateDom(300);
}
},
start: function() {
//Create active_calls array
this.active_calls = {};
//set timer
this.timer = false;
Log.info("Starting module: " + this.name);
},
getDom: function() {
//Create table
var wrapper = document.createElement("table");
//set table style
wrapper.className = "small";
var calls = this.active_calls;
console.log(this.active_calls);
//If there are no calls, set "noCall" text.
if (Object.keys(this.active_calls).length == 0 && this.data.header != null) {
wrapper.innerHTML = this.translate("NoActiveCalls");
wrapper.className = "xsmall dimmed";
return wrapper;
}
//For each call in calls
for (var call in calls) {
//Create callWrapper
var callWrapper = document.createElement("tr");
callWrapper.className = "normal";
//Set caller of row
var caller = document.createElement("td");
caller.innerHTML = call;
caller.className = "title bright";
callWrapper.appendChild(caller);
//Set time of row
var time = document.createElement("td");
time.innerHTML = moment.utc(moment(moment()).diff(moment(calls[call]))).format("HH:mm:ss");
time.className = "time light xsmall";
callWrapper.appendChild(time);
//Add to wrapper
wrapper.appendChild(callWrapper);
}
return wrapper;
}
});