-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard.html
326 lines (302 loc) · 12.7 KB
/
dashboard.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!DOCTYPE html>
<html>
<head>
<title>Socket Chat</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="/css/bootstrap-theme.min.css"/>
<link rel="stylesheet" type="text/css" href="/css/bootstrap-grid.min.css"/>
<link rel="stylesheet" type="text/css" href="/css/bootstrap-reboot.min.css"/>
<script src="/js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="/js/tether.min.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/socket.io/socket.io.js"></script>
<style>
*{margin:0;padding:0;box-sizing:border-box;}
body{font:13px Helvetica,Arial;}
form{background:#000;padding:3px;position:fixed;bottom:0;width:100%;}
form input{border:0;padding:10px;width:90%;margin-right:.5%;}
form button{width:9%;background:rgb(130,224,255);border:none;padding:10px}
#messages{list-style-type:none;margin:0;padding:0;}
#messages li{padding:10px;}
//#messages li:nth-child(odd){background:#eee;}
</style>
</head>
<body style="background-color:#f5f5f5">
<nav id="myNavbar" class="navbar navbar-inverse navbar-fixed-top navbar-toggleable-md" role="navigation">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#"><strong style="font-size:25px">Socket Chat</strong><small style="color:#ddd;margin-left:10px">by Abhilash Behera</small></a>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<!--<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>-->
<li class="nav-item">
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" style="color:#3f8;font-size:20px" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Hello User
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="http://localhost:3000/">Logout<span class="glyphicon glyphicon-off"></span></a>
<!--<a class="dropdown-item" href="https://socket-chat-abhilash.herokuapp.com/">Logout<span class="glyphicon glyphicon-off"></span></a>-->
</div>
</li>
<!--<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>-->
</ul>
</div>
</nav>
<div class="container" style="padding-top:50px;">
<div class="row">
<div class="col-lg-4">
<div class="card align-items-center">
<div class="card-block">
<h4 class="card-title" style="text-align:center"><strong>My Groups</strong></h4>
<progress id="progressGroups"></progress>
<div class="list-group" id="groupList">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="exampleModal">Create Group</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New Group</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="group-name" class="form-control-label">Group Name:</label>
<input type="text" class="form-control" id="group-name">
</div>
<div class = "form-group">
<button class = "btn btn-primary" id = "checkAvailability">Check Avilability</button>
<progress id = "check-progress"></progress>
</div>
</form>
</div>
<div class = "modal-footer">
<button class = "btn btn-secondary" data-dismiss = "modal">Cancel</button>
<button class = "btn btn-primary" data-dismiss = "modal" id = "creategroupchat">Create</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card align-items-center">
<div class="card-block">
<h4 class="card-title" style="text-align:center"><strong>My Buddies</strong></h4>
<progress id="progressBuddies"></progress>
<div class="list-group" id="buddyList"></div>
<!--<a href="#" class="btn btn-primary">Refresh</a>-->
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card align-items-center">
<div class="card-block">
<h4 class="card-title" style="text-align:center"><strong>Others</strong></h4>
<progress id="progressOthers"></progress>
<div class="list-group" id="userList" style="margin:auto -70px"></div>
<!--<a href="#" class="btn btn-primary">Refresh</a>-->
</div>
</div>
</div>
</div>
<div class="row" style="margin-top:50px">
<div class="col-lg-6" style="margin:0 auto;float:none;margin-bottom:10px;">
<div class="card align-items-center" id="chatCard" style="display:none">
<div class="card-block">
<h4 class="card-title" id="chatName" style="text-align:center"><strong>Chat Name</strong></h4>
<ul class="list-group" id="messages"></ul>
</div>
<div class="form-inline">
<div class="input-group">
<input type="text" class="form-control" id="txtMessage">
</div>
<button type="submit" class="btn btn-default" id="btnSend"><span class="glyphicon glyphicon-send">Send</span></button>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
function readCookie(name) {
var nameEQ = name + "=", ca = document.cookie.split(';'), i = 0, c;
for(;i < ca.length;i++) {
c = ca[i];
while (c[0]==' ') c = c.substring(1);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length);
}
return null;
}
document.getElementById("navbarDropdownMenuLink").innerHTML="Hello "+readCookie("customId");
var socket=io();
socket.on('connect',function(data){
socket.emit('storeClientInfo',{customId:readCookie("customId")});
});
function loadGroups(customId){
var xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function(){
if(this.readyState==4&&this.status==200){
document.getElementById("progressGroups").style.display="none";
var data=JSON.parse(xhttp.responseText);
if(data.success){
console.log('Success');
}else{
console.log('Data Empty');
}
}else{
console.log('Failure');
}
};
//xhttp.open("GET","http://localhost:3000/users",true);
xhttp.open("GET","https://socket-chat-abhilash.herokuapp.com/users",true);
xhttp.send();
}
function loadBuddies(customId){
var xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function(){
if(this.readyState==4&&this.status==200){
document.getElementById("progressGroups").style.display="none";
var data=JSON.parse(xhttp.responseText);
if(data.success){
console.log('Success');
}else{
console.log('Data Empty');
}
}else{
console.log('Failure');
}
};
//xhttp.open("GET","http://localhost:3000/users",true);
xhttp.open("GET","https://socket-chat-abhilash.herokuapp.com/users",true);
xhttp.send();
}
function loadUsers(){
var xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function(){
if(this.readyState==4&&this.status==200){
document.getElementById("progressOthers").style.display="none";
var data=JSON.parse(xhttp.responseText);
if(data.success){
console.log('Success data length:'+data.data.length);
var listContainer=$('#userList');
for(var i=0;i<data.data.length;i++){
var friendId=data.data[i].customId;
var myId=readCookie('customId');
if(friendId.localeCompare(myId)!=0){
//listContainer.prepend('<a href="/startChat?myId='+myId+'&otherId='+friendId+'" class="list-group-item">'+friendId+'</a>');
var link="\""+friendId+"\"";
listContainer.prepend('<a href="#" class="list-group-item" id="'+friendId+'">'+friendId+'</a>');
document.getElementById(""+friendId).addEventListener("click",function(){
startChat(""+friendId);
});
}
}
}else{
console.log('Data Empty');
}
}else{
console.log('Failure');
}
};
//xhttp.open("GET","http://localhost:3000/users",true);
xhttp.open("GET","https://socket-chat-abhilash.herokuapp.com/users",true);
xhttp.send();
}
loadUsers();
function trim(value) {
return value.replace(/^\s+|\s+$/g,"");
}
function startChat(friendId){
document.getElementById("chatCard").style.display="block";
document.getElementById("chatName").innerHTML="<b>Chatting With: </b>"+friendId;
document.getElementById("btnSend").addEventListener("click",function(){
var message=document.getElementById("txtMessage").value;
console.log(message);
if(trim(message).localeCompare("")==0){
alert("Please enter some message first.");
}else{
var msg={
from:readCookie("customId"),
to:friendId,
msg:message
};
console.log('Sending message:'+msg);
socket.emit('chat message',msg);
}
});
}
socket.on('chat message',function(msg){
if(msg.from.localeCompare(readCookie('customId'))==0){
$('#messages').append($('<li style="text-align:right">').text("Me: "+msg.msg));
}else{
$('#messages').append($('<li style="text-align:left">').text(msg.from+": "+msg.msg));
}
});
</script>
<script>
//button for creating group
$('exampleModal').on('show.bs.modal', function(){
});
document.getElementById('groupname').addEventListener('input', function(event){
})
var available=false;
$('.alert .close').on('click',function(e){
$(this).parent().hide();
});
function trim(value) {
return value.replace(/^\s+|\s+$/g,"");
}
document.getElementById('checkAvailability').addEventListener("click", function(){
if(trim(document.getElementById("group-name").value)==""){
document.getElementById("alert").style.display = "block";
$('#alert').show();
document.getElementById("group-name").focus();
}else{
document.getElementById("check-progress").style.display="block";
var id1 = document.getElementById('group-name').value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4&&this.status == 200){
document.getElementById("check-progress").style.display = "none";
var data = JSON.parse(xhttp.responseText);
if(data.success){
console.log('success');
if(data.data.length!=0){
console.log('data is not empty' +data.data.length);
for(var i = 0; i<data.data.length;i++){
console.log('ClientID:'+data.data[i].clientId+' CustomId:'+data.data[i].customId);
.........
.........
.........
.........//write more i am not gatting properly
}
}
}
}
}
}
})
document.getElementById('creategroupchat').addEventListener('click', function(){
if(available){//group name is available
}
})
</script>
</html>