Skip to content

Instantly share code, notes, and snippets.

@simoneb simoneb/repro.js
Last active Feb 15, 2016

Embed
What would you like to do?
repro
let stream;
let events = ['message', 'tweet', 'delete', 'limit', 'scrub_geo', 'disconnect',
'connect', 'connected', 'reconnect', 'warning', 'status_withheld',
'user_withheld', 'friends', 'direct_message', 'user_event'];
function start(path, params) {
if (stream) stream.stop();
let T = new Twit({
consumer_key: ...,
consumer_secret: ...,
access_token: ...,
access_token_secret: ...,
timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
});
subscribe(stream = T.stream(path, params));
disableReconnectWhenStopped(stream);
}
function subscribe() {
events.forEach(event =>
stream.on(event, msg =>
$rootScope.$apply(() =>
$rootScope.$broadcast('twitter:' + event, msg))));
}
function disableReconnectWhenStopped(_stream) {
_stream.on('reconnect', () => {
if (!stream) _stream.stop();
});
}
function stop() {
if (stream) {
stream.stop();
stream = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.