SpiderStrategies / node-tweet-stream

Node twitter module to hook into the public filter streaming, seamlessly updating the tracking keywords.
210 stars 43 forks source link

Avoid closing stream when destroying parser #52

Closed djelic closed 7 years ago

djelic commented 7 years ago

Hi,

I was having some trouble using this module with node 8. If you run following snippet on node 6, after 30 seconds it adds new keyword, reconnects and continue emitting tweets. On node 8 however, it stops emitting after reconnect. Connection to Twitter results with 200 Success and after some debugging, connection is live and content is arriving.

const TweetStream = require('node-tweet-stream')

const stream = new TweetStream({
  consumer_key: process.env.TWITTER_CONSUMER_KEY,
  consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
  token: process.env.TWITTER_ACCESS_TOKEN,
  token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
})
stream.on('error', (err) => log(`error: ${err.message}`))
stream.on('tweet', (tweet) => log('tweet'))
stream.on('connect', () => log(`tracking: ${stream.tracking().join(',')}`))

log('track')
stream.track('apple')

setTimeout(() => {
  log('track')
  stream.track('google')
}, 30 * 1000)

function log (msg) {
  console.log('%s: %s', (new Date()).toISOString(), msg)
}

With previous node versions, following code does not end stream even if it should since here, this.parser.pipe(this) is done without {end: false}.

This pull request resolves this issue.

nathanbowser commented 7 years ago

Did you check if this works w/ the older versions of node?

djelic commented 7 years ago

Yes, tried with node 4, 6 and 8 and works fine.

nathanbowser commented 7 years ago

Cool. Thanks.

nathanbowser commented 7 years ago

@djelic published v2.0.3

djelic commented 7 years ago

Great! Tnx a lot!