-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
37 lines (33 loc) · 1.14 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
<div style="float:left;width:100px;border-right:1px solid black;height:300px;padding:10px;overflow:scroll-y;">
<b>Thành viên</b>
<div id="users"></div>
</div>
<div style="float:left;width:300px;height:250px;overflow:scroll-y;padding:10px;">
<div id="conversation"></div>
<input id="data" style="width:200px;" />
<input type="button" id="datasend" value="send" />
</div>
<script src="socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
let socket = io("http://localhost:3000");
socket.on('connect', function(){
socket.emit('add_user', prompt("Nhập tên của bạn"));
});
socket.on('update_users', (data) => {
$('#users').empty();
$.each(data, (key, value) => {
$('#users').append('<div>' + value + '</div>');
});
});
$(function(){
$('#datasend').click( function() {
var message = $('#data').val();
$('#data').val('');
socket.emit('send_message', message);
});
});
socket.on('notification', function (username, data) {
$('#conversation').append('<b>'+username + ':</b> ' + data + '<br>');
});
</script>