Permalink
Browse files

initial code from Guillermo

  • Loading branch information...
0 parents commit ce56113e1a7abb4bed2a596bbd2711b506ad2db1 @gerad gerad committed Aug 15, 2011
Showing with 67 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +29 −0 app.js
  3. +29 −0 index.html
  4. +8 −0 package.json
@@ -0,0 +1 @@
+node_modules/
29 app.js
@@ -0,0 +1,29 @@
+var sio = require('socket.io')
+ , http = require('http')
+ , index = require('fs').readFileSync(__dirname + '/index.html')
+ , request = require('request')
+
+var app = http.createServer(function (req, res) {
+ res.writeHead(200, { 'Content-Type': 'text/html' });
+ res.end(index);
+ })
+ , io = sio.listen(app);
+
+setInterval(function () {
+ request({
+ url: 'http://search.twitter.com/search.json?q=today'
@kenCode-de

kenCode-de Oct 30, 2014

Twitter broke this url, not sure what it's supposed to be now, maybe something similar to this: https://api.twitter.com/1.1/search/tweets.json?q=

+ }, function (err, res, data) {
+ var obj = JSON.parse(data);
+ io.sockets.emit('tweets', obj.results.map(function (v) { return v.text; }));
+ });
+}, 2000);
+
+io.sockets.on('connection', function (socket) {
+ socket.broadcast.emit('someone connected');
+
+ socket.on('some event', function () {
+ console.log('I got an event');
+ });
+});
+
+app.listen(3000);
@@ -0,0 +1,29 @@
+<!doctype html>
+<html>
+ <head>
+ <script src="/socket.io/socket.io.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
+
+ <script>
+ var socket = io.connect();
+
+ $(function () {
+ socket.on('tweets', function (tweets) {
+ $.each(tweets, function (i, tweet) {
+ $('#tweets').prepend($('<li>').text(tweet));
+ });
+ });
+
+ socket.on('someone connected', function () {
+ $('body').prepend('<p>someone just connected!</p>');
+ });
+
+ socket.emit('some event');
+ });
+ </script>
+ </head>
+ <body>
+ <h1>tweets</h1>
+ <ul id="tweets"></ul>
+ </body>
+</html>
@@ -0,0 +1,8 @@
+{
+ "name": "example",
+ "version": "0.0.1",
+ "dependencies": {
+ "socket.io": "0.7.7" ,
+ "request": "2.0.0"
+ }
+}

0 comments on commit ce56113

Please sign in to comment.