-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.html
91 lines (80 loc) · 2.96 KB
/
server.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
<!DOCTYPE html>
<!--[if lte IE 7 ]><html lang="en" class="no-js ie ie7 ie-lte7 ie-lte9"><![endif]-->
<!--[if IE 8 ]><html lang="en" class="no-js ie ie8 ie-lte9"><![endif]-->
<!--[if IE 9 ]><html lang="en" class="no-js ie9 ie-lte9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="en" class="no-js"><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Poker game server client</title>
<link rel="stylesheet" href="/app.css">
</head>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
var socket = io.connect('127.0.0.1:8013'); //set this to the ip address of your node.js server
// on connection to server, ask for user's name with an anonymous callback
socket.on('connect', function(){
// call the server-side function 'requestuserlist'
socket.emit('requestuserlist');
});
// listener, whenever the server emits 'updatechat', this updates the chat body
socket.on('updatechat', function (username, data) {
$('.conversation').append('<strong>'+username + ':</strong> ' + data + '<br>');
});
// listener, whenever the server emits 'updateusers', this updates the username list
socket.on('updateusers', function(data) {
$('.users').empty();
var msg = undefined;
$.each(data, function(key, value) {
msg = '<li>' + key;
if (value.length > 0) { msg += '(' + value + ')'; }
msg += '</li>';
$('.users').append(msg);
});
});
// on load of page
$(function(){
$('.reset').click(function(e) {
e.preventDefault();
// tell server to execute 'resetchoices'
socket.emit('reset');
});
$('.release').click(function(e) {
e.preventDefault();
// tell server to execute 'resetchoices'
socket.emit('release');
});
// when the client clicks SEND
$('#datasend').click( function() {
var message = $('#data').val();
$('#data').val('');
// tell server to execute 'sendchat' and send along one parameter
socket.emit('sendchat', message);
});
// when the client hits ENTER on their keyboard
$('#data').keypress(function(e) {
if(e.which == 13) {
$(this).blur();
$('#datasend').focus().click();
}
});
});
</script>
<body>
<ul>
<li><a href="#" class="reset">Reset values</a></li>
<li><a href="#" class="release">Release values</a></li>
</ul>
<div class="userlist">
<strong>Users</strong>
<ul class="users"></ul>
</div>
<div class="messages">
<input id="data"/>
<input type="button" id="datasend" class="send" value="send" />
<div class="conversation"></div>
</div>
</body>
</html>