-
Notifications
You must be signed in to change notification settings - Fork 25
/
dashboard.js
executable file
·69 lines (61 loc) · 1.52 KB
/
dashboard.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
64
65
66
67
68
69
#!/usr/bin/env node
sys = require('util');
express = require('express');
http = require('http');
twitter = require('ntwitter');
app = express();
//app.configure(function(){
app.use(express.static(__dirname + '/public'));
//});
app.get('/', function(req, res, next){
res.render('/public/index.html');
});
server = http.createServer(app)
server.listen(8081);
console.log('Server running at http://localhost:8081/');
var io = require('socket.io').listen(server);
io.set('log level', 0);
myList = [];
Array.prototype.del = function(val) {
for(var i=0; i<this.length; i++) {
if(this[i] == val) {
this.splice(i, 1);
break;
}
}
}
CreateTwitter();
io.sockets.on('connection', function(socket) {
socket.on('data', function(action,data) {
if(action==='+') {
myList.push(data);
}
if(action==='-') {
myList.del(data);
}
if(action==='*') {
twit.updateStatus(data,
function (err, data) {
// console.log(data);
});
}
});
socket.on('getfilter', function() {
socket.emit('pushfilter', myList);
});
if(myList.length!=0) {
twit.stream('user',{track:myList}, function(stream) {
stream.on('data', function (tweet) {
socket.emit('message', JSON.stringify(tweet));
});
});
}
});
function CreateTwitter() {
twit = new twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
}