I im using node js to pass data from watcher every few seconds to function streamplay that stores id.ts filenames in array this works fine as it stores but when i callback from another function in my program i get undefined value from this array....and i can't figure out how it needs to be written:
var stream_play = [];
watch('/tmp/1_.m3u8', function(event, name) {
/* DEFINE - variables */
var ts = [];
ts.push(1);
streamplay(id, ts[ts.length-1]);
});
function streamplay(id, ts, callback) {
/* CHECH - ts */
if (ts !== 0) {
console.log('adding id..'+id+'...with ts...'+ts)
stream_play[id] = ts;
} else {
return callback(stream_play[id]);
}
}
And calling from main function in node like this:
streamplay(stream, 0, function(response) {
console.log('streaming ts file...'+response+'...to client...')
res.write(fs.readFileSync('/tmp/'+response));
})
I get this:
streaming ts file...undefined...to client...
stream_playarray is empty