I’m new to meteor and i’m really enjoying using the platform.
However i’m stuck! I have no clue if it’s possible.
But what want to do is communicate the progress on the server method download on the client side?
I want show the download progress (0% / 100%).
console.log("Downloading " + (100.0 * cur / len).toFixed(2) + "% ");
Are there any packages or methods to show this?
if (Meteor.isClient) {
Template.npmtest.events({
'click button': function () {
Meteor.call('download', 'https://www.youtube.com/watch?v=bpBOhxwlEYA');
}
});
}
if (Meteor.isServer) {
Meteor.methods({
download: function (link) {
var fs = Meteor.npmRequire('fs');
var youtubedl = Meteor.npmRequire('youtube-dl', ['--format=140']);
var video = youtubedl(link);
var cur = 0;
var len = 0;
video.on('info', function(info) {
len = info.size;
});
video.on("data", function(chunk) {
cur += chunk.length;
console.log("Downloading " + (100.0 * cur / len).toFixed(2) + "% ");
});
video.pipe(fs.createWriteStream('myvideo.mp4'));
}
});
}