I have a page with text input and a button. When I insert link to youtube video into text field and press the button - video downloads into the local folder.
The problem: how can I send link to local copy of the downloaded video back to the client?
More general question: How can I send a variable from server to client (this variable is temporary and is not going to be stored anywhere) ?
The code I have right now:
if (Meteor.isClient) {
Path = new Meteor.Collection("path");
Meteor.subscribe("path");
Template.hello.events(
{
'submit .form' : function() {
var link = document.getElementById("youtube-url").value;
Meteor.call('download', link);
event.preventDefault();
}
}
);
}
if (Meteor.isServer) {
Meteor.startup(function () {
Meteor.methods({
download: function (link) {
var youtubedl = Npm.require('youtube-dl');
var Fiber = Npm.require("fibers");
var dl = youtubedl.download(link, './videos');
// called when youtube-dl finishes
dl.on('end', function(data) {
console.log('\nDownload finished!');
Fiber(function() {
Path = new Meteor.Collection("path");
Path.insert({path: './videos/' + data.filename});
})
});
}
});
});
}
Thanks!
You can use this small package: https://atmosphere.meteor.com/package/client-call . It allows to call client-side methods from the server in the same way as Meteor.methods do for the other way.