summaryrefslogtreecommitdiff
path: root/public/js/game.js
blob: c348e9ae853feb8c49742b970594bdccacd82b27 (plain)
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
var socket = io.connect(window.location.hostname);

var Game = {
	nick: null,
	
	init: function(){

		// Bind events from the server
		socket.on('event-join', Events.receive.join);
		socket.on('event-message', Events.receive.message);
		socket.on('event-image', Events.receive.image);
		Auth.init();
		Chat.init();
	}
}

var Events = {

	receive: {
	
		join: function(data){
			for (var i in data.messages) {
				Chat.add(data.messages[i]);
			}
		},
		
		message: function(msg) {
			Chat.add(msg);
		},
		
		image: function(data) {
			console.log(data);
			if (data.nick == Game.nick) return;
			$("#image").attr("src", data.url).show();
		}
		
	},

	send: {

		message: function(msg) {
			socket.emit('event-message', msg);
		}

	},
	
};


$(Game.init);