-
Notifications
You must be signed in to change notification settings - Fork 20
/
MMM-MirrorMirrorOnTheWall.js
101 lines (88 loc) · 2.76 KB
/
MMM-MirrorMirrorOnTheWall.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
/* global Module */
/* Magic Mirror
* Module: MMM-MirrorMirrorOnTheWall
*
*
* MIT Licensed.
*/
Module.register('MMM-MirrorMirrorOnTheWall', {
defaults: {},
start: function() {
Log.info('Starting module: ' + this.name);
this.clear = false
this.sendSocketNotification('ALEXA_START', {});
},
getStyles: function() {
return [
"MMM-MirrorMirrorOnTheWall.css",
"https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css"
]
},
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
Log.info(this.name + "received a socket notification:\n" + notification);
if (notification === "RESULT") {
this.clear = false
this.result = payload;
this.updateDom()
this.show(1000, function() {
Log.log(this.name + ' is shown.');
});
} else if (notification === "MODULE") {
let self = this
MM.getModules().enumerate(function(module) {
if (module.name === payload.moduleName || payload.moduleName === "all_modules") {
if (payload.turnOn) {
if (module.name === self.name) {
self.clear = false
self.updateDom();
}
module.show(1000, function() {
Log.log(module.name + ' is shown.');
});
} else {
if (module.name === self.name) {
self.clear = true
self.updateDom();
}
module.hide(1000, function() {
Log.log(module.name + ' is hidden.');
});
}
}
});
}
},
getDom: function() {
wrapper = document.createElement("div");
wrapper.className = 'thin large bright';
if (this.result && !this.clear) {
if (this.result.images) {
var row = document.createElement("div")
row.className = "row"
for (var i = 0; i < this.result.images.length; i++) {
var img = document.createElement("img");
img.src = this.result.images[i].url
row.appendChild(img)
}
wrapper.appendChild(row)
}
if (this.result.videoId) {
var videoWrapper = document.createElement("div")
videoWrapper.className = "videoWrapper"
var iframe = document.createElement('iframe')
iframe.src = "https://www.youtube.com/embed/" + this.result.videoId + "?autoplay=1&controls=0"
videoWrapper.appendChild(iframe)
wrapper.appendChild(videoWrapper)
}
if (this.result.displayText) {
var h1 = document.createElement('h1')
h1.className = "animated fadeIn"
var t = document.createTextNode(this.result.displayText)
h1.appendChild(t)
wrapper.appendChild(h1)
}
}
return wrapper;
}
});