Server crashes if no tweets
I'm doing a project and pooling for a nonexisting hashtag. Your server code crashes 1 minute after the 1st connection attempt if no tweet are available after the 1st minute.
Your server implementation doesn't take keepalives in consideration. https://dev.twitter.com/docs/streaming-apis/connecting#Stalls
Will throw
events.js:45
throw arguments[1]; // Unhandled 'error' event
and crash.
I'm in the process of writing something that catches keepalives but I'm brand new at node.js so I'm not ready to submit a pull request just yet.
Can you give me an example search that you're using? I will try to reproduce. path: '/1/statuses/filter.json?locations=-122.75,36.8,-121.75,37.8',
I've been searching for path: /1/statuses/filter.json?track=some_random_hastag_no_one_will_ever_use.
The idea is that this search will not return anything and the browser will close the connection. I got a fix working earlier today. Maybe you can include that.
//stream.js [server side]
result.on('data', function(chunk){
if(chunk == '\r\n'){//got a keepalive
res.write("event: keepalive\n");
}else{
jsonTwitter.feed(chunk);
}
});
//main.js [client side]
source.addEventListener('keepalive', function(e){
//you don't actually have to do anything with this.
console.log("keepalive received");
});
Thanks. I will add this fix soon. I am thinking about revamping the entire app to use express.