-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
41 lines (34 loc) · 1.2 KB
/
node_helper.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
const NodeHelper = require('node_helper');
const request = require('request');
const SpotifyConnector = require('./SpotifyConnector');
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node_helper for: " + this.name);
this.connector = undefined;
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case 'CONNECT_TO_SPOTIFY':
this.connector = new SpotifyConnector(payload);
this.retrieveLatestReleases();
break;
case 'UPDATE_RELEASES':
this.retrieveLatestReleases();
break;
}
},
retrieveLatestReleases: function () {
this.connector.retrieveReleases()
.then((response) => {
if (response) {
this.sendSocketNotification('RETRIEVED_SONG_DATA', response);
} else {
this.sendSocketNotification('RETRIEVED_SONG_DATA', "FAILED!");
}
})
.catch((error) => {
console.error('Can’t retrieve current song. Reason: ');
console.error(error);
});
},
});