-
Notifications
You must be signed in to change notification settings - Fork 4
/
MMM-MusicOnDemand.js
123 lines (111 loc) · 3.55 KB
/
MMM-MusicOnDemand.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Module.register("MMM-MusicOnDemand",{
defaults:{
chromiumPath: "/usr/bin/chromium-browser", // Set: chromiumPath : null, if you want to use the puppeteer chromium
showCover : true,
showBrowser : false, // change to true if you want to see whats going on in the browser
userDataDir : "/home/pi/.config/chromium" //the directory of your user data from the browser, default is for raspberry pi without changes
},
getStyles: function() {
return ['style.css',];
},
start: function(){
this.init = "Initializing...";
this.Title = "";
this.Artist = "";
this.currentTime = "";
this.maxTime = "";
this.CoverLink = "";
this.closed = false;
this.sendSocketNotification("CONFIG", this.config);
},
getDom: function(){
var wrapper = document.createElement("div");
var text = '';
if(!this.closed){
text += "<div class='MOD_player'>";
text += "<div class='MOD_text-container'><table class='small'><tr class='MOD_init'><td>"+ this.init +"</td></tr><tr class='MOD_title bright'><td>"+ this.Title +"</td></tr><tr class='MOD_artist'><td>"+ this.Artist +"</td></tr><tr class='MOD_time'><td>"+ this.currentTime + " " + this.maxTime + "</td></tr></table></div>";
if(this.config.showCover && this.Artist != "Deezer"){
text += "<div class='MOD_cover-container'><div class='MOD_cover'><img src='"+ this.CoverLink +"' width='250'></div></div>";
}
text += "</div>";
//text = "<p>" + init + "<br>" + "Title: " + Title + "<br>" + "Artist: " + Artist + "<br>" + currentTime + "/" + maxTime + "</p>" + Cover;
}else{
wrapper.innerHTML = "";
wrapper.className = "dimmed light small";
return wrapper;
}
wrapper.innerHTML = text;
return wrapper;
},
socketNotificationReceived: function(notification, payload) {
switch(notification){
case("Ready"):
this.init = "";
break;
case("Title"):
this.Title = payload;
break;
case("Update"):
this.Artist = payload.Artist;
this.Title = payload.Title;
this.maxTime = payload.MaxTime;
this.currentTime = payload.CurrentTime + ' /';
break;
case("Ads"):
this.Title = "Ads";
this.Artist = "Deezer";
this.currentTime = "";
this.maxTime = "";
this.Cover = "";
case("Cover"):
this.CoverLink = payload;
break;
case("Closed"):
this.closed = true;
break;
default:
break;
}
this.updateDom();
},
notificationReceived: function(notification, payload, sender) {
if (sender) {
Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
} else {
Log.log(this.name + " received a system notification: " + notification);
}
if(notification == "AtMusicOnDemand"){
switch(payload.message){
case("Play"):
this.sendSocketNotification("PLAY", "");
break;
case("Pause"):
this.sendSocketNotification("PAUSE", "");
break;
case("Next"):
this.sendSocketNotification("NEXT", "");
break;
case("Previous"):
this.sendSocketNotification("PREVIOUS", "");
break;
case("Artist"):
this.sendSocketNotification("Artist", payload.Artist);
break;
case("Close"):
this.sendSocketNotification("Close", "");
break;
case("Title"):
this.sendSocketNotification("Title", payload.Title);
break;
case("Flow"):
this.sendSocketNotification("FLOW", "");
break;
case("Loved"):
this.sendSocketNotification("LOVED", "");
break;
default:
break;
}
}
}
});