filesbox/web/dist/design/designstatic/newJS/chatroom/wap/live_wap.js
2024-07-26 14:10:54 +08:00

2 lines
17 KiB
JavaScript

var socketEmu={a:"groupMsg",b:"chatlist",e:"mixcurrent",f:"barrage",g:"closeBarrage"};function singleType(e){var t=e[0],s=e[2]||new Date().getTime(),a=e[1]||"",o=e[3]||"",n=e[4]||"",r=e[5]||"",c=e[6]||"",l={type:socketEmu[t],timestamp:s,content:a,userOnline:{uid:o,groupid:n,name:r,avatar:c}};return l}function socketTypeChange(e){if(Array.isArray(e)){var t=e[0];if(socketEmu[t]==="chatlist"){var s=e.slice(1),a=[];return s.forEach(function(o){a.push(singleType(o))}),{type:"chatlist",chatlist:a}}return socketEmu[t]==="barrage"?{type:"barrage",color:e[3],position:e[2],text:e[1]||"",uid:e[4],name:e[5],avatar:e[6],groupId:e[7]}:socketEmu[t]==="closeBarrage"?{type:"closeBarrage",isOpen:e[1]}:socketEmu[t]==="mixcurrent"?{type:"mixcurrent",isOpen:e[1]}:socketEmu[t]?singleType(e):e}else return e}function LiveOperation(){var e=this;e.init()}LiveOperation.prototype={init:function(){var e=this;layui.config({base:"/design/designstatic/chatroom/wap/js/",version:"000000000"}),layui.use(["chatroom","element"],function(t){e.chatroom=t,element=layui.element(),e.$=layui.jquery,e.allowSend=!0,e.blackSend=!0,e.isAdd=!0,e.pingTime=null,e.courseWareId=e.getUrlParms("cwid"),e.courseId=e.getUrlParms("courseId"),e.token=$.cookie("token"),e.tokenState=0,e.tabArrNum=1,e.relationCount=null,e.wareInfo=null,e.getClassData(),e.chatroom.on("init",function(s){e.initCallback(e,s)}),e.chatroom.on("sendGroupMessage",function(s){e.groupMessageCallback(e,s)}),e.chatroom.on("sendMessage",function(s){e.messageCallback(e,s)}),e.chatroom.on("getChatListFun",function(s){e.chatListCallback(e,s)}),$(window).ready(function(){setTimeout(function(){e.selfZoom()},500),$("#group-msg-input").on("keyup",function(){e.inputNum(this)})}),$(window).resize(function(){setTimeout(function(){e.selfZoom()},500)})})},setNotice:function(e){var t=e.notice||"";if(t.length>0){var s='<div class="studio_notice_box js_notice_box"><div class="header js_play_notice">\u516C\u544A<div class="close_Btn_notice"></div></div><div class="studio_notice js_studio_notice"></div></div>';$("#content-list").append(s),$(".js_studio_notice").text(t)}},getClassData:function(){var e=this;$.ajax({url:"/api/course/getCourseWareInfo",headers:{token:e.token},data:{courseWareId:e.courseWareId,needSchoolName:"1"},type:"GET",dataType:"json",success:function(t){var s=t.success;if(s){var a=t.data;a.timeStamp=t.timeStamp,a.courseId=e.courseId,a.isBarrage||$(".live_wap_bar").hide(),a.mixV&&(a.oriDocPlay=a.httpDocPlay,a.httpDocPlay=a.httpMixedPlay),e.getIsPay.call(e,a),e.setNotice(a),e.setCourseInfo.call(e,a),e.wareInfo=a}else if(t.code=="401")if($.cookie("stoken")&&e.tokenState==0)e.token=$.cookie("stoken"),e.tokenState=1,console.log("stoken"),e.getClassData();else if($.cookie("atoken")&&e.tokenState==1)e.token=$.cookie("atoken"),e.tokenState=2,console.log("atoken"),e.getClassData();else{var o="&redirect=/liveclass/wap/livecourse.html&cwid="+e.courseWareId+"&courseId="+e.courseId;window.location.href=location.protocol+"//"+location.host+"/pages/wap/info.html?cid="+e.courseId+""+o}else{var n=t.message;layer.msg(n)}}})},setCourseInfo:function(e){window.sessionStorage&&localStorage.setItem("courseInfo",JSON.stringify(e))},getIsPay:function(e){var t=this;$.ajax({url:"/api/course/checkUserViewRight",headers:{token:this.token},data:{courseWareId:this.courseWareId,courseId:this.courseId},type:"GET",dataType:"json",success:function(s){var a=s.data,o=a.checkViewRight,n=a.userType;if(e.userType=n,e.token=t.token,o)t.courseData=e,t.liveInit.call(t);else{console.log("\u672A\u8D2D\u4E70");var r="&redirect=/liveclass/wap/livecourse.html&cwid="+t.courseWareId+"&courseId="+t.courseId;window.location.href=location.protocol+"//"+location.host+"/pages/wap/info.html?cid="+t.courseId+""+r}}})},liveInit:function(){var e=this.courseData;this.setOptions(),this.setIntoSign(),this.setTab(e),this.addPlay=new PlayMethod(e),this.addAttachment=new AttachmentWap(e),this.connect(),this.getOtherCount(),e.userType==1&&this.getExamList()},setTab:function(e){(e.courseWareType=="1"||e.courseWareType=="3")&&(this.tabArrNum++,$(".videolist").show()),e.isOpenAnswer==1&&(this.tabArrNum++,$(".answer_tab").show()),e.userType==1&&e.isOpenStudent==1&&(this.tabArrNum++,$(".works_tab").show()),this.setTabOnceW()},setTabOnceW:function(){},setOptions:function(){var e=this.courseData.loginHeadPortrait,t=this.courseData.loginName,s=this.courseData.loginNickname,a=this.courseData.loginRealName,o=this.courseData.realName,n=this.courseData.courseWareName,r=this.courseData.introduce;this.courseData.loginName=t?this.setEscape(t):"",this.courseData.loginNickname=s?this.setEscape(s):"",this.courseData.loginRealName=a?this.setEscape(a):"",this.courseData.loginHeadPortrait=e?this.setEscape(e):"",this.courseData.realName=o?this.setEscape(o):"",this.courseData.courseWareName=n?this.setEscape(n):"",this.courseData.introduce=r?this.setEscape(r):""},setIntoSign:function(){var e="\u7528\u6237"+this.courseData.loginUserId+"\u8FDB\u5165\u8BFE\u4EF6\uFF1A"+this.courseData.courseWareId;window.Sentry&&Sentry.captureMessage(e,"info")},setEscape:function(e){var t=document.createElement("div"),s=document.createTextNode(e);return t.appendChild(s),t.innerHTML},connect:function(){var e=document.location.protocol,t=443,s="",a=t?":"+t:"",o=s?s+""+a:location.host,n="";if(this.courseData.userType==1?n="/api/webchat/student/":n="/api/webchat/teacher/",e=="http:")var r="ws://"+o+""+n+""+this.courseWareId;else var r="wss://"+o+""+n+""+this.courseWareId;this.ws=new ReconnectingWebSocket(r),this.ws.onopen=this.onopen.bind(this),this.ws.onmessage=this.onmessage.bind(this),this.ws.onerror=this.onerror.bind(this),this.ws.onclose=this.onclose.bind(this)},onopen:function(){if(!this.courseData.loginUserId&&(this.courseData.isPublic||!parseInt(this.courseData.courseId))){var e=window.localStorage.getItem("visitorIdEncrypt")||this.visitorIdEncrypt(this.randomNum(0,99999999999));window.localStorage.setItem("visitorIdEncrypt",e),this.sendFun({type:"loginPublic",visitorIdEncrypt:e});return}var t={type:"login",token:this.token,ebhbrowser:!1,mic:!1,cam:!1};if(window._AgentInfo){var s=_AgentInfo.OSname+" "+_AgentInfo.browserName;t.c_t=s}this.sendFun(t),this.socketNum++,this.socketNum>=3&&this.courseData.loginUserId&&layer.msg("\u804A\u5929\u670D\u52A1\u5DF2\u91CD\u65B0\u8FDE\u63A5")},onclose:function(e){this.socketNum==3&&layer.msg("\u60A8\u5DF2\u4E0E\u804A\u5929\u670D\u52A1\u5668\u65AD\u5F00\u8FDE\u63A5"),console.log("\u65AD\u5F00")},onerror:function(e){console.log(e)},onmessage:function(e){var preData=eval("("+e.data+")"),data=socketTypeChange(preData);switch(data.type){case"pong":this.socketPing(data);break;case"login":this.socketLogin(data);break;case"init":this.socketInit(data);break;case"groupMsg":var selfUid=this.chatroom.me().uid,uid=data.userOnline.uid;selfUid!=uid&&this.socketGroupMsg(data);break;case"friendMsg":this.socketFriendMsg(data);break;case"unableQuestions":this.socketUnableQes(data);break;case"enableQuestions":this.socketEnableQes(data);break;case"chatlist":this.socketChatlist(data);break;case"take_off":this.closeWindow();break;case"leave":this.socketLeave(data);break;case"loginPublic":this.socketPublicInit(data);break;case"repeat_login":var _this=this;layer.msg("\u5F53\u524D\u8D26\u53F7\u5DF2\u5728\u522B\u5904\u4E0A\u7EBF\uFF0C\u60A8\u88AB\u8FEB\u4E0B\u7EBF\u3002"),setTimeout(function(){_this.ws.close()},1e3);break;case"tips":this.chatroom.newMsgTips(data);break;case"gag":this.socketGag(data);break;case"updateCourse":this.socketGag(data);break;case"classover":this.socketClassover(data);break;case"add_black_list":this.socketAddBlacklist(data);break;case"del_black_list":this.socketDelBlacklist(data);break;case"saveStuLog":var logid=data.logId;this.addPlay.logid=logid;break;case"saveLiveSign":this.addPlay.setCourseSignInArr();break;case"askformic":this.sendFun({type:"hasmic",ishasmic:!1});break;case"mixcurrent":this.mixFlow(data);break;case"barrage":this.socketDM(data);var databarrage={content:data.text,isbarrage:1,timestamp:0,type:"groupMsg",userOnline:{avatar:data.avatar,groupid:data.groupId,name:data.name,uid:data.uid}};this.socketGroupMsg(databarrage);break;case"closeBarrage":this.socketCloseDM(data);break}},sendFun:function(e){this.ws.send(JSON.stringify(e))},socketCloseDM:function(e){e.isOpen?$(".live_wap_bar").show():($(".live_wap_bar").hide(),$("#danmu").hide())},socketDM:function(e){var t=this.chatroom.me().uid,s=e.uid===t;e.isMy=s,acceptDM(e)},socketPing:function(e){var t=this;clearTimeout(t.pingTime),t.pingTime=setTimeout(function(){var s={};s.type="ping",t.sendFun(s)},9e4),this.addPlay.setViewRecord&&this.addPlay.setViewRecord("set")},socketLogin:function(e){this.chatroom.newUserJoin(e),$(".tall_list_once").length<120&&this.chatroom.addOnlineList(e.userinfo,!1),this.chatroom.setOnlineCount(e.online_count)},mixFlow:function(e){var t=e.isOpen,s=this,a=this.wareInfo,o=a.mixV;t&&!o?s.changeFlv(a.httpMixedPlay):!t&&o&&s.changeFlv(a.oriDocPlay)},changeFlv:function(e){this.addPlay.switchFlv(e)},socketInit:function(e){var t=this.addPlay.review,s=$("#online_list_"+e.userinfo.client_id);if(e.userinfo.takeoff&&t!=1&&this.closeWindow(),e.course=this.courseData,this.chatroom.init(e),this.chatroom.flushOnlineList(e.client_list,e.online_count),$(".tall_list_once[data-blacklist=1]").find(".online_blackRadius").css("display","block"),e.camera_list.length>0)for(i=0;i<e.camera_list.length;i++)this.chatroom.addUserCamera(e.camera_list[i]);if(e.room_config.gag&&(this.groupMsgState(!0),this.remind.call(this,"\u7BA1\u7406\u5458\u5DF2\u5173\u95ED\u7FA4\u804A\u529F\u80FD")),e.userinfo.is_black_list&&(this.gagState(s),this.remind.call(this,"\u60A8\u5DF2\u88AB\u52A9\u6559\u5C4F\u853D\u53D1\u8A00")),!e.userinfo.questions){var a=$("#answerIframe").contents().find("#mobileAddBox");a.css("background","#d9d9d9"),this.isAdd=!1,this.remind.call(this,"\u60A8\u5DF2\u88AB\u7981\u6B62\u63D0\u95EE")}this.sendFun({type:"ping"})},socketPublicInit:function(e){var t=this;e.course=t.courseData,e.camera_list=e.camera_list||[],this.chatroom.initPublic(e),this.chatroom.flushOnlineList(e.client_list,e.online_count),this.sendFun({type:"ping"})},socketGroupMsg:function(e){this.chatroom.appendMessage(e)},socketFriendMsg:function(e){},socketEnableQes:function(e){var t=$("#answerIframe").contents().find("#mobileAddBox");t.css("background","#1890ff"),this.isAdd=!0,this.remind.call(this,"\u7981\u6B62\u63D0\u95EE\u5DF2\u88AB\u53D6\u6D88")},socketUnableQes:function(){var e=$("#answerIframe").contents().find("#mobileAddBox");e.css("background","#d9d9d9"),this.isAdd=!1,this.remind.call(this,"\u60A8\u5DF2\u88AB\u7981\u6B62\u63D0\u95EE")},socketChatlist:function(e){var t=e.chatlist;this.chatroom.beforeMessage(t)},socketLeave:function(e){this.chatroom.userLeave(e),this.chatroom.setOnlineCount(e.online_count)},newMsgTips:function(e){this.chatroom.newMsgTips(e)},socketGag:function(e){var t=$("#online_list_"+this.chatroom.me().uid);if(this.chatroom.setGagStatus(e.gag),e.gag)this.groupMsgState(e.gag),t.attr("gag","true");else{if(t.attr("gag","false"),t.attr("data-blacklist")=="1")return;(t.attr("data-blacklist")=="0"||!t.attr("data-blacklist"))&&(this.groupMsgState(e.gag),t.attr("gag","false"))}},socketClassover:function(e){var t=this,s=this.randomNum(0,3)*1e3;this.courseData.userType==1&&(this.addPlay.isLiveNum=0,this.addPlay.isStart=!1,this.addPlay.isBtn=!1,setTimeout(function(){t.addPlay.getFeedback(0),t.addPlay.studyData(1)},s))},socketAddBlacklist:function(e){if(e.uid==this.chatroom.me().uid){var t=$("#online_list_"+e.uid);this.gagState(t),this.remind.call(this,"\u60A8\u5DF2\u88AB\u52A9\u6559\u5C4F\u853D\u53D1\u8A00")}},socketDelBlacklist:function(e){if(e.uid==this.chatroom.me().uid){var t=$("#online_list_"+e.uid);this.noGagState(t),this.remind.call(this,"\u60A8\u5DF2\u88AB\u53D6\u6D88\u5C4F\u853D\uFF0C\u53EF\u4EE5\u53D1\u8A00\u4E86")}},initCallback:function(e,t){var s=t.cache.room_config.allow_raise,a=t.cache.room_config.gag;a?e.closeState($(".gag"),"gag"):e.waitState($(".gag"),"gag")},groupMessageCallback:function(e,t){if($(".text_font_num>span").html("0"),e.ws.readyState==1){e.sendFun(t);var s={};s.userOnline=e.chatroom.me(),s.content=t.content,s.type=t.type,s.timestamp=new Date().getTime(),e.chatroom.appendMessage(s)}else layer.msg("\u60A8\u5DF2\u548C\u804A\u5929\u670D\u52A1\u5668\u65AD\u5F00\u8FDE\u63A5,\u65E0\u6CD5\u53D1\u9001")},chatListCallback:function(e,t){var s=e.ws;s.readyState==1?t.state=="true"&&e.sendFun({type:"chatlist"}):layer.msg("\u60A8\u5DF2\u548C\u804A\u5929\u670D\u52A1\u5668\u65AD\u5F00\u8FDE\u63A5,\u65E0\u6CD5\u53D1\u9001")},sendMessage:function(){},remind:function(e,t){t!=null?data={type:"tips",content:e,isth:t}:data={type:"tips",content:e},this.chatroom.newMsgTips(data)},getUrlParms:function(e){var t=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),s=window.location.search.substr(1).match(t);return s!=null?unescape(s[2]):null},randomNum:function(e,t){var s=t-e+1,a=Math.floor(Math.random()*s+e);return a},selfZoom:function(e){var t=$("body").width()/(16/9),s=$("body").height()-t,a=$(".layui-tab-title").height(),o=$(".tall_text").height(),n=s-a+"px",r=s-a-o+"px";$("#tall_all").css("height",s+"px"),$(".layui-tab-content").css("height",n),$("#content-list").css("height",r),$(".show_content").css("height",n)},closeState:function(e,t){e.removeClass(t+"_back_open"),e.removeClass(t+"_back_statr"),e.addClass(t+"_back_on")},openState:function(e,t){e.removeClass(t+"_back_on"),e.removeClass(t+"_back_statr"),e.addClass(t+"_back_open")},waitState:function(e,t){e.removeClass(t+"_back_open"),e.removeClass(t+"_back_on"),e.addClass(t+"_back_statr")},groupMsgState:function(e){e?($(".send_btn").removeClass("chat_send"),$(".send_btn").addClass("gag_send"),$(".send_btn").attr("chatroom-event",""),$(".group_chat_img").attr("disabled",!0)):($(".send_btn").removeClass("gag_send"),$(".send_btn").addClass("chat_send"),$(".send_btn").attr("chatroom-event","sendGroup"),$(".group_chat_img").attr("disabled",!1))},gagState:function(e){e.attr("data-blacklist","1"),$(".send_btn").removeClass("chat_send"),$(".send_btn").addClass("gag_send"),$(".send_btn").attr("chatroom-event",""),$(".group_chat_img").attr("disabled",!0),this.blackSend=!1},noGagState:function(e){$(e).attr("data-blacklist","0"),(e.attr("gag")=="false"||e.attr("gag")==null)&&($(".send_btn").removeClass("gag_send"),$(".send_btn").addClass("chat_send"),$(".send_btn").attr("chatroom-event","sendGroup"),$(".group_chat_img").attr("disabled",!1)),this.blackSend=!0},getOtherCount:function(){var e=this,t=this.courseData.userType;$.ajax({url:"/api/course/findCWRelationCount",type:"GET",headers:{token:this.token},data:{courseWareId:this.courseWareId},dataType:"json",success:function(s){var a=s.success;if(a){var o=s.data,n=o.fileCount,r=o.answeringQuestionCount;e.relationCount=o;var c=$(".attachment_tab").css("display");if(n>0){var l=n>99?"99+":n;c=="none"&&e.tabArrNum++,$(".attachment_tab").show()}else c!="none"&&e.tabArrNum--,$(".attachment_tab").hide();if(r>0){var u=r>99?"99+":r;$(".answer_num").html(u),$(".answer_num").show()}else $(".answer_num").hide();e.setTabOnceW.call(e)}t==1&&e.getExamCount.call(e)}})},getExamCount:function(){var e=this,t=this.courseData.userType;$.ajax({url:"/api/homework/findCWHomeworkCount",type:"GET",headers:{token:this.token},data:{courseWareId:this.courseWareId},dataType:"json",success:function(s){var a=s.success;if(a){var o=s.data,n=o.homeworkCount;e.relationCount.homeworkCount=n;var r=$(".exam_tab").css("display");if(n>0&&t==1){var c=n>99?"99+":n;r=="none"&&e.tabArrNum++,$(".exam_num").html(c),$(".exam_tab").show(),$(".exam_num").show()}e.setTabOnceW.call(e)}}})},getExamList:function(){var e=this,t=this.courseData.userType,s,a=t==1?"/api/homework/getUserHomeworkList":"/api/homework/homeworkListByCondition";t==1?s={currentPage:1,pageSize:10}:s={pageNum:1,pageSize:10,state:"1",homeworkType:"1"},s.courseWareId=this.courseWareId,$.ajax({type:"GET",headers:{token:this.token},url:a,data:s,dataType:"json",success:function(o){var n=o.success;if(n){var r=o.data.list,c=$(".exam_tab").css("display");r&&r.length?(c=="none"&&e.tabArrNum++,$(".exam_tab").show()):c!="none"&&(e.tabArrNum--,$(".exam_tab").hide()),e.setTabOnceW.call(e)}}})},inputNum:function(e){var t=e.value,s=e.value.length;s>100&&(t=t.substring(0,100),$("#group-msg-input").val(t),s=100),$(".text_font_num>span").html(s)},closeWindow:function(){var e=this;layer.msg("\u4F60\u5DF2\u88AB\u79FB\u51FA\u6559\u5BA4\uFF0C5\u5206\u949F\u540E\u53EF\u4EE5\u91CD\u65B0\u8FDB\u5165\u6559\u5BA4"),setTimeout(function(){var t=new Date().getTime();return e.ws.close(),window.location.href=window.location.origin+"/myroom/#/learn/center?time="+t,!1},3e3)},sendDm:function(e){this.sendFun(e)},randomNum:function(e,t){switch(arguments.length){case 1:return parseInt(Math.random()*e+1,10);case 2:return parseInt(Math.random()*(t-e+1)+e,10);default:return 0}},visitorIdEncrypt:function(e){var t=CryptoJS.enc.Utf8.parse("OQKAnpEaoB7ZG69Y"),s=CryptoJS.enc.Utf8.parse(e),a=CryptoJS.AES.encrypt(s,t,{mode:CryptoJS.mode.ECB,padding:CryptoJS.pad.Pkcs7});return a.toString()}};var liveObj=new LiveOperation;