2 lines
2.6 KiB
JavaScript
2 lines
2.6 KiB
JavaScript
(function(s){let f,g,c,n,u,d,h=C("cwid"),l,m=w();setTimeout(()=>{y()},m?0:4500);function w(){const{href:e=""}=window.location;return e.indexOf("troom/allCamera.html")>-1}function y(e){const t=window.localStorage.getItem("courseInfo");window.AgoraRTC||T("/design/designstatic/lib/AgoraRTC/AgoraRTCSDK-3.6.11.js?my_version="),n=AgoraRTC.createClient({mode:"live"}),m?b():A(),k()}function A(){try{navigator.mediaDevices.getUserMedia({video:!0,audio:!0}).then(e=>{e.getTracks()[0].stop(),liveObj.sendAvaCamera()}).catch(e=>{console.log("\u6444\u50CF\u5934\u68C0\u6D4B\u5931\u8D25:",e)})}catch(e){console.log("\u5524\u8D77\u5931\u8D25:",e)}}function T(e,t){$.ajax({url:e,cache:!0,async:!1,success:function(){t&&t()}})}function k(e){AgoraRTC.getDevices(function(t){let a=!1,o=!1;for(var i=0;i!==t.length;++i){var r=t[i];r.kind==="audioinput"?(u===""&&(u=r.deviceId),o=!0):r.kind==="videoinput"?(d===""&&(d=r.deviceId),a=!0):console.log("Some other kind of source/device: ",r)}})}function v(e={}){try{const a=`#remote_video_${e.getId()}`;$(a).length>0&&$(a).remove()}catch(t){console.log("\u7528\u6237\u79BB\u573A:",t)}}function b(){n.on("stream-subscribed",e=>{const t=e.stream,a=t.getId(),o=`remote_video_${a}`,r=(window.getAvaCameraList?getAvaCameraList():[]).filter(j=>j.uid===a);let I="";r.length>0&&(I=r[0].name||""),$(`#${o}`).length<1&&($("#myCamera").append(`<div id="${o}" class="remote_camera"></div>`),$(`#${o}`).append(`<div class="camera_name">${I}</div>`),t.play(o))}),n.on("stream-added",function(e){var t=e.stream;n.subscribe(t,function(a){console.log("Subscribe stream failed",a)})}),n.on("peer-leave",function(e){v(e.stream)}),n.on("stream-removed",function(e){v(e.stream)})}function R(){n.init(g,()=>{n.join(f,h,l,function(e){m||(c=AgoraRTC.createStream({streamID:l,audio:!1,video:!0,screen:!1,mirror:!1,cameraId:d,microphoneId:u}),c.init(()=>{n.publish(c,function(t){},function(t){})}))})},e=>{console.log("\u521B\u5EFA\u672C\u5730\u6D41:",e)})}function p(e){l=e;const t=m?C("key"):$.cookie("token");$.ajax({url:"/api/webchat/getAgoraToken",type:"POST",headers:{token:t},contentType:"application/json; charset=utf-8",data:JSON.stringify({cwId:h}),success:(a={})=>{const o=JSON.parse(a),{data:i={}}=o;f=i.token,g=i.appID,R()}})}function C(e){var t=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),a=window.location.search.substr(1).match(t);return a!=null?unescape(a[2]):null}function S(e){p(e)}function D(){n.leave(()=>{try{c.close()}catch(e){console.log("\u6444\u50CF\u5934\u5173\u95ED:",e)}})}function M(){n.publish(c,function(e){console.log("Publish local stream error: "+e)})}function _(e){l=e}s.checkAllCamera=S,s.closeAllCamera=D,s.openAllCamera=M,s.loginRtc=p,s.setCameraUser=_})(window);
|