UNPKG

zego-express-engine-webrtc

Version:

zego webrtc express sdk

1 lines 71.1 kB
!function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("long"));else if("function"==typeof define&&define.amd)define(["long"],i);else{var n="object"==typeof exports?i(require("long")):i(t.long);for(var e in n)("object"==typeof exports?exports:t)[e]=n[e]}}("undefined"!=typeof self?self:this,(function(t){return function(){"use strict";var i={2362:function(){!function(){function t(t){this.zegoStream=t}Object.defineProperty(t.prototype,"active",{get:function(){return this.zegoStream.active},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this.zegoStream.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"videoCaptureStream",{get:function(){return this.zegoStream.originVideoStream},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"audioCaptureStream",{get:function(){return this.zegoStream.originAudioStream},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"stream",{get:function(){return this.zegoStream.stream},enumerable:!1,configurable:!0}),t.prototype.getAudioTracks=function(){return this.zegoStream.getAudioTracks()},t.prototype.getVideoTracks=function(){return this.zegoStream.getVideoTracks()},t.prototype.getTracks=function(){return this.zegoStream.getTracks()},Object.defineProperty(t.prototype,"videoDeviceId",{get:function(){return this.zegoStream.videoDeviceId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"audioDeviceId",{get:function(){return this.zegoStream.audioDeviceId},enumerable:!1,configurable:!0}),t.prototype.on=function(t,i){return this.zegoStream.on(t,i)},t.prototype.off=function(t,i){return this.zegoStream.off(t,i)},t.prototype.startCaptureMicrophone=function(t){return this.zegoStream.startCaptureMicrophone(t)},t.prototype.startCaptureCamera=function(t){return this.zegoStream.startCaptureCamera(t)},t.prototype.startCaptureCameraAndMicrophone=function(t,i){return this.zegoStream.startCaptureCameraAndMicrophone(t,i)},t.prototype.startCaptureCustomAudio=function(t){return this.zegoStream.startCaptureCustomAudio(t)},t.prototype.startCaptureCustomVideo=function(t){return this.zegoStream.startCaptureCustomVideo(t)},t.prototype.startCaptureCustomVideoAndAudio=function(t,i){return this.zegoStream.startCaptureCustomVideoAndAudio(t,i)},t.prototype.startCaptureScreen=function(t){return this.zegoStream.startCaptureScreen(t)},t.prototype.startCaptureScreenWithAudio=function(t,i){return this.zegoStream.startCaptureScreenWithAudio(t,i)},t.prototype.stopCaptureAudio=function(){return this.zegoStream.stopCaptureAudio()},t.prototype.stopCaptureVideo=function(){return this.zegoStream.stopCaptureVideo()},t.prototype.playAudio=function(t){this.zegoStream.playAudio(t)},t.prototype.playCaptureAudio=function(t){this.zegoStream.playCaptureAudio(t)},t.prototype.playVideo=function(t,i){this.zegoStream.playVideo(t,i)},t.prototype.playCaptureVideo=function(t,i){this.zegoStream.playCaptureVideo(t,i)},t.prototype.takeStreamSnapshot=function(t){return this.zegoStream.takeStreamSnapshot(t)},t.prototype.resumeVideo=function(){return this.zegoStream.resumeVideo()},t.prototype.resumeAudio=function(){return this.zegoStream.resumeAudio()},t.prototype.stopVideo=function(){this.zegoStream.stopVideo()},t.prototype.stopAudio=function(){this.zegoStream.stopAudio()},t.prototype.stopPlayCaptureVideo=function(){this.zegoStream.stopPlayCaptureVideo()},t.prototype.stopPlayCaptureAudio=function(){this.zegoStream.stopPlayCaptureAudio()},t.prototype.setVolume=function(t){return this.zegoStream.setVolume(t)},t.prototype.useAudioOutputDevice=function(t){return this.zegoStream.setAudioOutputDevice(t)}}()},8899:function(t,i,n){var e,r,o,s;n.d(i,{UF:function(){return o},eI:function(){return e},ju:function(){return s},kf:function(){return r}}),function(t){t[t.Off=0]="Off",t[t.TurningOn=1]="TurningOn",t[t.On=2]="On"}(e||(e={})),function(t){t[t.World=0]="World",t[t.Team=1]="Team",t[t.SecretTeam=2]="SecretTeam"}(r||(r={})),function(t){t[t.All=0]="All",t[t.World=1]="World",t[t.Team=2]="Team"}(o||(o={})),function(t){t[t.All=0]="All",t[t.World=1]="World",t[t.Team=2]="Team"}(s||(s={}))},166:function(t,i,n){var e,r,o,s;n.d(i,{PP:function(){return s}}),function(t){t[t.NONE=0]="NONE",t[t.MEN_TO_CHILD=1]="MEN_TO_CHILD",t[t.MEN_TO_WOMEN=2]="MEN_TO_WOMEN",t[t.WOMEN_TO_CHILD=3]="WOMEN_TO_CHILD",t[t.WOMEN_TO_MEN=4]="WOMEN_TO_MEN",t[t.FOREIGNER=5]="FOREIGNER",t[t.OPTIMUS_PRIME=6]="OPTIMUS_PRIME",t[t.ANDROID=7]="ANDROID",t[t.ETHEREAL=8]="ETHEREAL",t[t.MALE_MAGNETIC=9]="MALE_MAGNETIC",t[t.FEMALE_FRESH=10]="FEMALE_FRESH",t[t.MAJOR_C=11]="MAJOR_C",t[t.MINOR_A=12]="MINOR_A",t[t.HARMONIC_MINOR=13]="HARMONIC_MINOR",t[t.FEMALE_ENERGETIC=14]="FEMALE_ENERGETIC",t[t.RICHNESS=15]="RICHNESS",t[t.MUFFLED=16]="MUFFLED",t[t.ROUNDNESS=17]="ROUNDNESS",t[t.FALSETTO=18]="FALSETTO",t[t.FULLNESS=19]="FULLNESS",t[t.CLEAR=20]="CLEAR",t[t.HIGHLY_RESONANT=21]="HIGHLY_RESONANT",t[t.LOUD_CLEAR=22]="LOUD_CLEAR"}(e||(e={})),function(t){t[t.None=0]="None",t[t.SoftRoom=1]="SoftRoom",t[t.LargeRoom=2]="LargeRoom",t[t.ConcertHall=3]="ConcertHall",t[t.Valley=4]="Valley",t[t.RecordingStudio=5]="RecordingStudio",t[t.Basement=6]="Basement",t[t.KTV=7]="KTV",t[t.Popular=8]="Popular",t[t.Rock=9]="Rock",t[t.VocalConcert=10]="VocalConcert",t[t.GramoPhone=11]="GramoPhone",t[t.EnhancedKTV=12]="EnhancedKTV"}(r||(r={})),function(t){t[t.None=0]="None",t[t.Local=1]="Local",t[t.Publish=2]="Publish",t[t.All=3]="All"}(o||(o={})),function(t){t[t.AI=0]="AI",t[t.AIBalanced=1]="AIBalanced",t[t.AIAggressive=2]="AIAggressive"}(s||(s={}))},8627:function(t,i,n){n(8866)},8866:function(t,i,n){n.d(i,{Rl:function(){return l},VJ:function(){return r},Wk:function(){return f},aw:function(){return u},dO:function(){return h},fT:function(){return o},h2:function(){return a},l3:function(){return e},pt:function(){return s},qC:function(){return c}});n(7202),n(8627),n(4872);var e=Promise,r=document;var o="room not exist",s="device is not found",u="stream is not from zego",h="input param error",c="local stream wrong",a="no preview",f="publish stream no found",l="network is broken"},7202:function(t,i,n){n(6994)},4872:function(t,i,n){n.d(i,{Cs:function(){return e},JO:function(){return u},QP:function(){return r},Si:function(){return h},TE:function(){return s},dd:function(){return o}});n(2362);function e(t){return"number"==typeof t}function r(t){return"string"==typeof t}function o(t){return"boolean"==typeof t}function s(t){return void 0===t}function u(t){return"function"==typeof t}function h(t){return t instanceof HTMLMediaElement}},6493:function(t,i,n){function e(){return navigator.userAgent||""}function r(){var t,i=navigator.userAgent,n=i.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*([\d\.]+)/i)||[];return/trident/i.test(n[1])?{name:"IE",version:(t=/\brv[ :]+([\d\.]+)/g.exec(i)||[])[1]||""}:"Chrome"===n[1]&&null!=(t=i.match(/\bOPR|Edge\/([\d\.]+)/))?{name:"Opera",version:t[1]}:(n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(t=i.match(/version\/([\d+\.]+)/i))&&n.splice(1,1,t[1]),{name:n[0],version:n[1]})}function o(){return"chrome"==r().name.toLowerCase()}function s(){var t=e();return!!(t.match(/Mobi/i)||t.match(/Android/i)||t.match(/iPhone/i))}n.d(i,{$t:function(){return e},Fr:function(){return s},H8:function(){return o}})},6994:function(i){i.exports=t}},n={};function e(t){var r=n[t];if(void 0!==r)return r.exports;var o=n[t]={exports:{}};return i[t](o,o.exports,e),o.exports}e.d=function(t,i){for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},e.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};e.r(r),e.d(r,{RangeAudio:function(){return nt}});var o=e(8899),s=e(8866),u=function(){function t(){}return t.generateEls=function(t){if(void 0===t&&(t=30),this.elements.length>=t)this.elements.forEach((function(t){t.dom.play().catch((function(t){}))}));else{var i=Array(t-this.elements.length).fill(0).map((function(t,i){var n=s.VJ.createElement("audio");return n.muted=!0,n.setAttribute("autoplay","autoplay"),n.setAttribute("playsInline","playsInline"),n.id="audio"+i,{dom:n,id:i,used:!1}}));this.elements=this.elements.concat(i)}},t.useAudioEl=function(){0===this.elements.length&&this.generateEls();var t=this.elements.find((function(t){return!t.used}));return t&&(t.used=!0),t},t.stopUsingAudioEl=function(t){var i=this.elements[t];i&&(i.dom.onpause=null,i.dom.onerror=null,i.dom.muted=!0,i.used=!1)},t.elements=[],t}(),h=function(t,i,n,e){return new(n||(n=Promise))((function(r,o){function s(t){try{h(e.next(t))}catch(t){o(t)}}function u(t){try{h(e.throw(t))}catch(t){o(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,u)}h((e=e.apply(t,i||[])).next())}))},c=function(t,i){var n,e,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(h){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,h])}}},a="zc.ra.3",f=function(){function t(t,i){this.t=t,this.i=i,this.rtcConn=null,this.loopbackConn=null,this.destStream=new MediaStream,this.onError=null}return t.prototype.bindStream=function(t,i){var n,e;return h(this,void 0,void 0,(function(){var r,o,s,u,h,f,l=this;return c(this,(function(c){switch(c.label){case 0:return i&&(this.t=i),r=["completed","connected"],this.rtcConn&&this.loopbackConn&&r.includes(this.rtcConn.connectionState)?(o=null===(n=this.rtcConn)||void 0===n?void 0:n.getSenders().find((function(t){var i;return"audio"===(null===(i=t.track)||void 0===i?void 0:i.kind)})),t.getTracks().forEach((function(t){"audio"===t.kind&&(null==o||o.replaceTrack(t))})),[3,10]):[3,1];case 1:this.rtcConn=new RTCPeerConnection,this.loopbackConn=new RTCPeerConnection,s={offerVideo:!0,offerAudio:!0,offerToReceiveAudio:!1,offerToReceiveVideo:!1},this.rtcConn.onicecandidateerror=function(t){l.i.warn(a+" ".concat(l.t," loopback in ice error: ").concat(JSON.stringify(t)))},this.loopbackConn.onicecandidateerror=function(t){l.i.warn(a+" ".concat(l.t," loopback out ice error: ").concat(JSON.stringify(t)))},this.rtcConn.onicecandidate=function(t){var i,n=t.candidate;n&&(l.i.info(a+" ".concat(l.t," loopback add out candidate: ").concat(n)),null===(i=l.loopbackConn)||void 0===i||i.addIceCandidate(new RTCIceCandidate(n)))},this.loopbackConn.onicecandidate=function(t){var i,n=t.candidate;n&&(l.i.info(a+" ".concat(l.t," loopback add in candidate: ").concat(n)),null===(i=l.rtcConn)||void 0===i||i.addIceCandidate(new RTCIceCandidate(n)))},window.setTimeout((function(){l.rtcConn&&l.loopbackConn&&(r.includes(l.rtcConn.iceConnectionState)&&r.includes(l.loopbackConn.iceConnectionState)?l.i.info(a+" ".concat(l.t," loopback connect ok.")):(l.i.warn(a+" ".concat(l.t," loopback connect failed. in state: ").concat(l.rtcConn.iceConnectionState,", out state: ").concat(l.loopbackConn.iceConnectionState)),l.close(),l.onError&&l.onError("time out")))}),2e3),this.loopbackConn.ontrack=function(t){var i=t.track;l.i.info(a+" ".concat(l.t," loopback receive track")),l.replaceTrack(i)},t.getTracks().find((function(i){var n;if("audio"===i.kind)return null===(n=l.rtcConn)||void 0===n||n.addTrack(i,t),!0})),c.label=2;case 2:return c.trys.push([2,9,,10]),[4,this.rtcConn.createOffer(s)];case 3:return u=c.sent(),[4,this.rtcConn.setLocalDescription(u)];case 4:return c.sent(),[4,this.loopbackConn.setRemoteDescription(u)];case 5:return c.sent(),[4,this.loopbackConn.createAnswer()];case 6:return(h=c.sent()).sdp=null===(e=h.sdp)||void 0===e?void 0:e.replace(/useinbandfec=/,"stereo=1;useinbandfec="),[4,this.loopbackConn.setLocalDescription(h)];case 7:return c.sent(),[4,this.rtcConn.setRemoteDescription(h)];case 8:return c.sent(),this.i.info(a+" ".concat(this.t," loopback set sdp completed.")),[3,10];case 9:return f=c.sent(),this.i.error(a+" ".concat(this.t," loopback connect failed.").concat(f)),this.close(),this.onError&&this.onError("connect failed"),this.onError=null,[3,10];case 10:return[2,this.destStream]}}))}))},t.prototype.replaceTrack=function(t){var i=this;"audio"===t.kind&&(this.destStream.getTracks().forEach((function(t){i.destStream.removeTrack(t)})),this.destStream.addTrack(t))},t.prototype.close=function(){var t=this,i=this.rtcConn,n=this.loopbackConn;this.destStream.getTracks().forEach((function(i){t.destStream.removeTrack(i)})),null==i||i.close(),null==n||n.close(),this.rtcConn=null,this.loopbackConn=null},t}();var l=e(4872),d=e(6493),v=function(t,i,n,e){return new(n||(n=Promise))((function(r,o){function s(t){try{h(e.next(t))}catch(t){o(t)}}function u(t){try{h(e.throw(t))}catch(t){o(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,u)}h((e=e.apply(t,i||[])).next())}))},p=function(t,i){var n,e,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(h){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,h])}}},m="zc.ra.5";var w,b=function(){function t(t,i){this.i=t,this.userID="base"+(new Date).getTime(),this.isHide=!1,this.distance=null,this.maxDistance=1e3,this.position=null,this.speaker="",this.audioEl=null,this.sourceNode=null,this.isPlaying=!1,this.config={needLoopback:!0,useGain:!0,playOnAudioContext:!1,useWebAudio:!0},this.volume=1,this.gainNode=null,this.isSpatial=!1,this.panner=null,this.audioCtx=i.audioCtx,this.isSpatial=i.isSpatial,this.setMaxDistance((0,l.Cs)(i.maxDistance)?i.maxDistance:1e5),this.destNode=this.audioCtx.createMediaStreamDestination(),this.setVolume(i.volume),this.setSpeaker(i.speaker).catch((function(t){})),this.inBackground(i.isHide)}return t.prototype.setPosition=function(t){this.i.info(m+" ".concat(this.userID," set position: ")+t),this.position=t,this.panner&&(void 0!==this.panner.positionX?(this.panner.positionX.value=t[1],this.panner.positionY.value=t[2],this.panner.positionZ.value=-t[0]):this.panner.setPosition(t[1],t[2],-t[0]))},t.prototype.getDistanceFromListener=function(t){return this.distance=function(t,i){if(!i||!t)return null;var n=[t[0]-i[0],t[1]-i[1],t[2]-i[2]];return Math.sqrt(Math.pow(n[0],2)+Math.pow(n[1],2)+Math.pow(n[2],2))}(this.position,t.position),this.distance},t.prototype.setMaxDistance=function(t){this.maxDistance=t,this.panner&&(t<10&&(t=10),this.panner.maxDistance=2.6*t)},t.prototype.setVolume=function(t){isNaN(t)||(this.volume=t,this.gainNode&&(this.gainNode.gain.value=this.volume))},t.prototype.setSpeaker=function(t){var i;return v(this,void 0,void 0,(function(){var n,e,r;return p(this,(function(o){switch(o.label){case 0:if(!(0,l.QP)(t))return[2];if(this.speaker=t,!(n=null===(i=this.audioEl)||void 0===i?void 0:i.dom))return[3,10];if(!(e=n.setSinkId))return[3,8];o.label=1;case 1:return o.trys.push([1,6,,7]),this.config.playOnAudioContext?[3,3]:[4,e.call(n,t||"")];case 2:return o.sent(),[3,5];case 3:return[4,e.call(n,"")];case 4:o.sent(),o.label=5;case 5:return this.i.info(m+" ".concat(this.userID," set speaker success. id: ").concat(t,".")),[3,7];case 6:throw r=o.sent(),this.i.error(m+" ".concat(this.userID," set speaker failed. id: ").concat(t," error: ").concat(r,".")),r;case 7:return[3,9];case 8:throw"setting speaker not support.";case 9:return[3,11];case 10:this.i.info(m+" ".concat(this.userID," no element for set speaker.")),o.label=11;case 11:return[2]}}))}))},t.prototype.initPanner=function(){if(!this.panner){var t=function(t,i,n){var e=n||[0,0,0],r=t.createPanner(),o=t.createGain();return r.panningModel="HRTF",r.distanceModel="linear",r.refDistance=1,r.maxDistance=2.6*i||1,r.rolloffFactor=1,r.coneOuterGain=.4,void 0!==r.positionX?(r.positionX.value=e[1],r.positionY.value=e[2],r.positionZ.value=-e[0]):r.setPosition(e[1],e[2],-e[0]),{panner:r,gainNode:o}}(this.audioCtx,this.maxDistance,this.position),i=t.gainNode;this.panner=t.panner,this.gainNode=i,i.gain.value=this.volume}},t.prototype.changeRenderConfig=function(t,i,n,e){var r,o,s,u,h;return void 0===i&&(i=!1),void 0===n&&(n=!1),void 0===e&&(e=!0),v(this,void 0,void 0,(function(){var c,a,l,v,w,b,y,g,E,k,S,O,x=this;return p(this,(function(p){switch(p.label){case 0:return i||this.isSpatial!==t?(this.isSpatial=t,c=(0,d.H8)()&&(0,d.Fr)(),[4,K()]):[2];case 1:return a=p.sent(),l="Windows"===a.platform&&a.majorPlatformVersion>=13,v=this.isHide&&(l||c),w="running"!==this.audioCtx.state,e&&(v||w)&&(this.i.warn("".concat(m," ").concat(this.userID," stop web audio. system: ").concat(a.platform," ").concat(a.majorPlatformVersion)),e=!1),this.config.useWebAudio=e,b=(0,d.$t)(),y=b.includes("safari")&&!b.includes("chrome"),g=b.includes("micromessenger")&&new RegExp(/(iphone|ipad|ipod|ios)/i).test(b),e||this.stream||(n=!0),this.config.playOnAudioContext=n,this.initPanner(),this.isPlaying&&this.sourceNode?(this.lastNode&&this.lastNode.disconnect(),E=this.sourceNode,this.sourceNode.disconnect(),null===(r=this.panner)||void 0===r||r.disconnect(),null===(o=this.gainNode)||void 0===o||o.disconnect(),this.gainNode?(e&&(this.config.useGain&&(E=this.sourceNode.connect(this.gainNode)),this.panner&&t&&(E=E.connect(this.panner))),E.connect(n?this.audioCtx.destination:this.destNode),this.lastNode=E,this.position&&this.setPosition(this.position),this.i.info(m+" '".concat(this.userID,"' play ").concat(t?"3d":"normal"," stream on ").concat(n?"audio ctx":"element")),(k=null===(s=this.audioEl)||void 0===s?void 0:s.dom)?(k.onpause=function(){x.i.warn(m+" ".concat(x.streamID," audio paused"))},k.onerror=function(t){x.i.warn(m+" ".concat(x.streamID," audio error, ").concat(t))},n?(this.stream&&k.srcObject!==this.stream&&(k.srcObject=this.stream,k.muted=!0,k.oncanplay=function(){k.play().then((function(){x.i.info(m+" ".concat(x.userID," ctx autoplay success.")),x.checkPlayStatus()})).catch((function(t){x.i.warn(m+" ".concat(x.userID," ctx autoplay failed."))}))}),[3,6]):[3,2]):[3,6]):[3,6]):[3,6];case 2:return S=this.destNode.stream,(O=this.config.needLoopback&&!g&&!y)&&this.loopbackConn&&(this.loopbackConn.close(),this.loopbackConn.onError=null),e||!this.stream?[3,3]:(this.i.info("".concat(m," ").concat(this.userID," stop audio api")),this.sourceNode.disconnect(),null===(u=this.panner)||void 0===u||u.disconnect(),null===(h=this.gainNode)||void 0===h||h.disconnect(),S=this.stream,[3,5]);case 3:return O&&S?(this.loopbackConn=this.loopbackConn||new f(this.streamID||"",this.i),this.loopbackConn.onError=function(t){x.i.warn(m+" ".concat(x.userID," loopback failed! ").concat(t)),x.changeRenderConfig(x.isSpatial,!0,!0)},[4,this.loopbackConn.bindStream(S,this.streamID||void 0)]):[3,5];case 4:return S=p.sent(),[3,5];case 5:k.muted=!0,k.srcObject=S,this.setSpeaker(this.speaker).catch((function(t){})),k.oncanplay=function(){if(k){k.muted=!1;var t=function(t){x.i.error(m+" ".concat(x.userID," autoplay failed. error: ").concat(t)),x.changeRenderConfig(x.isSpatial,!0,!0)};k.play().then((function(){(null==k?void 0:k.paused)?t("audio paused"):(x.i.info(m+" ".concat(x.userID," element autoplay success.")),x.checkPlayStatus())})).catch((function(i){t(i)}))}},p.label=6;case 6:return[2]}}))}))},t.prototype.checkPlayStatus=function(){var t=this;setTimeout((function(){var i;if(t.isPlaying){var n=null===(i=t.audioEl)||void 0===i?void 0:i.dom,e=t.audioCtx.state;!n||n.paused||n.muted&&!t.config.playOnAudioContext||"running"!==e?(t.i.warn("".concat(m," ").concat(t.userID," play detection is abnormal. audio ctx:").concat(e,", paused:").concat(null==n?void 0:n.paused,", muted:").concat(null==n?void 0:n.muted)),"running"!==e&&(t.audioCtx.resume(),setTimeout((function(){t.i.warn("".concat(m," ").concat(t.userID," play resume. audio ctx:").concat(e,", paused:").concat(null==n?void 0:n.paused,", muted:").concat(null==n?void 0:n.muted))}),1e3))):t.i.info("".concat(m," ").concat(t.userID," play detection is fine"))}}),2e3)},t.prototype.inBackground=function(t,i){void 0===t&&(t=!1),void 0===i&&(i=!1),this.isHide!==t&&(this.isHide=t,t||this.config.useWebAudio||this.changeRenderConfig(this.isSpatial,!0))},t}(),y=(w=function(t,i){return w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])},w(t,i)},function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}w(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}),g=function(t,i,n,e){return new(n||(n=Promise))((function(r,o){function s(t){try{h(e.next(t))}catch(t){o(t)}}function u(t){try{h(e.throw(t))}catch(t){o(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,u)}h((e=e.apply(t,i||[])).next())}))},E=function(t,i){var n,e,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(h){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,h])}}},k="zc.ra.1",S=function(t){function i(i,n,e){var r=t.call(this,i,e)||this;return r.i=i,r.audioTrack=null,r.zegoRTC=e.zegoRTC,r.userID=n.userID,r.teamID=n.teamID,r.raMode=void 0!==n.raMode?n.raMode:o.kf.World,n.position&&(r.position=n.position),r}return y(i,t),Object.defineProperty(i.prototype,"sendMode",{get:function(){return void 0!==this._sendMode?this._sendMode:this.raMode===o.kf.World?o.UF.All:o.UF.Team},set:function(t){this._sendMode=t},enumerable:!1,configurable:!0}),i.prototype.checkTrackChanged=function(){var t;if(this.stream){var i=this.stream.getAudioTracks()[0];i&&i!==this.audioTrack&&(this.i.info(k+" retry play success, render stream."),null===(t=this.sourceNode)||void 0===t||t.disconnect(),this.sourceNode=this.audioCtx.createMediaStreamSource(this.stream),this.changeRenderConfig(this.isSpatial,!0),this.audioTrack=i)}},i.prototype.startPlayingAudio=function(t){var i,n;return g(this,void 0,void 0,(function(){var e,r,o;return E(this,(function(h){switch(h.label){case 0:if(!this.streamID)return[2];h.label=1;case 1:return h.trys.push([1,3,,4]),t&&this.i.info(k+" ".concat(this.streamID," ")+t),this.isPlaying=!0,e=this,[4,this.zegoRTC.startPlayingStream(this.streamID)];case 2:return e.stream=h.sent(),this.audioTrack=this.stream.getAudioTracks()[0],[3,4];case 3:if(r=h.sent(),this.isPlaying=!1,1103049===r.code)return[2];throw r;case 4:return this.audioEl=this.audioEl||u.useAudioEl()||null,this.i.info(k+" ".concat(this.streamID," start using audio el ").concat(null===(i=this.audioEl)||void 0===i?void 0:i.id)),(o=null===(n=this.audioEl)||void 0===n?void 0:n.dom)||(this.i.error(k+" not enough audio elements"),o=s.VJ.createElement("audio"),this.audioEl={id:-1,dom:o,used:!0},o.setAttribute("autoplay","autoplay")),o.muted=!0,this.stream&&(this.sourceNode=this.audioCtx.createMediaStreamSource(this.stream)),this.sourceNode?[4,this.changeRenderConfig(this.isSpatial,!0)]:[3,6];case 5:h.sent(),h.label=6;case 6:return"suspended"===this.audioCtx.state&&this.audioCtx.resume(),[2]}}))}))},i.prototype.stopPlayingAudio=function(t){this.isPlaying&&this.streamID?(this.i.info(k+" ".concat(this.streamID," ")+t),this.zegoRTC.stopPlayingStream(this.streamID),this.isPlaying=!1):this.streamID&&this.i.info(k+" ".concat(this.streamID," not playing, ")+t),this.stream=void 0,this.sourceNode&&(this.sourceNode.disconnect(),this.sourceNode=null);var i=this.audioEl,n=null==i?void 0:i.dom;n&&(n.srcObject=null,n.parentNode&&n.parentNode.removeChild(n));var e=(null==i?void 0:i.id)||-1;i&&e>=0&&(u.stopUsingAudioEl(e),this.i.info(k+" ".concat(this.streamID," stop using audio el ").concat(e))),this.audioEl=null,this.loopbackConn&&(this.loopbackConn.close(),this.loopbackConn.onError=null)},i.prototype.isSpeakInTeam=function(t){var i=![this.teamID,t].includes(void 0)&&""!==this.teamID&&this.teamID===t,n=[o.UF.Team,o.UF.All].includes(this.sendMode);return i&&n},i}(b),O=function(){var t=function(i,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])},t(i,n)};return function(i,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=i}t(i,n),i.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}}(),x=function(t,i,n,e){return new(n||(n=Promise))((function(r,o){function s(t){try{h(e.next(t))}catch(t){o(t)}}function u(t){try{h(e.throw(t))}catch(t){o(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,u)}h((e=e.apply(t,i||[])).next())}))},A=function(t,i){var n,e,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(h){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,h])}}},T="zc.ra.4",N=function(t){function i(i,n,e){var r=t.call(this,i,e)||this;return r.i=i,r.media=n.media,r.position=n.position||null,r.createSource(),r.userID="custom"+(new Date).getTime(),r.config={needLoopback:!1,useGain:!1,playOnAudioContext:!1,useWebAudio:!0},r}return O(i,t),i.prototype.createSource=function(){var t=this;if((0,d.Fr)())return this.i.info("".concat((0,d.Fr)()," ").concat(this.userID," not create src.")),void(this.changeRenderConfig=function(){return x(t,void 0,void 0,(function(){return A(this,(function(t){return[2]}))}))});this.media&&(this.i.info(T+" create el source."),this.sourceNode||(this.sourceNode=this.audioCtx.createMediaElementSource(this.media)),null!==this.distance&&this.distance<this.maxDistance&&this.startPlayingAudio("in range"))},i.prototype.startPlayingAudio=function(t){var i,n;return x(this,void 0,void 0,(function(){var e;return A(this,(function(r){switch(r.label){case 0:return this.isPlaying?(this.i.info(T+" ".concat(this.userID," is already playing")),[2]):(t&&this.i.info(T+" vocal ".concat(this.userID," play for ").concat(t)),this.isPlaying=!0,(0,d.Fr)()?(this.media.muted=!1,[2]):(this.audioEl=this.audioEl||u.useAudioEl()||null,this.i.info(T+" ".concat(this.userID," start using audio el ").concat(null===(i=this.audioEl)||void 0===i?void 0:i.id)),(e=null===(n=this.audioEl)||void 0===n?void 0:n.dom)||(this.i.error(T+" ".concat(this.userID," not enough audio elements")),e=s.VJ.createElement("audio"),this.audioEl={id:-1,dom:e,used:!0},e.setAttribute("autoplay","autoplay")),e.muted=!0,e.setAttribute("autoplay","autoplay"),e.setAttribute("id","zg-audio-source-"+this.userID),this.sourceNode?[4,this.changeRenderConfig(this.isSpatial,!0)]:[3,2]));case 1:r.sent(),r.label=2;case 2:return"suspended"===this.audioCtx.state&&this.audioCtx.resume(),[2]}}))}))},i.prototype.stopPlayingAudio=function(t){if(void 0===t&&(t=""),this.isPlaying&&(this.i.info(T+" vocal ".concat(this.userID," stop for ")+t),this.isPlaying=!1),(0,d.Fr)())this.media.muted=!0;else{this.sourceNode&&this.sourceNode.disconnect();var i=this.audioEl,n=null==i?void 0:i.dom;n&&(n.srcObject=null,n.parentNode&&n.parentNode.removeChild(n));var e=(null==i?void 0:i.id)||-1;i&&e>=0&&(u.stopUsingAudioEl(e),this.i.info(T+" ".concat(this.userID," stop using audio el ").concat(e))),this.audioEl=null}},i.prototype.checkIfCanPlay=function(t){var i=this.distance=this.getDistanceFromListener(t);null===i||i>this.maxDistance||0===this.maxDistance?this.stopPlayingAudio("out of range. ".concat(i," > ").concat(this.maxDistance)):this.startPlayingAudio("in range")},i}(b),_=function(){var t=function(i,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])},t(i,n)};return function(i,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=i}t(i,n),i.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}}(),C=function(t,i,n,e){return new(n||(n=Promise))((function(r,o){function s(t){try{h(e.next(t))}catch(t){o(t)}}function u(t){try{h(e.throw(t))}catch(t){o(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,u)}h((e=e.apply(t,i||[])).next())}))},R=function(t,i){var n,e,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(h){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,h])}}},I="zc.ra.4",P=function(t){function i(i,n,e){var r=t.call(this,i,e)||this;return r.i=i,r.streamView=n.streamView,r.position=n.position||null,r.createSource(),r.userID="stream"+(new Date).getTime(),r.config={needLoopback:!1,useGain:!1,playOnAudioContext:!1,useWebAudio:!0},r.streamView.on("_trackChange",(function(t,i){"audio"===t&&(i?r.createSource(!0):r.i.error("".concat(I," ").concat(r.userID," audio track lost")))})),r}return _(i,t),i.prototype.createSource=function(t){var i=this;if(void 0===t&&(t=!1),(0,d.Fr)())return this.i.info("".concat(I," ").concat(this.userID," not create src.")),this.changeRenderConfig=function(){return C(i,void 0,void 0,(function(){return R(this,(function(t){return[2]}))}))},!1;if(!this.streamView)return!1;if(this.i.info(I+" create view source. trackChanged: "+t),!this.sourceNode||t){var n=this.streamView.v.getAudioNodeAndStopRender();if(!n)return this.i.error(I+" create view source failed."),!1;this.sourceNode&&this.sourceNode.disconnect(),this.sourceNode=n,this.changeRenderConfig(this.isSpatial,!0)}return null!==this.distance&&this.distance<this.maxDistance&&this.startPlayingAudio("in range"),!0},i.prototype.startPlayingAudio=function(t){var i,n;return C(this,void 0,void 0,(function(){var e;return R(this,(function(r){switch(r.label){case 0:return this.isPlaying?(this.i.info(I+" ".concat(this.userID," is already playing")),[2]):(t&&this.i.info(I+" vocal ".concat(this.userID," play for ").concat(t)),this.isPlaying=!0,(0,d.Fr)()?(this.streamView.setAudioMuted(!1),[2]):(this.audioEl=this.audioEl||u.useAudioEl()||null,this.i.info(I+" ".concat(this.userID," start using audio el ").concat(null===(i=this.audioEl)||void 0===i?void 0:i.id)),(e=null===(n=this.audioEl)||void 0===n?void 0:n.dom)||(this.i.error(I+" ".concat(this.userID," not enough audio elements")),e=s.VJ.createElement("audio"),this.audioEl={id:-1,dom:e,used:!0},e.setAttribute("autoplay","autoplay")),e.muted=!0,e.setAttribute("autoplay","autoplay"),e.setAttribute("id","zg-audio-source-"+this.userID),this.sourceNode?[4,this.changeRenderConfig(this.isSpatial,!0)]:[3,2]));case 1:r.sent(),r.label=2;case 2:return"suspended"===this.audioCtx.state&&this.audioCtx.resume(),[2]}}))}))},i.prototype.stopPlayingAudio=function(t){if(void 0===t&&(t=""),this.isPlaying&&(this.i.info(I+" vocal ".concat(this.userID," stop for ")+t),this.isPlaying=!1),(0,d.Fr)())this.streamView.setAudioMuted(!0);else{this.sourceNode&&this.sourceNode.disconnect();var i=this.audioEl,n=null==i?void 0:i.dom;n&&(n.srcObject=null,n.parentNode&&n.parentNode.removeChild(n));var e=(null==i?void 0:i.id)||-1;i&&e>=0&&(u.stopUsingAudioEl(e),this.i.info(I+" ".concat(this.userID," stop using audio el ").concat(e))),this.audioEl=null}},i.prototype.checkIfCanPlay=function(t){var i=this.distance=this.getDistanceFromListener(t);null===i||i>this.maxDistance||0===this.maxDistance?this.stopPlayingAudio("out of range. ".concat(i," > ").concat(this.maxDistance)):this.startPlayingAudio("in range")},i}(b),M=e(166),j=function(){function t(){this.u={}}return t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.addEventHandler=function(t,i){if(this.u[t]||(this.u[t]=[]),!(0,l.JO)(i))throw new Error("Params callBack is not a Function");return-1==this.u[t].indexOf(i)&&this.u[t].push(i),!0},t.prototype.removeEventHandler=function(t,i){return!!this.u[t]&&(this.u[t]=i?this.u[t].filter((function(t){return t!==i})):[],!0)},t.prototype.emit=function(t){for(var i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];this.u[t]&&this.u[t].forEach((function(n){try{setTimeout((function(){n.apply(void 0,i)}),0)}catch(i){console.error('Fail to execute callback of event "'.concat(t,'" : ').concat(i))}}))},t.prototype.reset=function(){this.u={}},t}(),D=j,L=function(t,i,n,e){return new(n||(n=Promise))((function(r,o){function s(t){try{h(e.next(t))}catch(t){o(t)}}function u(t){try{h(e.throw(t))}catch(t){o(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,u)}h((e=e.apply(t,i||[])).next())}))},F=function(t,i){var n,e,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(h){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,h])}}};var U,G=function(){function t(t,i){var n=this;this.raMode=o.kf.World,this.recvRange=null,this.position=null,this.forwardAxis=[1,0,0],this.upAxis=[0,0,1],this.audioStream=null,this.enableMic=!1,this.isPublishing=!1,this.streamID=null,this.isDenoise=!1,this.denoiseMode=M.PP.AI,this.voiceChanger=null,this.voiceParam=null,this.isUpdated=!0,this.zegoRTC=i,this.audioCtx=t,this.audioListener=this.audioCtx.listener,this.eventHandler=D.getInstance(),this.zegoRTC.on("publisherStateUpdate",(function(t){var i=t.state,e=t.errorCode,r=t.extendedData,s=t.streamID.match(/(.*)_(.*)/);if(3===(null==s?void 0:s.length)){if(n.userID!==s[1])return;"NO_PUBLISH"===i?(n.isPublishing=!1,n.stopPublishingStream()):(n.isPublishing=!0,n.isUpdated||(n.i.info(k+" resend stream info"),n.updateSteamExtraInfo())),n.eventHandler.emit("microphoneStateUpdate",{NO_PUBLISH:o.eI.Off,PUBLISH_REQUESTING:o.eI.TurningOn,PUBLISHING:o.eI.On}[i],e,r)}})),this.zegoRTC.on("deviceError",(function(t,i){return L(n,void 0,void 0,(function(){var n,e;return F(this,(function(r){switch(r.label){case 0:return this.i.info(k+" device fail ".concat(t," ").concat(i," ").concat(!!this.audioStream," ").concat(this.micID)),this.audioStream?[4,this.zegoRTC.enumDevices()]:[2];case 1:return n=r.sent(),e=n.microphones,this.micID||0!==e.length?1106009!==t?[3,3]:[4,this.zegoRTC.useAudioDevice(this.audioStream,this.micID||e[0].deviceID)]:[2];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))}))}return Object.defineProperty(t.prototype,"recvMode",{get:function(){return void 0!==this._recvMode?this._recvMode:[o.kf.World,o.kf.SecretTeam].includes(this.raMode)?o.ju.All:o.ju.Team},set:function(t){this._recvMode=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sendMode",{get:function(){return void 0!==this._sendMode?this._sendMode:this.raMode===o.kf.World?o.UF.All:o.UF.Team},set:function(t){this._sendMode=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"i",{get:function(){return this.zegoRTC.logger},enumerable:!1,configurable:!0}),t.getInstance=function(i,n){return t.instance||(t.instance=new t(i,n)),t.instance},t.prototype.updateSelfPosition=function(t,i,n){this.position=t,this.forwardAxis=i,Array.isArray(n)&&(this.upAxis=n),this.updateListenerEffect()},t.prototype.updateListenerEffect=function(){this.position&&(this.audioListener.positionX?(this.audioListener.positionX.value=this.position[1],this.audioListener.positionY.value=this.position[2],this.audioListener.positionZ.value=-this.position[0]):this.audioListener.setPosition(this.position[1],this.position[2],-this.position[0]),this.audioListener.forwardX?(this.audioListener.forwardX.value=this.forwardAxis[1],this.audioListener.forwardY.value=this.forwardAxis[2],this.audioListener.forwardZ.value=-this.forwardAxis[0],this.audioListener.upX.value=this.upAxis[1],this.audioListener.upY.value=this.upAxis[2],this.audioListener.upZ.value=-this.upAxis[0]):this.audioListener.setOrientation(this.forwardAxis[1],this.forwardAxis[2],-this.forwardAxis[0],this.upAxis[1],this.upAxis[2],-this.upAxis[0]))},t.prototype.startPublishingStream=function(){var t=this;this.enableMic?this.i.warn(k+" mic is already enabled"):(this.enableMic=!0,this.zegoRTC.createStream({camera:{video:!1,audio:!0,audioInput:this.micID||void 0,audioBitrate:30}}).then((function(i){return L(t,void 0,void 0,(function(){return F(this,(function(t){if(!this.userID)throw this.zegoRTC.destroyStream(i),this.enableMic=!1,Error("Enable mic failed. Please log in room first.");return this.audioStream&&this.audioStream!==i&&this.zegoRTC.destroyStream(this.audioStream),this.audioStream=i,this.isDenoise&&(this.enableDenoise(this.isDenoise),this.denoiseMode!==M.PP.AIBalanced&&this.denoiseMode!=M.PP.AIAggressive||this.setAiDenoiseMode(this.denoiseMode)),null!==this.voiceChanger&&this.setVoiceChangerPreset({voiceChanger:this.voiceChanger}),null!==this.voiceParam&&this.setVoiceChangerPreset({voiceParam:this.voiceParam}),this.streamID=this.userID+"_"+Date.now(),this.zegoRTC.startPublishingStream(this.streamID,i,{extraInfo:JSON.stringify(this.getExtraInfo())}),[2]}))}))})).catch((function(i){throw t.audioStream=null,t.enableMic=!1,i})))},t.prototype.stopPublishingStream=function(){this.isPublishing&&this.streamID&&this.zegoRTC.stopPublishingStream(this.streamID),this.isPublishing=!1,this.audioStream&&(this.zegoRTC.destroyStream(this.audioStream),this.audioStream=null),this.enableMic=!1},t.prototype.setCustomMode=function(t,i){var n=!1,e=!1,r=!1;return i!==this.recvMode&&(this.recvMode=i,r=!0),t!==this.sendMode&&(this.sendMode=t,n=!0,e=!0),n&&this.updateSteamExtraInfo(),{sendChange:e,recvChange:r}},t.prototype.setNormalMode=function(t){this.raMode=t,this.updateSteamExtraInfo()},t.prototype.setTeamID=function(t){this.teamID=t,this.updateSteamExtraInfo()},t.prototype.updateSteamExtraInfo=function(){var t=this;this.streamID&&this.isPublishing&&(this.isUpdated=!1,this.i.info(k+" update stream info"),this.zegoRTC.setStreamExtraInfo(this.streamID,JSON.stringify(this.getExtraInfo())).then((function(i){0===i.errorCode&&(t.i.info(k+" update stream info success"),t.isUpdated=!0)})))},t.prototype.getExtraInfo=function(){var t,i={range_audio_team_id:this.teamID||"",range_audio_mode:(t=this.raMode,{0:1,1:2,2:3}[t]),r_a_s_flag:1};return void 0===this._sendMode&&this.raMode!==o.kf.World||(i.r_a_speak=this.sendMode),i},t.prototype.reset=function(){this.audioStream&&this.stopPublishingStream(),this.userID=void 0,this.streamID=null},t.prototype.enableDenoise=function(t){var i=this;return this.audioStream&&this.zegoRTC._enableAiDenoise(this.audioStream,t).catch((function(t){i.isDenoise=!1;var n=t||{};i.eventHandler.emit("aiDenoiseError",n.errorCode,n.extendedData)})),this.isDenoise=t,!0},t.prototype.setAiDenoiseMode=function(t){var i=this;return this.audioStream&&this.zegoRTC.setAiDenoiseMode(this.audioStream,t).catch((function(t){i.denoiseMode=M.PP.AI;var n=t||{};i.eventHandler.emit("aiDenoiseError",n.errorCode,n.extendedData)})),this.denoiseMode=t,!0},t.prototype.setVoiceChangerPreset=function(t){var i=this;return this.audioStream&&this.zegoRTC.setVoiceChangerPreset(this.audioStream,t).catch((function(t){i.voiceChanger=null;var n=t||{};i.eventHandler.emit("voiceChangerError",n.errorCode,n.extendedData)})),"voiceChanger"in t&&void 0!==t.voiceChanger?(this.voiceChanger=t.voiceChanger,this.voiceParam=null):"voiceParam"in t&&void 0!==t.voiceParam&&(this.voiceParam=t.voiceParam,this.voiceChanger=null),!0},t}(),H=function(t,i,n){if(n||2===arguments.length)for(var e,r=0,o=i.length;r<o;r++)!e&&r in i||(e||(e=Array.prototype.slice.call(i,0,r)),e[r]=i[r]);return t.concat(e||Array.prototype.slice.call(i))},z="zc.ra.2",V=function(){function t(t,i){this.i=t,this.isEnable=!1,this.interval=100,this.timer=null,this.audioSourceList=[],this.hasChanged=!1,this.userChanged=!1,this.updateUserInterval=1e3,this.updateUserTimer=null,this.audioSourceUpdate=!1,this._maxPlayingQuantity=20,this.allAudioSourceList=[],this.audioSourceWithinRangeList=[],this.localUserList=[],this.h=i}return t.getInstance=function(i,n){return t.instance||(t.instance=new t(i,n)),t.instance},t.prototype.setAudioSourceUpdate=function(t){this.audioSourceUpdate=t},t.prototype.setListener=function(t){this.h=t,this.hasChanged=!0,this.userChanged=!0},t.prototype.setAudioSourceList=function(t){this.audioSourceList=t,this.i.info("".concat(z," set src list: [").concat(t.map((function(t){return t.userID})).join(","),"]")),this.hasChanged=!0},t.prototype.setAllAudioSourceList=function(t){t&&(this.allAudioSourceList=t),this.userChanged=!0},t.prototype.startPlayingAudioStream=function(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.hasChanged=!0,this.playAudioTask()},t.prototype.playAudioTask=function(){var t=this;this.hasChanged&&(this.hasChanged=!1,this.handlePlayAudioTask()),this.timer=window.setTimeout((function(){t.playAudioTask()}),this.interval)},t.prototype.handlePlayAudioTask=function(){var t=this;if(this.isEnable){this.i.info("".concat(z," handler task start"));var i=H([],this.audioSourceList,!0),n=0,e=this.h.recvMode;if([o.ju.Team,o.ju.All].includes(e)){var r=this.getTeamAudioSourceGroup();i=r.otherList,r.teamList.forEach((function(i){n<t._maxPlayingQuantity&&(i.isPlaying||i.startPlayingAudio("play for team"),n++)}))}var s=[o.ju.World,o.ju.All].includes(e);s&&(i.forEach((function(i){i.distance=i.getDistanceFromListener(t.h)})),i.sort((function(t,i){return null===t.distance?1:null===i.distance||t.distance<i.distance?-1:t.distance>i.distance?1:0}))),i.forEach((function(i){var e=[o.UF.All,o.UF.World].includes(i.sendMode)&&null!==i.distance&&(null===t.h.recvRange||i.distance<=t.h.recvRange);if(s&&n<t._maxPlayingQuantity&&e)i.isPlaying||i.startPlayingAudio("play for range"),n++;else{var r="stop for mode or range. mode: ".concat(i.sendMode,", range: ").concat(i.distance," > ").concat(t.h.recvRange);i.stopPlayingAudio(r)}})),this.i.info(z+" playing quantity: ".concat(n,"."))}else this.stopPlayingAudioStream()},t.prototype.startCheckUserInRange=function(){this.i.info(z+" start user check"),this.updateUserTimer&&(clearTimeout(this.updateUserTimer),this.updateUserTimer=null),this.userChanged=!0,this.userCheckTask()},t.prototype.stopCheckUserInRange=function(){this.i.info(z+" stop user check"),this.updateUserTimer&&(clearTimeout(this.updateUserTimer),this.updateUserTimer=null)},t.prototype.userCheckTask=function(){var t=this;this.userChanged&&(this.userChanged=!1,this.handleUserCheckTask()),this.updateUserTimer=window.setTimeout((function(){t.userCheckTask()}),this.updateUserInterval)},t.prototype.handleUserCheckTask=function(){var t=this;if(this.audioSourceUpdate){var i=[];this.allAudioSourceList.forEach((function(n){n.distance=n.getDistanceFromListener(t.h);var e=null!==n.distance&&(null===t.h.recvRange||n.distance<=t.h.recvRange),r=!!t.localUserList.find((function(t){return t.userID===n.userID}));e&&r&&i.push({userID:n.userID,position:n.position})})),this.checkAudioSourceListDiff(i,this.audioSourceWithinRangeList)&&this.h.eventHandler.emit("audioSourceWithinRangeUpdate",i),this.audioSourceWithinRangeList=i}},t.prototype.getTeamAudioSourceGroup=function(){var t=this,i=[],n=[];return this.audioSourceList.forEach((function(e){e.isSpeakInTeam(t.h.teamID)?i.push(e):n.push(e)})),{teamList:i,otherList:n}},t.prototype.stopPlayingAudioStream=function(){this.timer&&(clearTimeout(this.timer),this.timer=null);this.audioSourceList.forEach((function(t){t.stopPlayingAudio("stop for all stream")}))},t.prototype.setLocalUserList=function(t){this.localUserList=t,this.userChanged=!0},t.prototype.checkAudioSourceListDiff=function(t,i){for(var n,e=0;e<t.length;e++){n=!1;for(var r=0;r<i.length;r++)if(t[e].userID===i[r].userID){n=!0;break}if(!n)return!0}for(var o=0;o<i.length;o++){n=!1;for(var s=0;s<t.length;s++)if(i[o].userID===t[s].userID){n=!0;break}if(!n)return!0}return!1},t}();function W(t){return!isNaN(Number(t))&&""!==t&&Number.MAX_SAFE_INTEGER>=Number(t)&&Number(t)>=-Number.MAX_SAFE_INTEGER}function J(t){if(Array.isArray(t)){for(var i=0;i<3;i++){if(!W(t[i]))return!1}return!0}return!1}!function(t){t[t.Normal=0]="Normal",t[t.Custom=1]="Custom"}(U||(U={}));var q=function(){return q=Object.assign||function(t){for(var i,n=1,e=arguments.length;n<e;n++)for(var r in i=arguments[n])Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r]);return t},q.apply(this,arguments)},B=function(t,i,n,e){return new(n||(n=Promise))((function(r,o){function s(t){try{h(e.next(t))}catch(t){o(t)}}function u(t){try{h(e.throw(t))}catch(t){o(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,u)}h((e=e.apply(t,i||[])).next())}))},Q=function(t,i){var n,e,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(h){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&