UNPKG

zego-express-engine-webrtc

Version:

zego webrtc express sdk

1 lines 37 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 s in n)("object"==typeof exports?exports:t)[s]=n[s]}}("undefined"!=typeof self?self:this,(function(t){return function(){"use strict";var i={2638:function(t,i,n){var s;n(3052);!function(t){t[t.debug=0]="debug",t[t.info=1]="info",t[t.warn=2]="warn",t[t.error=3]="error",t[t.report=99]="report",t[t.disable=100]="disable"}(s||(s={}));var e,r,u;!function(t){t[t.disable=0]="disable",t[t.websocket=1]="websocket",t[t.https=2]="https"}(e||(e={})),function(t){t[t.SDKProject_ZegoWebRTC=6]="SDKProject_ZegoWebRTC",t[t.SDKProject_ZegoMiniProgram=7]="SDKProject_ZegoMiniProgram"}(r||(r={})),function(t){t[t.UDP=0]="UDP",t[t.RTMP=1]="RTMP",t[t.FLV=2]="FLV",t[t.HLS=3]="HLS",t[t.WEBRTC=4]="WEBRTC"}(u||(u={}));var h,o;h=1,function(){var t=1}();!function(t){t[t.ClientType_None=0]="ClientType_None",t[t.ClientType_H5=1]="ClientType_H5",t[t.ClientType_SmallPragram=2]="ClientType_SmallPragram",t[t.ClientType_Webrtc=3]="ClientType_Webrtc"}(o||(o={}));var f,a,c,l,d,m,v,p,g,b,y,I,D;!function(t){t[t.Default=0]="Default",t[t.Extranet=1]="Extranet",t[t.Intranet=2]="Intranet"}(f||(f={})),function(t){t[t.logout=0]="logout",t[t.trylogin=1]="trylogin",t[t.login=2]="login"}(a||(a={})),function(t){t[t.logout=0]="logout",t[t.trylogin=1]="trylogin",t[t.login=2]="login",t[t.reconnect=3]="reconnect"}(c||(c={})),function(t){t[t.stop=0]="stop",t[t.start=1]="start"}(l||(l={})),function(t){t[t.CDN=0]="CDN",t[t.RTC=1]="RTC",t[t.L3=2]="L3",t[t.DG=3]="DG"}(d||(d={})),function(t){t[t.useAnalyzer=0]="useAnalyzer",t[t.useWorklet=1]="useWorklet"}(m||(m={})),function(t){t[t.Default=3]="Default",t[t.StandardVideoCall=4]="StandardVideoCall",t[t.HighVideoCall=5]="HighVideoCall",t[t.StandardChatroom=6]="StandardChatroom",t[t.HighQualityChatroom=7]="HighQualityChatroom",t[t.Broadcast=8]="Broadcast",t[t.UNKNOWN=100]="UNKNOWN"}(v||(v={})),function(t){t.WIN32="WIN32",t.MAC="Mac",t.ANDROID="Android",t.LINUX="Linux",t.IOS="iOS",t.Harmony="Harmony",t.UNKNOWN="WTF"}(p||(p={})),function(t){t.CDN="cdn",t.L3="l3",t.RTC="rtc"}(g||(g={})),function(t){t[t.RTC=0]="RTC",t[t.CDN=1]="CDN",t[t.L3=2]="L3",t[t.DG=3]="DG",t[t.CUSTOM=5]="CUSTOM"}(b||(b={})),function(t){t[t.offline=0]="offline",t[t.online=1]="online"}(y||(y={})),function(t){t[t.MinQuality=0]="MinQuality",t[t.DieQuality=0]="DieQuality",t[t.PoorMinQuality=1]="PoorMinQuality",t[t.MiddleMinQuality=30]="MiddleMinQuality",t[t.GoodMinQuality=60]="GoodMinQuality",t[t.ExcellentMinQuality=85]="ExcellentMinQuality",t[t.MaxQuality=100]="MaxQuality"}(I||(I={})),function(t){t[t.Unknown=-1]="Unknown",t[t.Excellent=0]="Excellent",t[t.Good=1]="Good",t[t.Middle=2]="Middle",t[t.Poor=3]="Poor",t[t.Die=4]="Die"}(D||(D={}));var T,x,_=function(){function t(t,i){void 0===t&&(t=null),void 0===i&&(i=null),this.next=null,this.prev=null,this._id=t,this._data=i}return Object.defineProperty(t.prototype,"id",{get:function(){return this._id?this._id:null},set:function(t){this._id=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"data",{get:function(){return this._data},set:function(t){this._data=t},enumerable:!1,configurable:!0}),t.prototype.hasNext=function(){return this.next&&this.next.id},t.prototype.hasPrev=function(){return this.prev&&this.prev.id},t}();!function(){function t(){this.start=new _,this.end=new _,this._idCounter=0,this._numNodes=0,this.start.next=this.end,this.start.prev=null,this.end.prev=this.start,this.end.next=null}t.prototype.insertBefore=function(t,i){var n=new _(this._idCounter,i);return n.next=t,n.prev=t.prev,t.prev&&(t.prev.next=n),t.prev=n,++this._idCounter,++this._numNodes,n},t.prototype.addLast=function(t){return this.insertBefore(this.end,t)},t.prototype.add=function(t){return this.addLast(t)},t.prototype.getFirst=function(){return 0===this._numNodes?null:this.start.next},t.prototype.getLast=function(){return 0===this._numNodes?null:this.end.prev},t.prototype.size=function(){return this._numNodes},t.prototype.getFromFirst=function(t){var i=0,n=this.start.next;if(t>=0)for(;i<t&&null!==n;)n=n.next,++i;else n=null;if(null===n)throw"Index out of bounds.";return n},t.prototype.get=function(t){return 0===t?this.getFirst():t===this._numNodes-1?this.getLast():this.getFromFirst(t)},t.prototype.remove=function(t){return t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),--this._numNodes,t},t.prototype.removeFirst=function(){var t=null;return this._numNodes>0&&this.start.next&&(t=this.remove(this.start.next)),t},t.prototype.removeLast=function(){var t=null;return this._numNodes>0&&this.end.prev&&(t=this.remove(this.end.prev)),t},t.prototype.removeAll=function(){this.start.next=this.end,this.end.prev=this.start,this._numNodes=0,this._idCounter=0},t.prototype.each=function(t){for(var i=this.start;i.hasNext();)t(i=i.next)},t.prototype.find=function(t){for(var i=this.start,n=!1,s=null;i.hasNext()&&!n;)t(i=i.next)&&(s=i,n=!0);return s},t.prototype.map=function(t){for(var i=this.start,n=[];i.hasNext();)t(i=i.next)&&n.push(i);return n},t.prototype.push=function(t){return this.addLast(t)},t.prototype.unshift=function(t){this.insertBefore(this._numNodes>0?this.start.next:this.end,t)},t.prototype.pop=function(){return this.removeLast()},t.prototype.shift=function(){return this.removeFirst()}}();!function(t){t.ONLY_BASELINE="only_baseline",t.HARD_SOFT_ENCODEC_FIRST="hard_or_soft_encodec_first",t.HIGH_PROFILE_FIRST="high_profile_first"}(T||(T={})),function(t){t[t.None=0]="None",t[t.Vocalist=1]="Vocalist",t[t.BackingSinging=2]="BackingSinging"}(x||(x={}))},8627:function(t,i,n){n.d(i,{S6t:function(){return s}});n(8866);var s={code:1103057,message:"decode audio data fail"}},3052:function(t,i,n){var s,e;!function(t){t[t.SWITCH_ONE=1]="SWITCH_ONE",t[t.SWITCH_TWO=2]="SWITCH_TWO"}(s||(s={})),function(t){t[t.ZegoGeoFenceTypeNone=0]="ZegoGeoFenceTypeNone",t[t.ZegoGeoFenceTypeInclude=1]="ZegoGeoFenceTypeInclude",t[t.ZegoGeoFenceTypeExclude=2]="ZegoGeoFenceTypeExclude"}(e||(e={}));var r,u;!function(t){t[t.TT_NONE=0]="TT_NONE",t[t.TT_PC=1]="TT_PC",t[t.TT_IOS=2]="TT_IOS",t[t.TT_ANDROID=3]="TT_ANDROID",t[t.TT_MAC=4]="TT_MAC",t[t.TT_LINUX=5]="TT_LINUX",t[t.TT_WEB=6]="TT_WEB",t[t.TT_MINIPROGRAM=7]="TT_MINIPROGRAM",t[t.TT_UNKNOWN=32]="TT_UNKNOWN"}(r||(r={})),function(t){t[t.disconnected=0]="disconnected",t[t.connecting=1]="connecting",t[t.connected=2]="connected"}(u||(u={}));var h,o,f,a;!function(t){t[t.logout=0]="logout",t[t.trylogin=1]="trylogin",t[t.login=2]="login"}(h||(h={})),function(t){t[t.I=0]="I",t[t.H=10]="H",t[t.M=100]="M",t[t.L=1e3]="L"}(o||(o={})),function(t){t[t.offline=0]="offline",t[t.online=1]="online"}(f||(f={})),function(t){t[t.NT_NONE=0]="NT_NONE",t[t.NT_LINE=1]="NT_LINE",t[t.NT_WIFI=2]="NT_WIFI",t[t.NT_2G=3]="NT_2G",t[t.NT_3G=4]="NT_3G",t[t.NT_4G=5]="NT_4G",t[t.NT_UNKNOWN=32]="NT_UNKNOWN"}(a||(a={}))},8866:function(t,i,n){n.d(i,{EK:function(){return r},Rl:function(){return d},Wk:function(){return l},aw:function(){return o},dO:function(){return f},fT:function(){return u},h2:function(){return c},l3:function(){return s},pt:function(){return h},qC:function(){return a},rA:function(){return e}});n(7202),n(8627);var s=Promise;function e(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",d="network is broken"},7202:function(t,i,n){n(6994)},4872:function(t,i,n){function s(t){return"number"==typeof t}function e(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}n.d(i,{Cs:function(){return s},QP:function(){return e},SY:function(){return f},Si:function(){return o},TE:function(){return u},dd:function(){return r},dr:function(){return h}})},6493:function(t,i,n){n.d(i,{$t:function(){return s},nr:function(){return r}});n(2638);function s(){return navigator.userAgent||""}function e(){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"==e().name.toLowerCase()}},327:function(t,i,n){n.d(i,{L:function(){return e}});var s=n(4872);function e(t,i){if(t&&!(0,s.dr)(t)&&t.zegoStream){if(i.info("cu.gs type:zego"),(0,s.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 s(t){var e=n[t];if(void 0!==e)return e.exports;var r=n[t]={exports:{}};return i[t](r,r.exports,s),r.exports}s.d=function(t,i){for(var n in i)s.o(i,n)&&!s.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},s.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var e={};s.r(e),s.d(e,{AudioMix:function(){return j}});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",d="zc.p.0.pe.0",m="zc.p.0.pe.1",v="zc.p.0.re",p="zc.p.0.se",g="zc.p.0.sma.0",b="zc.smav",y="zc.p.0.mb",I="zc.p.0.smav",D=s(8627),T=function(){function t(t,i,n,s,e){this.t=t,this.ac=i,this.localStream=n,this.destination=s,this.rtcViewer=e,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,s,e){var r=this;!0!==this.isMixAudio?this.audioBuffer?(this.startOffset=t||0,this.loop=i||!1,this.replace=n||!1,this.effectEndedCallBack=e,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),s&&s()}))):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:D.S6t.code,message:D.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}(),x=s(6493),_=function(){function t(t,i,n,s,e,r,u){void 0===u&&(u=1);var h=this;this.t=t,this.acMgr=i,this.localStream=n,this.browser=s,this.destination=e,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," ").concat(null==t?void 0:t.type,": audio muted disconnect")),h.audioNode.disconnect()):(h.t.info("amu.sma.0 ".concat(h.id," ").concat(null==t?void 0:t.type,": 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," ").concat(i.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 s=this.acMgr.getMediaElementRenderer(t);if(!s)return!1;this.audioNode=s.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 e=this.getBrowserInfo(),r=!1;return n&&"10.15.6"===(null==e?void 0:e.sysVer)&&"13.1.2"===(null==e?void 0:e.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&&(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,x.$t)().toLowerCase();t=(n.match(/x [\d._]+/gi)+"").replace(/[^0-9|_.]/gi,"").replace(/_/gi,"."),i.sysVer=t;var s=n.match(/(msie|firefox|chrome|opera|version).*?([\d.]+)/);return s&&(i.browser=s[1].replace(/version/,"'safari"),i.ver=s[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}(),w=s(4872),z=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(g+" call"),!this._localStream)return this.t.error(g+" 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(g+" mix audio already exist");else if(i._localStream){i.h.soundLevelDelegate&&i.i.stopSoundLevel();var s=i.createDestNode(),e=new _(i.t,i.acMgr,i._localStream,i.u.browser,s,i.i.rtcViewer,i.volumeFactor);i._audioMixList.push({audioMix:e,media:t}),e.startMixingAudio(t)||(n=!1),e.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(I+" set factor: "+t),isNaN(t)&&this.t.error(I+" 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(I+" call");var n=this._audioMixList.find((function(t){return t.media===i}));return n?(n.audioMix.setMixingAudioVolume(t),this.t.info(I+" call success"),!0):(this.t.error(I+" audio is not mixing"),!1)},t.prototype.playEffect=function(t,i,n,s){var e=this;if(this.t.info(d+" call"),this._localStream)if(this._effectList.find((function(n){return n.effectID==t.effectID&&n.audioBuffer==i})))this.t.warn(d+" effect already exist ");else{this.h.soundLevelDelegate&&this.i.stopSoundLevel();var r=this.createDestNode(),u=new T(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];e._effectList=e._effectList.filter((function(t){return t!==h})),s&&s.apply(void 0,t)})),this.h.soundLevelDelegate&&this.i.startSoundLevel(),this.t.info(d+" play effect "+t.effectID+" success")}else this.t.warn(d+" 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(m+" pause "+t+" success");else{if(!(0,w.TE)(t))return this.t.error(m+" 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,w.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,w.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 s=this._effectList.find((function(t){return t.effectID==i}));if(s)s.processor.setMixingAudioVolume(t),s.processor.setDelay(n||1e-7),this.t.info("zp.sev.0 set volume "+i+" success");else{if(!(0,w.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 s=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(){s.h.soundLevelDelegate&&s.i.startSoundLevel(),n&&n()}));else{this.h.soundLevelDelegate&&this.i.stopSoundLevel();var e=this.createDestNode(),r=new T(this.t,this.ac,this._localStream,e,this.i.rtcViewer);this._arrayBufferMap[t]=r,r.mixingBuffer(i,(function(){s.h.soundLevelDelegate&&s.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,w.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}(),N=s(8866),O=s(327),M=function(t,i,n,s){return new(n||(n=Promise))((function(e,r){function u(t){try{o(s.next(t))}catch(t){r(t)}}function h(t){try{o(s.throw(t))}catch(t){r(t)}}function o(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(u,h)}o((s=s.apply(t,i||[])).next())}))},S=function(t,i){var n,s,e,r,u={label:0,sent:function(){if(1&e[0])throw e[1];return e[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,s&&(e=2&h[0]?s.return:h[0]?s.throw||((e=s.return)&&e.call(s),0):s.next)&&!(e=e.call(s,h[1])).done)return e;switch(s=0,e&&(h=[2&h[0],e.value]),h[0]){case 0:case 1:e=h;break;case 4:return u.label++,{value:h[1],done:!1};case 5:u.label++,s=h[1],h=[0];continue;case 7:h=u.ops.pop(),u.trys.pop();continue;default:if(!(e=u.trys,(e=e.length>0&&e[e.length-1])||6!==h[0]&&2!==h[0])){u=0;continue}if(3===h[0]&&(!e||h[1]>e[0]&&h[1]<e[3])){u.label=h[1];break}if(6===h[0]&&u.label<e[1]){u.label=e[1],e=h;break}if(e&&u.label<e[2]){u.label=e[2],u.ops.push(h);break}e[2]&&u.ops.pop(),u.trys.pop();continue}h=i.call(t,u)}catch(t){h=[6,t],s=0}finally{n=e=0}if(5&h[0])throw h[1];return{value:h[0]?h[1]:void 0,done:!0}}([h,o])}}},C=function(){function t(t,i,n,s,e,r){var u=this;this.t=t,this.dataReport=i,this.u=n,this.h=s,this.ac=e,this.rtcModules=r,this.buffer=null,this.blank=null,this.mixingDelay=0,(0,x.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,w.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 s=!!(null==n?void 0:n.effectID),e=!!(null==n?void 0:n.streamID),r=!!(null==n?void 0:n.previewer),u=i.effectID,h=i.streamID,o=h&&((0,w.QP)(h)?h:(0,O.L)(h,this.t));if((e||o)&&!(0,w.QP)(o)&&!(0,w.dr)(o))return this.t.error(t+" stream type error"),!1;if(s&&!u)return this.t.error(t+" effectID required"),!1;if(u&&!(0,w.QP)(u))return this.t.error(t+" effectID type error"),!1;if(r){var f=this.h.getPreviewer(o);return f||((0,w.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,w.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 s=this.checkPreviewer(h,{streamID:t,effectID:i},{effectID:!0,streamID:!0,previewer:!0});return!(0,w.dd)(s)&&this.getAudioManager(s).seekAudioEffect(i,n)},t.prototype.playEffect=function(t,i,n){return M(this,void 0,void 0,(function(){var s,e,r,h,o=this;return S(this,(function(f){switch(f.label){case 0:return s=(0,O.L)(t.stream,this.t)||t.streamID,e=t.path,this.checkPreviewer(u,{streamID:s,effectID:r=t.effectID},{streamID:!0,effectID:!0})?(h=this.u.audioEffectBuffer[r],e?h?(this.t.warn(u+" audio effect already exists"),[3,3]):[3,1]:[3,4]):[2];case 1:return[4,new N.l3((function(t,i){o.preloadEffect(r,e,(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,w.QP)(t)?t:(0,O.L)(t,this.t);return this._pauseEffect(n,i)},t.prototype.resumeEffect=function(t,i){var n=(0,w.QP)(t)?t:(0,O.L)(t,this.t);return this._resumeEffect(n,i)},t.prototype.stopEffect=function(t,i){var n=(0,w.QP)(t)?t:(0,O.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,s){if(!(0,w.Cs)(i)||i<0||i>200)return this.t.error(o+" volume must be a number between 0 and 200"),!1;var e=(0,w.QP)(t)?t:(0,O.L)(t,this.t),r=this.checkPreviewer(o,{streamID:e,effectID:n},{streamID:!0,previewer:!0});return!(0,w.dd)(r)&&this.getAudioManager(r).setEffectVolume(i/100,n,s)},t.prototype.startMixingAudio=function(t,i){var n=(0,w.QP)(t)?t:(0,O.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,w.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,w.QP)(t)?t:(0,O.L)(t,this.t);return n?Array.isArray(i)&&0!==i.length||(0,w.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,s){var e=(0,w.QP)(t)?t:(0,O.L)(t,this.t);this.t.info(c+" call streamID: "+JSON.stringify(e)+" sourceID:"+i),e?i&&(0,w.QP)(i)?(this._mixingBuffer(e,i,n,s),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,w.QP)(t)?t:(0,O.L)(t,this.t);return this._stopMixingBuffer(n,i)},t.prototype.setMixingAudioVolume=function(t,i,n){if(this.t.info(b+" call"),!t)return this.t.error(b+" stream not found"),!1;if(!(0,w.Cs)(i)||i<0||i>200)return this.t.error(b+" volume must be a number between 0 and 200"),!1;if(!n||!(0,w.Si)(n))return this.t.error(b+" no audio"),!1;var s=(0,w.QP)(t)?t:(0,O.L)(t,this.t);return this._setMixingAudioVolume(s,i,n)},t.prototype.getSoundLevel=function(t,i,n){var s="zc.gsl";(0,N.rA)(this.t,s);var e=this.h.getCloudSoundInterval();try{var r=this.h.createSoundLevel(this.ac,t,this.h.soundLevelInterval,e,(function(t){i(t)}));this.u.audioStreamList[t.id]={mic:r.mic,script:r.soundMeter}}catch(t){n(t)}(0,N.EK)(this.t,s)},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,s){var e=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){e.t.info("zc.pe.0 effect '".concat(i,"' preload success")),e.u.audioEffectBuffer[i]=t,s&&s()}),(function(t){e.t.error("zc.pe.0 effect '".concat(i,"' preload fail. ")+t),s&&s(t)}))}else{var n=r.statusText;e.t.error("zc.pe.0 effect '".concat(i,"' preload fail.")+n),s&&s(n)}},r.send()},t.prototype._playEffect=function(t,i,n){var s=(0,O.L)(t.stream,this.t)||t.streamID,e=this.u.audioEffectBuffer[t.effectID];if(e){var r=this.checkPreviewer(u,{streamID:s,effectID:t.effectID},{streamID:!0,effectID:!0,previewer:!0});(0,w.dd)(r)||this.getAudioManager(r).playEffect(t,e,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,w.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,w.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,w.dd)(n)&&this.getAudioManager(n).stopEffect(i)},t.prototype._setMixingAudioVolume=function(t,i,n){var s=this.h.getPreviewer(t);return s?this.getAudioManager(s).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,w.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,s){var e=this.checkPreviewer(l,{streamID:t,effectID:i},{effectID:!0,streamID:!0,previewer:!0});(0,w.dd)(e)||((0,w.SY)(n)?this.getAudioManager(e).mixingBuffer(i,n,s):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,w.dd)(n)&&this.getAudioManager(n).stopMixingBuffer(i)},t.prototype.getAudioManager=function(t){var i=t.audioMixManager;return i||(i=new z(t),1===this.u.engineConfig.choirRole&&i.setVolumeFactor(.6),t.audioMixManager=i),i},t}(),j={type:"AudioMix",install:function(t){Object.defineProperty(t.prototype,"initAudioMix",{value:function(){this.audioMixModule=new C(this.logger,this.dataReport,this.stateCenter,this.streamCenter,this.ac,this)}})}};return e}()}));