-
Notifications
You must be signed in to change notification settings - Fork 43
/
MMM-NowPlayingOnSpotify.js
76 lines (61 loc) · 1.78 KB
/
MMM-NowPlayingOnSpotify.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
'use strict';
Module.register('MMM-NowPlayingOnSpotify', {
// default values
defaults: {
// Module misc
name: 'MMM-NowPlayingOnSpotify',
hidden: false,
// user definable
updatesEvery: 1, // How often should the table be updated in s?
showCoverArt: true // Do you want the cover art to be displayed?
},
start: function () {
Log.info('Starting module: ' + this.name );
this.initialized = false;
this.context = {};
this.startFetchingLoop();
},
getDom: function () {
let domBuilder = new NPOS_DomBuilder(this.config, this.file(''));
if (this.initialized) {
return domBuilder.getDom(this.context);
} else {
return domBuilder.getInitDom(this.translate('LOADING'));
}
},
getStyles: function () {
return [
this.file('css/styles.css'),
this.file('node_modules/moment-duration-format/lib/moment-duration-format.js'),
'font-awesome.css'
];
},
getScripts: function () {
return [
this.file('core/NPOS_DomBuilder.js'),
'moment.js'
];
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case 'RETRIEVED_SONG_DATA':
this.initialized = true;
this.context = payload;
this.updateDom();
}
},
startFetchingLoop() {
// start immediately ...
let credentials = {
clientID: this.config.clientID,
clientSecret: this.config.clientSecret,
accessToken: this.config.accessToken,
refreshToken: this.config.refreshToken
};
this.sendSocketNotification('CONNECT_TO_SPOTIFY', credentials);
// ... and then repeat in the given interval
setInterval(() => {
this.sendSocketNotification('UPDATE_CURRENT_SONG');
}, this.config.updatesEvery * 1000);
}
});