-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
222 lines (189 loc) · 6.62 KB
/
Copy pathindex.html
File metadata and controls
222 lines (189 loc) · 6.62 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!doctype html>
<html>
<head>
<title>Socket.IO Chat</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<style>
.container-fluid{
background: #808080;
}
#messageArea {
height: 90vh;
display: block;
}
#username{
height: 10vh;
display: block;
}
.well{
margin: 0px;
border-radius: 0;
background-color: #e0e0e0;
}
.user-col{
height: 79vh;
border: 3px solid black;
border-radius: 5px;
overflow-y: auto;
overflow-x: hidden;
}
.chat{
position: absolute;
bottom: 0;
width: 100%;
max-height: 100%;
overflow-y: auto;
overflow-x: hidden;
border-radius: 5px;
}
.wrapper{
position: relative;
border: 3px solid black;
height: 79vh;
position: relative;
border-radius: 5px;
background-color: #e0e0e0;
}
body {
font: 15px Helvetica, Arial;
color: black;
}
form {
position: fixed;
bottom: 0;
width: 100%;
padding-bottom: 20px;
}
form input {
background-color: #e0e0e0;
border: 3px solid black;
border-radius: 5px;
padding: 15px;
width: 85%; margin-right: .5%;
}
form button {
width: 13%;
padding: 15px;
background: rgb(130, 224, 255);
border: 1px solid black;
}
.list-group-item {
border: none;
background: none;
}
/* Desktops */
@media only screen and (min-width : 992px) {
.wrapper, .user-col {
height: 79vh;
}
}
/* Small Devices, Tablets */
@media only screen and (max-width : 768px) {
.wrapper, .user-col {
height: 75vh;
}
}
</style>
</head>
<body>
<div class="container-fluid" >
<div id="username" class="row">
<div class="col-md-8 col-xs-8" id="heading-left">
<h2 id="welcome"> </h2>
</div>
<div class="col-md-4 col-xs-4" id="heading-right">
<h2 id="online">Online Users</h2>
</div>
</div>
<div id="messageArea" class="row">
<div class="col-md-8 col-xs-8">
<div class="wrapper">
<div class="chat" id="chat">
</div>
</div>
<form id = "messageForm">
<input id ="m" autocomplete="off" /><button><strong>Send</strong></button>
</form>
</div>
<div class="col-md-4 col-xs-4">
<div class="well user-col">
<ul class="list-group" id="users"></ul>
</div>
</div>
</div>
</div>
<script>
$(function () {
var socket = io();
var username = "";
var $messageForm = $('#messageForm');
var $message = $('#m');
var $chat = $('#chat');
var $users = $('#users');
var $welcome = $('#welcome');
$messageForm.submit(function(e){
e.preventDefault(); // prevents page reloading
socket.emit('send message', $message.val());
$message.val('');
return false;
});
socket.on('check cookies', function () {
if(document.cookie) {
var cookieSplit = document.cookie.split("=");
username = cookieSplit[1];
socket.emit('send cookies', document.cookie);
}
else {
document.cookie = "user="+username;
}
});
socket.on('new cookie', function (data) {
document.cookie = "user="+data;
});
socket.on('connecting', function(data){
for(let i = 0; i < data.length; i++){
$chat.append('<div class="well">' + data[i].time + ' ' + ' <span style="color: #' + data[i].color + '"> '+ data[i].user + ':</span> ' + data[i].msg + '</div>');
}
$chat.scrollTop($chat[0].scrollHeight);
});
socket.on('new message', function (data) {
console.log(data.user);
console.log(username);
if(username === data.user){
$chat.append('<div class="well"><strong>' + data.time + ' <span style="color: #' + data.color + '"> '+ data.user +':</span></strong>'+ ' ' + data.msg +'</div>');
}
else {
$chat.append('<div class="well">' + data.time + ' <span style="color: #' + data.color + '"> '+ data.user +': </span>'+ ' ' + data.msg +' </div>');
}
$chat.scrollTop($chat[0].scrollHeight);
});
socket.on('username', function (data) {
username = data;
var html = '';
html = 'Welcome ' + data + '!';
$welcome.html(html);
});
socket.on('not unique', function (data) {
alert("Username " + data + " is not unique. Try again.");
});
socket.on('bad name', function (data) {
alert("Invalid entry: " + data + " Use format /nick <new name>.");
});
socket.on('bad color', function (data) {
alert("Invalid color: " + data + ". Use format /nickcolor RRGGBB");
});
socket.on('get users', function (data) {
var html = '';
for(let i = 0; i < data.length; i++){
html += '<li class="list-group-item">' +data[i]+'</li>';
}
$users.html(html);
});
});
</script>
</body>
</html>