-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.html
227 lines (192 loc) · 7.52 KB
/
index1.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="Keywords" content="HTML,CSS,JavaScript,SQL,PHP,jQuery,ASP,XML,DOM,Bootstrap,Web development,W3C,tutorials,programming,training,learning,quiz,primer,lessons,references,examples,source code,colors,demos,tips">
<meta name="Description" content="Well organized and easy to understand Web bulding tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, and XML.">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link type="text/css" rel="stylesheet" href="lib/w3.css">
<link type="text/css" rel="stylesheet" href="css/reset.css">
<link type="text/css" rel="stylesheet" href="css/style.css">
<script src="/socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<!-- <script src="jquery.min.js"></script> -->
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
</head>
<body>
<script>
// var socket = io.connect('http://0.0.0.0:8081');
var socket = io.connect('http://moovo-chat-100.appspot.com:8081');
var conn_id;
console.log("this");
var myname='';
var talk_to=''
// on connection to server, ask for user's name with an anonymous callback
socket.on('connect', function(){
// call the server-side function 'adduser' and send one parameter (value of prompt)
console.log('connect event')
myname=prompt("what's your name?");
socket.emit('adduser', myname);
var sessionid = socket.io.engine.id;
conn_id=sessionid;
console.log(conn_id);
// conn_id=myname;
// talk_to=prompt('whom to talk');
// socket.emit('talk_to',talk_to);
// //default admin user code below
// var talk_to='Admin'
// var renderUser='<li class="person" data-chat="'+talk_to+'" onclick="personChat(\''+String(talk_to)+'\')">'
// renderUser+='<img src="http://s13.postimg.org/ih41k9tqr/img1.jpg" alt="" />'
// renderUser+='<span class="name">'+talk_to+'</span>'
// renderUser+='<span class="time">2:09 PM</span>'
// renderUser+='<span class="preview"></span></li>'
// console.log(renderUser)
// $('.people').append(renderUser);
// renderUser='<div class="top"><span>To: <span class="name">'+talk_to+'</span></span></div>'
// console.log(renderUser)
// $('.right').append(renderUser)
});
// listener, whenever the server emits 'updatechat', this updates the chat body
socket.on('updatechat', function (data) {
// $('#conversation').append('<b>'+data['who'] + ':</b> ' + data['msg'] + '<br>');
var rend='<div class="';
// console.log("myname: "+myname)
if (data['who']==myname){
rend=rend+'bubble me">'+data['msg']+'</div>';
$('.chat').append(rend)
// console.log(rend)
}
else if (data['who']==talk_to){
rend=rend+'bubble you">'+data['msg']+'</div>';
$('.chat').append(rend)
// console.log(rend)
}
});
socket.on('render', function (data) {
// $('#conversation').append('<b>'+data['sent_by'] + ':</b> ' + data['mess'] + '<br>');
var rend='<div class="';
// console.log("myname: "+myname)
if (data['sent_by']==myname){
rend=rend+'bubble me">'+data['mess']+'</div>';
$('.chat').append(rend)
// console.log(rend)
}
else if (data['sent_by']==talk_to){
rend=rend+'bubble you">'+data['mess']+'</div>';
$('.chat').append(rend)
// console.log(rend)
}
// $('.chat').append('<div class="bubble you">Hello you,</div>');
// $('.chat').append('<div class="bubble me">Hello you,</div>');
// console.log(data);
});
socket.on('offline',function (data){
var rend='<b>'+data["who"]+' </b> '+'is offline right now. But you can still send him messages'+'</br>'
// $('#conversation').append();
});
socket.on('typing', function (data){
console.log('nothing');
});
socket.on('addcontact',function (data){
var renderUser='<li class="person" onclick="personChat(\''+data["contact"]+'\')" data-chat="'+data["contact"]+'">'
renderUser+='<img src="http://s13.postimg.org/ih41k9tqr/img1.jpg" alt="" />'
renderUser+='<span class="name">'+data["contact"]+'</span>'
renderUser+='<span class="time">2:09 PM</span>'
renderUser+='<span class="preview"></span></li>'
console.log(renderUser)
$('.people').append(renderUser);
});
// on load of page
$(function(){
$('#deta').keypress(function(e) {
if (e.which == 13) {
// $(this).blur();
sendButton();
$(this).val('')
}
});
$('#adduser').keypress(function(e) {
if (e.which == 13) {
adduser();
$(this).val('')
}
});
});
function sendButton() {
var message = $('#deta').val();
socket.emit("new_msg", message);
// console.log("browser"+' : '+message);
}
function adduser(){
var new_name=$('#adduser').val();
var renderUser='<li class="person" onclick="personChat(\''+$('#adduser').val()+'\')" data-chat="'+new_name+'">'
renderUser+='<img src="http://s13.postimg.org/ih41k9tqr/img1.jpg" alt="" />'
renderUser+='<span class="name">'+new_name+'</span>'
renderUser+='<span class="time">2:09 PM</span>'
renderUser+='<span class="preview"></span></li>'
// console.log(renderUser)
$('.people').append(renderUser);
$('#adduser').val('');
}
function personChat(ideo){
console.log(ideo)
$('.right .top .name').html(ideo);
socket.emit('talk_to',ideo);
$('.chat').empty();
talk_to=ideo
// socket.emit('talk_to',String(ideo))
// console.log(String(ideo));
}
// $('.person').mousedown(function(){
// console.log("clicked")
// // if ($(this).hasClass('.active')) {
// // return false;
// // } else {
// //currently both are set to be same
// var uniqid = $(this).attr('data-chat');
// var personName = $(this).find('.name').text();
// $('.right .top .name').html(personName);
// $('.chat').removeClass('active-chat');
// $('.left .person').removeClass('active');
// $(this).addClass('active');
// $('.chat[data-chat = '+findChat+']').addClass('active-chat');
// });
</script>
<div class="wrapper">
<div class="container">
<div class="left">
<div class="top">
<input type="text" id="adduser" />
<a href="javascript:;" class="search" onclick="adduser()"></a>
</div>
<ul class="people">
<!-- <li class="person" data-chat="Admin" onclick="personChat('Admin')">
<img src="http://s13.postimg.org/ih41k9tqr/img1.jpg" alt="" />
<span class="name">Admin</span>
<span class="time">2:09 PM</span>
<span class="preview"></span>
</li> -->
</ul>
</div>
<div class="right">
<!-- <div style="float:left;width:300px;height:250px;overflow:scroll-y;padding:10px;"> -->
<div class="top"><span>To: <span class="name"></span></span></div>
<div class="chat" data-chat="person2">
<div class="conversation-start">
<span>Today, 6:48 AM</span>
</div>
<!-- <div class="bubble you">
Hello,
</div> -->
</div>
<div class="write">
<a href="javascript:;" class="write-link attach" onclick="attachButton()"></a>
<input type="text" id="deta"/>
<a href="javascript:;" class="write-link smiley"></a>
<a href="javascript:;" class="write-link send" onclick="sendButton()"></a>
</div>
</div>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>