2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{a as k}from"./live-student.aec0e85f.js";import{n as g}from"./vueComponentNormalizer.9ef17bb1.js";const $={data:()=>({msg:"",msg_list:[],user_list:[],currentUser:{},room:{}}),created(){var e;this.currentUser=JSON.parse(JSON.stringify((e=this.$store)==null?void 0:e.user,["id","name","photo"])),this.roomId=this.$route.query.id,this.getAllUserList()},activated(){this.getAllUserList()},deactivated(){this.ws_leave_live_room()},beforeDestroy(){this.ws_leave_live_room()},methods:{async getAllUserList(){const{data:e}=await k(this.roomId);this.user_list=e,this.get_room_users(),console.log(e)},initLiveRoom(e){this.$store.ws.on("received_live_msg",s=>{this.msg_list.push(s),s.type==="finish"&&this.$router.replace("/online-course/live-in-class").then(()=>{location.reload()}),this.$nextTick(()=>{this.$refs.roomList.scrollTop=this.$refs.roomList.scrollHeight})}),this.$store.ws.on("room_info",({users:s})=>{this.user_list=this.user_list.map(t=>({...t,status:0})),s.forEach(t=>{const i=this.user_list.find(n=>n.id===t.id);i&&(i.status=1)}),this.user_list.sort((t,i)=>i.status-t.status)}),this.ws_join_live_room(e)},ws_send_live_msg(e,s){this.$store.ws.emit("send_live_msg",{from:this.currentUser,roomId:+this.roomId,type:"msg",msg:this.msg,...e},t=>{this.msg_list.push(t),this.$nextTick(()=>{this.$refs.roomList.scrollTop=this.$refs.roomList.scrollHeight}),s==null||s(t)}),this.msg=""},ws_join_live_room(e){this.$store.ws.emit("join_live_room",{from:this.currentUser,type:"join",roomId:+this.roomId},s=>{this.msg_list.push(s),this.get_room_users(),e==null||e(s)})},get_room_users(){this.$store.ws.emit("find_room_info",+this.roomId,e=>{this.user_list=this.user_list.map(s=>({...s,status:0})),e.users.forEach(s=>{const t=this.user_list.find(i=>i.id===s.id);t&&(t.status=1)}),this.user_list.sort((s,t)=>t.status-s.status)})},ws_leave_live_room(e){this.isJoinRoom=!1,this.$store.ws.emit("leave_live_room",{from:this.currentUser,type:"leave",roomId:+this.roomId},e)},ws_finish_live(e){this.ws_send_live_msg({type:"finish"},e)}}};var T=function(){var e=this,s=e.$createElement,t=e._self._c||s;return t("div",{staticClass:"chat-layout"},[t("el-tabs",{attrs:{stretch:!0},on:{"tab-click":e.handleClick},model:{value:e.activeChatListOrUser,callback:function(i){e.activeChatListOrUser=i},expression:"activeChatListOrUser"}},[t("el-tab-pane",{attrs:{label:"\u804A\u5929\u4E92\u52A8",name:"chat"}}),t("el-tab-pane",{attrs:{label:"\u89C2\u770B\u4EBA\u5458",name:"user"}})],1),t("div",{directives:[{name:"show",rawName:"v-show",value:e.activeChatListOrUser=="chat",expression:"activeChatListOrUser == 'chat'"}],ref:"roomList",staticClass:"room-list chat-list"},e._l(e.msg_list,function(i,n){return t("div",{key:n},[i.type=="msg"&&i.from.id!==e.userId?t("div",{staticClass:"chat-item"},[t("span",{staticClass:"user-name"},[e._v(e._s(i.from.name)+"\uFF1A")]),e._v(e._s(i.msg)+" ")]):e._e(),i.type=="msg"&&i.from.id==e.userId?t("div",{staticClass:"chat-item chat-item-my"},[t("span",{staticClass:"user-name"},[e._v(e._s(i.from.name)+"\uFF1A")]),e._v(e._s(i.msg)+" ")]):e._e(),i.type==="join"?t("div",{staticClass:"chat-item chat-item-join"},[t("span",[e._v(e._s(i.from.name))]),e._v("\u52A0\u5165\u4E86\u623F\u95F4 ")]):e._e(),i.type==="leave"?t("div",{staticClass:"chat-item chat-item-leave"},[t("span",[e._v(e._s(i.from.name))]),e._v("\u79BB\u5F00\u4E86\u4E86\u623F\u95F4 ")]):e._e()])}),0),t("div",{directives:[{name:"show",rawName:"v-show",value:e.activeChatListOrUser=="user",expression:"activeChatListOrUser == 'user'"}],staticClass:"room-list user-list"},e._l(e.user_list,function(i){return t("div",{key:i.id,staticClass:"user-item",style:{filter:i.status==1?"unset":"grayscale(1)"}},[i.photo?t("div",{staticClass:"user-avatar"},[t("img",{attrs:{src:i.photo.fileLinkTransfer(),alt:""}})]):t("div",{staticClass:"user-avatar"},[e._v(e._s(i.name.slice(0,1)))]),t("div",{staticClass:"user-name"},[e._v(e._s(i.name))])])}),0),t("el-input",{directives:[{name:"show",rawName:"v-show",value:e.activeChatListOrUser=="chat",expression:"activeChatListOrUser == 'chat'"}],attrs:{maxlength:"225",placeholder:"\u8BF7\u8F93\u5165\u6D88\u606F\u5185\u5BB9"},nativeOn:{keydown:function(i){return e.sendMeeageForkeyboard.apply(null,arguments)}},model:{value:e.msg,callback:function(i){e.msg=i},expression:"msg"}},[t("div",{attrs:{slot:"append"},on:{click:e.sendMeeage},slot:"append"},[e._v("\u53D1\u9001")])])],1)},x=[];const I={props:{room:{type:Object}},data(){return{activeChatListOrUser:"chat",msg:"",userId:this.$store.user.id,searchUserListValue:"",searchUserList:"",isJoinRoom:!1}},mixins:[$],methods:{sendMeeage(){this.msg.trim().length<=0||this.ws_send_live_msg()},sendMeeageForkeyboard(e){e.code==="Enter"&&this.sendMeeage()}},activated(){},watch:{room(){this.isJoinRoom||(this.msg_list=[],this.initLiveRoom(),this.isJoinRoom=!0)},user_list(){this.$emit("userListChange",this.user_list.filter(e=>e.status===1).length)}}},f={};var L=g(I,T,x,!1,S,"d947721a",null,null);function S(e){for(let s in f)this[s]=f[s]}const O=function(){return L.exports}();var M=function(){var e,s,t,i,n,u,d,r,v,m,c,h,a=this,l=a.$createElement,o=a._self._c||l;return o("div",{directives:[{name:"loading",rawName:"v-loading",value:!a.liveInfo,expression:"!liveInfo"}],staticClass:"live-watch",on:{"~click":function(_){return a.cancelMuted.apply(null,arguments)}}},[o("div",{staticClass:"live-header"},[o("div",{staticClass:"live-title"},[a._v(a._s((e=a.liveInfo)===null||e===void 0?void 0:e.title))]),o("div",{staticClass:"live-quit"},[o("el-button",{attrs:{type:"danger",size:"mini",round:""},on:{click:function(_){return a.$emit("quitLive")}}},[a._v(a._s(a.quitText))])],1),o("div",{staticClass:"live-info"},[o("div",{staticClass:"live-usrcount"},[o("i",{staticClass:"i-h-jsgl-duoren"}),a._v(" "+a._s(a.userNumber)+"\u4EBA ")]),o("div",{staticClass:"live-lecture-name"},[(s=a.liveInfo)!==null&&s!==void 0&&(t=s.lecturerInfo)!==null&&t!==void 0&&t.photo?o("div",{staticClass:"user-avatar"},[o("img",{attrs:{src:(i=a.liveInfo)===null||i===void 0?void 0:i.lecturerInfo.photo.diskname.fileLinkTransfer(),alt:""}})]):o("div",{staticClass:"user-avatar"},[a._v(" "+a._s((n=a.liveInfo)===null||n===void 0||(u=n.lecturerInfo)===null||u===void 0?void 0:u.name.slice(0,1))+" ")]),o("div",[a._v(a._s((d=a.liveInfo)===null||d===void 0||(r=d.lecturerInfo)===null||r===void 0?void 0:r.name))])])])]),o("div",{staticClass:"live-body",style:{backgroundImage:`url(${(v=a.liveInfo)===null||v===void 0||(m=v.warmUpPicture)===null||m===void 0?void 0:m.fileLinkTransfer()}) `,"background-size":"cover",backgroundRepeat:"no-repeat",backgroundPosition:"center"}},[a._t("liveBodyLeftMenu"),o("div",{staticClass:"live-body-center"},[a._t("playingBox",function(){return[o("div",{staticClass:"live-not-start"},[a._v("\u76F4\u64AD\u672A\u5F00\u59CB\uFF0C\u7A0D\u7B49\u4E00\u4E0B\u5427\uFF01")]),o("div",{staticClass:"live-playing"})]})],2),o("div",{staticClass:"live-body-right"},[a._e(),o("ChatList",{staticClass:"live-chat-room",attrs:{room:a.liveInfo,liveId:a.liveId},on:{userListChange:function(_){a.userNumber=_}}})],1)],2),o("audio",{directives:[{name:"show",rawName:"v-show",value:!1,expression:"false"}],ref:"audio",attrs:{muted:"",autoplay:"",src:(c=a.liveInfo)===null||c===void 0||(h=c.warmUpMusice)===null||h===void 0?void 0:h.fileLinkTransfer()}})])},U=[];const b={components:{ChatList:O},props:{liveInfo:{type:Object},quitText:{type:String,default:"\u9000\u51FA\u76F4\u64AD"},warmAudio:null},data(){return{userNumber:0}},mounted(){},methods:{cancelMuted(){this.$refs.audio.muted=!1,this.$refs.audio.play(),this.warmAudio=this.$refs.audio}},watch:{}},w={};var N=g(b,M,U,!1,R,"787eb905",null,null);function R(e){for(let s in w)this[s]=w[s]}const E=function(){return N.exports}(),y=window.GyConfig.baseUrl;function p(e,s){this.name=e,this.message=s,this.stack=new Error().stack}p.prototype=Object.create(Error.prototype);p.prototype.constructor=p;function C(){return Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).slice(0,7)}function j(){const e={};return e.constraints={audio:!0,video:{width:{ideal:1920,max:1920}}},e.audioContext=new AudioContext,e.mixedOutput=e.audioContext.createMediaStreamDestination(),e.muted=function(s){e.mixedOutput.stream.getAudioTracks().forEach(i=>{i.enabled=s})},e.publish=async function(s,{micro:t}){if(e.pc.addTransceiver("video",{direction:"sendonly"}),e.pc.addTransceiver("audio",{direction:"sendonly"}),!navigator.mediaDevices&&window.location.protocol==="http:"&&window.location.hostname!=="localhost")throw new p("HttpsRequiredError","Please use HTTPS or localhost to publish, read https://github.com/ossrs/srs/issues/2762#issuecomment-983147576");let i=null,n=null;i=await navigator.mediaDevices.getDisplayMedia({audio:!0,video:{width:{ideal:1920,max:1920}}});try{n=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}catch(c){c instanceof DOMException&&c.name==="NotFoundError"&&console.info(c),n=null}e.audioContext=new AudioContext,e.mixedOutput=e.audioContext.createMediaStreamDestination(),i.getAudioTracks().length>0&&e.audioContext.createMediaStreamSource(i).connect(e.mixedOutput),n&&n.getAudioTracks().length>0&&e.audioContext.createMediaStreamSource(n).connect(e.mixedOutput),e.muted(t);const u=new MediaStream,d=i.getVideoTracks(),r=e.mixedOutput.stream.getTracks();d.length>0&&u.addTrack(d[0]),r.length>0&&u.addTrack(r[0]),u.getTracks().forEach(function(c){e.pc.addTrack(c),e.ontrack&&e.ontrack({track:c})});const v=await e.pc.createOffer();await e.pc.setLocalDescription(v);const m=await new Promise(function(c,h){const a={api:y+"/rtc/v1/publish/",tid:C(),streamurl:s,clientip:null,sdp:v.sdp},l=new XMLHttpRequest;l.onload=function(){if(l.readyState!==l.DONE)return;if(l.status!==200)return h(l);const o=JSON.parse(l.responseText);return o.code?h(l):c(o)},l.open("POST",a.api,!0),l.setRequestHeader("Content-type","application/json"),l.send(JSON.stringify(a))});return await e.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:m.sdp})),m},e.close=function(){e.pc&&e.pc.close(),e.pc=null},e.ontrack=function(s){e.stream.addTrack(s.track)},e.pc=new RTCPeerConnection(null),e.stream=new MediaStream,e}function A(){const e={};return e.play=async function(s){e.pc.addTransceiver("audio",{direction:"recvonly"}),e.pc.addTransceiver("video",{direction:"recvonly"});const t=await e.pc.createOffer();await e.pc.setLocalDescription(t);const i=await new Promise(function(n,u){const d={api:y+"/rtc/v1/play/",tid:C(),streamurl:s,clientip:null,sdp:t.sdp},r=new XMLHttpRequest;r.onload=function(){if(r.readyState!==r.DONE)return;if(r.status!==200)return u(r);const v=JSON.parse(r.responseText);return v.code?u(r):n(v)},r.open("POST",d.api,!0),r.setRequestHeader("Content-type","application/json"),r.send(JSON.stringify(d))});return await e.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:i.sdp})),i},e.close=function(){e.pc&&e.pc.close(),e.pc=null},e.ontrack=function(s){e.stream.addTrack(s.track)},e.pc=new RTCPeerConnection(null),e.stream=new MediaStream,e.pc.ontrack=function(s){e.ontrack&&e.ontrack(s)},e}function q(){const e={};return e.constraints={audio:!0,video:{width:{ideal:1920,max:1920}}},e.play=async function(){let s=null;try{s=await navigator.mediaDevices.getUserMedia({audio:!1,video:!0})}catch(t){throw console.info(t),t}s&&s.getTracks().forEach(function(t){e.ontrack&&e.ontrack({track:t})})},e.ontrack=function(s){e.stream.addTrack(s.track)},e.stream=new MediaStream,e}export{E as L,q as P,j as S,p as a,A as b,$ as c};
|