-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (51 loc) · 1.73 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//Requirements
var Twitter = require('twitter');
var env = require('dotenv').config();
//stream modules
var streamFilter = require('./streams/filters');
var streamError = require('./streams/error');
var streamIDs = require('./streams/ids');
//For serving the data to the client
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
//Just to make console logs pretty
var chalk = require('chalk');
//Twitter IDs for streaming
var streamParameters = {
follow: streamIDs.getStreamIDs()
};
//Setting up the Twitter client
var client = new Twitter({
consumer_key: process.env.consumer_key,
consumer_secret: process.env.consumer_secret,
access_token_key: process.env.access_token_key,
access_token_secret: process.env.access_token_secret
});
//Just to let you know that the app's starting
console.log(chalk.blue("Starting application..."));
//Listen to port
var port = process.env.PORT || 8080;
server.listen(port, function(){
console.log(chalk.green("Application started! Listening to: " + port));
});
//Serve the static files
app.use('/src', express.static('src'));
//Until I can figure out how to use AWS Cloudfront correctly,
//Just serve the audio files from src
app.use('/audio', express.static('mp3'));
//Start the stream. Find all Tweets with the word "bird"
client.stream('statuses/filter', {track: 'bird'}, function (stream) {
stream.on('data', function(tweet) {
io.sockets.volatile.emit('tweet', {
user: (tweet.user !== undefined) ? tweet.user.screen_name : '',
text: tweet.text
});
});
stream.on('error', streamError);
});
//Send the Twitter data to the client
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});