-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
62 lines (58 loc) · 1.72 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
56
57
58
59
60
61
62
<!doctype html>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(function () {
var socket = io();
socket.emit('authSocket', {'uid': 'whoimi'})
socket.on('*', function (msg) {
$('#messages').append($('<li>').text(msg));
});
socket.on('chatMessage', function (msg) {
$('#messages').append($('<li>').text(msg));
});
socket.on('sendMessageReply', function (msg) {
$('#messages').append($('<li>').text(msg));
});
socket.on('fetchChat', function (data) {
$('#messages').append($('<li>').text("Chat room"+ data['cId']))
for(let i=0;i<data['msgs'].length;i++)
$('#messages').append($('<li>').text(data['msgs'][i]['payload']))
});
$("#fetchChat").click(
function () {
socket.emit('fetchChat', [
{cId: 1, timestamp:2},
{cId:2, timestamp:0}
])
}
)
$("#sendMessage").click(
function () {
socket.emit('sendMessage', {
cId: 1,
message: {type: 'text', payload: 'ruaruarua'}
})
}
)
$("#connection").click(
function () {
socket.emit('connection', {})
}
)
});
</script>
<html>
<head>
<title>Socket.IO chat</title>
</head>
<body>
<ul id="messages"></ul>
<!-- <form action="">
<input id="e" autocomplete="off" /><input id="c" autocomplete="off" /><input id="m" autocomplete="off" /><button>Send</button>
</form> -->
<div id="fetchChat">fetchChat</div>
<div id="sendMessage">chatMessage</div>
<div id="connection">connection</div>
</body>
</html>