forked from StevenWill/twitterstream-ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter-stream-node-socket-io-websockets-html5.html
58 lines (55 loc) · 1.63 KB
/
twitter-stream-node-socket-io-websockets-html5.html
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
<!doctype html>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'></script>
<script src='http://www.dizorg.net:443/socket.io/socket.io.js'></script>
<script>
var socket = io.connect('http://www.dizorg.net:81/');
socket.on('news', function (data) {
console.log('news event on socket received');
console.log(data);
socket.emit('my other event', { my: 'data' });
payload = eval(data);
var p = $("<div class='tweet' style='display:none'><div class='content'><a class='main-screenname' href='http://www.twitter.com/" + payload.user.screen_name + "/status/" + payload.id + "' target='_blank'>" + payload.user.screen_name + "</a> " + payload.text + "</div></div>");
if($('#tweets div.tweet').size() > 15) {
$('#tweets div.tweet:last').slideDown(100, function() {
$(this).remove();
});
}
$('#tweets').prepend(p);
p.slideDown(140);
});
</script>
</head>
<body>
<div id="code">
<pre>
//
// stream via websockets with ntwitter and socket.io
//
var io = require('socket.io').listen(8888);
var uri = 'statuses/filter';
var twitter = require('ntwitter');
io.sockets.on('connection',function(socket){
socket.on('disconnect',function(){
io.sockets.emit('user disconnected');
});
});
var twit = new twitter({
consumer_key: 'key',
consumer_secret: 'secret',
access_token_key: 'token',
access_token_secret: 'secret'
});
twit.stream(uri, {track:'#dizorg,ufc,ufc152'},
function(stream) {
stream.on('data', function (data) {
console.log(data);
io.sockets.emit('news',data)
});
});
</pre>
</div>
<div id="tweets">
</div>
</body>