-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-Echo.js
109 lines (94 loc) · 3.03 KB
/
MMM-Echo.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
100
101
102
103
104
105
106
107
108
109
Module.register('MMM-Echo',{
defaults: {
// recognition intervall in seconds (scale this based on desired CPU usage)
interval: 1,
// Logout delay after last recognition so that a user does not get instantly logged out when out of cameras field of vision
logoutDelay: 15,
// Array with usernames
users: [],
// Module set used for strangers and if no user is detected
defaultClass: "default",
// Set of modules which should be shown for every user
everyoneClass: "everyone",
// Boolean to toggle welcomeMessage
welcomeMessage: true
},
// Define required translations.
getTranslations: function() {
return {
en: "translations/en.json",
de: "translations/de.json",
es: "translations/es.json",
zh: "translations/zh.json",
nl: "translations/nl.json",
sv: "translations/sv.json",
fr: "translations/fr.json",
id: "translations/id.json",
nb: "translations/nb.json"
};
},
login_user: function () {
MM.getModules().withClass(this.config.defaultClass).exceptWithClass(this.config.everyoneClass).enumerate(function(module) {
module.hide(1000, function() {
Log.log(module.name + ' is hidden.');
});
});
MM.getModules().withClass(this.current_user).enumerate(function(module) {
module.show(1000, function() {
Log.log(module.name + ' is shown.');
});
});
this.sendNotification("CURRENT_USER", this.current_user);
},
logout_user: function () {
MM.getModules().withClass(this.current_user).enumerate(function(module) {
module.hide(1000, function() {
Log.log(module.name + ' is hidden.');
});
});
MM.getModules().withClass(this.config.defaultClass).exceptWithClass(this.config.everyoneClass).enumerate(function(module) {
module.show(1000, function() {
Log.log(module.name + ' is shown.');
});
});
this.sendNotification("CURRENT_USER", "None");
},
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (payload.action == "login"){
if (this.current_user_id != payload.user){
this.logout_user()
}
if (payload.user == -1){
this.current_user = this.translate("stranger")
this.current_user_id = payload.user;
}
else{
this.current_user = this.config.users[payload.user];
this.current_user_id = payload.user;
this.login_user()
}
if (this.config.welcomeMessage) {
this.sendNotification("SHOW_ALERT", {type: "notification", message: this.translate("message").replace("%person", this.current_user), title: this.translate("title")});
}
}
else if (payload.action == "logout"){
this.logout_user()
this.current_user = null;
}
},
notificationReceived: function(notification, payload, sender) {
if (notification === 'DOM_OBJECTS_CREATED') {
MM.getModules().exceptWithClass("default").enumerate(function(module) {
module.hide(1000, function() {
Log.log('Module is hidden.');
});
});
}
},
start: function() {
this.current_user = null;
this.sendSocketNotification('CONFIG', this.config);
Log.info('Starting module: ' + this.name);
}
});