zego-express-engine-webrtc
Version:
zego webrtc express sdk
1 lines • 33.8 kB
JavaScript
!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)}}()},8627:function(t,i,n){n.d(i,{S6t:function(){return e}});n(8866);var e={code:1103057,message:"decode audio data fail"}},8866:function(t,i,n){n.d(i,{EK:function(){return r},Rl:function(){return m},Wk:function(){return l},aw:function(){return o},dO:function(){return f},fT:function(){return u},h2:function(){return c},l3:function(){return e},pt:function(){return h},qC:function(){return a},rA:function(){return s}});n(7202),n(8627),n(4872);var e=Promise;function s(t,i,n){void 0===n&&(n=""),t.info("".concat(i," call ").concat(n))}function r(t,i,n){void 0===n&&(n=""),t.info("".concat(i," success ").concat(n))}var u="room not exist",h="device is not found",o="stream is not from zego",f="input param error",a="local stream wrong",c="no preview",l="publish stream no found",m="network is broken"},7202:function(t,i,n){n(6994)},4872:function(t,i,n){n.d(i,{Cs:function(){return e},QP:function(){return s},SY:function(){return f},Si:function(){return o},TE:function(){return u},dd:function(){return r},dr:function(){return h}});n(2362);function e(t){return"number"==typeof t}function s(t){return"string"==typeof t}function r(t){return"boolean"==typeof t}function u(t){return void 0===t}function h(t){return t instanceof MediaStream}function o(t){return t instanceof HTMLMediaElement}function f(t){return t instanceof ArrayBuffer}},6493:function(t,i,n){function e(){return navigator.userAgent||""}function s(){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 r(){return"safari"==s().name.toLowerCase()}n.d(i,{$t:function(){return e},nr:function(){return r}})},327:function(t,i,n){n.d(i,{L:function(){return s}});var e=n(4872);function s(t,i){if(t&&!(0,e.dr)(t)&&t.zegoStream){if(i.info("cu.gs type:zego"),(0,e.dr)(t.stream))return t.stream;throw new Error("The ZegoLocalStream type requires first calling the capture api to capture the stream")}return t}},6994:function(i){i.exports=t}},n={};function e(t){var s=n[t];if(void 0!==s)return s.exports;var r=n[t]={exports:{}};return i[t](r,r.exports,e),r.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 s={};e.r(s),e.d(s,{AudioMix:function(){return C}});var r="zc.pe.0",u="zc.pe.1",h="zc.aep",o="zc.sev",f="zc.sma.0",a="zc.sma.1",c="zc.mb",l="zc.smb",m="zc.p.0.pe.0",d="zc.p.0.pe.1",v="zc.p.0.re",p="zc.p.0.se",b="zc.p.0.sma.0",g="zc.smav",y="zc.p.0.mb",D="zc.p.0.smav",I=e(8627),x=function(){function t(t,i,n,e,s){this.t=t,this.ac=i,this.localStream=n,this.destination=e,this.rtcViewer=s,this.audioBufferList=[],this.replace=!1,this.effectEndedCallBack=null,this.effectEndedListener=null,this.startTimes=0,this.startOffset=0,this.pauseTimes=0,this.resumeOffset=0,this.paused=!1,this.isMixAudio=!1,this.isMixingBuffer=!1,this.loop=!1}return t.prototype.playEffect=function(t,i,n,e,s){var r=this;!0!==this.isMixAudio?this.audioBuffer?(this.startOffset=t||0,this.loop=i||!1,this.replace=n||!1,this.effectEndedCallBack=s,this.mixEffect(this.audioBuffer,(function(){r.buffSource.loop=!!i,t?r.buffSource.start(0,t/1e3):r.buffSource.start(0),r.startTimes=Date.now(),r.effectEndedListener=r.effectEndedHandler.bind(r),r.buffSource.addEventListener("ended",r.effectEndedListener),e&&e()}))):this.t.error("amu.pe.1 no audio buffer found"):this.t.warn("amu.pe.1 audio is mixing")},t.prototype.stopMixingBuffer=function(){return this.isMixingBuffer=!1,this.stopMixingAudio()},t.prototype.playRealTimeEffect=function(t){var i=this;this.mixEffect(t,(function(){i.buffSource&&i.buffSource.start(0),i.buffSource&&i.buffSource.addEventListener("ended",(function(){i.audioBufferList.shift(),i.audioBufferList.length>0&&i.isMixAudio&&i.playRealTimeEffect(i.audioBufferList[0])}))}))},t.prototype.pauseEffect=function(){this.audioBufferList.length>0?this.t.error("amu.pe.0 real time buffer can not be paused"):(this.stopMixingAudio(!0),this.resumeOffset=(this.pauseTimes-this.startTimes+this.startOffset)%(1e3*this.audioBuffer.duration),this.paused=!0)},t.prototype.resumeEffect=function(){return this.audioBufferList.length>0?(this.t.error("amu.pe.0 real time buffer can not be resume"),!1):(this.playEffect(this.resumeOffset,this.loop,this.replace,void 0,this.effectEndedCallBack),this.startOffset=this.resumeOffset,this.paused=!1,!0)},t.prototype.mixEffect=function(t,i){this.localStream?(this.ac.resume(),this.gainNode=this.ac.createGain(),this.delayNode=this.ac.createDelay(1),this.delayNode.delayTime.value=0,this.buffSource=this.ac.createBufferSource(),this.buffSource.buffer=t,this.buffSource.connect(this.gainNode),this.gainNode.connect(this.ac.destination),this.replaceTrack()&&i()):this.t.error("amu.me.0 localStream can not be found")},t.prototype.replaceTrack=function(){if(!this.destination)return!1;this.gainNode.connect(this.delayNode),this.delayNode.connect(this.destination);var t=this.destination.stream.getAudioTracks()[0],i=this.localStream.getTracks();return this.micTrack=this.localStream.getAudioTracks()[0],this.micTrack!==t&&(this.micTrack?i.includes(this.micTrack)&&this.localStream.removeTrack(this.micTrack):this.t.warn("amu.rt.0 origin track not fonud"),i.includes(t)||(this.localStream.addTrack(t),this.rtcViewer&&this.rtcViewer.setAudio(t))),this.isMixAudio=!0,!0},t.prototype.effectEndedHandler=function(){this.stopMixingAudio(),this.effectEndedCallBack&&this.effectEndedCallBack(),this.effectEndedCallBack=null},t.prototype.stopMixingAudio=function(t){return void 0===t&&(t=!1),this.paused?(this.t.info("amu.sma.1 audioEffect is paused"),!t&&this.effectEndedListener&&(this.effectEndedCallBack&&this.effectEndedCallBack(),this.effectEndedCallBack=null),!0):this.isMixAudio?this.localStream?(this.buffSource&&(this.buffSource.removeEventListener("ended",this.effectEndedListener),this.buffSource.stop(),this.pauseTimes=Date.now(),this.buffSource.disconnect(this.gainNode),this.buffSource=null),this.gainNode.disconnect(),this.delayNode.disconnect(),this.isMixAudio=!1,this.audioBufferList=[],!t&&this.effectEndedListener&&(this.effectEndedCallBack&&this.effectEndedCallBack(),this.effectEndedCallBack=null),!0):(this.t.error("amu.sma.1 localStream can not be found"),!1):(this.t.warn("amu.sma.1 no mixing audio found"),!0)},t.prototype.getProcess=function(){var t=Date.now();return this.paused&&(t=this.pauseTimes),(t-this.startTimes+this.startOffset)%(1e3*this.audioBuffer.duration)},t.prototype.seekTo=function(t){void 0===t&&(t=0),this.startOffset=t,this.paused?this.resumeOffset=t:(this.stopMixingAudio(!0),this.playEffect(t,this.loop,this.replace,void 0,this.effectEndedCallBack))},t.prototype.mixingBuffer=function(t,i){var n=this;!0!==this.isMixAudio||0!=this.audioBufferList.length||0!=this.isMixingBuffer?(this.ac.resume(),this.ac.decodeAudioData(t,(function(t){n.audioBufferList.push(t),1==n.audioBufferList.length&&n.playRealTimeEffect(n.audioBufferList[0]),n.isMixingBuffer=!0,i&&i()}),(function(t){n.t.error("amu.mb.0 "+t),i&&i({code:I.S6t.code,message:I.S6t.message+" "+t})}))):this.t.error("amu.mb.0 audio is mixing")},t.prototype.setMixingAudioVolume=function(t){return this.gainNode?(console.error("ktv setVolume",t),this.gainNode.gain.value=t,!0):(this.t.error("amu.sma.2 no mixing audio found"),!1)},t.prototype.setDelay=function(t){return this.delayNode?(this.t.info("amu.sma.2 set delay: "+t),this.delayNode.delayTime.value=t,!0):(this.t.warn("amu.sma.2 no mixing audio found"),!1)},t}(),z=e(6493),w=function(){function t(t,i,n,e,s,r,u){void 0===u&&(u=1);var h=this;this.t=t,this.acMgr=i,this.localStream=n,this.browser=e,this.destination=s,this.rtcViewer=r,this.volumeFactor=u,this.isMixAudio=!1,this.maxDelay=1,this.audioCurrentTimer=null,this.audioResumedTimer=null,this.audioEl=null,this.eventHandler={volumechange:function(t){var i=t.target;i&&h.audioNode&&h.isMediaElSrc&&(i.muted||i.paused?(h.t.info("amu.sma.0 ".concat(h.id," audio muted disconnect")),h.audioNode.disconnect()):(h.t.info("amu.sma.0 ".concat(h.id," audio is connected")),h.audioNode.connect(h.gainNode)))},canplay:function(t){var i=t.target;i&&!h.isMediaElSrc&&h.isMixAudio&&(h.t.info("amu.sma.1 ".concat(h.id," canplay, remixing audio")),h.stopMixingAudio(),h.startMixingAudio(i))}},this.isMediaElSrc=!1,this.volume=1,this.delay=0,this.id=Date.now()%1e5+Math.floor(10*Math.random()),t.info("amu.sma.0 ".concat(this.id," init audio mix"))}return Object.defineProperty(t.prototype,"ac",{get:function(){return this.acMgr.ac},enumerable:!1,configurable:!0}),t.prototype.startMixingAudio=function(t){if(this.isMixAudio)return this.t.error("amu.sma.0 audio is mixing"),!1;if(!this.localStream)return this.t.error("amu.sma.0 localStream can not be found"),!1;var i;t.captureStream=t.captureStream||t.mozCaptureStream||t.webkitCaptureStream,this.isMixAudio=!0,this.gainNode||(this.gainNode=this.ac.createGain(),this.setMixingAudioVolume()),this.delayNode||(this.delayNode=this.ac.createDelay(this.maxDelay),this.t.info("amu.sma.1 ".concat(this.id," init set delay: ")+this.delay),this.delayNode.delayTime.value=this.delay);var n="safari"===this.browser;this.isMediaElSrc=!0;try{var e=this.acMgr.getMediaElementRenderer(t);if(!e)return!1;this.audioNode=e.getMixNode().mixOutputNode,this.audioEl=t}catch(t){i=t}t.addEventListener("volumechange",this.eventHandler.volumechange),t.addEventListener("pause",this.eventHandler.volumechange),t.addEventListener("play",this.eventHandler.volumechange);var s=this.getBrowserInfo(),r=!1;return n&&"10.15.6"===(null==s?void 0:s.sysVer)&&"13.1.2"===(null==s?void 0:s.ver)&&(r=!0),r&&(this.audioResumedTimer=setInterval((function(){t.currentTime=t.currentTime+.45}),6e3)),i?(this.t.info("amu.sma.1 ".concat(this.id," create source failed: ")+i),!0):(this.audioNode.connect(this.gainNode),this.t.info("amu.sma.1 ".concat(this.id," mix audio success.")),this.replaceTrack())},t.prototype.getBrowserInfo=function(){var t,i={},n=(0,z.$t)().toLowerCase();t=(n.match(/x [\d._]+/gi)+"").replace(/[^0-9|_.]/gi,"").replace(/_/gi,"."),i.sysVer=t;var e=n.match(/(msie|firefox|chrome|opera|version).*?([\d.]+)/);return e&&(i.browser=e[1].replace(/version/,"'safari"),i.ver=e[2]),i},t.prototype.replaceTrack=function(){if(!this.destination)return!1;this.gainNode.connect(this.delayNode),this.delayNode.connect(this.destination);var t=this.destination.stream.getAudioTracks()[0],i=this.localStream.getTracks();return this.micTrack=this.localStream.getAudioTracks()[0],this.micTrack!==t&&(this.micTrack?i.includes(this.micTrack)&&this.localStream.removeTrack(this.micTrack):this.t.warn("amu.rt.1 origin track not fonud"),i.includes(t)||(this.localStream.addTrack(t),this.rtcViewer&&this.rtcViewer.setAudio(t))),!0},t.prototype.stopMixingAudio=function(){return this.isMixAudio?this.localStream?(this.audioEl&&(this.audioEl.removeEventListener("volumechange",this.eventHandler.volumechange),this.audioEl.removeEventListener("pause",this.eventHandler.volumechange),this.audioEl.removeEventListener("play",this.eventHandler.volumechange),this.audioEl.removeEventListener("canplay",this.eventHandler.canplay),this.audioEl=null),this.audioNode&&(this.audioNode.disconnect(),this.audioNode=null,this.audioCurrentTimer&&(clearInterval(this.audioCurrentTimer),this.audioCurrentTimer=null),this.audioResumedTimer&&(clearInterval(this.audioResumedTimer),this.audioResumedTimer=null)),this.gainNode.disconnect(),this.delayNode.disconnect(),this.isMixAudio=!1,this.t.info("amu.sma.1 ".concat(this.id," stop mix audio success.")),!0):(this.t.error("amu.sma.1 localStream can not be found"),!1):(this.t.warn("amu.sma.1 no mixing audio found"),!0)},t.prototype.setMixingAudioVolume=function(t,i){if(void 0===t?t=this.volume:this.volume=t,void 0===i?i=this.volumeFactor:this.volumeFactor=i,!this.gainNode)return this.t.error("amu.sma.2 no mixing audio found"),!1;var n=t*this.volumeFactor;return this.t.info("amu.sma.2 "+this.id+" set volume: "+n),this.gainNode.gain.value=n,!0},t.prototype.setDelay=function(t){return this.delayNode?(t/=1e3,!isNaN(t)&&(t>this.maxDelay&&(t=this.maxDelay),t<0&&(t=0),this.t.info("amu.sma.1 ".concat(this.id," set delay: ")+t),this.delayNode.delayTime.value=t,this.delay=t,!0)):(this.t.warn("amu.sma.1 no mixing audio found"),!1)},t}(),j=e(4872),O=function(){function t(t){this.i=t,this.audioDestNode=void 0,this._audioMixList=[],this._arrayBufferMap={},this._effectList=[],this.volumeFactor=1}return Object.defineProperty(t.prototype,"delay",{get:function(){return this.u.engineConfig.mixingAudioDelay+this.u.engineConfig.baseMixingAudioDelay},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"t",{get:function(){return this.i.logger},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_localStream",{get:function(){return this.i.localStream},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"h",{get:function(){return this.i.streamCenter},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"u",{get:function(){return this.i.stateCenter},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ac",{get:function(){return this.acMgr.ac},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"acMgr",{get:function(){return this.i.acMgr},enumerable:!1,configurable:!0}),t.prototype.startMixingAudio=function(t){var i=this;if(this.t.info(b+" call"),!this._localStream)return this.t.error(b+" localStream not found"),!1;var n=!0;return t.forEach((function(t){if(i._audioMixList.find((function(i){return i.media==t})))i.t.warn(b+" mix audio already exist");else if(i._localStream){i.h.soundLevelDelegate&&i.i.stopSoundLevel();var e=i.createDestNode(),s=new w(i.t,i.acMgr,i._localStream,i.u.browser,e,i.i.rtcViewer,i.volumeFactor);i._audioMixList.push({audioMix:s,media:t}),s.startMixingAudio(t)||(n=!1),s.setDelay(i.delay),i.h.soundLevelDelegate&&i.i.startSoundLevel()}})),n},t.prototype.stopMixingAudio=function(t){var i=this;return this.t.info("zc.p.0.sma.1 call"),t?t.forEach((function(t){for(var n=0;n<i._audioMixList.length;n++)if(i._audioMixList[n].media==t){i._audioMixList[n].audioMix.stopMixingAudio()&&i._audioMixList.splice(n--,1);break}})):(this._audioMixList.forEach((function(t){return t.audioMix.stopMixingAudio()})),this._audioMixList=[]),!0},t.prototype.setVolumeFactor=function(t){this.t.info(D+" set factor: "+t),isNaN(t)&&this.t.error(D+" set factor failed"),this.volumeFactor=t,this._audioMixList.forEach((function(i){i.audioMix.setMixingAudioVolume(void 0,t)}))},t.prototype.setMixingAudioVolume=function(t,i){this.t.info(D+" call");var n=this._audioMixList.find((function(t){return t.media===i}));return n?(n.audioMix.setMixingAudioVolume(t),this.t.info(D+" call success"),!0):(this.t.error(D+" audio is not mixing"),!1)},t.prototype.playEffect=function(t,i,n,e){var s=this;if(this.t.info(m+" call"),this._localStream)if(this._effectList.find((function(n){return n.effectID==t.effectID&&n.audioBuffer==i})))this.t.warn(m+" effect already exist ");else{this.h.soundLevelDelegate&&this.i.stopSoundLevel();var r=this.createDestNode(),u=new x(this.t,this.ac,this._localStream,r,this.i.rtcViewer);u.audioBuffer=i;var h={processor:u,effectID:t.effectID,audioBuffer:i};this._effectList.push(h);u.playEffect(t.playTime,t.loop,!1,(function(){n&&n()}),(function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];s._effectList=s._effectList.filter((function(t){return t!==h})),e&&e.apply(void 0,t)})),this.h.soundLevelDelegate&&this.i.startSoundLevel(),this.t.info(m+" play effect "+t.effectID+" success")}else this.t.warn(m+" stream not found")},t.prototype.pauseEffect=function(t){var i=this._effectList.find((function(i){return i.effectID==t}));if(i)this.h.soundLevelDelegate&&this.i.stopSoundLevel(),i.processor.pauseEffect(),this.h.soundLevelDelegate&&this.i.startSoundLevel(),this.t.info(d+" pause "+t+" success");else{if(!(0,j.TE)(t))return this.t.error(d+" effect not found"),!1;this.h.soundLevelDelegate&&this.i.stopSoundLevel(),this._effectList.forEach((function(t){return t.processor.pauseEffect()})),this.h.soundLevelDelegate&&this.i.startSoundLevel()}return!0},t.prototype.resumeEffect=function(t){var i=this._effectList.find((function(i){return i.effectID==t}));if(i){this.h.soundLevelDelegate&&this.i.stopSoundLevel();var n=i.processor.resumeEffect();return this.h.soundLevelDelegate&&this.i.startSoundLevel(),this.t.info(v+" resume "+t+" success"),n}return(0,j.TE)(t)?(this.h.soundLevelDelegate&&this.i.stopSoundLevel(),this._effectList.forEach((function(t){return t.processor.resumeEffect()})),this.h.soundLevelDelegate&&this.i.startSoundLevel(),!0):(this.t.error(v+" no effect found"),!1)},t.prototype.stopEffect=function(t){var i=this._effectList.find((function(i){return i.effectID==t}));if(i)this.h.soundLevelDelegate&&this.i.stopSoundLevel(),i.processor.stopMixingAudio(),this._effectList=this._effectList.filter((function(t){return t!==i})),this.h.soundLevelDelegate&&this.i.startSoundLevel(),this.t.info(p+" pause "+t+" success");else{if(!(0,j.TE)(t))return this.t.error(p+" effect not found"),!1;this.h.soundLevelDelegate&&this.i.stopSoundLevel(),this._effectList.forEach((function(t){return t.processor.stopMixingAudio()})),this._effectList=[],this.h.soundLevelDelegate&&this.i.startSoundLevel()}return!0},t.prototype.setEffectVolume=function(t,i,n){var e=this._effectList.find((function(t){return t.effectID==i}));if(e)e.processor.setMixingAudioVolume(t),e.processor.setDelay(n||1e-7),this.t.info("zp.sev.0 set volume "+i+" success");else{if(!(0,j.TE)(i))return this.t.error("zp.sev.0 effect not found"),!1;this._effectList.forEach((function(i){return i.processor.setMixingAudioVolume(t)}))}return!0},t.prototype.mixingBuffer=function(t,i,n){var e=this;if(this.t.info(y+" call"),this._localStream)if(this._arrayBufferMap[t])this.h.soundLevelDelegate&&this.i.stopSoundLevel(),this._arrayBufferMap[t].mixingBuffer(i,(function(){e.h.soundLevelDelegate&&e.i.startSoundLevel(),n&&n()}));else{this.h.soundLevelDelegate&&this.i.stopSoundLevel();var s=this.createDestNode(),r=new x(this.t,this.ac,this._localStream,s,this.i.rtcViewer);this._arrayBufferMap[t]=r,r.mixingBuffer(i,(function(){e.h.soundLevelDelegate&&e.i.startSoundLevel(),n&&n()}))}},t.prototype.stopMixingBuffer=function(t){if(t&&this._arrayBufferMap[t])return this.h.soundLevelDelegate&&this.i.stopSoundLevel(),this._arrayBufferMap[t].stopMixingBuffer(),delete this._arrayBufferMap[t],this.h.soundLevelDelegate&&this.i.startSoundLevel(),!0;if((0,j.TE)(t)){for(var i in this.h.soundLevelDelegate&&this.i.stopSoundLevel(),this._arrayBufferMap)this._arrayBufferMap[i].stopMixingBuffer();return this.h.soundLevelDelegate&&this.i.startSoundLevel(),!0}return this.t.warn(y+" arrayBuffer no found"),!1},t.prototype.getEffectProgress=function(t){var i=this._effectList.find((function(i){return i.effectID==t}));return i?i.processor.getProcess():(this.t.error(h+" effect not found"),0)},t.prototype.seekAudioEffect=function(t,i){var n=this._effectList.find((function(i){return i.effectID==t}));return n?(this.h.soundLevelDelegate&&this.i.stopSoundLevel(),n.processor.seekTo(i),this.h.soundLevelDelegate&&this.i.startSoundLevel(),!0):(this.t.error(h+" effect not found"),!1)},t.prototype.stopAudioManager=function(){this.stopMixingAudio(),this.stopMixingBuffer(),this.stopEffect()},t.prototype.createDestNode=function(){var t=null,i=this.i.createDestNode(this._localStream);return this.i.audioNodeQueue||((t=this.i.createSrcNode()).disconnect(),t.connect(i)),i},t.prototype.setMixingDelay=function(t){this._audioMixList.forEach((function(i){i.audioMix.setDelay(t)}))},t}(),S=e(8866),M=e(327),_=function(t,i,n,e){return new(n||(n=Promise))((function(s,r){function u(t){try{o(e.next(t))}catch(t){r(t)}}function h(t){try{o(e.throw(t))}catch(t){r(t)}}function o(t){var i;t.done?s(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(u,h)}o((e=e.apply(t,i||[])).next())}))},k=function(t,i){var n,e,s,r,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return r={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function h(h){return function(o){return function(h){if(n)throw new TypeError("Generator is already executing.");for(;r&&(r=0,h[0]&&(u=0)),u;)try{if(n=1,e&&(s=2&h[0]?e.return:h[0]?e.throw||((s=e.return)&&s.call(e),0):e.next)&&!(s=s.call(e,h[1])).done)return s;switch(e=0,s&&(h=[2&h[0],s.value]),h[0]){case 0:case 1:s=h;break;case 4:return u.label++,{value:h[1],done:!1};case 5:u.label++,e=h[1],h=[0];continue;case 7:h=u.ops.pop(),u.trys.pop();continue;default:if(!(s=u.trys,(s=s.length>0&&s[s.length-1])||6!==h[0]&&2!==h[0])){u=0;continue}if(3===h[0]&&(!s||h[1]>s[0]&&h[1]<s[3])){u.label=h[1];break}if(6===h[0]&&u.label<s[1]){u.label=s[1],s=h;break}if(s&&u.label<s[2]){u.label=s[2],u.ops.push(h);break}s[2]&&u.ops.pop(),u.trys.pop();continue}h=i.call(t,u)}catch(t){h=[6,t],e=0}finally{n=s=0}if(5&h[0])throw h[1];return{value:h[0]?h[1]:void 0,done:!0}}([h,o])}}},E=function(){function t(t,i,n,e,s,r){var u=this;this.t=t,this.dataReport=i,this.u=n,this.h=e,this.ac=s,this.rtcModules=r,this.buffer=null,this.blank=null,this.mixingDelay=0,(0,z.nr)()&&null==this.blank&&null==this.buffer&&(this.buffer=this.ac.createBuffer(1,1,this.ac.sampleRate),this.blank=this.ac.createBufferSource(),this.blank.buffer=this.buffer,this.blank.connect(this.ac.destination),this.blank.start()),this.rtcModules.bindListener("_engineConfigUpdate",(function(t){var i=t.mixingAudioDelay+t.baseMixingAudioDelay;isNaN(i)||i===u.mixingDelay||(u.t.info("zc.am.mdu delay update:"+i+", origin:"+u.mixingDelay),u.mixingDelay=i,u.h.previewStreamList.forEach((function(t){t.audioMixManager&&t.audioMixManager.setMixingDelay(i)})))}))}return t.prototype.preloadEffect=function(t,i,n){if(this.checkPreviewer(r,{effectID:t},{effectID:!0}))if(i&&(0,j.QP)(i)){if(this.u.audioEffectBuffer[t])return this.t.warn(r+" audio buffer already exists"),void(n&&n());this.t.info(r+" start preload effect"),this._preloadEffect(this.ac,t,i,n)}else this.t.error(r+" params error")},t.prototype.checkPreviewer=function(t,i,n){void 0===i&&(i={});var e=!!(null==n?void 0:n.effectID),s=!!(null==n?void 0:n.streamID),r=!!(null==n?void 0:n.previewer),u=i.effectID,h=i.streamID,o=h&&((0,j.QP)(h)?h:(0,M.L)(h,this.t));if((s||o)&&!(0,j.QP)(o)&&!(0,j.dr)(o))return this.t.error(t+" stream type error"),!1;if(e&&!u)return this.t.error(t+" effectID required"),!1;if(u&&!(0,j.QP)(u))return this.t.error(t+" effectID type error"),!1;if(r){var f=this.h.getPreviewer(o);return f||((0,j.QP)(o)?this.t.error(t+" stream is not publishing",{streamid:o}):this.t.error(t+" stream doesn't exist"),!1)}return!0},t.prototype.getEffectDuration=function(t){if(!this.checkPreviewer(h,{effectID:t},{effectID:!0}))return 0;var i=this.u.audioEffectBuffer[t];return i?i.duration?Math.floor(1e3*i.duration):0:(this.t.error(h+" effect not found"),0)},t.prototype.getEffectProgress=function(t,i){var n=this.checkPreviewer(h,{streamID:t,effectID:i},{effectID:!0,streamID:!0,previewer:!0});return(0,j.dd)(n)?0:this.getAudioManager(n).getEffectProgress(i)},t.prototype.seekAudioEffect=function(t,i,n){if(n<0)return this.t.error(h+" param time error "),!1;var e=this.checkPreviewer(h,{streamID:t,effectID:i},{effectID:!0,streamID:!0,previewer:!0});return!(0,j.dd)(e)&&this.getAudioManager(e).seekAudioEffect(i,n)},t.prototype.playEffect=function(t,i,n){return _(this,void 0,void 0,(function(){var e,s,r,h,o=this;return k(this,(function(f){switch(f.label){case 0:return e=(0,M.L)(t.stream,this.t)||t.streamID,s=t.path,this.checkPreviewer(u,{streamID:e,effectID:r=t.effectID},{streamID:!0,effectID:!0})?(h=this.u.audioEffectBuffer[r],s?h?(this.t.warn(u+" audio effect already exists"),[3,3]):[3,1]:[3,4]):[2];case 1:return[4,new S.l3((function(t,i){o.preloadEffect(r,s,(function(n){n?(o.t.error(u+" preload audio effect failed"),i(n)):t(void 0)}))}))];case 2:f.sent(),f.label=3;case 3:return[3,5];case 4:if(!h)return this.t.error(u+" audio effect doesn't exists"),[2];f.label=5;case 5:return this._playEffect(t,i,n),[2]}}))}))},t.prototype.pauseEffect=function(t,i){var n=(0,j.QP)(t)?t:(0,M.L)(t,this.t);return this._pauseEffect(n,i)},t.prototype.resumeEffect=function(t,i){var n=(0,j.QP)(t)?t:(0,M.L)(t,this.t);return this._resumeEffect(n,i)},t.prototype.stopEffect=function(t,i){var n=(0,j.QP)(t)?t:(0,M.L)(t,this.t);return this._stopEffect(n,i)},t.prototype.unloadEffect=function(t){return!!this.checkPreviewer("zc.ue",{effectID:t},{effectID:!0})&&(delete this.u.audioEffectBuffer[t],!0)},t.prototype.setEffectVolume=function(t,i,n,e){if(!(0,j.Cs)(i)||i<0||i>200)return this.t.error(o+" volume must be a number between 0 and 200"),!1;var s=(0,j.QP)(t)?t:(0,M.L)(t,this.t),r=this.checkPreviewer(o,{streamID:s,effectID:n},{streamID:!0,previewer:!0});return!(0,j.dd)(r)&&this.getAudioManager(r).setEffectVolume(i/100,n,e)},t.prototype.startMixingAudio=function(t,i){var n=(0,j.QP)(t)?t:(0,M.L)(t,this.t);return this.t.info(f+" call "+n),n?i?(this.t.info(f+" end "+n),Array.isArray(i)&&0!==i.length&&i.every((function(t){return(0,j.Si)(t)}))?this.l(n,i):(this.t.error(f+" audio list param type error"),!1)):(this.t.error(f+" no audio"),!1):(this.t.error(f+" stream not found"),!1)},t.prototype.stopMixingAudio=function(t,i){var n=(0,j.QP)(t)?t:(0,M.L)(t,this.t);return n?Array.isArray(i)&&0!==i.length||(0,j.TE)(i)?this._stopMixingAudio(n,i):(this.t.error(a+" audio param type error"),!1):(this.t.error(a+" stream not found"),!1)},t.prototype.mixingBuffer=function(t,i,n,e){var s=(0,j.QP)(t)?t:(0,M.L)(t,this.t);this.t.info(c+" call streamID: "+JSON.stringify(s)+" sourceID:"+i),s?i&&(0,j.QP)(i)?(this._mixingBuffer(s,i,n,e),this.t.info(c+" end")):this.t.error(c+" param source id format error"):this.t.error(c+" param streamid format error")},t.prototype.stopMixingBuffer=function(t,i){var n=(0,j.QP)(t)?t:(0,M.L)(t,this.t);return this._stopMixingBuffer(n,i)},t.prototype.setMixingAudioVolume=function(t,i,n){if(this.t.info(g+" call"),!t)return this.t.error(g+" stream not found"),!1;if(!(0,j.Cs)(i)||i<0||i>200)return this.t.error(g+" volume must be a number between 0 and 200"),!1;if(!n||!(0,j.Si)(n))return this.t.error(g+" no audio"),!1;var e=(0,j.QP)(t)?t:(0,M.L)(t,this.t);return this._setMixingAudioVolume(e,i,n)},t.prototype.getSoundLevel=function(t,i,n){var e="zc.gsl";(0,S.rA)(this.t,e);var s=this.h.getCloudSoundInterval();try{var r=this.h.createSoundLevel(this.ac,t,this.h.soundLevelInterval,s,(function(t){i(t)}));this.u.audioStreamList[t.id]={mic:r.mic,script:r.soundMeter}}catch(t){n(t)}(0,S.EK)(this.t,e)},t.prototype.stopSoundLevel=function(t){this.t.info("zc.ssl call");var i=this.u.audioStreamList[t.id];i.mic.disconnect(),i.script.destroy(),delete this.u.audioStreamList[t.id]},t.prototype._preloadEffect=function(t,i,n,e){var s=this,r=new XMLHttpRequest;r.open("GET",n,!0),r.setRequestHeader("Range","none"),r.responseType="arraybuffer",r.onload=function(){if(200==r.status||304==r.status){t.decodeAudioData(r.response,(function(t){s.t.info("zc.pe.0 effect '".concat(i,"' preload success")),s.u.audioEffectBuffer[i]=t,e&&e()}),(function(t){s.t.error("zc.pe.0 effect '".concat(i,"' preload fail. ")+t),e&&e(t)}))}else{var n=r.statusText;s.t.error("zc.pe.0 effect '".concat(i,"' preload fail.")+n),e&&e(n)}},r.send()},t.prototype._playEffect=function(t,i,n){var e=(0,M.L)(t.stream,this.t)||t.streamID,s=this.u.audioEffectBuffer[t.effectID];if(s){var r=this.checkPreviewer(u,{streamID:e,effectID:t.effectID},{streamID:!0,effectID:!0,previewer:!0});(0,j.dd)(r)||this.getAudioManager(r).playEffect(t,s,i,n)}else this.t.error(u+" no audio buffer found")},t.prototype._pauseEffect=function(t,i){var n=this.checkPreviewer("zc.pe.2",{streamID:t,effectID:i},{streamID:!0,previewer:!0});return!(0,j.dd)(n)&&this.getAudioManager(n).pauseEffect(i)},t.prototype._resumeEffect=function(t,i){var n=this.checkPreviewer("zc.re",{streamID:t,effectID:i},{streamID:!0,previewer:!0});return!(0,j.dd)(n)&&this.getAudioManager(n).resumeEffect(i)},t.prototype._stopEffect=function(t,i){var n=this.checkPreviewer("zc.se",{streamID:t,effectID:i},{streamID:!0,previewer:!0});return!(0,j.dd)(n)&&this.getAudioManager(n).stopEffect(i)},t.prototype._setMixingAudioVolume=function(t,i,n){var e=this.h.getPreviewer(t);return e?this.getAudioManager(e).setMixingAudioVolume(i/100,n):(this.t.error("zc.sma.2 publisher doesn't exist"),!1)},t.prototype.l=function(t,i){var n=this.h.getPreviewer(t);return n?this.getAudioManager(n).startMixingAudio(i):((0,j.QP)(t)?this.t.error("zc.sma.0 "+t+" stream is not publishing"):this.t.error("zc.sma.0 stream doesn't exist"),!1)},t.prototype._stopMixingAudio=function(t,i){var n=this.h.getPreviewer(t);return n?this.getAudioManager(n).stopMixingAudio(i):(this.t.error("zc.sma.0 stream doesn't exist"),!1)},t.prototype._mixingBuffer=function(t,i,n,e){var s=this.checkPreviewer(l,{streamID:t,effectID:i},{effectID:!0,streamID:!0,previewer:!0});(0,j.dd)(s)||((0,j.SY)(n)?this.getAudioManager(s).mixingBuffer(i,n,e):this.t.error("zc.mb.0 array buffer not found"))},t.prototype._stopMixingBuffer=function(t,i){var n=this.checkPreviewer(l,{streamID:t,effectID:i},{effectID:!0,streamID:!0,previewer:!0});return!(0,j.dd)(n)&&this.getAudioManager(n).stopMixingBuffer(i)},t.prototype.getAudioManager=function(t){var i=t.audioMixManager;return i||(i=new O(t),1===this.u.engineConfig.choirRole&&i.setVolumeFactor(.6),t.audioMixManager=i),i},t}(),C={type:"AudioMix",install:function(t){Object.defineProperty(t.prototype,"initAudioMix",{value:function(){this.audioMixModule=new E(this.logger,this.dataReport,this.stateCenter,this.streamCenter,this.ac,this)}})}};return s}()}));