-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (54 loc) · 1.9 KB
/
server.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
var express = require('express')
, TwitterNode = require('twitter-node').TwitterNode
, sys = require('sys')
, nowjs = require('now');
//express setup
var app = express.createServer();
app.configure(function(){
app.use(express.logger());
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
});
app.listen(8000);
//twitter configs to connect to the twitter stream.
var twit = new TwitterNode({
user: 'your_user', //set your twitter user here
password: 'your_pass' //set your twitter pass here
});
//This function will be used by the 'tweet' event Emmiter
var onTweetListener = function(tweet){
console.log('tweet: '+ '@' + tweet.user.screen_name + ': ' + tweet.text );
everyone.now.renderStream(tweet.user.profile_image_url , tweet.user.screen_name, tweet.text);
};
twit
.on('error', function(error){
console.log('error: ' + error.message);
})
.on('tweet', onTweetListener)
.on('end', function(resp){
console.log('end:' + resp.statusCode);
});
//Now.js initialization
everyone = nowjs.initialize(app);
everyone.now.totalConnected = 0;
everyone.connected(function(){
console.log('user connected: ' + this.user.clientId);
everyone.now.updateTotalConnected(++everyone.now.totalConnected);
});
everyone.disconnected(function(){
console.log('user disconnected: ' + this.user.clientId);
everyone.now.updateTotalConnected(--everyone.now.totalConnected);
});
//Now.js functions called by the client
everyone.now.stopStreaming = function(){
console.log('stoping the streaming: ' + this.user.clientId);
twit.removeListener('tweet', onTweetListener);
};
everyone.now.goStreaming = function(term){
console.log('search for: ' + term);
everyone.now.clearContent();
twit.trackKeywords = [];
twit.track(term).stream();
twit.removeListener('tweet', onTweetListener);
twit.on('tweet', onTweetListener);
};