-
Notifications
You must be signed in to change notification settings - Fork 3
/
MMM-SpotifyConnectUI.js
executable file
·109 lines (90 loc) · 2.83 KB
/
MMM-SpotifyConnectUI.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
/* global Module */
/* Magic Mirror
* Module: SpotifyConnectUI
*
* By Cato Antonsen
* MIT Licensed.
*/
Module.register("MMM-SpotifyConnectUI",{
defaults: {
Protocol: "http",
Host: "localhost",
Port: 4000,
MetadataApi: "/api/info/metadata",
StatusApi: "/api/info/status",
RemoteName: "/api/info/display_name",
ImageUrlApi: "/api/info/image_url/"
},
start: function() {
this.spotifyData = null;
Log.info('Starting module: ' + this.name);
this.sendSocketNotification('CONFIG', this.config);
},
getDom: function() {
var wrapper = document.createElement("div");
wrapper.className = "spotifyWrapper small"; // align-right thin bright
if (this.spotifyData != null) {
// Image wrapper
var imgWrapper = document.createElement("div");
imgWrapper.className = "spotifyImageWrapper";
if (this.spotifyData.status.active) {
// Cover image
var coverImg = document.createElement("img");
coverImg.setAttribute("src", this.spotifyData.meta.cover_uri);
// Show pause-button?
if (this.spotifyData.status.playing) {
imgWrapper.appendChild(coverImg);
} else {
coverImg.style.opacity = "0.25";
imgWrapper.appendChild(coverImg);
var pauseImg = document.createElement("img");
pauseImg.src = this.file("images/music-pause-button-pair-of-lines.png");
pauseImg.className = "floating";
imgWrapper.appendChild(pauseImg);
}
// Track name
var track = document.createElement("div");
track.className = "title bright";
var trackName = document.createTextNode(this.spotifyData.meta.track_name);
track.appendChild(trackName);
// Artist name
var artist = document.createElement("div");
artist.className = "time light";
var artistName = document.createTextNode(this.spotifyData.meta.artist_name);
artist.appendChild(artistName);
// Add elements
wrapper.appendChild(imgWrapper);
wrapper.appendChild(track);
wrapper.appendChild(artist);
}
else {
// Image
var connectImg = document.createElement("img");
connectImg.src = this.file("images/Spotify_Icon_RGB_Black.png");
connectImg.className = "spotifyMissingConnectionImage";
// Message
var message = document.createElement("div");
message.className = "spotifyMissingConnectionMessage floating light xsmall dimmed";
var remoteName = document.createTextNode(this.spotifyData.remoteName);
remoteName.className = " ";
message.appendChild(remoteName);
// Add elements
imgWrapper.appendChild(connectImg);
imgWrapper.appendChild(message);
wrapper.appendChild(imgWrapper);
}
}
return wrapper;
},
getStyles: function() {
return [
'custom.css'
]
},
socketNotificationReceived: function(notification, payload) {
if (notification === "SpotifyConnectUI"){
this.spotifyData = payload;
this.updateDom(2000);
}
}
});