An API for streaming data in real time through Pusher channels.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore Initial commit Nov 3, 2015
Procfile Procfile for Heroku Nov 3, 2015 Tidy up README Nov 10, 2015
base64.js Initial commit Nov 3, 2015
index.js Tidy up logging Nov 3, 2015
package.json Initial commit Nov 3, 2015
streamer.js Log when we got a tweet Dec 17, 2015

Pusher Data Stream

A service that lets users search the Twitter stream for search terms using Pusher.

How it Works

  • The server listens to channel existence webhooks from Pusher.
  • When it receives a channel_occupied event, it creates a new search on Twitter using that channel name.
  • When it receives a channel_vacated event, it stops searching for that term on Twitter.
  • When a new tweet is found, the server triggers a Pusher event to the channel that corresponds to the search term the tweet matched.

Client Usage

Using the Pusher JS library, the client should subscribe to a channel name, where the channel name is the search term. Because of restrictions on Pusher channel names, this name should be Base64 encoded:

// Client
var pusher = new Pusher(YOUR_APP_KEY);
var channelName = 'javascript';
var channel = pusher.subscribe(btoa(channelName));

channel.bind('new_tweet', function(data) {
  console.log('got tweet', data.tweet);
  console.log('matched search term', data.searchTerm);

Configuring the server

You'll need to configure your Pusher app to send channel existence webhooks to this server, which accepts POST /webhook. The server will then start the Twitter stream and trigger events when new tweets are found.

The server supports searching for multiple keywords at once and will stop searching once all users vacate a given channel.

To run the server you'll need to make sure you've set the following environment variables. If you place them in a .env file, they will be loaded automatically by Dotenv.