-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
71 lines (59 loc) · 1.78 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
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
/*'use strict';*/
/* Magic Mirror
* Module: MMM-Dreambox
*
* By AxLED
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
const request = require('request');
const exec = require("child_process").exec;
const parser = require("./MMM-Podcast-xml2json.js");
var Errormessage = '';
module.exports = NodeHelper.create({
start: function() {
this.started = false;
this.config = null;
},
socketNotificationReceived: function(notification, payload) {
var self = this;
if (notification === 'CONFIG' && self.started == false) {
self.config = payload;
self.sendSocketNotification("STARTED", true);
self.getData2();//Inittal Dataload before timer interval is activated
self.started = true;
console.log("Starting node helper for: " + self.name);
}
if (notification === "BUTTON_PRESSED") {
if (payload[1] === 'PLAY') {
console.log('MMM-Podcast2 PLAY:');
exec('omxplayer '+self.config.omxargs+payload[0], null);//without --live buffering works
} else {
console.log('MMM-Podcast2 STOP:');
exec('pkill omxplayer', null);
}
self.getData2();
}
if (notification === "FETCH_DATA") {
self.getData2();
}
},
getData2: function() {
var self = this;
var myUrl = this.config.feedUrl;
request({url: myUrl }, function (error, response, body) {
if (!error && response.statusCode == 200) {
json = parser.xml2json(body);
self.sendSocketNotification("DATA",json);
} else {
if (!error && response.statusCode == 404){//because sometimes error is null
Errormessage = 'Error: '+response.statusCode+' in '+myUrl;
} else {
Errormessage = 'Error: '+error.code+' in '+myUrl;
}
console.log('MMM-Podcast2 Error :',Errormessage);
self.sendSocketNotification("DATA",['ERROR',Errormessage]);
}
});
},
});