-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
63 lines (42 loc) · 1.45 KB
/
index.html
File metadata and controls
63 lines (42 loc) · 1.45 KB
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.1.min.js"></script>
<script>
$(document).ready(function(){
$('#button').prop('disabled', true);
var conn = new WebSocket('ws://127.0.0.1:8080');
conn.onopen = function(e) {
console.log("Connection established!");
$('#button').prop('disabled', false);
};
conn.onmessage = function(e) {
console.log(e.data);
$('#messages').append('<span style="background-color: chartreuse;">' + e.data + '</span><br />');
$('#button').prop('disabled', false);
};
conn.onerror = function(e){
console.log(e);
};
$('#chat').submit(function(e){
e.preventDefault();
$('#button').prop('disabled', true);
var message = $('#message').val();
conn.send(JSON.stringify({message: message}));
$('#message').val('');
return false;
});
});
</script>
</head>
<body>
<div id="messages">
</div>
<form id="chat" method="post">
<input type="text" name="message" id="message">
<input type="submit" name="BUTTON" id="button">
</form>
</body>
</html>