summaryrefslogtreecommitdiff
path: root/public/js/game.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/game.js')
-rw-r--r--public/js/game.js60
1 files changed, 40 insertions, 20 deletions
diff --git a/public/js/game.js b/public/js/game.js
index 7bdabbf..461d96e 100644
--- a/public/js/game.js
+++ b/public/js/game.js
@@ -1,24 +1,44 @@
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--;
- }
+var Game = {
+ nick: "ryz",
+
+ init: function(){
+
+ // Bind events from the server
+ socket.on('event-join', Events.receive.join);
+ socket.on('event-message', Events.receive.message);
+ Chat.init();
+ }
}
+var Events = {
+
+ receive: {
+ join: function(data){
+ console.log("RECEIVE JOIN")
+ for (var i in data.messages) {
+ Chat.add(data.messages[i]);
+ }
+ },
+
+ message: function(msg){
+console.log("RECEIVE MESSAGE")
+ Chat.add(msg);
+ }
+ },
+
+ send: {
+
+ message: function(msg) {
+console.log("SE D MMESSAGe")
+ socket.emit('event-message', msg);
+ }
+
+ },
+
+};
+
+
+$(Game.init);
+