-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
129 lines (124 loc) · 2.99 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
<title>Chat Application</title>
</head>
<script src="/socket.io/socket.io.js"/></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style type="text/css">
body{
margin-top: 50px;
}
#messageWindow{
display: none;
}
#chat{
height: 450px;
overflow: auto;
}
#chatitem{
overflow: auto;
}
</style>
<body>
<div class="container">
<div class="row" id="userWindow">
<div class="col-md-12">
<form id="uForm">
<div class="form-group">
<label>Enter User Name:</label>
<input class="form-control" id="uname"></textarea>
<br>
<input type="submit" class="btn btn-lg btn-primary" value="Login">
</div>
</form>
</div>
</div>
<div class="row" id="goauth">
<div class="col-md-12">
<a href="/auth/google" class="btn-lg btn-danger"><span class="fa fa-google-plus"></span>Google</a>
</div>
</div>
<div class="row" id="messageWindow">
<div class="col-md-4">
<div class="well">
<h3>Online Users</h3>
<ul class="list-group" id="users">
</ul>
</div>
</div>
<div class="col-md-8">
<div class="chat" id="chat">
</div>
<form id="mForm">
<div class="form-group">
<label>Enter Message...</label>
<textarea class="form-control" id="message"></textarea>
<br>
<input type="submit" class="btn btn-lg btn-primary" value="Send Message">
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
var socket = io.connect();
var $users = $('#users');
var $mForm = $('#mForm');
var $message = $('#message');
var $chat = $('#chat');
var $messageWindow = $('#messageWindow');
var $userWindow = $('#userWindow');
var $uForm = $('#uForm');
var $uname = $('#uname');
$message.keydown((e) => {
if(e.which==13)
{
e.preventDefault();
if(e.shiftKey)
$message.val($message.val()+'\n');
else
$mForm.submit();
}
});
$mForm.submit((e) => {
e.preventDefault();
if($message.val())
socket.emit('sm',$message.val());
$message.val('');
});
socket.on('nm',(data) => {
$chat.append('<div class="well" id="chatitem"><strong>'+data.user+': </strong>'+data.msg+'</div>');
});
$uForm.submit((e) => {
e.preventDefault();
if(!$uname.val())
{
alert("Enter UserName");
return false;
}
socket.emit('newUser',$uname.val(), (data) => {
if(data)
{
$userWindow.hide();
$messageWindow.show();
}
});
});
socket.on('getUsers', (data) => {
list = ''
for(i=0;i<data.length;i++)
{
if(data[i]==$uname.val())
list+='<li class="list-group-item" id="chatitem"><strong>'+data[i]+'</strong></li>';
else
list+='<li class="list-group-item" id="chatitem">'+data[i]+'</li>';
}
$users.html(list);
});
});
</script>
</body>
</html>