Last active
February 15, 2016 22:42
-
-
Save simoneb/b946a254cdd48813719b to your computer and use it in GitHub Desktop.
repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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