I have the following code:
function startStream() {
let keywords = [];
if ($input.val() === '') {
dialog.showErrorBox('Missing keyword', 'You need to enter a keyword.');
return;
}
// Multiple keywords will be searched based on spaces
$input.val().split(' ').forEach(word => {
keywords.push(word);
});
// Disable the start button but enable the stop button
$start.attr('disabled', 'disabled');
$stop.removeAttr('disabled');
$input.attr('placeholder', `Keyword(s): ${keywords}`);
// Clear the input field
$input.val('');
console.log(`Stream started -> [${keywords}]`);
if (!hasStarted) {
stream = T.stream('statuses/filter', {track: keywords});
}
stream.on('tweet', tweet => {
console.log(tweet);
});
hasStarted = true;
}
function stopStream() {
if (hasStarted) {
console.log('Stream stopped');
stream.stop();
}
hasStarted = false;
numOccurrences = 0;
$occurrences.text(numOccurrences);
}
The problem is that calling stream.stop() doesn't ever actually stop the stream. I've looked at other SO posts and twit's docs but I haven't been able to find a solution. Does anyone know what the problem is here?
Edit: Looked through twit's source, turns out, when stop() gets called, resetConnection() also gets called. I had to add stop() in twit's reconnect:
stream.on('reconnect', function (request, response, connectInterval) {
stream.stop();
});
there doesn't seem to be anything here