Reputation: 1015
I'm playing working on a twitter streaming app using meteorjs. However, I have a problem destroying the stream and replace with a new one when the user enter a new track keyword. How am I able to call twitter streaming to destroy and stream new track on the server side when there a user enter a new track keyword?
//in 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');
}
}
});
//in 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);
Thanks in advance :)
Upvotes: 0
Views: 127
Reputation: 8928
You can add this to your 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);
}
});
And in your client:
if(typeof exist === 'undefined') {
Meteor.call('addNewTag', tag, 'feedback', function() {
Meteor.call("changeStream");
});
}
NOTE: you could simply pass the tag
up to the changeStream
method instead of waiting for the callback on the addNewTag
method, then forgo the server-side getLatestTag
because you'd already have it.
Upvotes: 1