forked from Gyran/MMM-plex-recently-added
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
40 lines (35 loc) · 969 Bytes
/
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
var NodeHelper = require('node_helper');
var Plex = require('./plex');
var NOTIFICATIONS = {
CONFIG: 'CONFIG',
DATA: 'DATA',
ERROR: 'ERROR',
};
module.exports = NodeHelper.create({
socketNotificationReceived: function(notification, payload) {
if (notification === NOTIFICATIONS.CONFIG) {
this.config = payload;
this.client = Plex({
token: this.config.token,
hostname: this.config.hostname,
port: this.config.port,
});
this.update();
setInterval(() => {
this.update();
}, this.config.updateInterval);
}
},
update: function() {
this.config.types.forEach((type) => {
this.client.recentlyAdded(type, this.config.limit).then((items) => {
this.sendSocketNotification(NOTIFICATIONS.DATA, {
type: type,
items: items,
});
}, (error) => {
this.sendSocketNotification(NOTIFICATIONS.ERROR, { error });
});
});
}
});