0

我正在使用meteorjs 开发一个推特流媒体应用程序。但是,当用户输入新的跟踪关键字时,我在销毁流并替换为新流时遇到问题。当用户输入新的曲目关键字时,我如何能够调用 twitter 流以在服务器端销毁和流式传输新曲目?

//在client.js中

Template.executefb.events({
'keyup input#searchFeedback': 
  function(e) { 
    if(e.which == '13')
    {
      var tag = $('#searchFeedback').val();
      var exist = searchTag(tag, 'feedback');
      if(typeof exist == 'undefined')
      {
        Meteor.call('addNewTag',tag, 'feedback');

       //I want to call server to call Meteor.call('getLatestTag', 'feedback');
       // and Meteor.call('streamTwit', Fiber, twit, feedback); in server again


      }
     Meteor.call('clearSearchbar');
    }
  }
});

//在 server.js 中

var require;
var ntwitter;
var Fiber;


require = Npm.require;
ntwitter = require('ntwitter');
Fiber = require('fibers');


var twit = new ntwitter({
consumer_key: 'some key',
consumer_secret: 'some key',
access_token_key: 'some key',
access_token_secret: 'some key'
});

//get latest tag entered by the user from mongodb
var feedback = Meteor.call('getLatestTag', 'feedback');

//this method call starts twitter streaming
Meteor.call('streamTwit', Fiber, twit, feedback);

提前致谢 :)

4

1 回答 1

1

您可以将此添加到您的server.js

Meteor.methods({
    changeStream: function() {
        //get latest tag entered by the user from mongodb
        var feedback = Meteor.call('getLatestTag', 'feedback');

        //this method call starts twitter streaming
        Meteor.call('streamTwit', Fiber, twit, feedback);
    }
});

在您的客户中:

if(typeof exist === 'undefined') {
    Meteor.call('addNewTag', tag, 'feedback', function() {
        Meteor.call("changeStream");
    });
}

注意:您可以简单地将tagup 传递给该changeStream方法,而不是等待该方法的回调addNewTag,然后放弃服务器端getLatestTag,因为您已经拥有它。

于 2013-05-23T16:52:49.183 回答