-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.html
More file actions
56 lines (50 loc) · 2.15 KB
/
chat.html
File metadata and controls
56 lines (50 loc) · 2.15 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Support Chat</title>
<!--Link to CSS -->
<link href="./css/chat.css" rel="stylesheet" />
<script type="text/javascript" src="//code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">
var socket;
$(document).ready(function(){
socket = io.connect('http://' + "127.0.0.1" + ':' + "5000" + '/chat');
socket.on('connect', function() {
socket.emit('join', {});
});
socket.on('status', function(data) {
$('#chat').val($('#chat').val() + '<' + data.msg + '>\n');
$('#chat').scrollTop($('#chat')[0].scrollHeight);
});
socket.on('message', function(data) {
$('#chat').val($('#chat').val() + data.msg + '\n');
$('#chat').scrollTop($('#chat')[0].scrollHeight);
});
$('#send').click(function(e) {
text = $('#text').val();
$('#text').val('');
socket.emit('text', {msg: text});
});
});
function leave_room() {
socket.emit('left', {}, function() {
socket.disconnect();
// go back to the login page
window.location.href = "index.html";
});
}
</script>
</head>
<body class="text-center">
<div class="chatwindow">
<form >
<h2 >Support Chat </h2>
<textarea id="chat" placeholder="No messages yet. Start one..." ></textarea><br /><br />
<input type="text" id="text" size="60" placeholder="Enter your message here" />
<button type="button" id="send" class="btn-success">SEND</button><br><br>
<center><button type="button" class="btn btn-danger" onclick=leave_room()>Leave this Chat</button></center>
</form>
</div>
</body>
</html>