2 lines
3.0 KiB
JavaScript
2 lines
3.0 KiB
JavaScript
(function(local){let courseData={},isConnect,avaList,pageSize=200,page=1,cameraList,total;const step=16;let openCam=[];$(function(){$(document).on("click",".js_change_btn",function(){const e=$(this),a=e.data("type");if(a==="pre"){page-=1;let t=page===1;$(".js_change_btn").prop("disabled",!1),e.prop("disabled",t)}else if(a==="next"){page+=1;let t=page===total;$(".js_change_btn").prop("disabled",!1),e.prop("disabled",t)}openCamera()})}),window.onload=function(){$.ajax({url:"/api/course/getCourseWareInfo",headers:{token:getUrlParms("key")},data:{courseWareId:getUrlParms("cwid")},type:"GET",dataType:"json",success:function(e){var a=e.success;if(a){if(courseData=e.data||{},window.setCameraUser){const{loginUserId:t=""}=courseData;setCameraUser(t)}initWebSocket()}}})};var ws=null,pingTime=null,myUid="",protocolStr=document.location.protocol,portName=document.location.port;function initWebSocket(){var e="",a=portName?":"+portName:"",t=e?e+""+a:location.host;if(protocolStr=="http:")var n="ws://"+t+"/api/webchat/"+getUrlParms("cwid");else var n="wss://"+t+"/api/webchat/"+getUrlParms("cwid");ws=new ReconnectingWebSocket(n),ws.onopen=onopen,ws.onclose=onclose,ws.onerror=onerror,ws.onmessage=onmessage}function getUrlParms(e){var a=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),t=window.location.search.substr(1).match(a);return t!=null?unescape(t[2]):null}function openCamera(){const e=page*step,a=openCam;openCam=cameraList.slice(e-step,e),page=page>total?1:page,ws.send(JSON.stringify({type:"allCamera",uid:a,open:!1})),setTimeout(()=>{ws.send(JSON.stringify({type:"allCamera",uid:openCam,open:!0}))},300),console.log("openCam",openCam),console.log("closeCam",a)}function getCameraList(e={}){const a=e.camera_list||[];cameraList=a.map(t=>t.uid),avaList=a,total=Math.ceil(cameraList.length/step),$(".js_btn_pre").prop("disabled",!0),total<=1?$(".js_change_btn").hide():$(".js_change_btn").show(),openCamera()}function sendAvaList(){ws.send(JSON.stringify({type:"cameraAvaList",pageSize,page}))}function onopen(){isConnect=!0;var e={type:"allCameraInit",token:getUrlParms("key")};ws.send(JSON.stringify(e)),sendAvaList()}function onclose(e){isConnect=!1,console.log("\u65AD\u5F00")}function onerror(e){isConnect=!1,console.log(e)}function onmessage(e){var data=eval("("+e.data+")");switch(console.log("socket:",data),data.type){case"pong":clearTimeout(pingTime),pingTime=setTimeout(function(){var a={};a.type="ping",ws.send(JSON.stringify(a))},4e4);break;case"allCameraInit":const{loginUserId:e}=courseData;loginRtc(e),ws.send(JSON.stringify({type:"ping"}));break;case"close_camera":for(var i=0;i<camList.length;i++)camList[i].client_id===data.client_id&&camList.splice(i,1);data.interactCount==0&&leaveRoom(),removeLoading(data.uid);break;case"leave":myUid==data.uid&&xxObject.Call("0");break;case"cameraAvaList":getCameraList(data);break;default:break}}function getAvaCameraList(){return avaList||[]}function stopCamera(){ws.send(JSON.stringify({type:"allCamera",uid:openCam,open:!1}))}window.getAvaCameraList=getAvaCameraList,window.leaveXxObjectAction=function(){stopCamera()}})(window);
|