/
index.html
223 lines (187 loc) · 5.51 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<html>
<head>
<title>Core Foo</title>
</head>
<body>
<p>Welcome to CoreFoo V0.01</p>
<div>
<p>
<label for="user1">User name</label>
<input type="text" id="user1"/>
</p>
<p>
<label for="user2">User name</label>
<input type="text" id="user2"/>
</p>
<p>
<label for="user3">User name</label>
<input type="text" id="user3"/>
</p>
<p>
<label for="user4">User name</label>
<input type="text" id="user4"/>
</p>
<p>
<label for="currentMatch">Current match</label>
<input type="text" id="currentMatch"/>
</p>
<p>
<button id="enterButton">Enter</button>
</p>
<p>
<button id="leaveButton">Leave</button>
</p>
<p>
<button id="checkStateButton">Check State</button>
</p>
<p>
<button id="endMatchButton">End match</button>
</p>
<p>
<button id="getListOfUsers">List of users</button>
</p>
<p>
<button id="currentMatchButton">Get current match</button>
</p>
<p>
<button id="lastFinishedMatch">Get last finished match</button>
</p>
<p>
<button id="numberOfPlayedMatchesButton">Number of played matches</button>
</p>
</div>
<p>Messages</p>
<div>
<ul id="messages">
</ul>
</div>
<p>Players</p>
<div>
<ul id="players">
</ul>
</div>
<p>Users Waiting</p>
<div>
<ul id="listOfUsers">
</ul>
</div>
<p>
<label for="numberOfPlayedMatches">Number of played matches: </label>
<span id="numberOfPlayedMatches"/>
</p>
<script type="text/javascript" src="http://localhost:2000/socket.io/socket.io.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var webSocket = io.connect('http://localhost:2000');
webSocket.on('connect', function () {
$('#messages').append('<li>Connected to the server.</li>');
});
webSocket.on('message', function (message) {
$('#messages').append('<li>' + message + '</li>');
});
webSocket.on('enter', function (user) {
$('#players').append('<li>' + user + '</li>');
});
webSocket.on('table_state', function (data) {
// $('#messages').append('<li>Is occupied?</li>');
$('#messages').append('<li>Is occupied=' + data.occupied + '</li>');
});
webSocket.on('waiting_matches', function (data) {
// $('#messages').append('<li>Is occupied?</li>');
alert('MATCHES:'+JSON.stringify(data));
if (data)
$('#messages').append('<li>There are currently ' + data.length + ' matches waiting</li>');
});
webSocket.on('leave', function (user) {
$('#players').append('<li>no more ' + user + '</li>');
});
webSocket.on('disconnect', function () {
$('#messages').append('<li>Disconnected from the server.</li>');
});
webSocket.on('start_match', function (data) {
// alert("Start match with " + JSON.stringify(data));
$('#messages').append('<li>Start match.</li>');
$('#currentMatch').val(data.match._id);
});
webSocket.on('list', function (users) {
$('#players').append('<li>Update</li>');
// $('#players').childdren().remove();
// $('#messages').append('<li>Update list</li>');
});
webSocket.on('current_match', function (match) {
if(match) {
$('#currentMatch').val(match._id);
}
});
webSocket.on('number_of_played_matches', function (number) {
$('#numberOfPlayedMatches').text(number);
});
webSocket.on('list_of_users', function (users) {
$('#listOfUsers').html('');
for (var i = 0; i < users.length; i++) {
$('#listOfUsers').append('<li>' + users[i].name + '</li>');
}
});
webSocket.on('last_finished_match', function (match) {
console.log('match:' + match);
if(match) {
console.dir(match.lastFinishedMatch);
console.log("minites: " + new Date(match.lastFinishedMatch.endDate).getUTCMinutes());
$('#lastFinishedtMatch').val(match.lastFinishedMatch._id);
}
});
$('#enterButton').bind('click', function () {
var user1 = $('#user1').val();
var user2 = $('#user2').val();
var user3 = $('#user3').val();
var user4 = $('#user4').val();
var users = new Array();
if (user1) {
users[0] = {name:user1};
}
if (user2) {
users[1] = {name:user2};
}
if (user3) {
users[2] = {name:user3};
}
if (user4) {
users[3] = {name:user4};
}
webSocket.emit("register", users);
$('#user1').val('');
$('#user2').val('');
$('#user3').val('');
$('#user4').val('');
});
$('#leaveButton').bind('click', function () {
var user = $('#user').val();
webSocket.emit("leave", user);
$('#user').val('');
});
$('#checkStateButton').bind('click', function () {
webSocket.emit("check_table_state");
webSocket.emit("waiting_matches");
});
$('#endMatchButton').bind('click', function () {
var matchId = $('#currentMatch').val();
webSocket.emit("end_match", {matchId:matchId});
$('#currentMatch').val('');
});
$('#getListOfUsers').bind('click', function () {
webSocket.emit("get_list_of_users");
});
$('#currentMatchButton').bind('click', function () {
webSocket.emit("current_match");
});
$('#lastFinishedMatch').bind('click', function () {
webSocket.emit("last_finished_match");
});
$('#numberOfPlayedMatchesButton').bind('click', function () {
webSocket.emit("number_of_played_matches");
});
});
</script>
</body>
</html>