-
Notifications
You must be signed in to change notification settings - Fork 227
/
index.js
3065 lines (2809 loc) · 89.1 KB
/
index.js
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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//当前激活tab
var activeTab = "main";
//agentId,保留,当前未使用,默认为""
var agentId = "";
//userId
var userId = "";
//各功能聊天室对话框
var videoMeetingMsgWindow = null;
var voipMsgWindow = null;
var videoLiveMsgWindow = null;
var superTalkMsgWindow = null;
// 集成文档请参考 https://docs.starrtc.com/en/docs/web-7.html
var aecRequestBaseURL = "https://www.starrtc.com/aec"; //开启AEC后,才生效,从此url获取各种列表信息
var privateURL = "demo.starrtc.com"; //后端服务地址,可为ip,也可为域名
var webrtcIP = "47.105.65.73"; //后端服务地址,必须为ip(目前只有chrome72以上支持设置成域名),webrtc ip,用于设置webrtc udp ip,用于setSrcServerInfo,setVdnServerInfo,setVoipServerInfo接口,不设置时与后端服务地址privateURL一致
/* var LOG_LEVEL = {
LOG_LEVEL_DEBUG: i++,
LOG_LEVEL_INFO: i++,
LOG_LEVEL_WARN: i++,
LOG_LEVEL_ERROR: i++ */
//设置日志等级,开启低等级日志会包含高等级日志,如开启DEBUG,则同时开启INFO、WARN、ERROR,默认为开启DEBUG
StarRtc.InitlogLevel(LOG_LEVEL.LOG_LEVEL_DEBUG);
//创建SDK对象
StarRtc.Instance = new StarRtc.StarSDK();
////////////////////////私有云改配置///////////////////////
///////////////////////以下privateURL需替换为私有部署IP////
//StarRtc.Instance.setConfigUseAEC(true); //是否开启AEC
StarRtc.Instance.setMsgServerInfo(privateURL, 19903) //ip, websocket port //需要手动从浏览器输入 https://ip:29991 信任证书
StarRtc.Instance.setChatRoomServerInfo(privateURL, 19906) //ip, websocket port //需要手动从浏览器输入 https://ip:29993 信任证书
StarRtc.Instance.setSrcServerInfo(privateURL, 19934, 19935, webrtcIP) //ip, websocket port, webrtc port, webrtc ip//需要手动从浏览器输入 https://ip:29994 信任证书
StarRtc.Instance.setVdnServerInfo(privateURL, 19940, 19941, webrtcIP) //ip, websocket port, webrtc port, webrtc ip //需要手动从浏览器输入 https://ip:29995 信任证书
StarRtc.Instance.setVoipServerInfo(privateURL, 10086, 10087, 10088, webrtcIP) //ip, voipServer port, websocket port, webrtc port, webrtc ip //需要手动从浏览器输入 https://ip:29992 信任证书
//白板画布类
var MyCanvas = function (_id, _draw_mode, _draw_callback) {
var id = _id;
var draw_mode = false || _draw_mode;
var draw_callback = null || _draw_callback;
var canvasObj = $("#" + id);
if (canvasObj == undefined) {
return null;
}
var ctx = canvasObj[0].getContext('2d');
ctx.fillStyle = 'rgba(255, 255, 255, 0)';
var drawPoints = [];
var points = {};
points["-1"] = [];
if (draw_mode) {
canvasObj.unbind("mousedown");
canvasObj.unbind("mousemove");
canvasObj.unbind("mouseup");
canvasObj.bind("mousedown", function (ev) {
var ev = ev || window.event;
ctx.strokeStyle = "red";
ctx.lineCap = 'round';
ctx.lineWidth = 4;
drawPoints = [];
ctx.beginPath();
ctx.moveTo(ev.offsetX, ev.offsetY);
drawPoints.push([ev.offsetX, ev.offsetY]);
canvasObj.bind("mousemove", function (ev) {
var ev = ev || window.event;
ctx.lineTo(ev.offsetX, ev.offsetY);
drawPoints.push([ev.offsetX, ev.offsetY]);
ctx.stroke();
});
});
canvasObj.bind("mouseup", function (ev) {
canvasObj.unbind("mousemove");
drawPoints.push([0, 0]);
if (draw_callback != null) {
draw_callback(drawPoints);
}
points["-1"] = points["-1"].concat(drawPoints);
});
}
MyCanvas.prototype.addPoint = function (_id, x, y) {
if (points[_id] == undefined) {
points[_id] = [];
}
points[_id].push([x, y]);
}
MyCanvas.prototype.setSize = function (width, height) {
canvasObj[0].width = width;
canvasObj[0].height = height;
ctx = canvasObj[0].getContext('2d');
ctx.fillStyle = 'rgba(255, 255, 255, 0)';
}
MyCanvas.prototype.fitSize = function () {
if (canvasObj[0].width != canvasObj[0].clientWidth || canvasObj[0].height != canvasObj[0].clientHeight) {
this.setSize(canvasObj[0].clientWidth, canvasObj[0].clientHeight);
}
}
MyCanvas.prototype.redraw = function () {
this.fitSize();
this.clearCanvas();
for (var upId in points) {
var count = 0;
if ((count = points[upId].length) > 1) {
var selectColor = "red";
switch (upId) {
case "-1":
selectColor = "#FF6c00";
break;
case "0":
selectColor = "#FF4081";
break;
case "1":
selectColor = "yellow";
break;
case "2":
selectColor = "blue";
break;
case "3":
selectColor = "cyan";
break;
case "4":
selectColor = "green";
break;
case "5":
selectColor = "magenta";
break;
case "6":
selectColor = "red";
break;
}
ctx.lineCap = 'round';
ctx.lineWidth = 4;
ctx.strokeStyle = selectColor;
var flag = false;
var linePoints = 0;
for (var i = 0; i < count; ++i) {
if (!flag) {
ctx.beginPath();
ctx.moveTo(points[upId][i][0], points[upId][i][1]);
flag = true;
linePoints = 1;
}
else {
if (points[upId][i][0] <= 0) {
if (linePoints > 1) {
ctx.stroke();
}
flag = false;
}
else {
ctx.lineTo(points[upId][i][0], points[upId][i][1]);
linePoints++;
}
}
}
if (flag && linePoints > 1) {
ctx.stroke();
}
}
}
}
MyCanvas.prototype.clearCanvas = function () {
ctx.clearRect(0, 0, canvasObj[0].width, canvasObj[0].height);
}
MyCanvas.prototype.clearAll = function () {
points = { "-1": [] };
this.clearCanvas();
}
return this;
}
//点击返回触发的函数
var currFunc = {
"exit": undefined
};
//登陆成功后界面设置
function loginSuccessViewSet() {
switchLogin(false);
$("#userId").html(userId);
$("#userImage").html("<image src=\"images/user.png\" />");
bindTabs(true);
videoMeetingMsgWindow.userName = userId;
videoMeetingMsgWindow.setShowHideCallBack(1000, null, 1000, function () {
$("#videoMeetingVideoZone").css("width", "100%");
$("#videoMeetingMessageButton").show();
});
superTalkMsgWindow.userName = userId;
superTalkMsgWindow.setShowHideCallBack(1000, null, 1000, function () {
$("#superTalkAudioZone").css("width", "100%");
$("#superTalkMessageButton").show();
});
voipMsgWindow.userName = userId;
voipMsgWindow.setShowHideCallBack(1000, null, 1000, function () {
$("#voipVideoZone").css("width", "100%");
$("#voipMessageButton").show();
});
videoLiveMsgWindow.userName = userId;
videoLiveMsgWindow.setShowHideCallBack(1000, null, 1000, function () {
$("#videoLiveVideoZone").css("width", "100%");
$("#videoLiveMessageButton").show();
});
}
//注销
function starlogout() {
StarRtc.Instance.logout();
bindTabs(false);
$("#userImage").html("");
userId = "";
$("#userId").html("请先登录");
switchLogin(true);
}
function switchLogin(flag) {
$("#login").unbind("click");
$("#login").bind("click", flag ? starlogin : starlogout);
$("#login").html(flag ? "登录" : "退出");
}
function showMainTab() {
activeTab = "main";
$(".tab[id!=mainTab]").hide();
$("#mainTab").slideDown(2000);
}
function showVoipTab() {
activeTab = "voip";
$(".tab").hide();
$("#voipTab").slideDown(2000, enterVoipFunc);
}
function showVideoLiveTab() {
activeTab = "videoLive";
$(".tab").hide();
$("#videoLiveTab").slideDown(2000, enterVideoLiveFunc);
}
function showVideoMeetingTab() {
activeTab = "videoMeeting";
$(".tab").hide();
$("#videoMeetingTab").slideDown(2000, enterVideoMeetingFunc);
}
function showSuperTalkTab() {
activeTab = "superTalk";
$(".tab").hide();
$("#superTalkTab").slideDown(2000, enterSuperTalkFunc);
}
function showSuperVideoTab() {
activeTab = "superVideo";
$(".tab").hide();
$("#superVideoTab").slideDown(2000, enterSuperVideoFunc);
}
function bindTabs(flag) {
if (flag) {
$("#voipButton").bind("click", showVoipTab);
$("#videoLiveButton").bind("click", showVideoLiveTab);
$("#videoMeetingButton").bind("click", showVideoMeetingTab);
$("#superTalkButton").bind("click", showSuperTalkTab);
$("#superVideoButton").bind("click", showSuperVideoTab);
}
else {
$("#voipButton").unbind("click");
$("#videoLiveButton").unbind("click");
$("#videoMeetingButton").unbind("click");
$("#superTalkButton").unbind("click");
$("#superVideoButton").unbind("click");
}
}
function bindEvent() {
$(".backButton").each(function (id, ele) {
$(ele).bind("click", function () {
showMainTab();
if (currFunc.exit != undefined) {
currFunc.exit();
}
});
});
$("#videoLiveApplyButton").bind("click", function () {
videoLiveApplyDialog.dialog("open");
});
$("#videoCanvasButton").bind("click", videoLiveCanvasShow)
$("#videoMeetingCreateButton").bind("click", videoMeetingCreateNewDlg);
$("#videoMeetingMessageButton").bind("click", function () {
$("#videoMeetingVideoZone").css("width", "85%");
$("#videoMeetingVideoZone").css("float", "left");
$("#videoMeetingMessageButton").hide();
videoMeetingMsgWindow.show();
});
$("#superTalkStartTalkButton").bind("click", superTalkStartTalkDlg);
$("#superTalkEndTalkButton").bind("click", superTalkEndTalkDlg);
$("#superTalkCreateButton").bind("click", superTalkCreateNewDlg);
$("#superTalkMessageButton").bind("click", function () {
$("#superTalkAudioZone").css("width", "85%");
$("#superTalkAudioZone").css("float", "left");
$("#superTalkMessageButton").hide();
superTalkMsgWindow.show();
});
$("#videoLiveCreateButton").bind("click", videoLiveCreateNewDlg);
$("#videoLiveMessageButton").bind("click", function () {
$("#videoLiveVideoZone").css("width", "85%");
$("#videoLiveVideoZone").css("float", "left");
$("#videoLiveMessageButton").hide();
videoLiveMsgWindow.show();
});
$("#voipMessageButton").bind("click", function () {
$("#voipVideoZone").css("width", "85%");
$("#voipVideoZone").css("float", "left");
$("#voipMessageButton").hide();
voipMsgWindow.show();
});
$("#voipCalling").bind("click", openCallDlg);
$("#voipHangup").bind("click", hangupVOIP);
$("#voipSmallVideo").bind("click", switchVoipVideo);
$("#voipBigVideo").bind("click", switchVoipVideo);
$("#videoMeetingVideoCtrl").bind("click", videoMeetingSelfVideoCtrl);
$("#videoMeetingAudioCtrl").bind("click", videoMeetingSelfAudioCtrl);
}
//////////////////////////////////////////////star box////////////////////////////////////////
function starlogin(evt, _userId) {
//userId随机生成,类型为字符串
if (_userId == undefined) {
_userId = "" + (Math.floor(Math.random() * 899999) + 100000);
}
userId = _userId;
$("#userImage").html("<div class=\"rect1\"></div>\n<div class=\"rect2\"></div>\n<div class=\"rect3\"></div>\n<div class=\"rect4\"></div>\n<div class=\"rect5\"></div>");
setCookie("starrtc_userId", userId, null);
//登录
starRtcLogin(agentId, userId, starRtcLoginCallBack);
}
//登录时传入的回调函数,IM,群组,系统消息在此回调中处理
function starRtcLoginCallBack(data, status) {
switch (status) {
//链接状态
case "connect success":
break;
case "connect failed":
alert("登录连接失败!");
break;
case "connect closed":
break;
//收到登录消息
case "onLoginMessage":
if (data.status == "success") {
loginSuccessViewSet();
}
console.log("login:" + data.status);
break;
//收到IM消息
case "onSingleMessage":
var fid = data.fromId;
voipMsgWindow.displayMessage(data.fromId, data.msg.contentData, false);
break;
//收到群组消息
case "onGroupMessage":
break;
//收到群组私聊消息
case "onGroupPrivateMessage":
break;
//收到群组推送消息
case "onGroupPushMessage":
break;
//收到系统推送消息
case "onSystemPushMessage":
break;
//收到voip消息
case "onVoipMessage":
switch (data.type) {
//收到voip视频呼叫消息
case "voipCall":
$("#callerId").html(data.fromId);
$("#callerType").html("视频");
voipAudio = false;
voipResponseDlg.dialog("open");
break;
//收到voip音频呼叫消息
case "voipAudioCall":
$("#callerId").html(data.fromId);
$("#callerType").html("音频");
voipAudio = true;
voipResponseDlg.dialog("open");
break;
//收到voip挂断消息
case "voipHangup":
voipResponseDlg.dialog("close");
break;
//收到voip拒绝消息
case "voipRefuse":
voipConnectDlg.dialog("close");
$("#callerId").html("");
alert("对方拒绝了通话!");
break;
}
break;
//收到错误消息
case "onErrorMessage":
switch (data.errId) {
//收到重复登录消息
case 2:
alert("您的账号在另外的设备登录,您已经下线");
$(".backButton")[0].click();
starlogout();
break;
}
break;
//收到群组列表回调(仅非AEC)
case "onGetGroupList":
break;
//收到在线人数回调
case "onGetOnlineNumber":
break;
//收到推送群组成员回调(仅非AEC)
case "onGetGroupUserList":
break;
//收到推送群组系统消息回调
case "onGetAllUserList":
break;
//收到推送群组系统消息回调
case "onPushGroupSystemMsgFin":
break;
//收到推送系统消息回调
case "onPushSystemMsgFin":
break;
//收到取消免打扰回调(仅非AEC)
case "onUnsetGroupMsgIgnoreFin":
break;
//收到设置免打扰回调(仅非AEC)
case "onSetGroupMsgIgnoreFin":
break;
//收到移除群组成员回调
case "onRemoveGroupUserFin":
break;
//收到添加群组成员回调
case "onAddGroupUserFin":
break;
//收到删除群组回调
case "onDelGroupFin":
break;
//收到创建群组回调
case "onCreateGroupFin":
break;
//收到发送群组消息回调
case "onSendGroupMsgFin":
break;
}
};
//登录函数
function starRtcLogin(agentId, userId, callBack) {
//获取SDK版本
StarRtc.Instance.version();
//SDK登录函数
StarRtc.Instance.login(agentId, userId, callBack);
}
//////////////////////////////////////////////star box end////////////////////////////////////////
//////////////////////////////////////////////videoMeeting////////////////////////////////////////
//房间列表
var videoMeetingIds;
//当前选中房间下标
var selectVideoMeetingIndex;
var videoMeetingCreateDialog;
var videoMeetingDelDialog;
//分享屏幕标志位
var meetingShareScreen = false;
//当前房间
var currRoom = null;
//流信息,用于切换大小图
var streamInfos = [];
//大图辅助变量
var oldBigVideo = -1;
var nowBigVideo = -1;
function streamInfo() {
this.videoId = "";
this.streamObj = null;
this.switchFlag = false;
}
//初始化
function resetStreamInfos() {
streamInfos = [];
for (var i = 0; i < 7; ++i) {
var stream = new streamInfo();
streamInfos.push(stream);
}
}
//切换大小图
function streamConfigChange(roomSDK, upId) {
if (nowBigVideo == upId) {
nowBigVideo = oldBigVideo;
oldBigVideo = upId
}
else {
oldBigVideo = nowBigVideo;
nowBigVideo = upId;
}
var streamConfig = [];
for (var i in streamInfos) {
var conf = 0;
if (oldBigVideo == nowBigVideo) {
conf = !streamInfos[i].switchFlag ? 2 : 1;
}
else if (i == oldBigVideo) {
conf = 1;
}
else if (i == nowBigVideo) {
conf = 2;
}
else {
conf = streamInfos[i].switchFlag ? 2 : 1
}
streamConfig.push(conf);
}
//切换大小图,streamConfig为数组,1为小图,2为大图[1,2,1,2...],会触发streamConfig回调
roomSDK.streamConfigApply(streamConfig);
}
//将stream中两个video track顺序对调,达到显示另一个流的效果
function switchStream(stream) {
var tracks = [];
stream.getVideoTracks().forEach(function (track) {
tracks.push(track);
stream.removeTrack(track);
});
for (var i = tracks.length - 1; i >= 0; i--) {
stream.addTrack(tracks[i]);
}
}
function switchStreamInfo(streamInfo) {
if (streamInfo) {
streamInfo.switchFlag = !streamInfo.switchFlag;
switchStream(streamInfo.streamObj);
}
}
function setStreamInfo(upId, videoId, stream) {
if (streamInfos[upId]) {
streamInfos[upId].videoId = videoId;
streamInfos[upId].streamObj = stream;
}
}
function getStreamInfo(upId) {
return streamInfos[upId];
}
//当一个上传者被移除后,需要重置该位置的流,否则当下一个上传者使用该位置时,可能会出现流顺序问题导致的显示异常
function resetStreamInfo(streamInfo) {
if (streamInfo.switchFlag) {
switchStreamInfo(streamInfo);
}
}
resetStreamInfos(streamInfos);
//进入视频会议tab
function enterVideoMeetingFunc() {
currFunc.exit = exitVideoMeetingFunc;
$("#videoMeetingList").html("");
loadVideoMeetingList();
}
//获取视频会议列表,AEC,非AEC
function loadVideoMeetingList(_callback) {
$("#videoMeetingList").html("");
//视频会议的两种类型,标准类型,推流类型
var listTypes = [CHATROOM_LIST_TYPE.CHATROOM_LIST_TYPE_MEETING, CHATROOM_LIST_TYPE.CHATROOM_LIST_TYPE_MEETING_PUSH];
//开启AEC时
if (StarRtc.Instance.starConfig.configUseAEC) {
$.get(aecRequestBaseURL + "/list/query.php?listTypes=" + listTypes.join(","), function (data, status) {
if (status === "success") {
var obj = JSON.parse(data);
if (obj.status == 1) {
videoMeetingIds = [];
//数据存储在obj.data中,为数组,单项存储在obj.data[i].data中,为json字符串,解析后结构为{"id", "name", "creator"}
for (var i = 0; i < obj.data.length; i++) {
var item = JSON.parse(decodeURIComponent(obj.data[i].data));
videoMeetingIds.push(item);
$("#videoMeetingList")[0].innerHTML +=
"<div class='button2' onclick='openVideoMeeting(" + i + ")'>" + item.name + "</div>";
}
if (_callback != undefined) {
_callback();
}
} else {
$("videoMeetingList").html("获取失败");
}
} else {
$("videoMeetingList").html("获取失败");
}
});
}
else {
//仅供测试使用
StarRtc.Instance.queryRoom(listTypes, function (status, listData) {
videoMeetingIds = listData;
//数据存储在listData中,为数组,单项结构为{"id", "name", "creator"}
for (var i = 0; i < listData.length; i++) {
var item = listData[i];
$("#videoMeetingList")[0].innerHTML +=
"<div class='button2' onclick='openVideoMeeting(" + i + ")'>" + item.name + "</div>";
}
if (_callback != undefined) {
_callback();
}
});
}
}
//进入视频会议
function openVideoMeeting(index, from) {
if (selectVideoMeetingIndex == index) return;
if (currRoom != null) {
//离开房间
currRoom.leaveRoom();
//断开连接
currRoom.sigDisconnect();
currRoom = null;
}
selectVideoMeetingIndex = index;
//获取视频会议SDK
currRoom = StarRtc.Instance.getVideoMeetingRoomSDK("open", videoMeetingCallBack, { "roomInfo": videoMeetingIds[index] });
//链接
currRoom.sigConnect();
}
//加入视频会议后设置界面
function joinMeetingRoom(meetingInfo) {
$('#videoMeetingTitle').html("");
$('#videoMeetingTitle').html(meetingInfo.name);
if (meetingInfo.creator == userId) {
var delButton = $("<div style=\"width:25px;height:25px;position:absolute;left:10px;top:10px;background-image: url(images/exitMsgWindow.jpg);background-size: cover;cursor:pointer;z-index:1;\"></div>");
delButton.bind("click", function () {
videoMeetingDelDialog.dialog("open");
});
$('#videoMeetingTitle').append(delButton);
}
}
//设置自己的本地视频流显示
function videoMeetingSetStream(object) {
var selfVideo = $("#videoMeetingSelfVideo")[0];
selfVideo.srcObject = object;
selfVideo.play();
$("#videoMeetingSelfVideoCtrl").show();
}
//视频会议回调函数
function videoMeetingCallBack(data, status, oper) {
//视频会议SDK对象
var thisRoom = data.obj;
switch (status) {
//链接状态
case "connect success":
switch (oper) {
case "open":
//创建视频流,会触发onWebrtcMessage中的streamCreated回调
thisRoom.createStream();
break;
case "new":
//创建新房间,会触发onWebrtcMessage中的createChannel回调
thisRoom.createNew();
break;
}
break;
case "connect failed":
case "connect closed":
stopVideoMeeting();
break;
//收到聊天室回调
case "onChatRoomMessage":
switch (data.type) {
//收到加入聊天室回调
case "joinChatRoom":
if (data.status == "success") { }
else {
alert(data.failedStatus);
}
break;
//收到聊天室私聊消息
case "recvChatPrivateMsg":
videoMeetingMsgWindow.displayMessage(data.msg.fromId + "私信", data.msg.contentData, false);
break;
//收到聊天室消息
case "recvChatMsg":
videoMeetingMsgWindow.displayMessage(data.msg.fromId, data.msg.contentData, false);
break;
//收到聊天室被踢消息
case "chatroomUserKicked":
thisRoom.leaveRoom();
alert("你已被踢出房间!");
break;
//收到服务器错误消息
case "serverErr":
alert("服务器错误:" + data.msg);
break;
}
break;
//收到视频相关回调
case "onWebrtcMessage":
switch (data.type) {
//收到流创建回调
case "streamCreated":
if (data.status == "success") {
videoMeetingSetStream(data.streamObj);
switch (oper) {
case "open":
//加入房间
thisRoom.joinRoom();
break;
case "new":
thisRoom.joinRoom();
break;
}
}
else {
alert("获取摄像头视频失败!请检查摄像头设备是否接入!error:" + data.error);
}
break;
//收到src加入房间回调
case "srcApplyUpload":
if (data.status == "success") {
//服务端录屏session id
console.log("recSessionId:" + data.recSessionId);
joinMeetingRoom(data.userData.roomInfo);
}
else {
alert("上传申请失败");
}
console.log("收到srcApplyUpload:" + data.status);
break;
//收到添加新的上传者回调
case "addUploader":
var newVideoId = "webrtc_video_" + data.upUserId;
//data.streamInfo.streamObj中有两个video track(对应大小图),默认情况下是小图video track顺序在前,更换大小图显示时,需要先向服务端发切换消息,切换成功后,再掉换大小图video track 顺序,哪个的顺序在前,显示哪个
setStreamInfo(data.upId, newVideoId, data.streamInfo.streamObj);
videoMeetingAddNewVideo(newVideoId, data.streamInfo.streamObj, function (evt) {
streamConfigChange(thisRoom, data.upId);
});
break;
//收到移除上传者回调
case "removeUploader":
var streamInfo = getStreamInfo(data.upId);
//如果移除的用户是大图,则向服务端发送消息,切换回小图,使得下一位用户占据此位置时,发送的是小图,发送消息后会触发streamConfig回调,在回调中设置大小图流顺序
if (nowBigVideo == data.upId) {
streamConfigChange(thisRoom, data.upId);
}
var newVideoId = streamInfo.videoId;
removeNewVideo($("#videoMeetingVideoZone"), $("#" + newVideoId));
if (data.bigFlag) {
var videos = $("#videoMeetingVideoZone").find("video[id!='videoMeetingSelfVideo']");
if (videos.length > 0) {
videos[videos.length - 1].click();
}
}
break;
//收到删除房间回调(废弃),不会触发,以下代码是正常的删除逻辑,请在回调外使用
case "delChannel":
if (data.status == "success") {
//开启AEC时,只需要在AEC列表中删除,不需要走此回调,也不需要调用对应删除函数,放在这个位置仅为示例
if (StarRtc.Instance.starConfig.configUseAEC) {
$.get(aecRequestBaseURL + "/list/del.php?userId=" + StarRtc.Instance.starUser.userId + "&listType=" + CHATROOM_LIST_TYPE.CHATROOM_LIST_TYPE_MEETING.toString() + "&roomId=" + data.userData.roomInfo.id, function (data, status) {
if (status === "success") {
var obj = JSON.parse(data);
if (obj.status == 1) {
console.log("保存成功")
} else {
console.log("保存失败")
}
} else {
console.log("保存失败")
}
});
}
else {
//仅供测试使用
StarRtc.Instance.delRoom(CHATROOM_LIST_TYPE.CHATROOM_LIST_TYPE_MEETING.toString(), data.userData.roomInfo, function (status) {
console.log("保存" + status);
});
}
videoMeetingDelDialog.dialog("close");
loadVideoMeetingList();
}
else {
alert("删除视频会议失败");
}
break;
//收到创建房间回调
case "createChannel":
if (data.status == "success") {
//开启AEC时,需要在AEC列表中保存房间信息
if (StarRtc.Instance.starConfig.configUseAEC) {
$.get(aecRequestBaseURL + "/list/save.php?userId=" + StarRtc.Instance.starUser.userId + "&listType=" + CHATROOM_LIST_TYPE.CHATROOM_LIST_TYPE_MEETING.toString() + "&roomId=" + data.userData.roomInfo.id + "&data=" + encodeURIComponent(JSON.stringify(data.userData.roomInfo)), function (data, status) {
if (status === "success") {
var obj = JSON.parse(data);
if (obj.status == 1) {
console.log("保存成功")
} else {
console.log("保存失败")
}
} else {
console.log("保存失败")
}
});
}
else {
//仅供测试使用
StarRtc.Instance.reportRoom(CHATROOM_LIST_TYPE.CHATROOM_LIST_TYPE_MEETING.toString(), data.userData.roomInfo, function (status) {
console.log("保存" + status);
});
}
videoMeetingCreateDialog.dialog("close");
loadVideoMeetingList(function () {
var index = -1;
for (var i in videoMeetingIds) {
if (videoMeetingIds[i].id == data.userData.roomInfo.id) {
index = i;
}
}
if (index >= 0) {
selectVideoMeetingIndex = index;
}
else {
selectVideoMeetingIndex = undefined;
}
if (meetingShareScreen) {
//创建屏幕分享流
thisRoom.createScreenCaptureStream();
}
else {
//创建视频流
thisRoom.createStream();
}
});
}
else {
alert("创建失败:" + data.msg);
}
break;
//设置大小图回调
case "streamConfig":
if (data.status == "success") {
if (oldBigVideo == nowBigVideo) {
var streamInfo = getStreamInfo(oldBigVideo);
switchStreamInfo(streamInfo);
break;
}
if (oldBigVideo != undefined) {
var streamInfo = getStreamInfo(oldBigVideo);
switchStreamInfo(streamInfo);
}
if (nowBigVideo != undefined) {
var streamInfo = getStreamInfo(nowBigVideo);
switchStreamInfo(streamInfo);
}
}
else {
}
break;
case "serverErr":
alert("服务器错误:" + data.msg);
break;
}
break;
}
}
//停止视频会议后设置界面
function stopVideoMeeting() {
//流信息,用于切换大小图
resetStreamInfos(streamInfos);
//大图辅助变量
oldBigVideo = -1;
nowBigVideo = -1;
videoMeetingCreateDialog.dialog("close");
videoMeetingDelDialog.dialog("close");
selectVideoMeetingIndex = undefined;
$('#videoMeetingTitle').html("");
$("#videoMeetingSelfVideoCtrl").hide();
$("#videoMeetingVideoZone").children().each(function (ids, ele) {
var video = $(ele).children("video").first();
if (video.attr("id") != "videoMeetingSelfVideo") {
$(ele).remove();
}
else {
video[0].srcObject = null;
}
});
}
//退出视频会议
function exitVideoMeetingFunc() {
if (currRoom != null) {
currRoom.leaveRoom();
currRoom.sigDisconnect();
currRoom = null;
}
}
//添加新的视频对象
function videoMeetingAddNewVideo(newVideoId, stream, clickCallback) {
var parentObj = $("#videoMeetingVideoZone");
var wrapperObj = $("<div></div>");
var videoObj = $("<video id=\"" + newVideoId + "\" style=\"width:100%;height:100%\"></video>");
videoObj.bind("click", clickCallback);
wrapperObj.append(videoObj);
addNewVideo(parentObj, wrapperObj);
videoObj[0].srcObject = stream;
videoObj[0].play();
}
//创建视频会议对话框
function videoMeetingCreateNewDlg() {
$("#newMeetingName").val("网页会议_" + userId);
videoMeetingCreateDialog.dialog("open");
}
//创建视频会议
function videoMeetingCreateNewMeeting() {
var newMeetingName = $("#newMeetingName").val();
if (newMeetingName == "") {
alert("会议室名称不能为空!");
}
else {
if (currRoom != null) {
//离开房间
currRoom.leaveRoom();
//断开连接
currRoom.sigDisconnect();
currRoom = null;
}
var type = $('#meetingTypecheck').is(':checked') ? 1 : 0;
meetingShareScreen = $('#meetingMediaSourceTypeCheck').is(':checked');
//获取视频会议SDK
currRoom = StarRtc.Instance.getVideoMeetingRoomSDK("new", videoMeetingCallBack, {
"roomInfo": {
"creator": userId,