多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
因为进入房间有先后。1、对方是先进入房间的。2、对方是后进入房间的、所以自动打开对方摄像头需要在2处回调那里进行打开。 1、 ~~~ // 用户进入(离开)房间,dwUserId表示用户ID号,bEnterRoom表示该用户是进入(1)或离开(0)房间 function OnAnyChatUserAtRoom(dwUserId, bEnterRoom) { AddLog("OnAnyChatUserAtRoom(userid=" + dwUserId + ", benter=" + bEnterRoom + ")", LOG_TYPE_EVENT); RoomUserListControl(dwUserId, bEnterRoom ? true : false); if (bEnterRoom == 1) { RequestVideoByUserId(dwUserId); ShowNotifyMessage(BRAC_GetUserName(dwUserId) +"&nbspenter room!", NOTIFY_TYPE_NORMAL); } else { ShowNotifyMessage(BRAC_GetUserName(dwUserId) +"&nbspleave room!", NOTIFY_TYPE_NORMAL); for(var i=0;i<list_videouser.length;i++) { if(list_videouser[i]==dwUserId) { BRAC_UserCameraControl(dwUserId, 0); // 打开对方视频 BRAC_UserSpeakControl(dwUserId, 0); // 打开对方音频 list_videouser[i]=0; list_videosite[i]=0; GetID("div_username"+i).innerHTML="当前没有人"; break; } } } DisplayScroll("room_div_userlist"); } ~~~ 2、 ~~~ // 收到当前房间的在线用户信息,进入房间后触发一次,dwUserCount表示在线用户数(包含自己),dwRoomId表示房间ID function OnAnyChatRoomOnlineUser(dwUserCount, dwRoomId) { AddLog("OnAnyChatRoomOnlineUser(count=" + dwUserCount + ", roomid=" + dwRoomId + ")", LOG_TYPE_EVENT); var useridlist = BRAC_GetOnlineUser(); for (var i = 0; i < useridlist.length; i++) { RoomUserListControl(useridlist[i], true); } onVideoScreenChange(); //调用打开摄像头并显示。 } ~~~ ~~~ function onVideoScreenChange() { //alert("hello select"); var div = GetID("AnyChatRemoteVideoDiv"); while(div.hasChildNodes()) //当div下还存在子节点时 循环继续 { div.removeChild(div.firstChild); } var objectDiv=GetID("videoscreensetting"); var videoCount=parseInt(objectDiv.options[(objectDiv.selectedIndex)].value); list_videouser=new Array(); list_videosite=new Array(); //创建分屏所需要的div for(var i=0;i<videoCount;i++) { // 创建用户视频面板的div var div_videosite = document.createElement("div"); div_videosite.id="div_videosite"+i; div_videosite.className = "CLASS_VIDEOSCREEN"+videoCount; // 创建视频用户姓名的div var div_username = document.createElement("div"); div_username.id="div_username"+i; div_username.className = "CLASS_VIDEOSCREEN_USERNAME"+videoCount; div_videosite.appendChild(div_username); // 创建用户视频区域的div var div_videoarea = document.createElement("div"); div_videoarea.id="div_videoarea"+i; div_videoarea.className = "CLASS_VIDEOSCREEN_VIDEOAREA"+videoCount; div_videosite.appendChild(div_videoarea); div.appendChild(div_videosite); list_videosite[i]=0; list_videouser[i]=0; } //显示视频 var useridlist = BRAC_GetOnlineUser(); var count=0; for(var i=0;i<useridlist.length;i++){ if(count>=videoCount) break; BRAC_SetVideoPos(useridlist[i], GetID("div_videoarea"+i), "ANYCHAT_VIDEO_REMOTE"+i);// 设置视频显示位置 BRAC_UserCameraControl(useridlist[i], 1); // 打开对方视频 BRAC_UserSpeakControl(useridlist[i], 1); // 打开对方音频 GetID("div_username"+i).innerHTML=BRAC_GetUserName(useridlist[i]); list_videouser[i]=useridlist[i]; list_videosite[i]=1; count++; } if(count<videoCount){ for(var i=0;i<videoCount-count;i++){ BRAC_SetVideoPos(0, GetID("div_videoarea"+(i+count)), "ANYCHAT_VIDEO_REMOTE"+(i+count));// 设置视频显示位置 GetID("div_username"+(i+count)).innerHTML="当前没有人"; } } } ~~~ 涉及相关function处理方式 ~~~ function RequestVideoByUserId(dwUserId) { var site=-1; for(var i=0;i<list_videosite.length;i++) { if(list_videosite[i]==0) { site=i; break; } } if(site<0) return; var bHashed=false; for(var i=0;i<list_videouser.length;i++) { if(list_videouser[i]==dwUserId) { bHashed=true; break; } } if(!bHashed) { BRAC_SetVideoPos(dwUserId, GetID("div_videoarea"+site), "ANYCHAT_VIDEO_REMOTE"+site);// 设置视频显示位置 BRAC_UserCameraControl(dwUserId, 1); // 打开对方视频 BRAC_UserSpeakControl(dwUserId, 1); // 打开对方音频 GetID("div_username"+site).innerHTML=BRAC_GetUserName(dwUserId); list_videouser[site]=dwUserId; list_videosite[site]=1; } } ~~~