-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
55 lines (54 loc) · 1.79 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
<!doctype html>
<html>
<head>
<title>Chat test</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css' />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
</head>
<body>
<div class='container'>
<div class='row'>
<div class='col-xs-8'>
<ul id='messages' class='list-unstyled well'></ul>
</div>
<div class='col-xs-3 col-xs-offset-1'>
<ul id='clients' class='list-unstyled well'></ul>
</div>
</div>
<div class='row'>
<form action="" role="form" class="form-inline">
<input id='msg' class='form-control' /><button class="btn btn-warning form-control">Send</button>
</form>
</div>
</div>
<script type='text/javascript' src="/socket.io/socket.io.js"></script>
<script type='text/javascript' src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type='text/javascript'>
(function(){
var socket = io();
name = prompt('What\'s your name ?');
socket.emit('registration', name);
$('form').submit(function(){
if ($('#msg').val() !== ""){
socket.emit('chat message', { name:name, msg: $('#msg').val() });
$('#msg').val('');
$('#msg').focus();
}
return false;
});
socket.on('chat message', function(data){
$('#messages').append($('<li>').text(data.name + ": " + data.msg));
}).on('message', function(msg){
if (msg != "undefined left")
$('#messages').append($('<li>').text(msg));
}).on('connected clients', function(clients){
$('#clients').empty();
clients.forEach(function(client){
$('#clients').append($('<li>').text(client));
});
});
})()
</script>
</body>
</html>