-
Notifications
You must be signed in to change notification settings - Fork 14
/
client.html
36 lines (33 loc) · 1.26 KB
/
client.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
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"
integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="
crossorigin="anonymous"></script>
<title>Chat</title>
</head>
<body>
<textarea id="message"></textarea>
<button id="send">Send</button>
<ul id="messages"></ul>
<script language="javascript">
var $messages = $("#messages"),
$send = $("#send"),
$message = $("#message"),
connection = new WebSocket('ws://test:1234@localhost:8080/chat')
$send.prop("disabled",true)
connection.onopen = function () {
$send.prop("disabled",false)
$messages.prepend($("<li>Connected</li>"))
$send.on('click', function() {
var text = $message.val()
$message.val("")
connection.send(text)
})
}
connection.onerror = function (error) { console.log('WebSocket Error ', error) }
connection.onmessage = function (event) {
$messages.prepend($("<li>" + event.data + "</li>"))
}
</script>
</body>
</html>