From 6a8ae720310021b13f8aec447482f05641c8f908 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 22 Feb 2013 11:50:49 -0800 Subject: dirs --- README.md | 3 +-- public/css/drawdrawdraw.css | 1 + public/index.html | 37 ++++--------------------------------- public/js/game.js | 26 ++++++++++++++++++++++++++ server.js | 21 ++++++++++++--------- 5 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 public/css/drawdrawdraw.css create mode 100644 public/js/game.js diff --git a/README.md b/README.md index 42f4b01..8c059f7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -dumpphone-server -================ \ No newline at end of file +DRAW DRAW DRAW \ No newline at end of file diff --git a/public/css/drawdrawdraw.css b/public/css/drawdrawdraw.css new file mode 100644 index 0000000..20f548b --- /dev/null +++ b/public/css/drawdrawdraw.css @@ -0,0 +1 @@ +html,body { padding: 0; margin: 0; width: 100%; height: 100%; } diff --git a/public/index.html b/public/index.html index 9fa2d48..2336d19 100644 --- a/public/index.html +++ b/public/index.html @@ -1,46 +1,17 @@ -dump2 +drawdrawdraw + - + + -
- - -
- -
- diff --git a/public/js/game.js b/public/js/game.js new file mode 100644 index 0000000..d7c96dc --- /dev/null +++ b/public/js/game.js @@ -0,0 +1,26 @@ +var socket = io.connect(window.location.hostname); + + + +var imageCount = 0; +socket.on('join', function(json) { + var data = JSON.parse(json); + for (var i in data) { + appendImage(data[i]); + } +}); +socket.on('url', function(json) { + var data = JSON.parse(json); + appendImage(data); +}); +function appendImage(img) { + var image = new Image(); + image.src = img.url; + $("#images").prepend(image); + imageCount++; + while (imageCount > 20) { + $("#images").children().last().remove(); + imageCount--; + } +} + diff --git a/server.js b/server.js index 948bc9e..e8d0aec 100644 --- a/server.js +++ b/server.js @@ -20,6 +20,9 @@ app.configure(function(){ app.use(express.static(__dirname + '/public')); }); +/******************************* ROUTES +*/ + app.get('/latest', function(req, res){ var data = { 'image_url': Images.latest() }; res.setHeader('Content-Type', 'application/json'); @@ -49,19 +52,14 @@ app.post('/upload', function(req, res) { }); }); +/******************************* WEBSOCKETS +*/ + io.sockets.on( 'connection', function(socket){ socket.emit( 'join', Channel.join() ); function echo }); -var port = process.env.PORT || 5000; -server.listen(port); -console.log('Listening on port ' + port); - -function timestamp() { - return Math.round(new Date().getTime()); -} - var State = { WAITING: 0, DRAWING: 1, @@ -77,7 +75,7 @@ function Channel() { } Channel.prototype.push = function(message){ if (this.messages.length > 20) this.messages.shift(); - var message = { id: ++this.message_id, content: message, user: username, faves: 0 }; + var message = { id: ++this.message_id, content: message, user: username, faves: 0, time: Date.now() }; this.messages.push(message); io.sockets.emit('message', JSON.stringify(message)); } @@ -96,4 +94,9 @@ Channel.prototype.join = function(){ } } +/******************************* DONE +*/ +var port = process.env.PORT || 5000; +server.listen(port); +console.log('Listening on port ' + port); -- cgit v1.2.3-70-g09d2