Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
773 lines (716 loc) · 28.2 KB
/
Copy pathindex.html
File metadata and controls
773 lines (716 loc) · 28.2 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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<!DOCTYPE html>
<html>
<head>
<title>骆驼 RTC </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="./jquery-1.10.2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="./aliyun-webrtc-sdk-1.12.0.js"></script>
<script src="./utils.js"></script>
<style>
</style>
</head>
<body>
<div class="login portlet">
<div class="main portlet-body">
<br><br>
<div class="jumbotron col-md-4 col-md-offset-4" >
<div class="container">
<div class="main-title">
<h2>欢迎光临骆驼</h2>
</div>
<br>
<div class="form-group">
<div class="main-input">
<input class="form-control" type="text" placeholder="请输入房间号">
</div>
<br>
<div class="name-input">
<input class="form-control" type="text" id="name" placeholder="请输入您的名字">
</div>
<br>
<div class="main-button">
<button class=" btn btn-primary ">进入房间</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="main-web" style="display: none;">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
骆驼
</a>
<div class="local-display-name pull-right">
<span class="username">用户: <b></b></span>
<span class="channelid">房间号: <b></b></span>
<span class="streamstate">推流状态:<b></b></span>
</div>
</div>
</div>
</nav>
<div class="row">
<div class="col-md-3 blokUser">
<div class="remote-user-list">
<ul class="user-ul list-group"></ul>
</div>
</div>
<div class="col-md-9">
<div class="container-box">
<div class="publisher">
<button class="select-preview">关闭预览</button>
<button class="push-stream">处理中...</button>
<span class="streamType" style="display: none;">
<label for="cameraPublisher">推视频流</label>
<input
id="cameraPublisher"
value="cameraPublisher"
type="checkbox"
name="streamType"
checked
/>
<label for="screenPublish">推共享流</label>
<input
id="screenPublish"
value="screenPublish"
type="checkbox"
name="streamType"
/>
</span>
</div>
<div class="local-video">
<video autoplay playsinline></video>
</div>
</div>
<div class="video-container"></div>
</div>
</div>
</div>
<div class="alert"></div>
</body>
</html>
<script>
/**
* 必须使用https
*/
var AppServerUrl ="https://ws.mzyun.ren:8877";
var channelId;
var publisherList = [];
var aliWebrtc;
var userName = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
aliWebrtc = new AliRtcEngine();
/**
* AliWebRTC isSupport检测
*/
aliWebrtc.isSupport().then(re => {
console.log(re);
init();
}).catch(error => {
alert(error.message);
})
function init() {
/**
* remote用户加入房间 onJoin
* 更新在线用户列表
*/
aliWebrtc.on("onJoin", (publisher) => {
if(publisher.userId){
updateUserList();
}
//重置订阅状态
//默认订阅远端音频和视频大流,但需要调用subscribe才能生效
//这里取消默认订阅,根据需求进行订阅
aliWebrtc.configRemoteAudio(publisher.userId, false);
aliWebrtc.configRemoteCameraTrack(publisher.userId, false, false);
// showAlert(publisher.displayName + "加入房间","success");
console.log(publisher.displayName + "加入房间");
});
/**
* remote流发布事件 onPublish
* 将该用户新增到推流列表
* 若该用户已存在推流列表,则进行状态更新
*/
aliWebrtc.on("onPublisher", (publisher) => {
console.log("onPublisher", publisher);
let index = publisherList.getIndexByProprety(publisher.userId, "userId");
if (index === -1) {
//新增
publisherList.push(publisher);
} else {
//流状态更新
updatePublisherStream(publisher, index);
}
});
/**
* remote流结束发布事件 onUnPublisher
* 推流列表删除该用户
* 移除用户视图
* 初始化订阅状态
*/
aliWebrtc.on("onUnPublisher", (publisher) => {
console.log("onUnPublisher",publisher);
detelePublisher(publisher.userId);
removeDom(publisher.userId);
initialization(publisher.userId);
});
/**
* 被服务器踢出或者频道关闭时回调 onBye
*/
aliWebrtc.on("onBye",(message) =>{
//1:被服务器踢出
//2:频道关闭
//3:同一个ID在其他端登录,被服务器踢出
var msg;
switch (message.code) {
case 1: msg = "被服务器踢出";
break;
case 2: msg = "频道关闭";
break;
case 3: msg = "同一个ID在其他端登录,被服务器踢出";
break;
default: msg = "onBye";
}
showAlert(msg,"danger");
});
/**
* 错误信息
*/
aliWebrtc.on("onError", (error) => {
console.log(error)
var msg = error && error.message ? error.message : error;
if (msg && msg.indexOf("no session") > -1) {
msg = "请重新登录:" + msg;
}
if (error.errorCode === 10011 || error.errorCode === 10012) {
msg = error.errorCode === 10011 ? "屏幕共享被禁止" : "屏幕共享已取消";
setTimeout(() => {
$("#screenPublish").removeAttr("checked");
getPublishState("danger");
}, 2000);
}
if(error.code == 15) {
msg = "没有开启H5兼容";
}
if(error.type === "publish") {
console.log("推流断开 需要停止推流,然后重新推流");
$(".push-stream").click();
//先记录当前推流状态
var pubAudio = aliWebrtc.configLocalAudioPublish;
var pubCamera = aliWebrtc.configLocalCameraPublish;
var pubScreen = aliWebrtc.configLocalScreenPublish;
aliWebrtc.publish().then(()=>{
console.log("推流断开取消推流成功");
aliWebrtc.configLocalAudioPublish = pubAudio;
aliWebrtc.configLocalCameraPublish = pubCamera;
aliWebrtc.configLocalScreenPublish = pubScreen;
aliWebrtc.publish().then(()=>{
console.log("推流断开重新推流成功");
}).catch(err => {
console.log("推流断开重新推流失败");
})
}).catch(err => {
console.log("推流断开取消推流失败");
})
}
if(error.type === "subscribe") {
console.log("订阅断开 取消订阅该userId的所有订阅并移除所有该userId的dom");
//先记录当前用户的订阅状态
var subInfo = getSubscribeInfo(error.userId);
//取消订阅状态
initialization(error.userId);
aliWebrtc.subscribe(error.userId).then(re => {
console.log("订阅断开 取消订阅成功");
aliWebrtc.configRemoteAudio(error.userId,subInfo.isSubAudio);
aliWebrtc.configRemoteCameraTrack(error.userId,subInfo.isSubLarge,subInfo.isSubCamera);
aliWebrtc.configRemoteScreenTrack(error.userId,subInfo.isSubScreen);
aliWebrtc.subscribe(error.userId).then(re => {
console.log("订阅断开 重新订阅成功")
if($("#" + error.userId + "_camera")){
aliWebrtc.setDisplayRemoteVideo(error.userId,$("#" + error.userId + "_camera video")[0], 1)
}
if($("#" + error.userId + "_screen")){
aliWebrtc.setDisplayRemoteVideo(error.userId,$("#" + error.userId + "_screen video")[0], 2)
}
}).catch(err=>{
console.log("订阅断开 重新订阅失败");
detelePublisher(error.userId);
removeDom(error.userId);
})
}).catch(err => {
console.log("订阅断开 取消订阅失败", err)
detelePublisher(error.userId);
removeDom(error.userId);
});
}
showAlert(msg,"danger")
});
/**
* 检测到用户离开频道
* 更新用户列表
* 移除用户视图
*/
aliWebrtc.on("onLeave", (publisher) => {
initialization(publisher.userId);
updateUserList();
removeDom(publisher.userId);
showAlert(publisher.displayName + "离开房间","success");
})
}
/**
* 加入房间
* 触发:输入房间号、单击加入房间按钮
* 更新页面信息
* 默认开启预览
* 获取鉴权信息
* 加入房间
* 本地默认自动推视频流(视频流 + 音频流)
* 发布本地流
*/
function joinroom(userName) {
$(".local-display-name .username b").text(userName);
$(".local-display-name .channelid b").text(channelId);
$(".local-display-name .streamstate b").text("当前未推流");
//1.预览
var localVideo = $(".local-video video");
aliWebrtc.startPreview(localVideo[0]).then((obj) => {
}).catch((error) => {
showAlert("[开启预览失败]" + error.message,"danger");
});
//2. 获取频道鉴权令牌参数 -->
getRTCAuthInfo().then((authInfo) => {
//3. 加入房间 默认推音频视频流
aliWebrtc.joinChannel(authInfo, userName).then(() => {
showAlert( "加入房间成功", "success");
// 4. 发布本地流
aliWebrtc.configLocalAudioPublish = true;
aliWebrtc.configLocalCameraPublish = true;
aliWebrtc.publish().then((res) => {
setTimeout(() => {
console.log("发布流成功");
$(".push-stream").text("停止推流");
$(".streamType").show();
$(".local-display-name .streamstate b").text("视频流");
},2000)
}, (error) => {
$(".streamType").show();
showAlert("[推流失败]" + error.message, "danger");
});
}).catch((error) => {
showAlert("[加入房间失败]" + error.message, "danger");
})
}).catch((error) => {
showAlert( error.message, "danger");
});
}
/**
* 更新在线用户列表
*/
var updateUserList = () => {
$(".user-ul").empty();
let userList = aliWebrtc.getUserList();
let frg = document.createDocumentFragment();
userList.map((user) => {
let html = $("<li class='user-ul-li list-group-item'>" + user.displayName + "<ul class='menu'></ul></li>");
$(html).bind("mouseover",user.userId,showUserMenu).bind("mouseleave",hideUserMenu);
frg.append(html[0]);
})
$(".user-ul").append($(frg));
}
/**
* 获取频道鉴权令牌参数这个方法需要客户重新实现,调用RTC服务的Open API获取
*/
var getRTCAuthInfo = () => {
return new Promise(function (resolve, reject) {
$.post(AppServerUrl + "?room=" + channelId + "&user=" + userName + "&passwd=1234", {}, (re) => {
console.log(re);
re.data.channel = channelId;
resolve(re.data);
}).error(function(error){
if(error.status == 404){
error.message = "获取鉴权信息失败,可能是AppServer地址错误";
} else if(error.status == 0){
error.message = "获取鉴权信息失败,可能是https证书错误";
}
reject(error);
});
});
}
/**
* 获取当前remote用户的流菜单
*/
var showUserMenu = (evt) => {
let userId = evt.data;
if(!$(event.target).eq(0).hasClass("user-ul-li")){
return
}
$(".menu").hide();
$(event.target).find(".menu").empty().show();
let userInfo = aliWebrtc.getUserInfo(userId);
let streamTypeList = userInfo.streamConfigs.filter(item => {
return item.state === "active";
});
var html = "";
if(streamTypeList.length == 0){
html = $("<li>该用户未推流</li>");
$(event.target).find(".menu").append(html[0]);
}else{
var frg = document.createDocumentFragment()
streamTypeList.map(item => {
item.userId = userId;
var labelName = "";
if(item.type === "video"){
switch (item.label) {
case "sophon_video_camera_large":
labelName = "视频流";
break;
case "sophon_video_screen_share":
labelName = "共享流";
break;
case "sophon_audio":
labelName = "";
break;
default:
labelName = "";
}
} else {
labelName = "";
}
//将音频流或小流的标签不显示
if(labelName !== ""){
let subState = item.subscribed === true ? "取消" : "查看";
html = $("<li>"+ labelName +" <span>"+ subState +"</span></li>");
$(html).find("span").off("click").on("click", item, unSub);
frg.append(html[0]);
}
})
$(event.target).find(".menu").append($(frg));
}
}
/**
* 隐藏当前remote用户的流菜单
*/
var hideUserMenu = () => {
$(event.currentTarget).find(".menu").hide();
}
/**
* 订阅&取消订阅
*/
var unSub = (evt) => {
let v = evt.data;
if(v.subscribed){
setConfigRemote(v.userId, v.label).then(re => {
removeDom(v.userId, v.label);
console.log("取消订阅");
});
}else {
receivePublishManual(v).then(re => {
creatDomAndshowRemoteVideo(v);
console.log("订阅成功");
});
}
$(".menu").hide();
}
/**
* 获取dom标签 设置video
*/
var creatDomAndshowRemoteVideo = (v) => {
var dom = getDisplayRemoteVideo(v.userId, v.label);
if (v.label != "sophon_video_screen_share") {
aliWebrtc.setDisplayRemoteVideo(v.userId, dom, 1);
} else {
aliWebrtc.setDisplayRemoteVideo(v.userId, dom, 2);
}
}
/**
* 创建获取订阅的remote的video标签
*/
var getDisplayRemoteVideo = function (userId, label) {
var label = label === "sophon_video_camera_large" ? "camera" : "screen";
var id = userId + "_" + label;
var videoWrapper = $("#" + id);
if (videoWrapper.length == 0) {
var userInfo = aliWebrtc.getUserList().filter(item => {
return item.userId === userId;
})
var displayName = userInfo[0].displayName;
videoWrapper = $("<div class='remote-subscriber' id=" + id + "> <video autoplay playsinline></video><div class='display-name'></div></div>");
$(".video-container").append(videoWrapper);
}
videoWrapper.find(".display-name").text(displayName + "—" + label);
return videoWrapper.find("video")[0];
}
/**
* 移除dom
*/
var removeDom = (userId, label) => {
if(label === "sophon_audio") return
if(userId) {
if(!label){
$("#" + userId + "_camera").remove();
$("#" + userId + "_screen").remove();
}else {
label = label === "sophon_video_camera_large" ? "camera" : "screen";
$("#" + userId + "_" + label).remove();
}
}
}
/**
* 取消订阅设置
*/
var setConfigRemote = (userId, label) => {
return new Promise((resolve, reject) => {
//demo中只订阅大流
if (label === "sophon_video_camera_large") {
aliWebrtc.configRemoteCameraTrack(userId, false, false);
aliWebrtc.configRemoteAudio(userId,false);
} else if (label === "sophon_video_screen_share") {
aliWebrtc.configRemoteScreenTrack(userId, false);
}
aliWebrtc.subscribe(userId).then(re => {
resolve();
}).catch(error => console.log("取消订阅失败", error))
});
}
/**
* 订阅设置
*/
var receivePublishManual = (v) =>{
console.log("receivePublishManual订阅", v);
return new Promise((resolve, reject) => {
if (v.label === "sophon_video_camera_large") {
console.log("订阅固定视频流");
aliWebrtc.configRemoteCameraTrack(v.userId, true, true);
aliWebrtc.configRemoteAudio(v.userId, true);
} else if (v.label === "sophon_video_screen_share") {
console.log("订阅屏幕共享流");
aliWebrtc.configRemoteScreenTrack(v.userId, true);
}
aliWebrtc.subscribe(v.userId).then(re => {
resolve();
}).catch((error) => {
reject(error);
showAlert("[subscribe失败]" + error.message, "danger");
});
})
}
/**
* 更新推流状态
* 当远端流发生变化时,通过onPublisher回调接收到信息
* 远端流不可用时其state值为inactive
* 通过对比本地维护的publisherList来进行dom的删除
* 并且更新本地维护的publisherList
*/
var updatePublisherStream = (publisher,index) => {
let oldStreamConfigs = JSON.parse(JSON.stringify(publisherList[index].streamConfigs));
let newStreamConfigs = publisher.streamConfigs;
let subscribeInfo = getSubscribeInfo(publisher.userId);
oldStreamConfigs.forEach((v, i, a) => {
let newStream = newStreamConfigs.getObjByProprety(v.label, "label");
// 判断流状态改变了 但不确定我们是否订阅了该流
if (v.state != newStream.state) {
console.log("流的状态变了" + v.label, v, v.type, ">"+ v.state + ">>" + newStream.state + ">", newStream, subscribeInfo);
//并且要取消订阅某个流,不然就不能再次订阅了
subscribeInfo.subscribeInfoArr.forEach(sv => {
if (v.label === sv.label) {
console.log("setConfigRemote取消订阅调用[api]:subscribe", publisher.userId, sv.type, sv.label);
setConfigRemote(publisher.userId, sv.type, sv.label).then(re => {
// 移除dom
removeDom(publisher.userId, v.label);
}).catch(error => {
console.error("流的状态变了重新订阅出问题", error);
});
}
});
}
});
publisherList.splice(index, 1, publisher);
}
/**
* 用户停止推流时 删除用户列表中该用户
*/
var detelePublisher = (userId) => {
let index = publisherList.getIndexByProprety(userId, "userId");
if (index != -1) {
publisherList.splice(index, 1);
this.detelePublisher(userId);
} else {
console.log("未找到之前的推流数据"); //删除推流用户
}
}
/**
* 正在推流时,热切换进行republish操作
*/
var rePublish = () => {
if($(".publisher .push-stream").text() === "停止推流"){
$(".publisher .push-stream").text("处理中...");
$(".streamType").hide();
aliWebrtc.publish().then(re => {
setTimeout(() => {
getPublishState("success");
},2000);
}).catch(error => {
setTimeout(() => {
getPublishState("danger");
}, 2000);
});
}
}
/**
* 根据推流状态设置当前推流UI
*/
var getPublishState = (type) => {
var streamstate = $(".streamstate b").text()
if(aliWebrtc.configLocalAudioPublish || aliWebrtc.configLocalCameraPublish || aliWebrtc.configLocalScreenPublish){
$(".publisher .push-stream").text("停止推流");
if(aliWebrtc.configLocalScreenPublish && aliWebrtc.configLocalCameraPublish){
streamstate = "视频流 + 共享流";
} else {
if(aliWebrtc.configLocalScreenPublish) {
streamstate = "共享流";
} else if(aliWebrtc.configLocalCameraPublish) {
streamstate = "视频流";
}
}
} else {
$(".publisher .push-stream").text("开始推流");
streamstate = "当前未推流";
}
showAlert("推流状态:" + streamstate, type);
$(".streamstate b").text(streamstate);
$(".streamType").show();
}
/**
* 进入房间
*/
$(".main-button button").click(() => {
var value = $(".main-input input").val();
userName= $(".name-input input").val();
if(!value){
showAlert("请输入房间号","danger");
return
}
if(!aliWebrtc){
showAlert("isSupport失败,未能初始化aliWebrtc","danger");
returnN
}
channelId = value;
joinroom(userName);
$(".login").hide();
$(".main-web").show();
})
/**
* 控制预览
*/
$(".publisher .select-preview").click(function(e) {
var localVideo = $(".local-video video");
if($(this).text() === "开启预览"){
$(this).text("处理中...");
aliWebrtc.startPreview(localVideo[0]).then((obj) => {
setTimeout(() => {
$(this).text("关闭预览");
},2500);
}).catch((error) => {
setTimeout(() => {
$(this).text("开启预览");
},2500);
showAlert("[关闭预览失败]" + error.message, "danger");
});
}else if($(this).text() === "关闭预览") {
$(this).text("处理中...");
aliWebrtc.stopPreview().then((re) => {
setTimeout(() => {
$(this).text("开启预览");
},2500);
}).catch((error) => {
setTimeout(() => {
$(this).text("关闭预览");
},2500);
showAlert("[开启预览失败]" + error.message, "danger");
});
}else {
return
}
})
/**
* 控制推流选项
*/
$(".publisher .streamType input").click(function(e) {
var config = $(this).val();
var isChecked = $(this).prop("checked");
if(config === "cameraPublisher"){
if(isChecked){
aliWebrtc.configLocalAudioPublish = true;
aliWebrtc.configLocalCameraPublish = true;
} else {
aliWebrtc.configLocalAudioPublish = false;
aliWebrtc.configLocalCameraPublish = false;
}
}else {
if(isChecked){
aliWebrtc.configLocalScreenPublish = true;
} else {
aliWebrtc.configLocalScreenPublish = false;
}
}
//正在推流时可以热切换
rePublish();
})
/**
* 处理推流
*/
$(".publisher .push-stream").click(function(e) {
if($(this).text() === "开始推流") {
$(this).text("处理中...")
$(".streamType").hide()
aliWebrtc
.publish()
.then(re => {
setTimeout(() => {
getPublishState("success");
},2000);
})
.catch(error => {
$(this).text("开始推流");
$(".streamType").show();
showAlert( "[开始推流失败]" + error.message, "danger");
});
}else if($(this).text() === "停止推流") {
$(this).text("处理中...");
$(".streamType").hide();
aliWebrtc.configLocalAudioPublish = false;
aliWebrtc.configLocalCameraPublish = false;
aliWebrtc.configLocalScreenPublish = false;
aliWebrtc.publish().then((re)=>{
setTimeout(() => {
$("input[type='checkbox']").removeAttr("checked");
$(".streamType").show();
$(this).text("开始推流");
$(".local-display-name .streamstate b").text("当前未推流");
},2000);
} ,(error)=>{
$(".streamType").show();
showAlert( "[停止推流失败]" + error.message, "danger");
});
}else {
return
}
});
/**
* 页面刷新时调用离会
*/
window.onbeforeunload = function (e) {
if(!aliWebrtc){
showAlert("isSupport失败,未能初始化aliWebrtc","danger");
return
}
aliWebrtc.leaveChannel();
aliWebrtc.dispose();
};
</script>