-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (41 loc) · 1.11 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Socket.IO chat</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<style>
</style>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off"/>
<button>Send</button>
</form>
<canvas id="firstCanvas" resize></canvas>
<script src="/socket.io/socket.io.js"></script>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script>
$(function() {
var socket = io();
$('form').submit(function() {
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
$('input').on('input', function() {
socket.emit('is typing');
})
socket.on('chat message', function(msg) {
$('#messages').append($('<li>').text(msg));
});
socket.on('is typing', function() {
$('#messages').append($('<li>').text('user is typign...'));
});
});
</script>
</body>
</html>