twit
twit copied to clipboard
Calling stream.stop() doesn't stop stream
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
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.
This library seems no longer maintained.
Here's how to stop streams in twitter-lite.
See also how to switch streams.
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?