-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
51 lines (49 loc) · 1.32 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
'use strict';
/* Magic Mirror
* Module: MMM-Video
*
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
module.exports = NodeHelper.create({
start: function () {
this.loaded = false;
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
const self = this;
this.config = payload;
if(notification == "VIDEO_DOWNLOAD"){
this.downloadVideo(self.config.videoUrl,"modules/MMM-Podcast/video.mp4",function(){self.loaded = true;});
}
else if (notification == 'VIDEO_CHANGED') {
var omx = require('omxdirector');
this.config = payload;
var status = omx.getStatus();
if(status.playing){
omx.stop();
}
else if(this.loaded){
omx.play("modules/MMM-Podcast/video.mp4");
}
else{
setTimeout(function(){this.socketNotificationReceived(notification, payload)},2000);
}
}
},
downloadVideo : function(url, dest, cb){
var normalizedUrl = url.replace("https://", "http://");
this.loaded = false;
var http = require('http');
var fs = require('fs');
const self = this;
var file = fs.createWriteStream(dest);
var request = http.get(normalizedUrl, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(cb);
self.sendSocketNotification("VIDEO_LOADED", true);
});
});
},
});