forked from EyPHP/live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
378 lines (350 loc) · 9.12 KB
/
client.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
*{
border: none;
padding: 0px;
margin: 0px;
}
::-webkit-scrollbar{
display:none;
}
.newList li{
width: 100%;
height: 50px;
}
.nesHead{
height: 44px;
margin-right: 20px;
line-height: 44px;
border-radius: 50%;
margin-left: 15px;
float: right;
}
.news{
display: block;
width: auto;
height: auto;
background: #2683f5;
padding: 10px 20px;
margin: 4px;
line-height: 20px;
font-size: 14px;
border-radius: 10px;
margin-left: 30px;
position: relative;
float: right;
color: white;
}
.answerHead{
height: 44px;
line-height: 44px;
border-radius: 50%;
margin-left: 15px;
float: left;
}
.answers{
width: auto;
height: 30px;
background: #eeeeee;
padding: 5px 20px;
margin: 4px;
line-height: 30px;
font-size: 14px;
border-radius: 10px;
margin-left: 10px;
position: relative;
float: left;
}
.userList li{
padding: 5px 10px;
}
</style>
<body>
<input type="hidden" value="" id="isLogin">
<div id="msg" style="display:none;width: 1200px; height:600px;margin: auto;margin-top: 50px;background-color: #0a8ddf">
<div style="float:left;width:18%;padding:10px;height:580px;background-color: #f0ad4e">
<div style="text-align: center;font-size: 24px;margin-bottom: 10px">陈立直播间</div>
<div style="height: 200px;background-color: #b65611">
<img id="img" src="" style="width: 215.99px;height: 200px">
</div>
</div>
<div style="float:left;width:63%;padding:10px;height:580px;background-color: #00aa00">
<div style="padding-bottom:15px;height: 465px;background-color: #8bc34a;overflow: auto;">
<ul id="newList" class="newList" style="list-style: none;padding: 15px 0px;">
<!--<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="answerHead">
用户一
</div>
<div class="answers">
你好
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="answerHead">
用户一
</div>
<div class="answers">
你好
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="answerHead">
用户一
</div>
<div class="answers">
你好
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="nesHead">
陈立
</div>
<div class="news">
是是是
</div>
</li>
<li>
<div class="answerHead">
用户一
</div>
<div class="answers">
你好
</div>
</li>-->
</ul>
</div>
<div style="height: 100px;background-color: #f96765">
<textarea name="" id="content" style="outline: none;font-size:18px;padding:10px;border:none;height: 80px;width:97%;resize: none;"></textarea>
<span id="send" onclick="send()" style="cursor:pointer;position: relative;top: -30px;right: -700px;padding:3px 10px;background-color: #8B6914;border: 1px solid #CDD8E3">发送</span>
</div>
</div>
<div style="float:right;width:14%;padding:10px;height:580px;background-color: #b65611;overflow: auto;">
<ul class="userList" id="userList">
</ul>
</div>
</div>
<div style="text-align: center;margin-top: 10%" id="setName">
<div style="margin-bottom: 10%;font-size: 20px;">欢迎来到陈立直播间</div>
<input type="name" style="width: 400px;padding: 10px;font-size:18px;border: 1px solid #F0C49B" id="name" value="">
<input id="button" type="button" onclick="send_name()" style="padding: 10px 20px;font-size: 17px;background-color: #f96765" value="进入">
</div>
<!--
<canvas id="output" style="display: block;"></canvas>-->
</body>
</html>
<script>
var socket = new WebSocket('ws://118.89.52.65:9502');
socket.onopen = function (event) {
console.log('连接服务器成功!');
}
socket.onclose = function (event) {
console.log('关闭服务器成功!');
}
socket.onerror = function (evt,e) {
console.log("错误:" + evt.data);
}
socket.onmessage = function (evt) {
var data = JSON.parse(evt.data);
var str = '';
if(data.type == 'user'){
var userList = data.list.fd;
// 在线用户列表
for(var i in userList) {
str += '<li style="cursor: pointer" data-fd="'+userList[i]['id']+'">'+userList[i]['name']+'</li>';
}
document.getElementById('userList').innerHTML = str;
}else if(data.type == 'message'){
var str = '';
if(data.myfd == data.fd){
str+='<li>'+
'<div class="nesHead">'+data.name+'</div>'+
'<div class="news">'+data.data+'</div>'+
'</li>';
}else{
str = '<li><div class="answerHead">'+data.name+'</div>\
<div class="answers">'+data.data+'</div></li>';
}
document.getElementById("newList").innerHTML +=str;
//$('.RightCont').scrollTop($('.RightCont')[0].scrollHeight );
}else if(data.type == 'video'){
document.getElementById("img").src = data.data;
}
//msg.innerHTML +=evt.data + '<br>';
//console.log("从服务器获取到的数据:"+evt.data);
}
// 发送 数据
function send(){
var message = document.getElementById('content').value;
if(message == ''){
alert('不能为空');
}else{
document.getElementById('content').value = '';
socket.send(JSON.stringify({
data:message,
type:'message'
}));
}
}
function send_name() {
var name = document.getElementById('name').value;
if (socket.readyState===1) {
socket.send(JSON.stringify({
data:"#name#"+name,
type:'setName'
}));
}
//var myTitle = document.getElementById("myTitle");
//myTitle.innerHTML = "即时聊天工具-"+text;
alert("设置成功!");
document.getElementById("msg").style.display = "block";
document.getElementById('setName').style.display = "none";
document.getElementById('isLogin').value = 1;
}
var isLogin = document.getElementById('isLogin').value;
if(isLogin == ''){
document.getElementById("msg").style.display = "none";
document.getElementById('setName').style.display = "block";
}
/*function success(stream){
video.src = window.URL.createObjectURL(stream);
}*/
/*function draw(){
back.width = 200;
back.height = 215.99;
backcontext.drawImage(video,0,0,back.width,back.height);
var str = back.toDataURL('image/jpeg',0.4);
if (socket.readyState===1) {
socket.send(JSON.stringify({
data:str,
type:'video'
}));
}
setTimeout(draw,80);
}*/
//draw();
</script>