-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathliveroom.html
More file actions
435 lines (418 loc) · 24.1 KB
/
liveroom.html
File metadata and controls
435 lines (418 loc) · 24.1 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
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<TITLE>腾讯视频云</TITLE>
<style>
.joinButton {background: transparent;}
.joinButton:hover {color: green;text-decoration: underline;}
a:hover {cursor: pointer;}
.tc-member-list-container {margin-top: 10px; width: 100%; height: 210px; background-color: #eee;}
</style>
<link href="./assets/css/index.css" rel="stylesheet" >
<script src="./js/vue.js"></script>
<script src="./js/vue-router.js"></script>
<script type="text/javascript" src="./js/EXEStarter.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/WebListOpt.js" charset="utf-8"></script>
</head>
<body onunload="dounload();">
<div id="vue-app">
<router-view></router-view>
</div>
<script>
function dounload() {
WebListOpt.unload();
};
function getRandomName() {
var randomNames = ['曹操', '刘备', '李白', '诸葛亮', '赵子龙', '孙权', '张飞',
'黄忠', '庞统', '貂蝉', '吕布', '马超', '孟获', '周瑜', '黄盖', '吕蒙']
var index = Math.ceil(Math.random() * 100) % randomNames.length;
return randomNames[index];
}
function randomUserId() {
var userID = "userid_web_" + Date.now().toString();
return userID;
}
var currentUserName = getRandomName();
var hasReLoginRoom = true;
//不同的WEB房间类型,需要改变ID和URL
var RoomTypeID = WebListOpt.webexe_roomtype.LiveRoom;
var RoomServerDomain = "https://room.qcloud.com/";
var ListServerDoMain = " http://xzb.qcloud.com/roomlist/weapp/webexe_room/"
var UnOpenRoomTips = "开课";
var OpenRoomTips = "已开课";
var CourseList = {
template: '\
<div class="edu-index-body"> \
<div class="edu-index-pop-ups" style="margin: 0 auto;"> \
<div class="edu-index-logo"> \
<img src="./assets/logo_edu.png" alt=""> \
</div> \
<!-- 创建课程 s --> \
<div class="edu-index-class-middle"> \
<div class="edu-index-class-middle" v-if="courseItems.length > 0"> \
<div class="edu-index-class-list"> \
<ul> \
<li v-for="(item, index) in courseItems"> \
<span>{{ item.courseName }}</span> \
<button class="joinButton" v-on:click="join(index)">{{ item.statusTips }}</button> \
<button class="joinButton" v-on:click="del(index)">关闭</button> \
</li> \
</ul> \
</div> \
</div> \
<div class="edu-index-class-prompt" v-if="courseItems.length === 0"> \
<p>暂时没有课程,请先创建</p> \
</div> \
</div> \
<!-- 创建课程 e --> \
\
<!-- 按钮 s --> \
<div class="edu-index-button"> \
<!-- 创建和加入课程 s --> \
<div class="tc-15-rich-dialog-ft"> \
<div class="tc-15-rich-dialog-ft-btn-wrap"> \
<button class="tc-15-btn" v-on:click="onCreateButtonClick">创建课程</button> \
</div> \
</div> \
<!-- 创建和加入课程 e --> \
</div> \
<!-- 按钮 e --> \
</div> \
<div id="toast_loading_exe" style="display:none;" class="toastload"> \
<div class="gif"></div> \
<div class="toastload_text"> \
<p>正在启动客户端,请稍候....</p> \
</div> \
</div> \
\
<div id="toast_download_exe" style="display:none;" class="toastdown"> \
<div class="toastdown_text"> \
<p>检测未安装客户端,请【<a href="javascript:void(0)" v-on:click="onDownloadButtonClick()">下载</a>】安装</p>\
</div> \
</div> \
</div>',
name: "CourseList",
data: function () {
return {
loginInfo: {
sdkAppID: '',
accountType: '',
userID: '',
userName: '',
userSig: ''
},
hasClass: false,
courseItems: [],
};
},
mounted: function () {
this.loginInfo.userName = currentUserName;
if (hasReLoginRoom == false) {
this.updateCourseList();
return;
}
this.initLoginInfo();
},
methods: {
join: function (idx) {
var room = this.courseItems[idx];
if (room.bOpen == true) {
alert("[" + room.courseName + "]" + "房间已经开启");
return;
}
/*
for (var i = 0; i < this.courseItems.length; i++) {
if (this.courseItems[i].bOpen == true) {
alert("已开启:【" + this.courseItems[i].courseName + "】房间,请先退出房间!");
return;
}
}*/
var index = idx;
if (/*room.pushers.length >= 5*/0) {
alert(room.courseName + "房间已经满人,请加入其他房间");
updateCourseList();
return;
}
console.log("跳转加入", JSON.stringify(room))
var self = this;
getSDKLoginInfo({
data: {
userID: randomUserId(),
loginServerDoMain: ListServerDoMain + "get_login_info",
method: "GET",
time: 24 * 60 * 60 * 7
},
success: function (res) {
if (res.status && res.status === 200) {
var info = res.data;
//console.log('loginInfo: ', JSON.stringify(info))
WebListOpt.initRoom({
data: {
userID: info.userID,
userName: self.loginInfo.userName,
sdkAppID: info.sdkAppID,
accType: info.accountType,
userSig: info.userSig,
roomType: RoomTypeID,
roomServerDoMain: RoomServerDomain,
listServerDoMain: ListServerDoMain
},
});
hasReLoginRoom = false;
console.log('getSDKLoginInfo 成功获取userID=', info.userID);
WebListOpt.setListener({
onRecvCmd: function (roomID, cmd) { },
onRoomClose: function (ret) {
//to do 必须把上层的房间关闭。
alert("房间:[" + ret.data.roomName + "]已关闭【errMsg:" + ret.data.msg + "】");
var index = -1;
for (var i = 0; i < self.courseItems.length; i++) {
if (self.courseItems[i].courseID == ret.data.roomID) {
index = i;
break;
}
}
if (index != -1) {
self.del(index);
}
},
});
document.getElementById('toast_loading_exe').style.display = 'none';
document.getElementById('toast_download_exe').style.display = 'none';
document.getElementById('toast_loading_exe').style.display = 'block';
WebListOpt.enterRoom({
data: {
roomID: room.courseID,
roomName: room.courseName,
roomType: room.roomType,
roomCreator: room.creator,
roomTitle: "互动课程Demo体验",
roomAction: EnumDef.RoomAction.CreateRoom,
roomLogo: "http://liteavsdk-1252463788.cosgz.myqcloud.com/windows/Cpp/logo/liveroom_logo.png",
},
success: function () {
console.log("courselist:进入房间成功");
document.getElementById('toast_loading_exe').style.display = 'none';
document.getElementById('toast_download_exe').style.display = 'none';
self.updateCourseList();
},
fail: function (ret) {
//当ret == -1,LiveRoom未检测到本地安装EXE,需要手动安装
if (ret.errCode == -1) {
console.log("courselist:进入房间 timeout!");
document.getElementById('toast_loading_exe').style.display = 'none';
document.getElementById('toast_download_exe').style.display = 'block';
}
else {
console.log("roomlist:进入房间失败!");
document.getElementById('toast_loading_exe').style.display = 'none';
document.getElementById('toast_download_exe').style.display = 'none';
alert("进入房间失败:" + ret.errMsg);
}
},
});
} else {
console.log('getSDKLoginInfo 获取登录信息失败')
}
},
fail: function (res) {
console.log('getSDKLoginInfo 获取登录信息失败: ', JSON.stringify(res))
}
})
},
del: function (idx) {
var room = this.courseItems[idx];
console.log("删除房间", JSON.stringify(room))
var self = this;
if (room.bOpen == true) {
WebListOpt.setListener({});
}
WebListOpt.exitRoom({
data: {
roomID: room.courseID,
roomType: room.roomType,
},
success: function (res) {
console.log("删除房间成功!");
self.updateCourseList();
},
fail: function () {
alert("删除房间失败");
}
});
},
onCreateButtonClick: function () {
var self = this;
console.log('onCreateButtonClick: self.loginInfo.userName = ', currentUserName)
this.$router.push({ path: 'create', query: { name: currentUserName } })
},
onDownloadButtonClick: function () {
window.open(EnumDef.EXEUrl);
document.getElementById('toast_loading_exe').style.display = 'none';
document.getElementById('toast_download_exe').style.display = 'none';
},
updateCourseList: function () {
var self = this;
self.courseItems = [];
WebListOpt.getRoomList({
data: {
index: 0,
count: 10,
},
success: function (res) {
var rooms = res.data.rooms
if (rooms) {
rooms.forEach(function (room) {
var courseInfo = {
courseID: room.roomID, // 用户ID
courseName: room.roomInfo, // 用户昵称
creator: room.roomCreator,
bOpen: room.status, //是否已经开课
statusTips: room.status == 1 ? OpenRoomTips : UnOpenRoomTips,
roomType: RoomTypeID,
}
self.courseItems.push(courseInfo);
});
console.log('courseItems: ', JSON.stringify(self.courseItems))
}
},
fail: function (res) {
console.warn('获取房间列表失败', JSON.stringify(res))
}
})
},
initLoginInfo: function () {
var self = this;
getSDKLoginInfo({
data: {
userID: randomUserId(),
loginServerDoMain: ListServerDoMain + "get_login_info",
method: "GET",
time: 24 * 60 * 60 * 7
},
success: function (res) {
if (res.status && res.status === 200) {
var info = res.data;
//console.log('loginInfo: ', JSON.stringify(info))
WebListOpt.initRoom({
data: {
userID: info.userID,
userName: self.loginInfo.userName,
sdkAppID: info.sdkAppID,
accType: info.accountType,
userSig: info.userSig,
roomType: RoomTypeID,
roomServerDoMain: RoomServerDomain,
listServerDoMain: ListServerDoMain
},
});
hasReLoginRoom = false;
console.log('getSDKLoginInfo 登录成功, userID=', info.userID);
self.updateCourseList();
} else {
alert('获取登录信息失败')
}
},
fail: function (res) {
console.log('获取登录信息失败: ', JSON.stringify(res))
}
})
}
},
};
var CreateCourse = {
template: '\
<div class="edu-index-body"> \
<div class="edu-index-pop-ups" style="margin: 0 auto;"> \
<div class="edu-index-logo"> \
<img src="./assets/logo_edu.png" alt="" /> \
</div> \
<!-- 输入直播房间 s --> \
<div class="edu-index-class-input"> \
<ul> \
<li><input type="text" placeholder="请输入课程名称" v-model="courseName" /></li> \
</ul> \
</div> \
<!-- 输入房间名称 e --> \
\
<!-- 按钮 s --> \
<div class="edu-index-button"> \
<!-- 加入教室的按钮 s --> \
<div class="tc-15-rich-dialog-ft"> \
<div class="tc-15-rich-dialog-ft-btn-wrap"> \
<button v-on:click="onClickCreate" class="tc-15-btn">创建</button> \
<button v-on:click="onClickCancel" class="tc-15-btn weak">取消</button> \
</div> \
</div> \
<!-- 加入教室的按钮 e --> \
</div> \
<!-- 按钮 e --> \
</div> \
</div>',
name: 'CreateCourse',
data: function () {
return {
courseName: null,
nickName: null,
};
},
mounted: function () {
if (hasReLoginRoom == true) {
this.onClickCancel();
}
},
methods: {
onClickCreate: function () {
var self = this;
console.log('create course: ', self.courseName, ' by ', self.nickName)
if (!self.courseName || !self.nickName) {
alert('课程名字和昵称不能为空!')
return;
} else {
console.log(self.nickName + "创建房间:" + self.courseName);
var name = this.nickName;
var course = this.courseName;
//此处创建房间
//this.courseName = null;
WebListOpt.createRoom({
data: {
roomInfo: course,
},
success: function (res) {
//self.courseId = res.roomID;
console.log("创建房间成功, roomID = ", res.data.roomID);
self.$router.push({ path: '/' });
},
fail: function () {
alert("创建房间失败");
}
});
}
},
onClickCancel: function () {
this.$router.push({ path: '/' });
}
},
created: function () {
console.log('创建房间 created: query=', JSON.stringify(this.$route.query))
this.nickName = this.$route.query.name
},
};
</script>
<script type="text/javascript" charset="utf-8">
var router = new VueRouter({
routes: [
{ path: '/', name: 'list', component: CourseList, },
{ path: '/create', name: 'create', component: CreateCourse, }
]
});
new Vue({
el: '#vue-app',
router: router,
});
</script>
</body>
</html>