twit icon indicating copy to clipboard operation
twit copied to clipboard

Calling stream.stop() doesn't stop stream

Open ctcuff opened this issue 6 years ago • 3 comments

I have the following code:

const Twit = require('twit');
const config = require('./config');
const T = new Twit(config);

let stream;
let hasStarted = false;

function startStream() {
  let input = document.getElementById('input-keyword');
  let body = document.getElementById('tweet-body');
  let keyword = input.value;

  if (keyword === '') {
    return;
  }
  console.log(`Stream started -> ${keyword}`);
  input.value = '';

  if (!hasStarted) {
    stream = T.stream('statuses/filter', {track: keyword});
  }

  stream.on('tweet', tweet => {
    console.log(`@${tweet.user.screen_name} => [${tweet.text}]`);
    body.innerHTML += `<code>@${tweet.user.screen_name} => [${tweet.text}]</code><br><br>`
  });

  hasStarted = true; 
}

function stopStream() {
  if (hasStarted) {
    console.log('Stream stopped');
    stream.stop();
  }
  hasStarted = false; 
}

The problem is that no matter how many times i call stopStream(), the stream continues. I'm not sure if this is just a problem with my set up but I honestly don't see what's wrong here

ctcuff avatar Nov 09 '18 06:11 ctcuff

In the portion of code shared above, stopStream is never called.

stream.stop works correctly in the code I'm using on my end, pretty similar to the one shared above.

mef avatar Dec 12 '18 23:12 mef

This library seems no longer maintained.

Here's how to stop streams in twitter-lite.

See also how to switch streams.

dandv avatar Dec 21 '18 04:12 dandv

I think I'm seeing the same behavior where repeated calls to stream.stop() are no longer working. I think it was working in the past, perhaps with an older version of twit?

edsu avatar Oct 08 '19 15:10 edsu