Permalink
Browse files

Twitter should auto reconnect

  • Loading branch information...
1 parent 3259e1f commit c314b1de1f8853c47187d5219fcbd63425081ca8 @Sutto committed Jul 28, 2011
Showing with 16 additions and 1 deletion.
  1. +10 −1 lib/pebble/twitter.js
  2. +6 −0 src/pebble/twitter.coffee
View
11 lib/pebble/twitter.js
@@ -26,6 +26,10 @@
access_token_key: config.access_token.key,
access_token_secret: config.access_token.secret
});
+ return outer = this;
+ };
+ Twitter.prototype.startStream = function() {
+ var outer;
outer = this;
return this.twitter.stream('statuses/filter', {
track: config.track
@@ -34,7 +38,12 @@
return outer.emit('tweet', outer.filtered(tweet));
}, this));
stream.on('end', function(resp) {
- return sys.puts("Twitter Connection ended, Status code was " + resp.statusCode);
+ var reconnect;
+ sys.puts("Twitter Connection ended, Status code was " + resp.statusCode);
+ reconnect = function() {
+ return outer.startStream();
+ };
+ return setTimeout(reconnect, 10000);
});
return stream.on('error', function(error) {
return sys.puts("Error in Twitter: " + error.message);
View
6 src/pebble/twitter.coffee
@@ -15,11 +15,17 @@ class Twitter extends Base
access_token_secret: config.access_token.secret
})
outer = @
+
+ startStream: ->
+ outer = this
@twitter.stream 'statuses/filter', track: config.track, (stream) =>
stream.on 'data', (tweet) =>
outer.emit 'tweet', outer.filtered tweet
stream.on 'end', (resp) ->
sys.puts "Twitter Connection ended, Status code was #{resp.statusCode}"
+ reconnect = -> outer.startStream()
+ # Reconnect in 10 secodns
+ setTimeout reconnect, 10000
stream.on 'error', (error) ->
sys.puts "Error in Twitter: #{error.message}"

0 comments on commit c314b1d

Please sign in to comment.