Last active
August 29, 2015 13:56
-
-
Save robwormald/9317945 to your computer and use it in GitHub Desktop.
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
var Twit = require('twit') | |
var twitterConnection = new Twit({ | |
/** | |
* details go here | |
*/ | |
}) | |
var openStreams = {} | |
//url : what path to listen to | |
//event : stream event to listen for | |
//handler : what to do when event is fired | |
module.exports.listenToStream = function(url,event,handler){ | |
//already an open listener | |
if(openStreams[url]) return openStreams[url] | |
var stream = twitterConnection.stream(url,options) | |
stream.on(event,handler) | |
openStreams[url] = stream; | |
return stream; | |
} | |
module.exports.closeStream = function(url){ | |
if(openStreams[url]) openStreams[url].close() | |
} | |
module.exports.reopenStream = function(url){ | |
if(openStreams[url]) openStreams[url].start() | |
} |
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
//anywehre else | |
var statusStream = twitterService.listenToStream('/statuses','tweet',function(tweet){ | |
//do something with a tweet | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment