如何在流星中从服务器向客户端发送变量?

eaw*_*wer 6 node.js meteor

我有一个带文本输入和按钮的页面.当我将youtube视频的链接插入文本字段并按下按钮 - 视频下载到本地文件夹.

问题:如何将下载视频的本地副本的链接发送回客户端?

更一般的问题:如何从服务器向客户端发送变量(此变量是临时的,不会存储在任何地方)?

我现在的代码:

客户代码

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();
            }
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

服务器代码('集合'部分不起作用)

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});
                  })
                });              
            }
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

Hub*_* OG 2

您可以使用这个小包: https: //atmosphere.meteor.com/package/client-callMeteor.methods它允许以与其他方式相同的方式从服务器调用客户端方法。