-
-
Save anabelle/9318274 to your computer and use it in GitHub Desktop.
idea to handle multiple twitter streams
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 | |
}) |
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment