我正在使用meteorjs在Twitter流媒体应用上工作。但是,当用户输入新的跟踪关键字时,我有一个问题是破坏流并替换为新流。当用户输入新的跟踪关键字时,如何在服务器端调用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);
提前致谢:)
答案 0 :(得分: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");
});
}
注意:您可以简单地将tag
传递给changeStream
方法,而不是等待addNewTag
方法的回调,然后放弃服务器-side getLatestTag
因为你已经拥有它。