-
Notifications
You must be signed in to change notification settings - Fork 2
/
node_helper.js
64 lines (60 loc) · 1.63 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
var fs = require('fs');
const path = require('path');
const NodeHelper = require('node_helper');
var self;
module.exports = NodeHelper.create({
// data defaults
defaults:{
videoDir:"videos",
posterDir:"posters",
},
self:0,
// make Promise version of fs.readdir()
readdirAsync : function(dirname) {
return new Promise(function(resolve, reject) {
fs.readdir(dirname, function(err, filenames){
if (err)
reject(err);
else
resolve(filenames);
});
});
},
// functions from here on
start: function() {
self=this;
console.log("Starting module: " + this.name);
},
getVideos: function(){
try {
var files=fs.readdirSync(self.config.videoDir)
return files;
}
catch(exception){
console.log("videoDir error ="+exception.message);
}
},
getPosters: function(){
try {
var files=fs.readdirSync(self.config.posterDir)
return files;
}
catch(exception){
console.log("posterDir error ="+exception.message);
}
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'CONFIG') {
this.config = payload;
console.log("config payload received");
self.config.videoDir=path.join(__dirname.toString(),self.config.videoDir);
self.config.posterDir=path.join(__dirname.toString(),self.config.posterDir);
}
else if (notification === 'GET_VIDEOS') {
self.sendSocketNotification("Videos",self.getVideos());
}
else if (notification === 'GET_POSTERS') {
self.sendSocketNotification("Posters",self.getPosters());
}
},
})