@ylink-sdk/stream
Advanced tools
Comparing version 0.2.0-beta.13 to 0.2.0-beta.14
@@ -1,1 +0,1 @@ | ||
"use strict";function e(e,t,i,r){return new(i||(i=Promise))((function(s,n){function a(e){try{l(r.next(e))}catch(t){n(t)}}function o(e){try{l(r.throw(e))}catch(t){n(t)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}l((r=r.apply(e,t||[])).next())}))}function t(e){return{all:e=e||new Map,on:function(t,i){var r=e.get(t);r?r.push(i):e.set(t,[i])},off:function(t,i){var r=e.get(t);r&&(i?r.splice(r.indexOf(i)>>>0,1):e.set(t,[]))},emit:function(t,i){var r=e.get(t);r&&r.slice().map((function(e){e(i)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,i)}))}}}var i,r,s,n,a,o;Object.defineProperty(exports,"__esModule",{value:!0}),exports.CHANNEL_EVENT=void 0,(i=exports.CHANNEL_EVENT||(exports.CHANNEL_EVENT={})).STATE="streamState",i.CHANNEL_REFRESH="channelRefresh",i.CHANNEL_BUSY="channelBusy",i.AUDIO_CHANNEL_OPENED="audioChannelOpened",i.VIDEO_CHANNEL_OPENED="videoChannelOpened",i.DATA_CHANNEL_OPENED="dataChannelOpened",i.MESSAGE_CHANNEL_OPENED="messageChannelOpened",i.VOICE_ACTIVE_SSRC="voiceActiveSsrc",i.AUDIO_PLAYER_CHANGE="audioPlayerChange",exports.CHANNEL_STATE=void 0,(r=exports.CHANNEL_STATE||(exports.CHANNEL_STATE={}))[r.STARTED=1]="STARTED",r[r.STOPPED=0]="STOPPED",exports.MEDIA_MANAGER_EVENT=void 0,(exports.MEDIA_MANAGER_EVENT||(exports.MEDIA_MANAGER_EVENT={})).STATE="state",exports.MEDIA_MANAGER_STATE=void 0,(s=exports.MEDIA_MANAGER_STATE||(exports.MEDIA_MANAGER_STATE={}))[s.NULL=0]="NULL",s[s.INITED=1]="INITED",exports.MEDIA_EVENT=void 0,(n=exports.MEDIA_EVENT||(exports.MEDIA_EVENT={})).STREAM_STATE="streamState",n.STREAM="stream",n.INPUT_DEVICES_UPDATED="inputDevicesUpdated",n.OUTPUT_DEVICES_UPDATED="outputDevicesUpdated",n.INPUT_DEVICE_CHANGED="inputDeviceChanged",n.OUTPUT_DEVICE_CHANGED="outputDeviceChanged",exports.MEDIA_STREAM_STATE=void 0,(a=exports.MEDIA_STREAM_STATE||(exports.MEDIA_STREAM_STATE={}))[a.NULL=0]="NULL",a[a.CAPTURING=1]="CAPTURING",a[a.FAILED=2]="FAILED",exports.MEDIA_STREAM_DETAIL=void 0,(o=exports.MEDIA_STREAM_DETAIL||(exports.MEDIA_STREAM_DETAIL={}))[o.NO_DEVICE=0]="NO_DEVICE",o[o.PERMISSION_DENIED=1]="PERMISSION_DENIED",o[o.COULD_NOT_START_VIDEO_SOURCE=2]="COULD_NOT_START_VIDEO_SOURCE",o[o.PERMISSION_DENIED_BY_SYSTEM=3]="PERMISSION_DENIED_BY_SYSTEM",o[o.OTHER_EXCEPTIONS=4]="OTHER_EXCEPTIONS";const l=(e,t)=>{const i=t.match(e);return i&&i.length>0&&i[1]||""},c=/version\/(\d+(\.?_?\d+)+)/i,d=[{test:[/\sedg\//i],describe(e){const t={name:"Microsoft Edge"},i=l(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/edg([ea]|ios)/i],describe(e){const t={name:"Microsoft Edge"},i=((e,t)=>{const i=t.match(e);return i&&i.length>1&&i[2]||""})(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/firefox|iceweasel|fxios/i],describe(e){const t={name:"Firefox"},i=l(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/chromium/i],describe(e){const t={name:"Chromium"},i=l(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||l(c,e);return i&&(t.version=i),t}},{test:[/chrome|crios|crmo/i],describe(e){const t={name:"Chrome"},i=l(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/safari|applewebkit/i],describe(e){const t={name:"Safari"},i=l(c,e);return i&&(t.version=i),t}}];let h;const u=d.find((e=>{if(e.test instanceof Array)return e.test.some((e=>e.test(navigator.userAgent)));throw new Error("Browser's test function is not valid")}));u&&(h=u.describe(navigator.userAgent));const E=h&&"Safari"===h.name,p=h&&"Firefox"===h.name,m=h&&"Chrome"===h.name,v=h&&"Microsoft Edge"===h.name,A=e=>/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e),T=(e,t)=>t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e,f=({src:e,id:t})=>new Promise(((i,r)=>{let s=document.querySelector(`#${t}`);if(s)return s.src=e,void i(s);s=document.createElement("script"),s.src=e,s.id=t,s.onload=()=>{i(s)},s.onerror=e=>{r(e)},document.head.appendChild(s)}));var S=class{constructor({namespace:e,debug:t}){Object.defineProperty(this,"initialized",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isDebugging",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useColors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"backend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"namespace",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.initialized=!0,this.isDebugging=t,this.backend=b(),this.namespace=e,this.useColors=this.backend.useColors,this.color=this.selectColor(e)}logger(e){e[0]=this.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let t=0;return e[0]=e[0].replace(/%([a-zA-Z%])/g,((i,r)=>{if("%%"===i)return i;t++;const s=this.backend.formatters[r];if("function"==typeof s){i=s(e[t]),e.splice(t,1),t--}return i})),this.backend.formatArgs(e,this)}coerce(e){return e instanceof Error?e.stack||e.message:e}selectColor(e){const t=Array.from(e).reduce(((e,t)=>(e=(e<<5)-e+t.charCodeAt(0),e|=0)),0);return this.backend.colors[Math.abs(t)%this.backend.colors.length]}switchDebug(e){this.isDebugging=e}log(...e){e=this.logger(e),this.backend.log.apply(this,e)}debug(...e){this.isDebugging&&(e=this.logger(e),this.backend.debug.apply(this,e))}warn(...e){this.backend.warn.apply(this,e)}error(...e){this.backend.error.apply(this,e)}};const b=()=>({colors:["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],formatters:{j:e=>{try{return JSON.stringify(e)}catch(t){return`[UnexpectedJSONParseError]: ${t.message}`}}},log:(...e)=>"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,e),debug:(...e)=>"object"==typeof console&&console.debug&&Function.prototype.apply.call(console.debug,console,e),warn:(...e)=>"object"==typeof console&&console.warn&&Function.prototype.apply.call(console.warn,console,e),error:(...e)=>"object"==typeof console&&console.error&&Function.prototype.apply.call(console.error,console,e),formatArgs:(e,t)=>{const{useColors:i,namespace:r,color:s}=t;if(e[0]=`${(i?"%c":"")+r+(i?" %c":" ")+e[0]+(i?"%c ":" ")}+${function(e){const t=Math.abs(e);if(t>=C)return`${Math.round(e/C)}d`;if(t>=_)return`${Math.round(e/_)}h`;if(t>=I)return`${Math.round(e/I)}m`;if(t>=D)return`${Math.round(e/D)}s`;return`${e}ms`}(0)}`,!i)return[];const n=`color: ${s}`;e.splice(1,0,n,"color: inherit");let a=0,o=0;return e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(a++,"%c"===e&&(o=a))})),e.splice(o,0,n),e},useColors:N()}),D=1e3,I=60*D,_=60*I,C=24*_;const N=()=>!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.webkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)),g=new S({namespace:"STREAM:Store",debug:!1});class y{constructor({baseURL:e,videoSDKLibDir:i,debug:r}){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:exports.CHANNEL_STATE.STOPPED}),Object.defineProperty(this,"SFUTransportType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEndpoint",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEngine",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audioChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"videoChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"messageChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"remoteControlStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"subtitleStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"videoSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dataSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioReceiver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"voiceActiveSsrc",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"audioChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"videoChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"dataChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"messageChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"baseURL",{enumerable:!0,configurable:!0,writable:!0,value:"https://meetings.ylyun.com"}),Object.defineProperty(this,"videoSDKLibDir",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"_audioPlayer",{enumerable:!0,configurable:!0,writable:!0,value:null}),e=e||"https://meetings.ylyun.com",i=i||"",g.switchDebug(r=r||!1),this.setBaseUrl(e),this.setVideoSDKLibDir(i),this.setup()}get audioPlayer(){return this._audioPlayer}set audioPlayer(e){this._audioPlayer=e,this.emitter.emit(exports.CHANNEL_EVENT.AUDIO_PLAYER_CHANGE,e)}setup(){return e(this,void 0,void 0,(function*(){}))}cleanup(){return e(this,void 0,void 0,(function*(){const{videoChannel:e,audioChannel:t,messageChannel:i,dataChannel:r,mediaEndpoint:s,remoteControlStream:n}=this;try{t&&(yield t.close()),e&&(yield e.close()),r&&(yield r.close()),n&&i&&(yield i.closeStream(n)),i&&(yield i.close()),s&&(s.stop(),s.destroy())}catch(a){g.error(a)}this.mediaEndpoint=null,this.mediaEngine=null,this.videoChannel=null,this.audioChannel=null,this.dataChannel=null,this.messageChannel=null,this.videoSender=null,this.audioSender=null,this.dataSender=null,this.audioReceiver=null,this.audioPlayer=null,this.audioChannelOpened=!1,this.videoChannelOpened=!1,this.dataChannelOpened=!1,this.messageChannelOpened=!1}))}getMss(t){return e(this,void 0,void 0,(function*(){const{mediaContent:e,userID:i,role:r,meetingID:s}=t,n=yield M.getMss(this.baseURL,{accessMCs:e.accessMCs,topMC:e.topMC,confId:s,ccid:i,userType:"audience"===r?"Broadcast":"Interactive"}).catch((e=>{g.error(e)}));if(g.debug(`response ${JSON.stringify(n)}`),!n||!n.data||!n.data.MssInfo)return g.error("getMss response error ",n),[];const a=n.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),o=n.data.MssInfo.map((e=>e.IntranetUri)).flat();return a.concat(o).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const{baseURL:t}=this,i=A(t)?(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[2]})(t):t,r=`${A(t)&&"http:"===(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[1]})(t)?"ws":"wss"}://${i}`,s=window.btoa(e.replace(/\w+:\/\//,""));return T(r,`/webapp/socket/${s}`)}))}))}mssRequest(t,i){return e(this,void 0,void 0,(function*(){const{mediaContent:r,userID:s,role:n,meetingID:a}=i,o=(i,o)=>new Promise(((l,c)=>{const d=new URL(i),h=d.searchParams.get("webapp");h&&(i=`https://${h}?mc=${d.host}`),M.mssRequest(i,{accessMCs:r.accessMCs,topMC:r.topMC,confId:a,ccid:s,userType:"audience"===n?"Broadcast":"Interactive"}).then((i=>e(this,void 0,void 0,(function*(){return console.log("result: ",i),i&&i.data?i.state&&300001===i.state?(console.log("getMss() wait 300ms"),t.splice(o,1),yield(e=300,new Promise((t=>setTimeout((()=>t(e)),e)))),c(i)):l(i):(t.splice(o,1),c(i));var e})))).catch((e=>{console.error(e),c()}))})),l=()=>e(this,void 0,void 0,(function*(){let e=null;try{e=yield Promise.race(t.map(o))}catch(i){console.error("request/mss ",i)}return e}));let c=[];const d=t.length;for(let e=0;e<d;e++){const e=yield l();if(e&&e.state&&3e5===e.state){const t=e.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),i=e.data.MssInfo.map((e=>e.IntranetUri)).flat();c=t.concat(i).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const t=new URL(e),i=t.searchParams.get("webapp");return i&&(e=`wss://${i}?mss=${t.host}`),e}));break}}return c}))}start(t){return e(this,void 0,void 0,(function*(){this.throwIfState(exports.CHANNEL_STATE.STARTED),yield w(this.videoSDKLibDir,!!t.develop).catch((e=>{g.error(e)}));const{LIBRTC:i}=window,{NativeMediaEndpoint:r,NativeMediaEngine:s,SFUTransportType:n}=i;this.SFUTransportType=n,t.config&&(i.config=t.config);const{mediaContent:a,user:o,meetingID:l,ctrlID:c,meetingNum:d,account:h}=t,u=new s;yield u.init();const E=new r;E.onrefresh=()=>e(this,void 0,void 0,(function*(){this.emitter.emit(exports.CHANNEL_EVENT.CHANNEL_REFRESH);const e=o.userID,t=o.role;let i=[];for(let s=0;s<a.accessMCs.length;s++){let n=[];try{n=JSON.parse(a.accessMCs[s])}catch(r){console.error(r)}const o=n.some((e=>(!e.extranet||!e.extranet.length)&&e.intranet&&e.intranet.length)),c=n.map((e=>{const t=e.extranet||[];return t.push(...e.intranet),t})).flat(),d={mediaContent:{accessMCs:[a.accessMCs[s]],topMC:a.topMC,crypto:a.crypto},meetingID:l,userID:e,role:t};if(-1!==c.findIndex((e=>new URL(e).searchParams.get("webapp")))){if(console.log("urls",c),i=yield this.mssRequest(c,d),i.length)break}else{if(o)break;if(i=yield this.getMss(d),i.length)break}}return i})),yield E.init(),yield E.start({meeting_number:d||"",user_account:h||"",confid:l,ccid:o.userID,role:1,encrypt:a.crypto,token:c}),this.mediaEndpoint=E,this.mediaEngine=u,this.state=exports.CHANNEL_STATE.STARTED,this.emitter.emit(exports.CHANNEL_EVENT.STATE,{state:this.state})}))}stop(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),yield this.cleanup(),this.state=exports.CHANNEL_STATE.STOPPED,this.emitter.emit(exports.CHANNEL_EVENT.STATE,{state:this.state})}))}destroy(){return e(this,void 0,void 0,(function*(){yield this.stop()}))}getChannelState(){return{audioChannelOpened:this.audioChannelOpened,videoChannelOpened:this.videoChannelOpened,dataChannelOpened:this.dataChannelOpened,messageChannelOpened:this.messageChannelOpened}}setBaseUrl(e){this.throwIfState(exports.CHANNEL_STATE.STARTED),e&&this.baseURL!==e&&("/"===e&&(e=window.location.origin),this.baseURL=e)}setVideoSDKLibDir(e){this.throwIfState(exports.CHANNEL_STATE.STARTED),e&&this.videoSDKLibDir!==e&&(this.videoSDKLibDir=e)}createAudioChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.audio.createChannel(t.createTransport(i.kAudio));this.audioChannel=r,r.onopen=()=>{g.debug("audioChannel onopen()"),this.audioChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.AUDIO_CHANNEL_OPENED)},yield r.open()}))}closeAudioChannel(){return e(this,void 0,void 0,(function*(){const{audioChannel:e}=this;e?(yield e.close(),this.audioChannel=null,this.audioSender=null,this.audioReceiver=null,this.audioChannelOpened=!1):g.error("audioChannel is miss")}))}createVideoChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.video.createChannel(t.createTransport(i.kVideo));this.videoChannel=r,r.onopen=()=>{g.debug("videoChannel onopen()"),this.videoChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.VIDEO_CHANNEL_OPENED)},yield r.open()}))}createDataChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.video.createChannel(t.createTransport(i.kData));this.dataChannel=r,r.onopen=()=>{g.debug("dataChannel onopen()")},yield r.open(),this.dataChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.DATA_CHANNEL_OPENED)}))}createMessageChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.video.createDataChannel(t.createTransport(i.kMessage));this.messageChannel=r,r.onopen=()=>{g.debug("messageChannel onopen()")};try{yield r.open()}catch(s){console.error(s)}this.messageChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.MESSAGE_CHANNEL_OPENED)}))}closeMessageChannel(){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?yield e.close():g.error("messageChannel is miss")}))}closeMessageStream(t){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?t&&(yield e.closeStream(t)):g.error("messageChannel is miss")}))}setupRemoteControl({element:t,remote:i}){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message"),t.setAttribute("tabIndex","-1"),t.style.outline="0";const{LIBRTC:e}=window,{messageChannel:r}=this,s=yield r.createStream(e.DataType.kRemoteControl);return this.remoteControlStream=s,e.setupRemoteControl(s,t,i)}))}createSubtitleStream(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this,t=yield e.createSubtitleStream();return t.subscribe([-1]),this.subtitleStream=t,t}))}closeSubtitleStream(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this;yield e.closeSubtitleStream(t),this.subtitleStream=null}))}createAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;if(!e)return g.error("audioChannel is miss"),null;const t=this.audioSender?this.audioSender:e.createSender();return this.audioSender=t,t}))}removeAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioSender:e}=this;if(e)try{e.stop(),this.audioChannel&&this.audioChannel.removeSender(e.ssrc)}catch(t){g.error("audioChannel removeSender() error: ",t)}else g.error("audioSender is miss")}))}createVideoSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e)return g.error("videoChannel is miss"),null;const t=this.videoSender?this.videoSender:e.createSender();return this.videoSender=t,t.onbusy=()=>{g.debug("onbusy"),this.emitter.emit(exports.CHANNEL_EVENT.CHANNEL_BUSY);const{audioChannel:e}=this;e&&e.ans(!1)},t}))}removeVideoSender(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoSender:e}=this;if(e)try{e.stop(),this.videoChannel&&this.videoChannel.removeSender(e.ssrc)}catch(t){g.error("videoChannel removeSender() error: ",t)}else g.error("videoSender is miss")}createDataSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e)return g.error("dataChannel is miss"),null;const t=this.dataSender?this.dataSender:e.createSender();return this.dataSender=t,t}))}removeDataSender(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataSender:e}=this;e?(e.stop(),this.dataChannel&&this.dataChannel.removeSender(e.ssrc),this.dataSender=null):g.error("dataSender is miss")}createAudioReceiver(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;if(!t)return g.error("audioChannel is miss"),null;const i=t.createReceiver();return this.audioReceiver=i,e?(i.setSink(e),this.audioPlayer=e,t.audioElement&&(t.audioElement.srcObject=null),i):(g.error("audioPlayer is miss"),null)}createVideoReceiver(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{ccid:t}=e;if(g.debug("createVideoReceiver ccid: ",t),!t)return g.error("params is missing or params error"),null;const{videoChannel:i}=this;if(!i)return g.error("videoChannel is miss"),null;return i.createReceiver(t)}createDataReceiver(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{ccid:t}=e;if(g.debug("createDataReceiver ccid: ",t),!t)return g.error("params is missing or params error"),null;const{dataChannel:i}=this;if(!i)return g.error("dataChannel is miss"),null;return i.createReceiver(t)}removeVideoReceiver(e){return this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video"),e?(e.stop(),this.videoChannel&&this.videoChannel.removeReceiver(e.ssrc),null):e}removeDataReceiver(e){return this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data"),e?(e.stop(),this.dataChannel&&this.dataChannel.removeReceiver(e.ssrc),null):e}loadVideoRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e||!t)return g.error("videoChannel or el is miss"),null;return(m||v)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadVideoRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;e&&t?(m||v)&&(yield e.offscreen.unload(t)):g.error("videoChannel or renderer is miss")}))}loadDataRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e||!t)return g.error("dataChannel or el is miss"),null;return(m||v)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadDataRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;e&&t?(m||v)&&(yield e.offscreen.unload(t)):g.error("dataChannel or renderer is miss")}))}bindAudioChannelEvent(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=e=>{if(this.voiceActiveSsrc.length&&e.length){if(this.voiceActiveSsrc[0]===e[0])return}else if(0===this.voiceActiveSsrc.length&&0===e.length)return;this.voiceActiveSsrc=e,this.emitter.emit(exports.CHANNEL_EVENT.VOICE_ACTIVE_SSRC,{ssrc:e})}:g.error("audioChannel is miss")}offAudioChannelEvent(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=null:g.error("audioChannel is miss")}setAudioPlayerVolume(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:t}=this;t?t.volume=e=e>=0&&e<1?e:e>=1&&e<=100?e/100:e:g.error("audioPlayer is miss")}getAudioPlayerVolume(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:e}=this;return e?e.volume:(g.error("audioPlayer is miss"),0)}getAudioChannelStats(){return e(this,void 0,void 0,(function*(){return this.state===exports.CHANNEL_STATE.STARTED&&this.audioChannelOpened&&this.audioChannel?yield this.audioChannel.getStats():{}}))}throwIfState(e,t){if(this.state===e)throw new Error(t||"Invalid State")}throwIfNotState(e,t){if(this.state!==e)throw new Error(t||"Invalid State")}throwIfChannelNotOpened(e,t=""){switch(e){case"audio":if(!this.audioChannelOpened)throw new Error(t||"Channel is not open");break;case"video":if(!this.videoChannelOpened)throw new Error(t||"Channel is not open");break;case"data":if(!this.dataChannelOpened)throw new Error(t||"Channel is not open");break;case"message":if(!this.messageChannelOpened)throw new Error(t||"Channel is not open")}}}const w=(e,t)=>Promise.all([f({src:`${e}/libsfu${t?"":".prod"}.js`,id:"ylink-sdk-stream-libsfu"}),f({src:`${e}/librtc.global${t?"":".prod"}.js`,id:"ylink-sdk-stream-librtc"})]),M={getMss:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(T(t,"/webapp/front/getMss"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify(i)}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()})))),mssRequest:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(T(t,"/api/v1/mss/request"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify({ConfId:i.confId,CCID:i.ccid,Rlp:{UpRlp:56,DownRlp:56},UserType:i.userType,TopMc:i.topMC})}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()}))))};class O{constructor(e){Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_enable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),this.stream=e}analyse(){}start(){this.stream&&(this.timer&&(clearInterval(this.timer),this.timer=null),this.analyse(),this.timer=setInterval((()=>this.analyse()),this.interval))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}destroy(){this.stop()}}var x;!function(e){e.AUDIO_STATE_CHANGED="audioStateChanged",e.VIDEO_STATE_CHANGED="videoStateChanged"}(x||(x={}));var R=class extends O{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(x.AUDIO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getAudioTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var L=class extends O{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(x.VIDEO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getVideoTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var P=class extends O{constructor(e){super(e),Object.defineProperty(this,"volume",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"contextAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"streamSource",{enumerable:!0,configurable:!0,writable:!0,value:null})}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.context&&this.contextAnalyser&&this.streamSource){const e=this.contextAnalyser.frequencyBinCount,t=new Uint8Array(e);this.contextAnalyser.getByteFrequencyData(t);const i=t.reduce(((e,t)=>e+t),0);this.volume=i/e}else this.volume=0}start(){this.createContextAnalyser(),this.createStreamSource(),this.streamSource&&super.start()}stop(){this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.volume=0,super.stop()}createContextAnalyser(){if(this.context&&this.contextAnalyser)return;if(!window.AudioContext&&!window.webkitAudioContext)return;const e=window.AudioContext||window.webkitAudioContext;this.context=new e,this.contextAnalyser=this.context.createAnalyser(),this.contextAnalyser.fftSize=1024,this.contextAnalyser.smoothingTimeConstant=.5}createStreamSource(){if(this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.context&&this.stream&&this.stream.getAudioTracks().length>0){if(this.streamSource=this.context.createMediaStreamSource(this.stream),!this.contextAnalyser)return;this.streamSource.connect(this.contextAnalyser),"suspended"===this.context.state&&this.context.resume()}}destroy(){this.contextAnalyser&&(this.contextAnalyser.disconnect(),this.contextAnalyser=null),this.context&&(this.context=null),super.destroy()}};const k={autoGainControl:!0,echoCancellation:!0,latency:0,noiseSuppression:!0},H={aspectRatio:16/9,frameRate:30,width:640,height:360},j={width:1920,height:1080,frameRate:5},V=e=>(e.close=e.stop=function(){e.getTracks().forEach((e=>e.stop()))},e.pause=function(){this.getTracks().forEach((e=>e.enabled=!1))},e.play=function(){this.getTracks().forEach((e=>e.enabled=!0))},e.muteAudio=function(e=!0){this.getAudioTracks().forEach((t=>t.enabled=!e))},e.muteVideo=function(e=!0){this.getVideoTracks().forEach((t=>t.enabled=!e))},e),U=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getUserMedia(t);return V(e)})),G=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getDisplayMedia(t);return V(e)})),F=(e,t,i=!1)=>{if(!e||!t)return!1;const r=e.deviceId===t.deviceId&&e.label===t.label&&e.kind===t.kind;return i?e.groupId===t.groupId&&r:r},$=({deviceList:e,device:t,deviceId:i})=>(t=(t=i?e.find((e=>e.deviceId===i))||null:t&&e.find((e=>F(e,t)))||null)||(e[0]||null))&&t.deviceId?t.deviceId:"",B=(e,t)=>{if(!e||!t||e.length!==t.length)return!1;let i=!0;for(let r=0;r<e.length;r++){if(!F(e[r],t[r])){i=!1;break}}return i},q=(e,t)=>{e.removeEventListener("inactive",t);(e.getVideoTracks()||[]).forEach((e=>{e.removeEventListener("ended",t)}))};var Y;exports.MediaType=void 0,(Y=exports.MediaType||(exports.MediaType={}))[Y.kAudio=0]="kAudio",Y[Y.kVideo=1]="kVideo",Y[Y.kData=2]="kData";class z{constructor(e,i){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_streamState",{enumerable:!0,configurable:!0,writable:!0,value:{state:exports.MEDIA_STREAM_STATE.NULL}}),Object.defineProperty(this,"_inputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_outputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_outputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_inputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_outputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_mediaTrackConstraints",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"queue",{enumerable:!0,configurable:!0,writable:!0,value:Promise.resolve(null)}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"analyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"volumeAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"onStreamInactive",{enumerable:!0,configurable:!0,writable:!0,value:this.streamInactive.bind(this)}),this.type=e,this.ctx=i,this.setup()}get mediaTrackConstraints(){return this._mediaTrackConstraints}set mediaTrackConstraints(e){this._mediaTrackConstraints=e,this.streamState.state!==exports.MEDIA_STREAM_STATE.NULL&&this.createStream()}get inputDevices(){return this._inputDevices||[]}set inputDevices(e){B(e,this._inputDevices)||(this._inputDevices=e,this.ctx.state===exports.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(exports.MEDIA_EVENT.INPUT_DEVICES_UPDATED,{deviceList:e}))}get outputDevices(){return this._outputDevices||[]}set outputDevices(e){B(e,this._outputDevices)||(this._outputDevices=e,this.ctx.state===exports.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(exports.MEDIA_EVENT.OUTPUT_DEVICES_UPDATED,{deviceList:e}))}get inputDeviceId(){return this._inputDeviceId||""}set inputDeviceId(e){if(this._inputDeviceId&&this._inputDeviceId===e)return;const{inputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.inputDevice=i,this._inputDeviceId=i?i.deviceId:"",this.streamState.state!==exports.MEDIA_STREAM_STATE.NULL&&this.createStream()}get outputDeviceId(){return this._outputDeviceId||""}set outputDeviceId(e){if(this._outputDeviceId&&this._outputDeviceId===e)return;const{outputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.outputDevice=i,this._outputDeviceId=i?i.deviceId:""}get inputDevice(){return this._inputDevice}set inputDevice(e){const t=this._inputDevice&&!F(this._inputDevice,e),i=!this._inputDevice&&!!e;(i||t)&&(this._inputDevice=e,!i&&t&&this.emitter.emit(exports.MEDIA_EVENT.INPUT_DEVICE_CHANGED,{device:e}))}get outputDevice(){return this._outputDevice}set outputDevice(e){const t=this._outputDevice&&!F(this._outputDevice,e),i=!this._outputDevice&&!!e;(i||t)&&(this._outputDevice=e,!i&&t&&this.emitter.emit(exports.MEDIA_EVENT.OUTPUT_DEVICE_CHANGED,{device:e}))}get streamState(){return this._streamState}set streamState(e){const{_streamState:t}=this;t.state===e.state&&t.detail===e.detail||(this._streamState=e,this.emitter.emit(exports.MEDIA_EVENT.STREAM_STATE,this._streamState))}setup(){this.type!==exports.MediaType.kData&&(this.type===exports.MediaType.kAudio?(this.analyser=new R(this.stream),this.volumeAnalyser=new P(this.stream)):this.analyser=new L(this.stream),this.analyser.on(x.AUDIO_STATE_CHANGED,(({state:e})=>{!e.hasStream||e.track&&e.active||(this.streamState={state:exports.MEDIA_STREAM_STATE.FAILED,detail:exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS})})))}cleanup(){this.closeStream(),this.inputDevices=[],this.inputDeviceId="",this.outputDevices=[],this.outputDeviceId=""}streamInactive(){this.stream&&(this.stream.close(),this.stream=null,this.streamState={state:exports.MEDIA_STREAM_STATE.NULL},this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream}))}getMediaStream(t){return e(this,void 0,void 0,(function*(){let e=null;switch(this.type){case exports.MediaType.kAudio:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:r,groupId:s}=e||{deviceId:"",groupId:""};return i.audio=!!e&&(t&&p?{deviceId:{exact:r},groupId:{exact:s}}:{deviceId:r,groupId:s}),i.audio&&!E&&Object.assign(i.audio,k),i})(this.inputDevice,t),e.audio||(e=null);break;case exports.MediaType.kVideo:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:r,groupId:s}=e||{deviceId:"",groupId:""};return i.video=t||!!e&&(p?{deviceId:{exact:r},groupId:{exact:s}}:{deviceId:r,groupId:s}),i.video&&Object.assign(i.video,H),i})(this.inputDevice,this.mediaTrackConstraints),e.video||(e=null);break;case exports.MediaType.kData:e={video:j}}let i=this.streamState;if(!e)return i={state:exports.MEDIA_STREAM_STATE.FAILED,detail:exports.MEDIA_STREAM_DETAIL.NO_DEVICE},{stream:null,streamState:i};let r,s=null;try{s=yield(this.type===exports.MediaType.kData?G:U)(e)}catch(n){r=n}if(s)i={state:exports.MEDIA_STREAM_STATE.CAPTURING};else{r=r||new Error("Stream is null");const e=this.type===exports.MediaType.kAudio?X:this.type===exports.MediaType.kVideo?J:K;i={state:exports.MEDIA_STREAM_STATE.FAILED,detail:e.get(r.message)||exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS}}return{stream:s,streamState:i}}))}closeStream(){this.stream&&(this.type===exports.MediaType.kData&&q(this.stream,this.onStreamInactive),this.stream.close()),this.stream=null,this.switchAnalyserEnable(this.stream,{enable:!1}),this.streamState={state:exports.MEDIA_STREAM_STATE.NULL},this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream})}createStream(){return this.ctx.throwIfNotState(exports.MEDIA_MANAGER_STATE.INITED),this.queue=this.queue.then((()=>e(this,void 0,void 0,(function*(){this.switchAnalyserEnable(this.stream,{enable:!1});const e=!(this.streamState.state!==exports.MEDIA_STREAM_STATE.CAPTURING||!this.stream),{stream:t,streamState:i}=yield this.getMediaStream(e);if(this.streamState.state===exports.MEDIA_STREAM_STATE.CAPTURING&&this.stream&&(this.type===exports.MediaType.kData&&q(this.stream,this.onStreamInactive),this.stream.close(),this.stream=null),this.ctx.state!==exports.MEDIA_MANAGER_STATE.INITED)return t&&t.close(),this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream}),Promise.resolve(this.stream);this.type===exports.MediaType.kData&&((e,t)=>{e&&e.addEventListener("inactive",t),p&&e&&(e.getVideoTracks()||[]).forEach((e=>{e.addEventListener("ended",t)}))})(t,this.onStreamInactive),this.stream=t,this.streamState=i,this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream});let r=!0;return t||i.state!==exports.MEDIA_STREAM_STATE.FAILED||(r=!1),this.switchAnalyserEnable(t,{enable:r}),Promise.resolve(this.stream)}))))}getMicVolume(){return this.volumeAnalyser?this.volumeAnalyser.volume:0}switchAnalyserEnable(e,{enable:t=!1}){this.type!==exports.MediaType.kData&&(this.analyser?(this.analyser.stream=e,this.analyser.enable=t,this.type===exports.MediaType.kAudio&&this.volumeAnalyser&&(this.volumeAnalyser.stream=e,this.volumeAnalyser.enable=t)):console.error(""))}}const X=new Map([["No Device",exports.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["The request is not allowed by the user agent or the platform in the current context.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["Stream is null",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),J=new Map([["No Device",exports.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",exports.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["The request is not allowed by the user agent or the platform in the current context.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",exports.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["Stream is null",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),K=new Map([["Permission denied by system",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The object can not be found here.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM]]);exports.Channel=y,exports.MediaInterface=z,exports.createChannel=e=>new y(e),exports.createMediaManager=()=>{const i={state:exports.MEDIA_MANAGER_STATE.NULL,emitter:t(),deviceList:[],throwIfState:(e,t)=>{if(i.state===e)throw new Error(t||"Invalid State")},throwIfNotState:(e,t)=>{if(i.state!==e)throw new Error(t||"Invalid State")}},r=new z(exports.MediaType.kAudio,i),s=new z(exports.MediaType.kVideo,i),n=new z(exports.MediaType.kData,i),a=t=>e(void 0,void 0,void 0,(function*(){if(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)return void console.error("mediaDevices or enumerateDevices is miss");const e=yield navigator.mediaDevices.enumerateDevices().catch((e=>{console.error("enumerate devices error: ",e)}));i.deviceList=e&&e.map((e=>e.toJSON()))||[],r.inputDevices=i.deviceList.filter((e=>"audioinput"===e.kind)),r.inputDeviceId=$({deviceList:r.inputDevices,device:r.inputDevice,deviceId:t&&t.audioInputDeviceId||""}),r.outputDevices=i.deviceList.filter((e=>"audiooutput"===e.kind)),r.outputDeviceId=$({deviceList:r.outputDevices,device:r.outputDevice,deviceId:t&&t.audioOutputDeviceId||""}),s.inputDevices=i.deviceList.filter((e=>"videoinput"===e.kind)),s.inputDeviceId=$({deviceList:s.inputDevices,device:s.inputDevice,deviceId:t&&t.videoInputDeviceId||""})}));return{ctx:i,get state(){return i.state},on:i.emitter.on,off:i.emitter.off,init:t=>e(void 0,void 0,void 0,(function*(){if(window.ActiveXObject||"ActiveXObject"in window)throw new Error("Not compatible with this browser yet, please use other browsers instead.");i.throwIfState(exports.MEDIA_MANAGER_STATE.INITED),navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=function(){a()}),yield a(t),i.state=exports.MEDIA_MANAGER_STATE.INITED,i.emitter.emit(exports.MEDIA_MANAGER_EVENT.STATE,{state:i.state})})),destroy:()=>{try{r.cleanup(),s.cleanup(),n.cleanup()}catch(e){}i.state=exports.MEDIA_MANAGER_STATE.NULL,i.emitter.emit(exports.MEDIA_MANAGER_EVENT.STATE,{state:i.state})},audioMedia:r,videoMedia:s,dataMedia:n}}; | ||
"use strict";function e(e,t,i,r){return new(i||(i=Promise))((function(s,n){function a(e){try{c(r.next(e))}catch(t){n(t)}}function o(e){try{c(r.throw(e))}catch(t){n(t)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((r=r.apply(e,t||[])).next())}))}function t(e){return{all:e=e||new Map,on:function(t,i){var r=e.get(t);r?r.push(i):e.set(t,[i])},off:function(t,i){var r=e.get(t);r&&(i?r.splice(r.indexOf(i)>>>0,1):e.set(t,[]))},emit:function(t,i){var r=e.get(t);r&&r.slice().map((function(e){e(i)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,i)}))}}}var i,r,s,n,a,o;Object.defineProperty(exports,"__esModule",{value:!0}),exports.CHANNEL_EVENT=void 0,(i=exports.CHANNEL_EVENT||(exports.CHANNEL_EVENT={})).STATE="streamState",i.CHANNEL_REFRESH="channelRefresh",i.CHANNEL_BUSY="channelBusy",i.AUDIO_CHANNEL_OPENED="audioChannelOpened",i.VIDEO_CHANNEL_OPENED="videoChannelOpened",i.DATA_CHANNEL_OPENED="dataChannelOpened",i.MESSAGE_CHANNEL_OPENED="messageChannelOpened",i.VOICE_ACTIVE_SSRC="voiceActiveSsrc",i.AUDIO_PLAYER_CHANGE="audioPlayerChange",exports.CHANNEL_STATE=void 0,(r=exports.CHANNEL_STATE||(exports.CHANNEL_STATE={}))[r.STARTED=1]="STARTED",r[r.STOPPED=0]="STOPPED",exports.MEDIA_MANAGER_EVENT=void 0,(exports.MEDIA_MANAGER_EVENT||(exports.MEDIA_MANAGER_EVENT={})).STATE="state",exports.MEDIA_MANAGER_STATE=void 0,(s=exports.MEDIA_MANAGER_STATE||(exports.MEDIA_MANAGER_STATE={}))[s.NULL=0]="NULL",s[s.INITED=1]="INITED",exports.MEDIA_EVENT=void 0,(n=exports.MEDIA_EVENT||(exports.MEDIA_EVENT={})).STREAM_STATE="streamState",n.STREAM="stream",n.INPUT_DEVICES_UPDATED="inputDevicesUpdated",n.OUTPUT_DEVICES_UPDATED="outputDevicesUpdated",n.INPUT_DEVICE_CHANGED="inputDeviceChanged",n.OUTPUT_DEVICE_CHANGED="outputDeviceChanged",exports.MEDIA_STREAM_STATE=void 0,(a=exports.MEDIA_STREAM_STATE||(exports.MEDIA_STREAM_STATE={}))[a.NULL=0]="NULL",a[a.CAPTURING=1]="CAPTURING",a[a.FAILED=2]="FAILED",exports.MEDIA_STREAM_DETAIL=void 0,(o=exports.MEDIA_STREAM_DETAIL||(exports.MEDIA_STREAM_DETAIL={}))[o.NO_DEVICE=0]="NO_DEVICE",o[o.PERMISSION_DENIED=1]="PERMISSION_DENIED",o[o.COULD_NOT_START_VIDEO_SOURCE=2]="COULD_NOT_START_VIDEO_SOURCE",o[o.PERMISSION_DENIED_BY_SYSTEM=3]="PERMISSION_DENIED_BY_SYSTEM",o[o.OTHER_EXCEPTIONS=4]="OTHER_EXCEPTIONS";const c=(e,t)=>{const i=t.match(e);return i&&i.length>0&&i[1]||""},l=/version\/(\d+(\.?_?\d+)+)/i,d=[{test:[/\sedg\//i],describe(e){const t={name:"Microsoft Edge"},i=c(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/edg([ea]|ios)/i],describe(e){const t={name:"Microsoft Edge"},i=((e,t)=>{const i=t.match(e);return i&&i.length>1&&i[2]||""})(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/firefox|iceweasel|fxios/i],describe(e){const t={name:"Firefox"},i=c(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/chromium/i],describe(e){const t={name:"Chromium"},i=c(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||c(l,e);return i&&(t.version=i),t}},{test:[/chrome|crios|crmo/i],describe(e){const t={name:"Chrome"},i=c(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/safari|applewebkit/i],describe(e){const t={name:"Safari"},i=c(l,e);return i&&(t.version=i),t}}];let h;const u=d.find((e=>{if(e.test instanceof Array)return e.test.some((e=>e.test(navigator.userAgent)));throw new Error("Browser's test function is not valid")}));u&&(h=u.describe(navigator.userAgent));const p=h&&"Safari"===h.name,E=h&&"Firefox"===h.name,m=h&&"Chrome"===h.name,v=h&&"Microsoft Edge"===h.name,A=e=>/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e),T=(e,t)=>t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e,f=({src:e,id:t})=>new Promise(((i,r)=>{let s=document.querySelector(`#${t}`);if(s)return s.src=e,void i(s);s=document.createElement("script"),s.src=e,s.id=t,s.onload=()=>{i(s)},s.onerror=e=>{r(e)},document.head.appendChild(s)}));var S=class{constructor({namespace:e,debug:t}){Object.defineProperty(this,"initialized",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isDebugging",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useColors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"backend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"namespace",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.initialized=!0,this.isDebugging=t,this.backend=b(),this.namespace=e,this.useColors=this.backend.useColors,this.color=this.selectColor(e)}logger(e){e[0]=this.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let t=0;return e[0]=e[0].replace(/%([a-zA-Z%])/g,((i,r)=>{if("%%"===i)return i;t++;const s=this.backend.formatters[r];if("function"==typeof s){i=s(e[t]),e.splice(t,1),t--}return i})),this.backend.formatArgs(e,this)}coerce(e){return e instanceof Error?e.stack||e.message:e}selectColor(e){const t=Array.from(e).reduce(((e,t)=>(e=(e<<5)-e+t.charCodeAt(0),e|=0)),0);return this.backend.colors[Math.abs(t)%this.backend.colors.length]}switchDebug(e){this.isDebugging=e}log(...e){e=this.logger(e),this.backend.log.apply(this,e)}debug(...e){this.isDebugging&&(e=this.logger(e),this.backend.debug.apply(this,e))}warn(...e){this.backend.warn.apply(this,e)}error(...e){this.backend.error.apply(this,e)}};const b=()=>({colors:["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],formatters:{j:e=>{try{return JSON.stringify(e)}catch(t){return`[UnexpectedJSONParseError]: ${t.message}`}}},log:(...e)=>"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,e),debug:(...e)=>"object"==typeof console&&console.debug&&Function.prototype.apply.call(console.debug,console,e),warn:(...e)=>"object"==typeof console&&console.warn&&Function.prototype.apply.call(console.warn,console,e),error:(...e)=>"object"==typeof console&&console.error&&Function.prototype.apply.call(console.error,console,e),formatArgs:(e,t)=>{const{useColors:i,namespace:r,color:s}=t;if(e[0]=`${(i?"%c":"")+r+(i?" %c":" ")+e[0]+(i?"%c ":" ")}+${function(e){const t=Math.abs(e);if(t>=N)return`${Math.round(e/N)}d`;if(t>=_)return`${Math.round(e/_)}h`;if(t>=I)return`${Math.round(e/I)}m`;if(t>=D)return`${Math.round(e/D)}s`;return`${e}ms`}(0)}`,!i)return[];const n=`color: ${s}`;e.splice(1,0,n,"color: inherit");let a=0,o=0;return e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(a++,"%c"===e&&(o=a))})),e.splice(o,0,n),e},useColors:C()}),D=1e3,I=60*D,_=60*I,N=24*_;const C=()=>!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.webkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)),g=new S({namespace:"STREAM:Store",debug:!1});class y{constructor({baseURL:e,videoSDKLibDir:i,clientID:r,debug:s}){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:exports.CHANNEL_STATE.STOPPED}),Object.defineProperty(this,"clientID",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"SFUTransportType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEndpoint",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEngine",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audioChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"videoChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"messageChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"remoteControlStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"subtitleStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"videoSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dataSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioReceiver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"voiceActiveSsrc",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"audioChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"videoChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"dataChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"messageChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"baseURL",{enumerable:!0,configurable:!0,writable:!0,value:"https://meetings.ylyun.com"}),Object.defineProperty(this,"videoSDKLibDir",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"_audioPlayer",{enumerable:!0,configurable:!0,writable:!0,value:null}),e=e||"https://meetings.ylyun.com",i=i||"",g.switchDebug(s=s||!1),this.clientID=r,this.setBaseUrl(e),this.setVideoSDKLibDir(i),this.setup()}get audioPlayer(){return this._audioPlayer}set audioPlayer(e){this._audioPlayer=e,this.emitter.emit(exports.CHANNEL_EVENT.AUDIO_PLAYER_CHANGE,e)}setup(){return e(this,void 0,void 0,(function*(){}))}cleanup(){return e(this,void 0,void 0,(function*(){const{videoChannel:e,audioChannel:t,messageChannel:i,dataChannel:r,mediaEndpoint:s,remoteControlStream:n}=this;try{t&&(yield t.close()),e&&(yield e.close()),r&&(yield r.close()),n&&i&&(yield i.closeStream(n)),i&&(yield i.close()),s&&(s.stop(),s.destroy())}catch(a){g.error(a)}this.mediaEndpoint=null,this.mediaEngine=null,this.videoChannel=null,this.audioChannel=null,this.dataChannel=null,this.messageChannel=null,this.videoSender=null,this.audioSender=null,this.dataSender=null,this.audioReceiver=null,this.audioPlayer=null,this.audioChannelOpened=!1,this.videoChannelOpened=!1,this.dataChannelOpened=!1,this.messageChannelOpened=!1}))}getMss(t){return e(this,void 0,void 0,(function*(){const{mediaContent:e,userID:i,role:r,meetingID:s,appId:n,meetingNumber:a,meetingParam:o,userAccount:c}=t,l=yield M.getMss(this.baseURL,{appId:n,meetingNumber:a,meetingParam:o,userAccount:c,accessMCs:e.accessMCs,topMC:e.topMC,confId:s,ccid:i,userType:"audience"===r?"Broadcast":"Interactive"}).catch((e=>{g.error(e)}));if(g.debug(`response ${JSON.stringify(l)}`),!l||!l.data||!l.data.MssInfo)return g.error("getMss response error ",l),[];const d=l.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),h=l.data.MssInfo.map((e=>e.IntranetUri)).flat();return d.concat(h).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const{baseURL:t}=this,i=A(t)?(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[2]})(t):t,r=`${A(t)&&"http:"===(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[1]})(t)?"ws":"wss"}://${i}`,s=window.btoa(e.replace(/\w+:\/\//,""));return T(r,`/webapp/socket/${s}`)}))}))}mssRequest(t,i){return e(this,void 0,void 0,(function*(){const{mediaContent:r,userID:s,role:n,meetingID:a,appId:o,meetingNumber:c,meetingParam:l,userAccount:d}=i,h=(i,h)=>new Promise(((u,p)=>{const E=new URL(i),m=E.searchParams.get("webapp");m&&(i=`https://${m}?mc=${E.host}`),M.mssRequest(i,{appId:o,meetingNumber:c,meetingParam:l,userAccount:d,accessMCs:r.accessMCs,topMC:r.topMC,confId:a,ccid:s,userType:"audience"===n?"Broadcast":"Interactive"}).then((i=>e(this,void 0,void 0,(function*(){return console.log("result: ",i),i&&i.data?i.state&&300001===i.state?(console.log("getMss() wait 300ms"),t.splice(h,1),yield(e=300,new Promise((t=>setTimeout((()=>t(e)),e)))),p(i)):u(i):(t.splice(h,1),p(i));var e})))).catch((e=>{console.error(e),p()}))})),u=()=>e(this,void 0,void 0,(function*(){let e=null;try{e=yield Promise.race(t.map(h))}catch(i){console.error("request/mss ",i)}return e}));let p=[];const E=t.length;for(let e=0;e<E;e++){const e=yield u();if(e&&e.state&&3e5===e.state){const t=e.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),i=e.data.MssInfo.map((e=>e.IntranetUri)).flat();p=t.concat(i).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const t=new URL(e),i=t.searchParams.get("webapp");return i&&(e=`wss://${i}?mss=${t.host}`),e}));break}}return p}))}start(t){return e(this,void 0,void 0,(function*(){this.throwIfState(exports.CHANNEL_STATE.STARTED),yield w(this.videoSDKLibDir,!!t.develop).catch((e=>{g.error(e)}));const{LIBRTC:i}=window,{NativeMediaEndpoint:r,NativeMediaEngine:s,SFUTransportType:n}=i;this.SFUTransportType=n,t.config&&(i.config=t.config);const{mediaContent:a,user:o,meetingID:c,ctrlID:l,meetingNum:d="",account:h=""}=t,u=new s;yield u.init();const p=new r;p.onrefresh=()=>e(this,void 0,void 0,(function*(){this.emitter.emit(exports.CHANNEL_EVENT.CHANNEL_REFRESH);const e=o.userID,t=o.role;let i=[];for(let s=0;s<a.accessMCs.length;s++){let n=[];try{n=JSON.parse(a.accessMCs[s])}catch(r){console.error(r)}const o=n.some((e=>(!e.extranet||!e.extranet.length)&&e.intranet&&e.intranet.length)),l=n.map((e=>{const t=e.extranet||[];return t.push(...e.intranet),t})).flat(),u={appId:this.clientID,mediaContent:{accessMCs:[a.accessMCs[s]],topMC:a.topMC,crypto:a.crypto,meetingParam:a.meetingParam},meetingID:c,userID:e,role:t,meetingParam:a.meetingParam,meetingNumber:d,userAccount:h};if(-1!==l.findIndex((e=>new URL(e).searchParams.get("webapp")))){if(console.log("urls",l),i=yield this.mssRequest(l,u),i.length)break}else{if(o)break;if(i=yield this.getMss(u),i.length)break}}return i})),yield p.init(),yield p.start({meeting_number:d||"",user_account:h||"",meeting_param:a.meetingParam,client_type:"WebApp",confid:c,ccid:o.userID,role:1,encrypt:a.crypto,token:l}),this.mediaEndpoint=p,this.mediaEngine=u,this.state=exports.CHANNEL_STATE.STARTED,this.emitter.emit(exports.CHANNEL_EVENT.STATE,{state:this.state})}))}stop(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),yield this.cleanup(),this.state=exports.CHANNEL_STATE.STOPPED,this.emitter.emit(exports.CHANNEL_EVENT.STATE,{state:this.state})}))}destroy(){return e(this,void 0,void 0,(function*(){yield this.stop()}))}getChannelState(){return{audioChannelOpened:this.audioChannelOpened,videoChannelOpened:this.videoChannelOpened,dataChannelOpened:this.dataChannelOpened,messageChannelOpened:this.messageChannelOpened}}setBaseUrl(e){this.throwIfState(exports.CHANNEL_STATE.STARTED),e&&this.baseURL!==e&&("/"===e&&(e=window.location.origin),this.baseURL=e)}setVideoSDKLibDir(e){this.throwIfState(exports.CHANNEL_STATE.STARTED),e&&this.videoSDKLibDir!==e&&(this.videoSDKLibDir=e)}createAudioChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.audio.createChannel(t.createTransport(i.kAudio));this.audioChannel=r,r.onopen=()=>{g.debug("audioChannel onopen()"),this.audioChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.AUDIO_CHANNEL_OPENED)},yield r.open()}))}closeAudioChannel(){return e(this,void 0,void 0,(function*(){const{audioChannel:e}=this;e?(yield e.close(),this.audioChannel=null,this.audioSender=null,this.audioReceiver=null,this.audioChannelOpened=!1):g.error("audioChannel is miss")}))}createVideoChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.video.createChannel(t.createTransport(i.kVideo));this.videoChannel=r,r.onopen=()=>{g.debug("videoChannel onopen()"),this.videoChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.VIDEO_CHANNEL_OPENED)},yield r.open()}))}createDataChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.video.createChannel(t.createTransport(i.kData));this.dataChannel=r,r.onopen=()=>{g.debug("dataChannel onopen()")},yield r.open(),this.dataChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.DATA_CHANNEL_OPENED)}))}createMessageChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:i}=this,r=e.video.createDataChannel(t.createTransport(i.kMessage));this.messageChannel=r,r.onopen=()=>{g.debug("messageChannel onopen()")};try{yield r.open()}catch(s){console.error(s)}this.messageChannelOpened=!0,this.emitter.emit(exports.CHANNEL_EVENT.MESSAGE_CHANNEL_OPENED)}))}closeMessageChannel(){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?yield e.close():g.error("messageChannel is miss")}))}closeMessageStream(t){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?t&&(yield e.closeStream(t)):g.error("messageChannel is miss")}))}setupRemoteControl({element:t,remote:i}){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message"),t.setAttribute("tabIndex","-1"),t.style.outline="0";const{LIBRTC:e}=window,{messageChannel:r}=this,s=yield r.createStream(e.DataType.kRemoteControl);return this.remoteControlStream=s,e.setupRemoteControl(s,t,i)}))}createSubtitleStream(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this,t=yield e.createSubtitleStream();return t.subscribe([-1]),this.subtitleStream=t,t}))}closeSubtitleStream(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this;yield e.closeSubtitleStream(t),this.subtitleStream=null}))}createAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;if(!e)return g.error("audioChannel is miss"),null;const t=this.audioSender?this.audioSender:e.createSender();return this.audioSender=t,t}))}removeAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioSender:e}=this;if(e)try{e.stop(),this.audioChannel&&this.audioChannel.removeSender(e.ssrc)}catch(t){g.error("audioChannel removeSender() error: ",t)}else g.error("audioSender is miss")}))}createVideoSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e)return g.error("videoChannel is miss"),null;const t=this.videoSender?this.videoSender:e.createSender();return this.videoSender=t,t.onbusy=()=>{g.debug("onbusy"),this.emitter.emit(exports.CHANNEL_EVENT.CHANNEL_BUSY);const{audioChannel:e}=this;e&&e.ans(!1)},t}))}removeVideoSender(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoSender:e}=this;if(e)try{e.stop(),this.videoChannel&&this.videoChannel.removeSender(e.ssrc)}catch(t){g.error("videoChannel removeSender() error: ",t)}else g.error("videoSender is miss")}createDataSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e)return g.error("dataChannel is miss"),null;const t=this.dataSender?this.dataSender:e.createSender();return this.dataSender=t,t}))}removeDataSender(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataSender:e}=this;e?(e.stop(),this.dataChannel&&this.dataChannel.removeSender(e.ssrc),this.dataSender=null):g.error("dataSender is miss")}createAudioReceiver(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;if(!t)return g.error("audioChannel is miss"),null;const i=t.createReceiver();return this.audioReceiver=i,e?(i.setSink(e),this.audioPlayer=e,t.audioElement&&(t.audioElement.srcObject=null),i):(g.error("audioPlayer is miss"),null)}createVideoReceiver(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{ccid:t}=e;if(g.debug("createVideoReceiver ccid: ",t),!t)return g.error("params is missing or params error"),null;const{videoChannel:i}=this;if(!i)return g.error("videoChannel is miss"),null;return i.createReceiver(t)}createDataReceiver(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{ccid:t}=e;if(g.debug("createDataReceiver ccid: ",t),!t)return g.error("params is missing or params error"),null;const{dataChannel:i}=this;if(!i)return g.error("dataChannel is miss"),null;return i.createReceiver(t)}removeVideoReceiver(e){return this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video"),e?(e.stop(),this.videoChannel&&this.videoChannel.removeReceiver(e.ssrc),null):e}removeDataReceiver(e){return this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data"),e?(e.stop(),this.dataChannel&&this.dataChannel.removeReceiver(e.ssrc),null):e}loadVideoRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e||!t)return g.error("videoChannel or el is miss"),null;return(m||v)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadVideoRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;e&&t?(m||v)&&(yield e.offscreen.unload(t)):g.error("videoChannel or renderer is miss")}))}loadDataRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e||!t)return g.error("dataChannel or el is miss"),null;return(m||v)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadDataRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;e&&t?(m||v)&&(yield e.offscreen.unload(t)):g.error("dataChannel or renderer is miss")}))}bindAudioChannelEvent(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=e=>{if(this.voiceActiveSsrc.length&&e.length){if(this.voiceActiveSsrc[0]===e[0])return}else if(0===this.voiceActiveSsrc.length&&0===e.length)return;this.voiceActiveSsrc=e,this.emitter.emit(exports.CHANNEL_EVENT.VOICE_ACTIVE_SSRC,{ssrc:e})}:g.error("audioChannel is miss")}offAudioChannelEvent(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=null:g.error("audioChannel is miss")}setAudioPlayerVolume(e){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:t}=this;t?t.volume=e=e>=0&&e<1?e:e>=1&&e<=100?e/100:e:g.error("audioPlayer is miss")}getAudioPlayerVolume(){this.throwIfNotState(exports.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:e}=this;return e?e.volume:(g.error("audioPlayer is miss"),0)}getAudioChannelStats(){return e(this,void 0,void 0,(function*(){return this.state===exports.CHANNEL_STATE.STARTED&&this.audioChannelOpened&&this.audioChannel?yield this.audioChannel.getStats():{}}))}throwIfState(e,t){if(this.state===e)throw new Error(t||"Invalid State")}throwIfNotState(e,t){if(this.state!==e)throw new Error(t||"Invalid State")}throwIfChannelNotOpened(e,t=""){switch(e){case"audio":if(!this.audioChannelOpened)throw new Error(t||"Channel is not open");break;case"video":if(!this.videoChannelOpened)throw new Error(t||"Channel is not open");break;case"data":if(!this.dataChannelOpened)throw new Error(t||"Channel is not open");break;case"message":if(!this.messageChannelOpened)throw new Error(t||"Channel is not open")}}}const w=(e,t)=>Promise.all([f({src:`${e}/libsfu${t?"":".prod"}.js`,id:"ylink-sdk-stream-libsfu"}),f({src:`${e}/librtc.global${t?"":".prod"}.js`,id:"ylink-sdk-stream-librtc"})]),M={getMss:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(T(t,"/webapp/front/getMss"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify(i)}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()})))),mssRequest:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(T(t,"/api/v1/mss/request"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify({ConfId:i.confId,CCID:i.ccid,Rlp:{UpRlp:56,DownRlp:56},ClientType:"WebApp",TimeStamp:(new Date).getTime(),MeetingParam:i.meetingParam,VideoParam:{Width:1920,Height:1080,Fr:30},MeetingNumber:i.meetingNumber,UserAccount:i.userAccount,UserType:i.userType,TopMc:i.topMC})}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()}))))};class O{constructor(e){Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_enable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),this.stream=e}analyse(){}start(){this.stream&&(this.timer&&(clearInterval(this.timer),this.timer=null),this.analyse(),this.timer=setInterval((()=>this.analyse()),this.interval))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}destroy(){this.stop()}}var x;!function(e){e.AUDIO_STATE_CHANGED="audioStateChanged",e.VIDEO_STATE_CHANGED="videoStateChanged"}(x||(x={}));var R=class extends O{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(x.AUDIO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getAudioTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var P=class extends O{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(x.VIDEO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getVideoTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var L=class extends O{constructor(e){super(e),Object.defineProperty(this,"volume",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"contextAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"streamSource",{enumerable:!0,configurable:!0,writable:!0,value:null})}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.context&&this.contextAnalyser&&this.streamSource){const e=this.contextAnalyser.frequencyBinCount,t=new Uint8Array(e);this.contextAnalyser.getByteFrequencyData(t);const i=t.reduce(((e,t)=>e+t),0);this.volume=i/e}else this.volume=0}start(){this.createContextAnalyser(),this.createStreamSource(),this.streamSource&&super.start()}stop(){this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.volume=0,super.stop()}createContextAnalyser(){if(this.context&&this.contextAnalyser)return;if(!window.AudioContext&&!window.webkitAudioContext)return;const e=window.AudioContext||window.webkitAudioContext;this.context=new e,this.contextAnalyser=this.context.createAnalyser(),this.contextAnalyser.fftSize=1024,this.contextAnalyser.smoothingTimeConstant=.5}createStreamSource(){if(this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.context&&this.stream&&this.stream.getAudioTracks().length>0){if(this.streamSource=this.context.createMediaStreamSource(this.stream),!this.contextAnalyser)return;this.streamSource.connect(this.contextAnalyser),"suspended"===this.context.state&&this.context.resume()}}destroy(){this.contextAnalyser&&(this.contextAnalyser.disconnect(),this.contextAnalyser=null),this.context&&(this.context=null),super.destroy()}};const k={autoGainControl:!0,echoCancellation:!0,latency:0,noiseSuppression:!0},H={aspectRatio:16/9,frameRate:30,width:640,height:360},j={width:1920,height:1080,frameRate:5},V=e=>(e.close=e.stop=function(){e.getTracks().forEach((e=>e.stop()))},e.pause=function(){this.getTracks().forEach((e=>e.enabled=!1))},e.play=function(){this.getTracks().forEach((e=>e.enabled=!0))},e.muteAudio=function(e=!0){this.getAudioTracks().forEach((t=>t.enabled=!e))},e.muteVideo=function(e=!0){this.getVideoTracks().forEach((t=>t.enabled=!e))},e),U=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getUserMedia(t);return V(e)})),G=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getDisplayMedia(t);return V(e)})),F=(e,t,i=!1)=>{if(!e||!t)return!1;const r=e.deviceId===t.deviceId&&e.label===t.label&&e.kind===t.kind;return i?e.groupId===t.groupId&&r:r},$=({deviceList:e,device:t,deviceId:i})=>(t=(t=i?e.find((e=>e.deviceId===i))||null:t&&e.find((e=>F(e,t)))||null)||(e[0]||null))&&t.deviceId?t.deviceId:"",B=(e,t)=>{if(!e||!t||e.length!==t.length)return!1;let i=!0;for(let r=0;r<e.length;r++){if(!F(e[r],t[r])){i=!1;break}}return i},q=(e,t)=>{e.removeEventListener("inactive",t);(e.getVideoTracks()||[]).forEach((e=>{e.removeEventListener("ended",t)}))};var Y;exports.MediaType=void 0,(Y=exports.MediaType||(exports.MediaType={}))[Y.kAudio=0]="kAudio",Y[Y.kVideo=1]="kVideo",Y[Y.kData=2]="kData";class z{constructor(e,i){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_streamState",{enumerable:!0,configurable:!0,writable:!0,value:{state:exports.MEDIA_STREAM_STATE.NULL}}),Object.defineProperty(this,"_inputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_outputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_outputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_inputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_outputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_mediaTrackConstraints",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"queue",{enumerable:!0,configurable:!0,writable:!0,value:Promise.resolve(null)}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"analyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"volumeAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"onStreamInactive",{enumerable:!0,configurable:!0,writable:!0,value:this.streamInactive.bind(this)}),this.type=e,this.ctx=i,this.setup()}get mediaTrackConstraints(){return this._mediaTrackConstraints}set mediaTrackConstraints(e){this._mediaTrackConstraints=e,this.streamState.state!==exports.MEDIA_STREAM_STATE.NULL&&this.createStream()}get inputDevices(){return this._inputDevices||[]}set inputDevices(e){B(e,this._inputDevices)||(this._inputDevices=e,this.ctx.state===exports.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(exports.MEDIA_EVENT.INPUT_DEVICES_UPDATED,{deviceList:e}))}get outputDevices(){return this._outputDevices||[]}set outputDevices(e){B(e,this._outputDevices)||(this._outputDevices=e,this.ctx.state===exports.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(exports.MEDIA_EVENT.OUTPUT_DEVICES_UPDATED,{deviceList:e}))}get inputDeviceId(){return this._inputDeviceId||""}set inputDeviceId(e){if(this._inputDeviceId&&this._inputDeviceId===e)return;const{inputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.inputDevice=i,this._inputDeviceId=i?i.deviceId:"",this.streamState.state!==exports.MEDIA_STREAM_STATE.NULL&&this.createStream()}get outputDeviceId(){return this._outputDeviceId||""}set outputDeviceId(e){if(this._outputDeviceId&&this._outputDeviceId===e)return;const{outputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.outputDevice=i,this._outputDeviceId=i?i.deviceId:""}get inputDevice(){return this._inputDevice}set inputDevice(e){const t=this._inputDevice&&!F(this._inputDevice,e),i=!this._inputDevice&&!!e;(i||t)&&(this._inputDevice=e,!i&&t&&this.emitter.emit(exports.MEDIA_EVENT.INPUT_DEVICE_CHANGED,{device:e}))}get outputDevice(){return this._outputDevice}set outputDevice(e){const t=this._outputDevice&&!F(this._outputDevice,e),i=!this._outputDevice&&!!e;(i||t)&&(this._outputDevice=e,!i&&t&&this.emitter.emit(exports.MEDIA_EVENT.OUTPUT_DEVICE_CHANGED,{device:e}))}get streamState(){return this._streamState}set streamState(e){const{_streamState:t}=this;t.state===e.state&&t.detail===e.detail||(this._streamState=e,this.emitter.emit(exports.MEDIA_EVENT.STREAM_STATE,this._streamState))}setup(){this.type!==exports.MediaType.kData&&(this.type===exports.MediaType.kAudio?(this.analyser=new R(this.stream),this.volumeAnalyser=new L(this.stream)):this.analyser=new P(this.stream),this.analyser.on(x.AUDIO_STATE_CHANGED,(({state:e})=>{!e.hasStream||e.track&&e.active||(this.streamState={state:exports.MEDIA_STREAM_STATE.FAILED,detail:exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS})})))}cleanup(){this.closeStream(),this.inputDevices=[],this.inputDeviceId="",this.outputDevices=[],this.outputDeviceId=""}streamInactive(){this.stream&&(this.stream.close(),this.stream=null,this.streamState={state:exports.MEDIA_STREAM_STATE.NULL},this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream}))}getMediaStream(t){return e(this,void 0,void 0,(function*(){let e=null;switch(this.type){case exports.MediaType.kAudio:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:r,groupId:s}=e||{deviceId:"",groupId:""};return i.audio=!!e&&(t&&E?{deviceId:{exact:r},groupId:{exact:s}}:{deviceId:r,groupId:s}),i.audio&&!p&&Object.assign(i.audio,k),i})(this.inputDevice,t),e.audio||(e=null);break;case exports.MediaType.kVideo:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:r,groupId:s}=e||{deviceId:"",groupId:""};return i.video=t||!!e&&(E?{deviceId:{exact:r},groupId:{exact:s}}:{deviceId:r,groupId:s}),i.video&&Object.assign(i.video,H),i})(this.inputDevice,this.mediaTrackConstraints),e.video||(e=null);break;case exports.MediaType.kData:e={video:j}}let i=this.streamState;if(!e)return i={state:exports.MEDIA_STREAM_STATE.FAILED,detail:exports.MEDIA_STREAM_DETAIL.NO_DEVICE},{stream:null,streamState:i};let r,s=null;try{s=yield(this.type===exports.MediaType.kData?G:U)(e)}catch(n){r=n}if(s)i={state:exports.MEDIA_STREAM_STATE.CAPTURING};else{r=r||new Error("Stream is null");const e=this.type===exports.MediaType.kAudio?X:this.type===exports.MediaType.kVideo?J:K;i={state:exports.MEDIA_STREAM_STATE.FAILED,detail:e.get(r.message)||exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS}}return{stream:s,streamState:i}}))}closeStream(){this.stream&&(this.type===exports.MediaType.kData&&q(this.stream,this.onStreamInactive),this.stream.close()),this.stream=null,this.switchAnalyserEnable(this.stream,{enable:!1}),this.streamState={state:exports.MEDIA_STREAM_STATE.NULL},this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream})}createStream(){return this.ctx.throwIfNotState(exports.MEDIA_MANAGER_STATE.INITED),this.queue=this.queue.then((()=>e(this,void 0,void 0,(function*(){this.switchAnalyserEnable(this.stream,{enable:!1});const e=!(this.streamState.state!==exports.MEDIA_STREAM_STATE.CAPTURING||!this.stream),{stream:t,streamState:i}=yield this.getMediaStream(e);if(this.streamState.state===exports.MEDIA_STREAM_STATE.CAPTURING&&this.stream&&(this.type===exports.MediaType.kData&&q(this.stream,this.onStreamInactive),this.stream.close(),this.stream=null),this.ctx.state!==exports.MEDIA_MANAGER_STATE.INITED)return t&&t.close(),this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream}),Promise.resolve(this.stream);this.type===exports.MediaType.kData&&((e,t)=>{e&&e.addEventListener("inactive",t),E&&e&&(e.getVideoTracks()||[]).forEach((e=>{e.addEventListener("ended",t)}))})(t,this.onStreamInactive),this.stream=t,this.streamState=i,this.emitter.emit(exports.MEDIA_EVENT.STREAM,{stream:this.stream});let r=!0;return t||i.state!==exports.MEDIA_STREAM_STATE.FAILED||(r=!1),this.switchAnalyserEnable(t,{enable:r}),Promise.resolve(this.stream)}))))}getMicVolume(){return this.volumeAnalyser?this.volumeAnalyser.volume:0}switchAnalyserEnable(e,{enable:t=!1}){this.type!==exports.MediaType.kData&&(this.analyser?(this.analyser.stream=e,this.analyser.enable=t,this.type===exports.MediaType.kAudio&&this.volumeAnalyser&&(this.volumeAnalyser.stream=e,this.volumeAnalyser.enable=t)):console.error(""))}}const X=new Map([["No Device",exports.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["The request is not allowed by the user agent or the platform in the current context.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["Stream is null",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),J=new Map([["No Device",exports.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",exports.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["The request is not allowed by the user agent or the platform in the current context.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",exports.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["Stream is null",exports.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),K=new Map([["Permission denied by system",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The object can not be found here.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.",exports.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM]]);exports.Channel=y,exports.MediaInterface=z,exports.createChannel=e=>new y(e),exports.createMediaManager=()=>{const i={state:exports.MEDIA_MANAGER_STATE.NULL,emitter:t(),deviceList:[],throwIfState:(e,t)=>{if(i.state===e)throw new Error(t||"Invalid State")},throwIfNotState:(e,t)=>{if(i.state!==e)throw new Error(t||"Invalid State")}},r=new z(exports.MediaType.kAudio,i),s=new z(exports.MediaType.kVideo,i),n=new z(exports.MediaType.kData,i),a=t=>e(void 0,void 0,void 0,(function*(){if(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)return void console.error("mediaDevices or enumerateDevices is miss");const e=yield navigator.mediaDevices.enumerateDevices().catch((e=>{console.error("enumerate devices error: ",e)}));i.deviceList=e&&e.map((e=>e.toJSON()))||[],r.inputDevices=i.deviceList.filter((e=>"audioinput"===e.kind)),r.inputDeviceId=$({deviceList:r.inputDevices,device:r.inputDevice,deviceId:t&&t.audioInputDeviceId||""}),r.outputDevices=i.deviceList.filter((e=>"audiooutput"===e.kind)),r.outputDeviceId=$({deviceList:r.outputDevices,device:r.outputDevice,deviceId:t&&t.audioOutputDeviceId||""}),s.inputDevices=i.deviceList.filter((e=>"videoinput"===e.kind)),s.inputDeviceId=$({deviceList:s.inputDevices,device:s.inputDevice,deviceId:t&&t.videoInputDeviceId||""})}));return{ctx:i,get state(){return i.state},on:i.emitter.on,off:i.emitter.off,init:t=>e(void 0,void 0,void 0,(function*(){if(window.ActiveXObject||"ActiveXObject"in window)throw new Error("Not compatible with this browser yet, please use other browsers instead.");i.throwIfState(exports.MEDIA_MANAGER_STATE.INITED),navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=function(){a()}),yield a(t),i.state=exports.MEDIA_MANAGER_STATE.INITED,i.emitter.emit(exports.MEDIA_MANAGER_EVENT.STATE,{state:i.state})})),destroy:()=>{try{r.cleanup(),s.cleanup(),n.cleanup()}catch(e){}i.state=exports.MEDIA_MANAGER_STATE.NULL,i.emitter.emit(exports.MEDIA_MANAGER_EVENT.STATE,{state:i.state})},audioMedia:r,videoMedia:s,dataMedia:n}}; |
@@ -155,2 +155,3 @@ /// <reference types="node" /> | ||
state: CHANNEL_STATE; | ||
clientID: string; | ||
SFUTransportType: any; | ||
@@ -212,3 +213,3 @@ mediaEndpoint: any; | ||
_audioPlayer: HTMLMediaElement | null; | ||
constructor({ baseURL, videoSDKLibDir, debug }: ChannelConfig); | ||
constructor({ baseURL, videoSDKLibDir, clientID, debug }: ChannelConfig); | ||
get audioPlayer(): HTMLMediaElement | null; | ||
@@ -542,2 +543,6 @@ set audioPlayer(value: HTMLMediaElement | null); | ||
/** | ||
* 设备ID | ||
*/ | ||
clientID: string; | ||
/** | ||
* debug 日志 | ||
@@ -760,2 +765,3 @@ */ | ||
topMC: string; | ||
meetingParam: string; | ||
} | ||
@@ -762,0 +768,0 @@ |
@@ -1,1 +0,1 @@ | ||
function e(e,t,i,n){return new(i||(i=Promise))((function(r,s){function a(e){try{l(n.next(e))}catch(t){s(t)}}function o(e){try{l(n.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}l((n=n.apply(e,t||[])).next())}))}function t(e){return{all:e=e||new Map,on:function(t,i){var n=e.get(t);n?n.push(i):e.set(t,[i])},off:function(t,i){var n=e.get(t);n&&(i?n.splice(n.indexOf(i)>>>0,1):e.set(t,[]))},emit:function(t,i){var n=e.get(t);n&&n.slice().map((function(e){e(i)})),(n=e.get("*"))&&n.slice().map((function(e){e(t,i)}))}}}var i,n,r,s,a,o,l;!function(e){e.STATE="streamState",e.CHANNEL_REFRESH="channelRefresh",e.CHANNEL_BUSY="channelBusy",e.AUDIO_CHANNEL_OPENED="audioChannelOpened",e.VIDEO_CHANNEL_OPENED="videoChannelOpened",e.DATA_CHANNEL_OPENED="dataChannelOpened",e.MESSAGE_CHANNEL_OPENED="messageChannelOpened",e.VOICE_ACTIVE_SSRC="voiceActiveSsrc",e.AUDIO_PLAYER_CHANGE="audioPlayerChange"}(i||(i={})),function(e){e[e.STARTED=1]="STARTED",e[e.STOPPED=0]="STOPPED"}(n||(n={})),function(e){e.STATE="state"}(r||(r={})),function(e){e[e.NULL=0]="NULL",e[e.INITED=1]="INITED"}(s||(s={})),function(e){e.STREAM_STATE="streamState",e.STREAM="stream",e.INPUT_DEVICES_UPDATED="inputDevicesUpdated",e.OUTPUT_DEVICES_UPDATED="outputDevicesUpdated",e.INPUT_DEVICE_CHANGED="inputDeviceChanged",e.OUTPUT_DEVICE_CHANGED="outputDeviceChanged"}(a||(a={})),function(e){e[e.NULL=0]="NULL",e[e.CAPTURING=1]="CAPTURING",e[e.FAILED=2]="FAILED"}(o||(o={})),function(e){e[e.NO_DEVICE=0]="NO_DEVICE",e[e.PERMISSION_DENIED=1]="PERMISSION_DENIED",e[e.COULD_NOT_START_VIDEO_SOURCE=2]="COULD_NOT_START_VIDEO_SOURCE",e[e.PERMISSION_DENIED_BY_SYSTEM=3]="PERMISSION_DENIED_BY_SYSTEM",e[e.OTHER_EXCEPTIONS=4]="OTHER_EXCEPTIONS"}(l||(l={}));const c=(e,t)=>{const i=t.match(e);return i&&i.length>0&&i[1]||""},d=/version\/(\d+(\.?_?\d+)+)/i,h=[{test:[/\sedg\//i],describe(e){const t={name:"Microsoft Edge"},i=c(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/edg([ea]|ios)/i],describe(e){const t={name:"Microsoft Edge"},i=((e,t)=>{const i=t.match(e);return i&&i.length>1&&i[2]||""})(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/firefox|iceweasel|fxios/i],describe(e){const t={name:"Firefox"},i=c(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/chromium/i],describe(e){const t={name:"Chromium"},i=c(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||c(d,e);return i&&(t.version=i),t}},{test:[/chrome|crios|crmo/i],describe(e){const t={name:"Chrome"},i=c(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/safari|applewebkit/i],describe(e){const t={name:"Safari"},i=c(d,e);return i&&(t.version=i),t}}];let u;const m=h.find((e=>{if(e.test instanceof Array)return e.test.some((e=>e.test(navigator.userAgent)));throw new Error("Browser's test function is not valid")}));m&&(u=m.describe(navigator.userAgent));const v=u&&"Safari"===u.name,f=u&&"Firefox"===u.name,p=u&&"Chrome"===u.name,b=u&&"Microsoft Edge"===u.name,S=e=>/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e),g=(e,t)=>t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e,E=({src:e,id:t})=>new Promise(((i,n)=>{let r=document.querySelector(`#${t}`);if(r)return r.src=e,void i(r);r=document.createElement("script"),r.src=e,r.id=t,r.onload=()=>{i(r)},r.onerror=e=>{n(e)},document.head.appendChild(r)}));var D=class{constructor({namespace:e,debug:t}){Object.defineProperty(this,"initialized",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isDebugging",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useColors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"backend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"namespace",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.initialized=!0,this.isDebugging=t,this.backend=y(),this.namespace=e,this.useColors=this.backend.useColors,this.color=this.selectColor(e)}logger(e){e[0]=this.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let t=0;return e[0]=e[0].replace(/%([a-zA-Z%])/g,((i,n)=>{if("%%"===i)return i;t++;const r=this.backend.formatters[n];if("function"==typeof r){i=r(e[t]),e.splice(t,1),t--}return i})),this.backend.formatArgs(e,this)}coerce(e){return e instanceof Error?e.stack||e.message:e}selectColor(e){const t=Array.from(e).reduce(((e,t)=>(e=(e<<5)-e+t.charCodeAt(0),e|=0)),0);return this.backend.colors[Math.abs(t)%this.backend.colors.length]}switchDebug(e){this.isDebugging=e}log(...e){e=this.logger(e),this.backend.log.apply(this,e)}debug(...e){this.isDebugging&&(e=this.logger(e),this.backend.debug.apply(this,e))}warn(...e){this.backend.warn.apply(this,e)}error(...e){this.backend.error.apply(this,e)}};const y=()=>({colors:["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],formatters:{j:e=>{try{return JSON.stringify(e)}catch(t){return`[UnexpectedJSONParseError]: ${t.message}`}}},log:(...e)=>"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,e),debug:(...e)=>"object"==typeof console&&console.debug&&Function.prototype.apply.call(console.debug,console,e),warn:(...e)=>"object"==typeof console&&console.warn&&Function.prototype.apply.call(console.warn,console,e),error:(...e)=>"object"==typeof console&&console.error&&Function.prototype.apply.call(console.error,console,e),formatArgs:(e,t)=>{const{useColors:i,namespace:n,color:r}=t;if(e[0]=`${(i?"%c":"")+n+(i?" %c":" ")+e[0]+(i?"%c ":" ")}+${function(e){const t=Math.abs(e);if(t>=T)return`${Math.round(e/T)}d`;if(t>=w)return`${Math.round(e/w)}h`;if(t>=I)return`${Math.round(e/I)}m`;if(t>=C)return`${Math.round(e/C)}s`;return`${e}ms`}(0)}`,!i)return[];const s=`color: ${r}`;e.splice(1,0,s,"color: inherit");let a=0,o=0;return e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(a++,"%c"===e&&(o=a))})),e.splice(o,0,s),e},useColors:O()}),C=1e3,I=60*C,w=60*I,T=24*w;const O=()=>!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.webkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)),A=new D({namespace:"STREAM:Store",debug:!1});class N{constructor({baseURL:e,videoSDKLibDir:i,debug:r}){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:n.STOPPED}),Object.defineProperty(this,"SFUTransportType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEndpoint",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEngine",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audioChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"videoChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"messageChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"remoteControlStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"subtitleStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"videoSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dataSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioReceiver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"voiceActiveSsrc",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"audioChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"videoChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"dataChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"messageChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"baseURL",{enumerable:!0,configurable:!0,writable:!0,value:"https://meetings.ylyun.com"}),Object.defineProperty(this,"videoSDKLibDir",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"_audioPlayer",{enumerable:!0,configurable:!0,writable:!0,value:null}),e=e||"https://meetings.ylyun.com",i=i||"",A.switchDebug(r=r||!1),this.setBaseUrl(e),this.setVideoSDKLibDir(i),this.setup()}get audioPlayer(){return this._audioPlayer}set audioPlayer(e){this._audioPlayer=e,this.emitter.emit(i.AUDIO_PLAYER_CHANGE,e)}setup(){return e(this,void 0,void 0,(function*(){}))}cleanup(){return e(this,void 0,void 0,(function*(){const{videoChannel:e,audioChannel:t,messageChannel:i,dataChannel:n,mediaEndpoint:r,remoteControlStream:s}=this;try{t&&(yield t.close()),e&&(yield e.close()),n&&(yield n.close()),s&&i&&(yield i.closeStream(s)),i&&(yield i.close()),r&&(r.stop(),r.destroy())}catch(a){A.error(a)}this.mediaEndpoint=null,this.mediaEngine=null,this.videoChannel=null,this.audioChannel=null,this.dataChannel=null,this.messageChannel=null,this.videoSender=null,this.audioSender=null,this.dataSender=null,this.audioReceiver=null,this.audioPlayer=null,this.audioChannelOpened=!1,this.videoChannelOpened=!1,this.dataChannelOpened=!1,this.messageChannelOpened=!1}))}getMss(t){return e(this,void 0,void 0,(function*(){const{mediaContent:e,userID:i,role:n,meetingID:r}=t,s=yield P.getMss(this.baseURL,{accessMCs:e.accessMCs,topMC:e.topMC,confId:r,ccid:i,userType:"audience"===n?"Broadcast":"Interactive"}).catch((e=>{A.error(e)}));if(A.debug(`response ${JSON.stringify(s)}`),!s||!s.data||!s.data.MssInfo)return A.error("getMss response error ",s),[];const a=s.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),o=s.data.MssInfo.map((e=>e.IntranetUri)).flat();return a.concat(o).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const{baseURL:t}=this,i=S(t)?(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[2]})(t):t,n=`${S(t)&&"http:"===(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[1]})(t)?"ws":"wss"}://${i}`,r=window.btoa(e.replace(/\w+:\/\//,""));return g(n,`/webapp/socket/${r}`)}))}))}mssRequest(t,i){return e(this,void 0,void 0,(function*(){const{mediaContent:n,userID:r,role:s,meetingID:a}=i,o=(i,o)=>new Promise(((l,c)=>{const d=new URL(i),h=d.searchParams.get("webapp");h&&(i=`https://${h}?mc=${d.host}`),P.mssRequest(i,{accessMCs:n.accessMCs,topMC:n.topMC,confId:a,ccid:r,userType:"audience"===s?"Broadcast":"Interactive"}).then((i=>e(this,void 0,void 0,(function*(){return console.log("result: ",i),i&&i.data?i.state&&300001===i.state?(console.log("getMss() wait 300ms"),t.splice(o,1),yield(e=300,new Promise((t=>setTimeout((()=>t(e)),e)))),c(i)):l(i):(t.splice(o,1),c(i));var e})))).catch((e=>{console.error(e),c()}))})),l=()=>e(this,void 0,void 0,(function*(){let e=null;try{e=yield Promise.race(t.map(o))}catch(i){console.error("request/mss ",i)}return e}));let c=[];const d=t.length;for(let e=0;e<d;e++){const e=yield l();if(e&&e.state&&3e5===e.state){const t=e.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),i=e.data.MssInfo.map((e=>e.IntranetUri)).flat();c=t.concat(i).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const t=new URL(e),i=t.searchParams.get("webapp");return i&&(e=`wss://${i}?mss=${t.host}`),e}));break}}return c}))}start(t){return e(this,void 0,void 0,(function*(){this.throwIfState(n.STARTED),yield _(this.videoSDKLibDir,!!t.develop).catch((e=>{A.error(e)}));const{LIBRTC:r}=window,{NativeMediaEndpoint:s,NativeMediaEngine:a,SFUTransportType:o}=r;this.SFUTransportType=o,t.config&&(r.config=t.config);const{mediaContent:l,user:c,meetingID:d,ctrlID:h,meetingNum:u,account:m}=t,v=new a;yield v.init();const f=new s;f.onrefresh=()=>e(this,void 0,void 0,(function*(){this.emitter.emit(i.CHANNEL_REFRESH);const e=c.userID,t=c.role;let n=[];for(let i=0;i<l.accessMCs.length;i++){let s=[];try{s=JSON.parse(l.accessMCs[i])}catch(r){console.error(r)}const a=s.some((e=>(!e.extranet||!e.extranet.length)&&e.intranet&&e.intranet.length)),o=s.map((e=>{const t=e.extranet||[];return t.push(...e.intranet),t})).flat(),c={mediaContent:{accessMCs:[l.accessMCs[i]],topMC:l.topMC,crypto:l.crypto},meetingID:d,userID:e,role:t};if(-1!==o.findIndex((e=>new URL(e).searchParams.get("webapp")))){if(console.log("urls",o),n=yield this.mssRequest(o,c),n.length)break}else{if(a)break;if(n=yield this.getMss(c),n.length)break}}return n})),yield f.init(),yield f.start({meeting_number:u||"",user_account:m||"",confid:d,ccid:c.userID,role:1,encrypt:l.crypto,token:h}),this.mediaEndpoint=f,this.mediaEngine=v,this.state=n.STARTED,this.emitter.emit(i.STATE,{state:this.state})}))}stop(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),yield this.cleanup(),this.state=n.STOPPED,this.emitter.emit(i.STATE,{state:this.state})}))}destroy(){return e(this,void 0,void 0,(function*(){yield this.stop()}))}getChannelState(){return{audioChannelOpened:this.audioChannelOpened,videoChannelOpened:this.videoChannelOpened,dataChannelOpened:this.dataChannelOpened,messageChannelOpened:this.messageChannelOpened}}setBaseUrl(e){this.throwIfState(n.STARTED),e&&this.baseURL!==e&&("/"===e&&(e=window.location.origin),this.baseURL=e)}setVideoSDKLibDir(e){this.throwIfState(n.STARTED),e&&this.videoSDKLibDir!==e&&(this.videoSDKLibDir=e)}createAudioChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.audio.createChannel(t.createTransport(r.kAudio));this.audioChannel=s,s.onopen=()=>{A.debug("audioChannel onopen()"),this.audioChannelOpened=!0,this.emitter.emit(i.AUDIO_CHANNEL_OPENED)},yield s.open()}))}closeAudioChannel(){return e(this,void 0,void 0,(function*(){const{audioChannel:e}=this;e?(yield e.close(),this.audioChannel=null,this.audioSender=null,this.audioReceiver=null,this.audioChannelOpened=!1):A.error("audioChannel is miss")}))}createVideoChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.video.createChannel(t.createTransport(r.kVideo));this.videoChannel=s,s.onopen=()=>{A.debug("videoChannel onopen()"),this.videoChannelOpened=!0,this.emitter.emit(i.VIDEO_CHANNEL_OPENED)},yield s.open()}))}createDataChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.video.createChannel(t.createTransport(r.kData));this.dataChannel=s,s.onopen=()=>{A.debug("dataChannel onopen()")},yield s.open(),this.dataChannelOpened=!0,this.emitter.emit(i.DATA_CHANNEL_OPENED)}))}createMessageChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.video.createDataChannel(t.createTransport(r.kMessage));this.messageChannel=s,s.onopen=()=>{A.debug("messageChannel onopen()")};try{yield s.open()}catch(a){console.error(a)}this.messageChannelOpened=!0,this.emitter.emit(i.MESSAGE_CHANNEL_OPENED)}))}closeMessageChannel(){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?yield e.close():A.error("messageChannel is miss")}))}closeMessageStream(t){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?t&&(yield e.closeStream(t)):A.error("messageChannel is miss")}))}setupRemoteControl({element:t,remote:i}){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("message"),t.setAttribute("tabIndex","-1"),t.style.outline="0";const{LIBRTC:e}=window,{messageChannel:r}=this,s=yield r.createStream(e.DataType.kRemoteControl);return this.remoteControlStream=s,e.setupRemoteControl(s,t,i)}))}createSubtitleStream(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this,t=yield e.createSubtitleStream();return t.subscribe([-1]),this.subtitleStream=t,t}))}closeSubtitleStream(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this;yield e.closeSubtitleStream(t),this.subtitleStream=null}))}createAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;if(!e)return A.error("audioChannel is miss"),null;const t=this.audioSender?this.audioSender:e.createSender();return this.audioSender=t,t}))}removeAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioSender:e}=this;if(e)try{e.stop(),this.audioChannel&&this.audioChannel.removeSender(e.ssrc)}catch(t){A.error("audioChannel removeSender() error: ",t)}else A.error("audioSender is miss")}))}createVideoSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e)return A.error("videoChannel is miss"),null;const t=this.videoSender?this.videoSender:e.createSender();return this.videoSender=t,t.onbusy=()=>{A.debug("onbusy"),this.emitter.emit(i.CHANNEL_BUSY);const{audioChannel:e}=this;e&&e.ans(!1)},t}))}removeVideoSender(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoSender:e}=this;if(e)try{e.stop(),this.videoChannel&&this.videoChannel.removeSender(e.ssrc)}catch(t){A.error("videoChannel removeSender() error: ",t)}else A.error("videoSender is miss")}createDataSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e)return A.error("dataChannel is miss"),null;const t=this.dataSender?this.dataSender:e.createSender();return this.dataSender=t,t}))}removeDataSender(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataSender:e}=this;e?(e.stop(),this.dataChannel&&this.dataChannel.removeSender(e.ssrc),this.dataSender=null):A.error("dataSender is miss")}createAudioReceiver(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;if(!t)return A.error("audioChannel is miss"),null;const i=t.createReceiver();return this.audioReceiver=i,e?(i.setSink(e),this.audioPlayer=e,t.audioElement&&(t.audioElement.srcObject=null),i):(A.error("audioPlayer is miss"),null)}createVideoReceiver(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{ccid:t}=e;if(A.debug("createVideoReceiver ccid: ",t),!t)return A.error("params is missing or params error"),null;const{videoChannel:i}=this;if(!i)return A.error("videoChannel is miss"),null;return i.createReceiver(t)}createDataReceiver(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{ccid:t}=e;if(A.debug("createDataReceiver ccid: ",t),!t)return A.error("params is missing or params error"),null;const{dataChannel:i}=this;if(!i)return A.error("dataChannel is miss"),null;return i.createReceiver(t)}removeVideoReceiver(e){return this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video"),e?(e.stop(),this.videoChannel&&this.videoChannel.removeReceiver(e.ssrc),null):e}removeDataReceiver(e){return this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data"),e?(e.stop(),this.dataChannel&&this.dataChannel.removeReceiver(e.ssrc),null):e}loadVideoRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e||!t)return A.error("videoChannel or el is miss"),null;return(p||b)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadVideoRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;e&&t?(p||b)&&(yield e.offscreen.unload(t)):A.error("videoChannel or renderer is miss")}))}loadDataRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e||!t)return A.error("dataChannel or el is miss"),null;return(p||b)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadDataRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;e&&t?(p||b)&&(yield e.offscreen.unload(t)):A.error("dataChannel or renderer is miss")}))}bindAudioChannelEvent(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=e=>{if(this.voiceActiveSsrc.length&&e.length){if(this.voiceActiveSsrc[0]===e[0])return}else if(0===this.voiceActiveSsrc.length&&0===e.length)return;this.voiceActiveSsrc=e,this.emitter.emit(i.VOICE_ACTIVE_SSRC,{ssrc:e})}:A.error("audioChannel is miss")}offAudioChannelEvent(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=null:A.error("audioChannel is miss")}setAudioPlayerVolume(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:t}=this;t?t.volume=e=e>=0&&e<1?e:e>=1&&e<=100?e/100:e:A.error("audioPlayer is miss")}getAudioPlayerVolume(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:e}=this;return e?e.volume:(A.error("audioPlayer is miss"),0)}getAudioChannelStats(){return e(this,void 0,void 0,(function*(){return this.state===n.STARTED&&this.audioChannelOpened&&this.audioChannel?yield this.audioChannel.getStats():{}}))}throwIfState(e,t){if(this.state===e)throw new Error(t||"Invalid State")}throwIfNotState(e,t){if(this.state!==e)throw new Error(t||"Invalid State")}throwIfChannelNotOpened(e,t=""){switch(e){case"audio":if(!this.audioChannelOpened)throw new Error(t||"Channel is not open");break;case"video":if(!this.videoChannelOpened)throw new Error(t||"Channel is not open");break;case"data":if(!this.dataChannelOpened)throw new Error(t||"Channel is not open");break;case"message":if(!this.messageChannelOpened)throw new Error(t||"Channel is not open")}}}const _=(e,t)=>Promise.all([E({src:`${e}/libsfu${t?"":".prod"}.js`,id:"ylink-sdk-stream-libsfu"}),E({src:`${e}/librtc.global${t?"":".prod"}.js`,id:"ylink-sdk-stream-librtc"})]),P={getMss:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(g(t,"/webapp/front/getMss"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify(i)}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()})))),mssRequest:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(g(t,"/api/v1/mss/request"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify({ConfId:i.confId,CCID:i.ccid,Rlp:{UpRlp:56,DownRlp:56},UserType:i.userType,TopMc:i.topMC})}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()}))))},R=e=>new N(e);class k{constructor(e){Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_enable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),this.stream=e}analyse(){}start(){this.stream&&(this.timer&&(clearInterval(this.timer),this.timer=null),this.analyse(),this.timer=setInterval((()=>this.analyse()),this.interval))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}destroy(){this.stop()}}var M;!function(e){e.AUDIO_STATE_CHANGED="audioStateChanged",e.VIDEO_STATE_CHANGED="videoStateChanged"}(M||(M={}));var L=class extends k{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(M.AUDIO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getAudioTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var j=class extends k{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(M.VIDEO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getVideoTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var U=class extends k{constructor(e){super(e),Object.defineProperty(this,"volume",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"contextAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"streamSource",{enumerable:!0,configurable:!0,writable:!0,value:null})}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.context&&this.contextAnalyser&&this.streamSource){const e=this.contextAnalyser.frequencyBinCount,t=new Uint8Array(e);this.contextAnalyser.getByteFrequencyData(t);const i=t.reduce(((e,t)=>e+t),0);this.volume=i/e}else this.volume=0}start(){this.createContextAnalyser(),this.createStreamSource(),this.streamSource&&super.start()}stop(){this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.volume=0,super.stop()}createContextAnalyser(){if(this.context&&this.contextAnalyser)return;if(!window.AudioContext&&!window.webkitAudioContext)return;const e=window.AudioContext||window.webkitAudioContext;this.context=new e,this.contextAnalyser=this.context.createAnalyser(),this.contextAnalyser.fftSize=1024,this.contextAnalyser.smoothingTimeConstant=.5}createStreamSource(){if(this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.context&&this.stream&&this.stream.getAudioTracks().length>0){if(this.streamSource=this.context.createMediaStreamSource(this.stream),!this.contextAnalyser)return;this.streamSource.connect(this.contextAnalyser),"suspended"===this.context.state&&this.context.resume()}}destroy(){this.contextAnalyser&&(this.contextAnalyser.disconnect(),this.contextAnalyser=null),this.context&&(this.context=null),super.destroy()}};const x={autoGainControl:!0,echoCancellation:!0,latency:0,noiseSuppression:!0},V={aspectRatio:16/9,frameRate:30,width:640,height:360},H={width:1920,height:1080,frameRate:5},F=e=>(e.close=e.stop=function(){e.getTracks().forEach((e=>e.stop()))},e.pause=function(){this.getTracks().forEach((e=>e.enabled=!1))},e.play=function(){this.getTracks().forEach((e=>e.enabled=!0))},e.muteAudio=function(e=!0){this.getAudioTracks().forEach((t=>t.enabled=!e))},e.muteVideo=function(e=!0){this.getVideoTracks().forEach((t=>t.enabled=!e))},e),$=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getUserMedia(t);return F(e)})),B=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getDisplayMedia(t);return F(e)})),G=(e,t,i=!1)=>{if(!e||!t)return!1;const n=e.deviceId===t.deviceId&&e.label===t.label&&e.kind===t.kind;return i?e.groupId===t.groupId&&n:n},q=({deviceList:e,device:t,deviceId:i})=>(t=(t=i?e.find((e=>e.deviceId===i))||null:t&&e.find((e=>G(e,t)))||null)||(e[0]||null))&&t.deviceId?t.deviceId:"",Y=(e,t)=>{if(!e||!t||e.length!==t.length)return!1;let i=!0;for(let n=0;n<e.length;n++){if(!G(e[n],t[n])){i=!1;break}}return i},z=(e,t)=>{e.removeEventListener("inactive",t);(e.getVideoTracks()||[]).forEach((e=>{e.removeEventListener("ended",t)}))};var X;!function(e){e[e.kAudio=0]="kAudio",e[e.kVideo=1]="kVideo",e[e.kData=2]="kData"}(X||(X={}));class J{constructor(e,i){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_streamState",{enumerable:!0,configurable:!0,writable:!0,value:{state:o.NULL}}),Object.defineProperty(this,"_inputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_outputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_outputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_inputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_outputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_mediaTrackConstraints",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"queue",{enumerable:!0,configurable:!0,writable:!0,value:Promise.resolve(null)}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"analyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"volumeAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"onStreamInactive",{enumerable:!0,configurable:!0,writable:!0,value:this.streamInactive.bind(this)}),this.type=e,this.ctx=i,this.setup()}get mediaTrackConstraints(){return this._mediaTrackConstraints}set mediaTrackConstraints(e){this._mediaTrackConstraints=e,this.streamState.state!==o.NULL&&this.createStream()}get inputDevices(){return this._inputDevices||[]}set inputDevices(e){Y(e,this._inputDevices)||(this._inputDevices=e,this.ctx.state===s.INITED&&this.emitter.emit(a.INPUT_DEVICES_UPDATED,{deviceList:e}))}get outputDevices(){return this._outputDevices||[]}set outputDevices(e){Y(e,this._outputDevices)||(this._outputDevices=e,this.ctx.state===s.INITED&&this.emitter.emit(a.OUTPUT_DEVICES_UPDATED,{deviceList:e}))}get inputDeviceId(){return this._inputDeviceId||""}set inputDeviceId(e){if(this._inputDeviceId&&this._inputDeviceId===e)return;const{inputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.inputDevice=i,this._inputDeviceId=i?i.deviceId:"",this.streamState.state!==o.NULL&&this.createStream()}get outputDeviceId(){return this._outputDeviceId||""}set outputDeviceId(e){if(this._outputDeviceId&&this._outputDeviceId===e)return;const{outputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.outputDevice=i,this._outputDeviceId=i?i.deviceId:""}get inputDevice(){return this._inputDevice}set inputDevice(e){const t=this._inputDevice&&!G(this._inputDevice,e),i=!this._inputDevice&&!!e;(i||t)&&(this._inputDevice=e,!i&&t&&this.emitter.emit(a.INPUT_DEVICE_CHANGED,{device:e}))}get outputDevice(){return this._outputDevice}set outputDevice(e){const t=this._outputDevice&&!G(this._outputDevice,e),i=!this._outputDevice&&!!e;(i||t)&&(this._outputDevice=e,!i&&t&&this.emitter.emit(a.OUTPUT_DEVICE_CHANGED,{device:e}))}get streamState(){return this._streamState}set streamState(e){const{_streamState:t}=this;t.state===e.state&&t.detail===e.detail||(this._streamState=e,this.emitter.emit(a.STREAM_STATE,this._streamState))}setup(){this.type!==X.kData&&(this.type===X.kAudio?(this.analyser=new L(this.stream),this.volumeAnalyser=new U(this.stream)):this.analyser=new j(this.stream),this.analyser.on(M.AUDIO_STATE_CHANGED,(({state:e})=>{!e.hasStream||e.track&&e.active||(this.streamState={state:o.FAILED,detail:l.OTHER_EXCEPTIONS})})))}cleanup(){this.closeStream(),this.inputDevices=[],this.inputDeviceId="",this.outputDevices=[],this.outputDeviceId=""}streamInactive(){this.stream&&(this.stream.close(),this.stream=null,this.streamState={state:o.NULL},this.emitter.emit(a.STREAM,{stream:this.stream}))}getMediaStream(t){return e(this,void 0,void 0,(function*(){let e=null;switch(this.type){case X.kAudio:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:n,groupId:r}=e||{deviceId:"",groupId:""};return i.audio=!!e&&(t&&f?{deviceId:{exact:n},groupId:{exact:r}}:{deviceId:n,groupId:r}),i.audio&&!v&&Object.assign(i.audio,x),i})(this.inputDevice,t),e.audio||(e=null);break;case X.kVideo:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:n,groupId:r}=e||{deviceId:"",groupId:""};return i.video=t||!!e&&(f?{deviceId:{exact:n},groupId:{exact:r}}:{deviceId:n,groupId:r}),i.video&&Object.assign(i.video,V),i})(this.inputDevice,this.mediaTrackConstraints),e.video||(e=null);break;case X.kData:e={video:H}}let i=this.streamState;if(!e)return i={state:o.FAILED,detail:l.NO_DEVICE},{stream:null,streamState:i};let n,r=null;try{r=yield(this.type===X.kData?B:$)(e)}catch(s){n=s}if(r)i={state:o.CAPTURING};else{n=n||new Error("Stream is null");i={state:o.FAILED,detail:(this.type===X.kAudio?K:this.type===X.kVideo?W:Z).get(n.message)||l.OTHER_EXCEPTIONS}}return{stream:r,streamState:i}}))}closeStream(){this.stream&&(this.type===X.kData&&z(this.stream,this.onStreamInactive),this.stream.close()),this.stream=null,this.switchAnalyserEnable(this.stream,{enable:!1}),this.streamState={state:o.NULL},this.emitter.emit(a.STREAM,{stream:this.stream})}createStream(){return this.ctx.throwIfNotState(s.INITED),this.queue=this.queue.then((()=>e(this,void 0,void 0,(function*(){this.switchAnalyserEnable(this.stream,{enable:!1});const e=!(this.streamState.state!==o.CAPTURING||!this.stream),{stream:t,streamState:i}=yield this.getMediaStream(e);if(this.streamState.state===o.CAPTURING&&this.stream&&(this.type===X.kData&&z(this.stream,this.onStreamInactive),this.stream.close(),this.stream=null),this.ctx.state!==s.INITED)return t&&t.close(),this.emitter.emit(a.STREAM,{stream:this.stream}),Promise.resolve(this.stream);this.type===X.kData&&((e,t)=>{e&&e.addEventListener("inactive",t),f&&e&&(e.getVideoTracks()||[]).forEach((e=>{e.addEventListener("ended",t)}))})(t,this.onStreamInactive),this.stream=t,this.streamState=i,this.emitter.emit(a.STREAM,{stream:this.stream});let n=!0;return t||i.state!==o.FAILED||(n=!1),this.switchAnalyserEnable(t,{enable:n}),Promise.resolve(this.stream)}))))}getMicVolume(){return this.volumeAnalyser?this.volumeAnalyser.volume:0}switchAnalyserEnable(e,{enable:t=!1}){this.type!==X.kData&&(this.analyser?(this.analyser.stream=e,this.analyser.enable=t,this.type===X.kAudio&&this.volumeAnalyser&&(this.volumeAnalyser.stream=e,this.volumeAnalyser.enable=t)):console.error(""))}}const K=new Map([["No Device",l.NO_DEVICE],["Permission denied",l.PERMISSION_DENIED],["Permission dismissed",l.PERMISSION_DENIED],["Could not start video source",l.OTHER_EXCEPTIONS],["The request is not allowed by the user agent or the platform in the current context.",l.PERMISSION_DENIED],["Failed to allocate videosource",l.OTHER_EXCEPTIONS],["Stream is null",l.OTHER_EXCEPTIONS]]),W=new Map([["No Device",l.NO_DEVICE],["Permission denied",l.PERMISSION_DENIED],["Permission dismissed",l.PERMISSION_DENIED],["Could not start video source",l.COULD_NOT_START_VIDEO_SOURCE],["The request is not allowed by the user agent or the platform in the current context.",l.PERMISSION_DENIED],["Failed to allocate videosource",l.COULD_NOT_START_VIDEO_SOURCE],["Stream is null",l.OTHER_EXCEPTIONS]]),Z=new Map([["Permission denied by system",l.PERMISSION_DENIED_BY_SYSTEM],["The object can not be found here.",l.PERMISSION_DENIED_BY_SYSTEM],["The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.",l.PERMISSION_DENIED_BY_SYSTEM]]),Q=()=>{const i={state:s.NULL,emitter:t(),deviceList:[],throwIfState:(e,t)=>{if(i.state===e)throw new Error(t||"Invalid State")},throwIfNotState:(e,t)=>{if(i.state!==e)throw new Error(t||"Invalid State")}},n=new J(X.kAudio,i),a=new J(X.kVideo,i),o=new J(X.kData,i),l=t=>e(void 0,void 0,void 0,(function*(){if(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)return void console.error("mediaDevices or enumerateDevices is miss");const e=yield navigator.mediaDevices.enumerateDevices().catch((e=>{console.error("enumerate devices error: ",e)}));i.deviceList=e&&e.map((e=>e.toJSON()))||[],n.inputDevices=i.deviceList.filter((e=>"audioinput"===e.kind)),n.inputDeviceId=q({deviceList:n.inputDevices,device:n.inputDevice,deviceId:t&&t.audioInputDeviceId||""}),n.outputDevices=i.deviceList.filter((e=>"audiooutput"===e.kind)),n.outputDeviceId=q({deviceList:n.outputDevices,device:n.outputDevice,deviceId:t&&t.audioOutputDeviceId||""}),a.inputDevices=i.deviceList.filter((e=>"videoinput"===e.kind)),a.inputDeviceId=q({deviceList:a.inputDevices,device:a.inputDevice,deviceId:t&&t.videoInputDeviceId||""})}));return{ctx:i,get state(){return i.state},on:i.emitter.on,off:i.emitter.off,init:t=>e(void 0,void 0,void 0,(function*(){if(window.ActiveXObject||"ActiveXObject"in window)throw new Error("Not compatible with this browser yet, please use other browsers instead.");i.throwIfState(s.INITED),navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=function(){l()}),yield l(t),i.state=s.INITED,i.emitter.emit(r.STATE,{state:i.state})})),destroy:()=>{try{n.cleanup(),a.cleanup(),o.cleanup()}catch(e){}i.state=s.NULL,i.emitter.emit(r.STATE,{state:i.state})},audioMedia:n,videoMedia:a,dataMedia:o}};export{i as CHANNEL_EVENT,n as CHANNEL_STATE,N as Channel,a as MEDIA_EVENT,r as MEDIA_MANAGER_EVENT,s as MEDIA_MANAGER_STATE,l as MEDIA_STREAM_DETAIL,o as MEDIA_STREAM_STATE,J as MediaInterface,X as MediaType,R as createChannel,Q as createMediaManager}; | ||
function e(e,t,i,n){return new(i||(i=Promise))((function(r,s){function a(e){try{c(n.next(e))}catch(t){s(t)}}function o(e){try{c(n.throw(e))}catch(t){s(t)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))}function t(e){return{all:e=e||new Map,on:function(t,i){var n=e.get(t);n?n.push(i):e.set(t,[i])},off:function(t,i){var n=e.get(t);n&&(i?n.splice(n.indexOf(i)>>>0,1):e.set(t,[]))},emit:function(t,i){var n=e.get(t);n&&n.slice().map((function(e){e(i)})),(n=e.get("*"))&&n.slice().map((function(e){e(t,i)}))}}}var i,n,r,s,a,o,c;!function(e){e.STATE="streamState",e.CHANNEL_REFRESH="channelRefresh",e.CHANNEL_BUSY="channelBusy",e.AUDIO_CHANNEL_OPENED="audioChannelOpened",e.VIDEO_CHANNEL_OPENED="videoChannelOpened",e.DATA_CHANNEL_OPENED="dataChannelOpened",e.MESSAGE_CHANNEL_OPENED="messageChannelOpened",e.VOICE_ACTIVE_SSRC="voiceActiveSsrc",e.AUDIO_PLAYER_CHANGE="audioPlayerChange"}(i||(i={})),function(e){e[e.STARTED=1]="STARTED",e[e.STOPPED=0]="STOPPED"}(n||(n={})),function(e){e.STATE="state"}(r||(r={})),function(e){e[e.NULL=0]="NULL",e[e.INITED=1]="INITED"}(s||(s={})),function(e){e.STREAM_STATE="streamState",e.STREAM="stream",e.INPUT_DEVICES_UPDATED="inputDevicesUpdated",e.OUTPUT_DEVICES_UPDATED="outputDevicesUpdated",e.INPUT_DEVICE_CHANGED="inputDeviceChanged",e.OUTPUT_DEVICE_CHANGED="outputDeviceChanged"}(a||(a={})),function(e){e[e.NULL=0]="NULL",e[e.CAPTURING=1]="CAPTURING",e[e.FAILED=2]="FAILED"}(o||(o={})),function(e){e[e.NO_DEVICE=0]="NO_DEVICE",e[e.PERMISSION_DENIED=1]="PERMISSION_DENIED",e[e.COULD_NOT_START_VIDEO_SOURCE=2]="COULD_NOT_START_VIDEO_SOURCE",e[e.PERMISSION_DENIED_BY_SYSTEM=3]="PERMISSION_DENIED_BY_SYSTEM",e[e.OTHER_EXCEPTIONS=4]="OTHER_EXCEPTIONS"}(c||(c={}));const l=(e,t)=>{const i=t.match(e);return i&&i.length>0&&i[1]||""},d=/version\/(\d+(\.?_?\d+)+)/i,h=[{test:[/\sedg\//i],describe(e){const t={name:"Microsoft Edge"},i=l(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/edg([ea]|ios)/i],describe(e){const t={name:"Microsoft Edge"},i=((e,t)=>{const i=t.match(e);return i&&i.length>1&&i[2]||""})(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/firefox|iceweasel|fxios/i],describe(e){const t={name:"Firefox"},i=l(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/chromium/i],describe(e){const t={name:"Chromium"},i=l(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||l(d,e);return i&&(t.version=i),t}},{test:[/chrome|crios|crmo/i],describe(e){const t={name:"Chrome"},i=l(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/safari|applewebkit/i],describe(e){const t={name:"Safari"},i=l(d,e);return i&&(t.version=i),t}}];let u;const m=h.find((e=>{if(e.test instanceof Array)return e.test.some((e=>e.test(navigator.userAgent)));throw new Error("Browser's test function is not valid")}));m&&(u=m.describe(navigator.userAgent));const v=u&&"Safari"===u.name,p=u&&"Firefox"===u.name,f=u&&"Chrome"===u.name,b=u&&"Microsoft Edge"===u.name,S=e=>/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e),g=(e,t)=>t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e,E=({src:e,id:t})=>new Promise(((i,n)=>{let r=document.querySelector(`#${t}`);if(r)return r.src=e,void i(r);r=document.createElement("script"),r.src=e,r.id=t,r.onload=()=>{i(r)},r.onerror=e=>{n(e)},document.head.appendChild(r)}));var D=class{constructor({namespace:e,debug:t}){Object.defineProperty(this,"initialized",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isDebugging",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useColors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"backend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"namespace",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.initialized=!0,this.isDebugging=t,this.backend=I(),this.namespace=e,this.useColors=this.backend.useColors,this.color=this.selectColor(e)}logger(e){e[0]=this.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let t=0;return e[0]=e[0].replace(/%([a-zA-Z%])/g,((i,n)=>{if("%%"===i)return i;t++;const r=this.backend.formatters[n];if("function"==typeof r){i=r(e[t]),e.splice(t,1),t--}return i})),this.backend.formatArgs(e,this)}coerce(e){return e instanceof Error?e.stack||e.message:e}selectColor(e){const t=Array.from(e).reduce(((e,t)=>(e=(e<<5)-e+t.charCodeAt(0),e|=0)),0);return this.backend.colors[Math.abs(t)%this.backend.colors.length]}switchDebug(e){this.isDebugging=e}log(...e){e=this.logger(e),this.backend.log.apply(this,e)}debug(...e){this.isDebugging&&(e=this.logger(e),this.backend.debug.apply(this,e))}warn(...e){this.backend.warn.apply(this,e)}error(...e){this.backend.error.apply(this,e)}};const I=()=>({colors:["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],formatters:{j:e=>{try{return JSON.stringify(e)}catch(t){return`[UnexpectedJSONParseError]: ${t.message}`}}},log:(...e)=>"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,e),debug:(...e)=>"object"==typeof console&&console.debug&&Function.prototype.apply.call(console.debug,console,e),warn:(...e)=>"object"==typeof console&&console.warn&&Function.prototype.apply.call(console.warn,console,e),error:(...e)=>"object"==typeof console&&console.error&&Function.prototype.apply.call(console.error,console,e),formatArgs:(e,t)=>{const{useColors:i,namespace:n,color:r}=t;if(e[0]=`${(i?"%c":"")+n+(i?" %c":" ")+e[0]+(i?"%c ":" ")}+${function(e){const t=Math.abs(e);if(t>=T)return`${Math.round(e/T)}d`;if(t>=w)return`${Math.round(e/w)}h`;if(t>=C)return`${Math.round(e/C)}m`;if(t>=y)return`${Math.round(e/y)}s`;return`${e}ms`}(0)}`,!i)return[];const s=`color: ${r}`;e.splice(1,0,s,"color: inherit");let a=0,o=0;return e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(a++,"%c"===e&&(o=a))})),e.splice(o,0,s),e},useColors:O()}),y=1e3,C=60*y,w=60*C,T=24*w;const O=()=>!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.webkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)),A=new D({namespace:"STREAM:Store",debug:!1});class N{constructor({baseURL:e,videoSDKLibDir:i,clientID:r,debug:s}){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:n.STOPPED}),Object.defineProperty(this,"clientID",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"SFUTransportType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEndpoint",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEngine",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audioChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"videoChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"messageChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"remoteControlStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"subtitleStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"videoSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dataSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioReceiver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"voiceActiveSsrc",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"audioChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"videoChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"dataChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"messageChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"baseURL",{enumerable:!0,configurable:!0,writable:!0,value:"https://meetings.ylyun.com"}),Object.defineProperty(this,"videoSDKLibDir",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"_audioPlayer",{enumerable:!0,configurable:!0,writable:!0,value:null}),e=e||"https://meetings.ylyun.com",i=i||"",A.switchDebug(s=s||!1),this.clientID=r,this.setBaseUrl(e),this.setVideoSDKLibDir(i),this.setup()}get audioPlayer(){return this._audioPlayer}set audioPlayer(e){this._audioPlayer=e,this.emitter.emit(i.AUDIO_PLAYER_CHANGE,e)}setup(){return e(this,void 0,void 0,(function*(){}))}cleanup(){return e(this,void 0,void 0,(function*(){const{videoChannel:e,audioChannel:t,messageChannel:i,dataChannel:n,mediaEndpoint:r,remoteControlStream:s}=this;try{t&&(yield t.close()),e&&(yield e.close()),n&&(yield n.close()),s&&i&&(yield i.closeStream(s)),i&&(yield i.close()),r&&(r.stop(),r.destroy())}catch(a){A.error(a)}this.mediaEndpoint=null,this.mediaEngine=null,this.videoChannel=null,this.audioChannel=null,this.dataChannel=null,this.messageChannel=null,this.videoSender=null,this.audioSender=null,this.dataSender=null,this.audioReceiver=null,this.audioPlayer=null,this.audioChannelOpened=!1,this.videoChannelOpened=!1,this.dataChannelOpened=!1,this.messageChannelOpened=!1}))}getMss(t){return e(this,void 0,void 0,(function*(){const{mediaContent:e,userID:i,role:n,meetingID:r,appId:s,meetingNumber:a,meetingParam:o,userAccount:c}=t,l=yield P.getMss(this.baseURL,{appId:s,meetingNumber:a,meetingParam:o,userAccount:c,accessMCs:e.accessMCs,topMC:e.topMC,confId:r,ccid:i,userType:"audience"===n?"Broadcast":"Interactive"}).catch((e=>{A.error(e)}));if(A.debug(`response ${JSON.stringify(l)}`),!l||!l.data||!l.data.MssInfo)return A.error("getMss response error ",l),[];const d=l.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),h=l.data.MssInfo.map((e=>e.IntranetUri)).flat();return d.concat(h).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const{baseURL:t}=this,i=S(t)?(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[2]})(t):t,n=`${S(t)&&"http:"===(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[1]})(t)?"ws":"wss"}://${i}`,r=window.btoa(e.replace(/\w+:\/\//,""));return g(n,`/webapp/socket/${r}`)}))}))}mssRequest(t,i){return e(this,void 0,void 0,(function*(){const{mediaContent:n,userID:r,role:s,meetingID:a,appId:o,meetingNumber:c,meetingParam:l,userAccount:d}=i,h=(i,h)=>new Promise(((u,m)=>{const v=new URL(i),p=v.searchParams.get("webapp");p&&(i=`https://${p}?mc=${v.host}`),P.mssRequest(i,{appId:o,meetingNumber:c,meetingParam:l,userAccount:d,accessMCs:n.accessMCs,topMC:n.topMC,confId:a,ccid:r,userType:"audience"===s?"Broadcast":"Interactive"}).then((i=>e(this,void 0,void 0,(function*(){return console.log("result: ",i),i&&i.data?i.state&&300001===i.state?(console.log("getMss() wait 300ms"),t.splice(h,1),yield(e=300,new Promise((t=>setTimeout((()=>t(e)),e)))),m(i)):u(i):(t.splice(h,1),m(i));var e})))).catch((e=>{console.error(e),m()}))})),u=()=>e(this,void 0,void 0,(function*(){let e=null;try{e=yield Promise.race(t.map(h))}catch(i){console.error("request/mss ",i)}return e}));let m=[];const v=t.length;for(let e=0;e<v;e++){const e=yield u();if(e&&e.state&&3e5===e.state){const t=e.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),i=e.data.MssInfo.map((e=>e.IntranetUri)).flat();m=t.concat(i).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const t=new URL(e),i=t.searchParams.get("webapp");return i&&(e=`wss://${i}?mss=${t.host}`),e}));break}}return m}))}start(t){return e(this,void 0,void 0,(function*(){this.throwIfState(n.STARTED),yield _(this.videoSDKLibDir,!!t.develop).catch((e=>{A.error(e)}));const{LIBRTC:r}=window,{NativeMediaEndpoint:s,NativeMediaEngine:a,SFUTransportType:o}=r;this.SFUTransportType=o,t.config&&(r.config=t.config);const{mediaContent:c,user:l,meetingID:d,ctrlID:h,meetingNum:u="",account:m=""}=t,v=new a;yield v.init();const p=new s;p.onrefresh=()=>e(this,void 0,void 0,(function*(){this.emitter.emit(i.CHANNEL_REFRESH);const e=l.userID,t=l.role;let n=[];for(let i=0;i<c.accessMCs.length;i++){let s=[];try{s=JSON.parse(c.accessMCs[i])}catch(r){console.error(r)}const a=s.some((e=>(!e.extranet||!e.extranet.length)&&e.intranet&&e.intranet.length)),o=s.map((e=>{const t=e.extranet||[];return t.push(...e.intranet),t})).flat(),l={appId:this.clientID,mediaContent:{accessMCs:[c.accessMCs[i]],topMC:c.topMC,crypto:c.crypto,meetingParam:c.meetingParam},meetingID:d,userID:e,role:t,meetingParam:c.meetingParam,meetingNumber:u,userAccount:m};if(-1!==o.findIndex((e=>new URL(e).searchParams.get("webapp")))){if(console.log("urls",o),n=yield this.mssRequest(o,l),n.length)break}else{if(a)break;if(n=yield this.getMss(l),n.length)break}}return n})),yield p.init(),yield p.start({meeting_number:u||"",user_account:m||"",meeting_param:c.meetingParam,client_type:"WebApp",confid:d,ccid:l.userID,role:1,encrypt:c.crypto,token:h}),this.mediaEndpoint=p,this.mediaEngine=v,this.state=n.STARTED,this.emitter.emit(i.STATE,{state:this.state})}))}stop(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),yield this.cleanup(),this.state=n.STOPPED,this.emitter.emit(i.STATE,{state:this.state})}))}destroy(){return e(this,void 0,void 0,(function*(){yield this.stop()}))}getChannelState(){return{audioChannelOpened:this.audioChannelOpened,videoChannelOpened:this.videoChannelOpened,dataChannelOpened:this.dataChannelOpened,messageChannelOpened:this.messageChannelOpened}}setBaseUrl(e){this.throwIfState(n.STARTED),e&&this.baseURL!==e&&("/"===e&&(e=window.location.origin),this.baseURL=e)}setVideoSDKLibDir(e){this.throwIfState(n.STARTED),e&&this.videoSDKLibDir!==e&&(this.videoSDKLibDir=e)}createAudioChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.audio.createChannel(t.createTransport(r.kAudio));this.audioChannel=s,s.onopen=()=>{A.debug("audioChannel onopen()"),this.audioChannelOpened=!0,this.emitter.emit(i.AUDIO_CHANNEL_OPENED)},yield s.open()}))}closeAudioChannel(){return e(this,void 0,void 0,(function*(){const{audioChannel:e}=this;e?(yield e.close(),this.audioChannel=null,this.audioSender=null,this.audioReceiver=null,this.audioChannelOpened=!1):A.error("audioChannel is miss")}))}createVideoChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.video.createChannel(t.createTransport(r.kVideo));this.videoChannel=s,s.onopen=()=>{A.debug("videoChannel onopen()"),this.videoChannelOpened=!0,this.emitter.emit(i.VIDEO_CHANNEL_OPENED)},yield s.open()}))}createDataChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.video.createChannel(t.createTransport(r.kData));this.dataChannel=s,s.onopen=()=>{A.debug("dataChannel onopen()")},yield s.open(),this.dataChannelOpened=!0,this.emitter.emit(i.DATA_CHANNEL_OPENED)}))}createMessageChannel(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED);const{mediaEngine:e,mediaEndpoint:t,SFUTransportType:r}=this,s=e.video.createDataChannel(t.createTransport(r.kMessage));this.messageChannel=s,s.onopen=()=>{A.debug("messageChannel onopen()")};try{yield s.open()}catch(a){console.error(a)}this.messageChannelOpened=!0,this.emitter.emit(i.MESSAGE_CHANNEL_OPENED)}))}closeMessageChannel(){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?yield e.close():A.error("messageChannel is miss")}))}closeMessageStream(t){return e(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?t&&(yield e.closeStream(t)):A.error("messageChannel is miss")}))}setupRemoteControl({element:t,remote:i}){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("message"),t.setAttribute("tabIndex","-1"),t.style.outline="0";const{LIBRTC:e}=window,{messageChannel:r}=this,s=yield r.createStream(e.DataType.kRemoteControl);return this.remoteControlStream=s,e.setupRemoteControl(s,t,i)}))}createSubtitleStream(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this,t=yield e.createSubtitleStream();return t.subscribe([-1]),this.subtitleStream=t,t}))}closeSubtitleStream(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:e}=this;yield e.closeSubtitleStream(t),this.subtitleStream=null}))}createAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;if(!e)return A.error("audioChannel is miss"),null;const t=this.audioSender?this.audioSender:e.createSender();return this.audioSender=t,t}))}removeAudioSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioSender:e}=this;if(e)try{e.stop(),this.audioChannel&&this.audioChannel.removeSender(e.ssrc)}catch(t){A.error("audioChannel removeSender() error: ",t)}else A.error("audioSender is miss")}))}createVideoSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e)return A.error("videoChannel is miss"),null;const t=this.videoSender?this.videoSender:e.createSender();return this.videoSender=t,t.onbusy=()=>{A.debug("onbusy"),this.emitter.emit(i.CHANNEL_BUSY);const{audioChannel:e}=this;e&&e.ans(!1)},t}))}removeVideoSender(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoSender:e}=this;if(e)try{e.stop(),this.videoChannel&&this.videoChannel.removeSender(e.ssrc)}catch(t){A.error("videoChannel removeSender() error: ",t)}else A.error("videoSender is miss")}createDataSender(){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e)return A.error("dataChannel is miss"),null;const t=this.dataSender?this.dataSender:e.createSender();return this.dataSender=t,t}))}removeDataSender(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataSender:e}=this;e?(e.stop(),this.dataChannel&&this.dataChannel.removeSender(e.ssrc),this.dataSender=null):A.error("dataSender is miss")}createAudioReceiver(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;if(!t)return A.error("audioChannel is miss"),null;const i=t.createReceiver();return this.audioReceiver=i,e?(i.setSink(e),this.audioPlayer=e,t.audioElement&&(t.audioElement.srcObject=null),i):(A.error("audioPlayer is miss"),null)}createVideoReceiver(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{ccid:t}=e;if(A.debug("createVideoReceiver ccid: ",t),!t)return A.error("params is missing or params error"),null;const{videoChannel:i}=this;if(!i)return A.error("videoChannel is miss"),null;return i.createReceiver(t)}createDataReceiver(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{ccid:t}=e;if(A.debug("createDataReceiver ccid: ",t),!t)return A.error("params is missing or params error"),null;const{dataChannel:i}=this;if(!i)return A.error("dataChannel is miss"),null;return i.createReceiver(t)}removeVideoReceiver(e){return this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video"),e?(e.stop(),this.videoChannel&&this.videoChannel.removeReceiver(e.ssrc),null):e}removeDataReceiver(e){return this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data"),e?(e.stop(),this.dataChannel&&this.dataChannel.removeReceiver(e.ssrc),null):e}loadVideoRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;if(!e||!t)return A.error("videoChannel or el is miss"),null;return(f||b)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadVideoRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:e}=this;e&&t?(f||b)&&(yield e.offscreen.unload(t)):A.error("videoChannel or renderer is miss")}))}loadDataRenderer(t,i=!0){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;if(!e||!t)return A.error("dataChannel or el is miss"),null;return(f||b)&&void 0!==t.transferControlToOffscreen?yield e.offscreen.load(t.transferControlToOffscreen(),i):t}))}unloadDataRenderer(t){return e(this,void 0,void 0,(function*(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:e}=this;e&&t?(f||b)&&(yield e.offscreen.unload(t)):A.error("dataChannel or renderer is miss")}))}bindAudioChannelEvent(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=e=>{if(this.voiceActiveSsrc.length&&e.length){if(this.voiceActiveSsrc[0]===e[0])return}else if(0===this.voiceActiveSsrc.length&&0===e.length)return;this.voiceActiveSsrc=e,this.emitter.emit(i.VOICE_ACTIVE_SSRC,{ssrc:e})}:A.error("audioChannel is miss")}offAudioChannelEvent(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:e}=this;e?e.onfocusing=null:A.error("audioChannel is miss")}setAudioPlayerVolume(e){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:t}=this;t?t.volume=e=e>=0&&e<1?e:e>=1&&e<=100?e/100:e:A.error("audioPlayer is miss")}getAudioPlayerVolume(){this.throwIfNotState(n.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:e}=this;return e?e.volume:(A.error("audioPlayer is miss"),0)}getAudioChannelStats(){return e(this,void 0,void 0,(function*(){return this.state===n.STARTED&&this.audioChannelOpened&&this.audioChannel?yield this.audioChannel.getStats():{}}))}throwIfState(e,t){if(this.state===e)throw new Error(t||"Invalid State")}throwIfNotState(e,t){if(this.state!==e)throw new Error(t||"Invalid State")}throwIfChannelNotOpened(e,t=""){switch(e){case"audio":if(!this.audioChannelOpened)throw new Error(t||"Channel is not open");break;case"video":if(!this.videoChannelOpened)throw new Error(t||"Channel is not open");break;case"data":if(!this.dataChannelOpened)throw new Error(t||"Channel is not open");break;case"message":if(!this.messageChannelOpened)throw new Error(t||"Channel is not open")}}}const _=(e,t)=>Promise.all([E({src:`${e}/libsfu${t?"":".prod"}.js`,id:"ylink-sdk-stream-libsfu"}),E({src:`${e}/librtc.global${t?"":".prod"}.js`,id:"ylink-sdk-stream-librtc"})]),P={getMss:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(g(t,"/webapp/front/getMss"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify(i)}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()})))),mssRequest:(t,i)=>"function"!=typeof fetch?Promise.reject():fetch(g(t,"/api/v1/mss/request"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify({ConfId:i.confId,CCID:i.ccid,Rlp:{UpRlp:56,DownRlp:56},ClientType:"WebApp",TimeStamp:(new Date).getTime(),MeetingParam:i.meetingParam,VideoParam:{Width:1920,Height:1080,Fr:30},MeetingNumber:i.meetingNumber,UserAccount:i.userAccount,UserType:i.userType,TopMc:i.topMC})}).then((t=>e(void 0,void 0,void 0,(function*(){return yield t.json()}))))},R=e=>new N(e);class k{constructor(e){Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_enable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),this.stream=e}analyse(){}start(){this.stream&&(this.timer&&(clearInterval(this.timer),this.timer=null),this.analyse(),this.timer=setInterval((()=>this.analyse()),this.interval))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}destroy(){this.stop()}}var M;!function(e){e.AUDIO_STATE_CHANGED="audioStateChanged",e.VIDEO_STATE_CHANGED="videoStateChanged"}(M||(M={}));var L=class extends k{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(M.AUDIO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getAudioTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var j=class extends k{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(M.VIDEO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getVideoTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var U=class extends k{constructor(e){super(e),Object.defineProperty(this,"volume",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"contextAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"streamSource",{enumerable:!0,configurable:!0,writable:!0,value:null})}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.context&&this.contextAnalyser&&this.streamSource){const e=this.contextAnalyser.frequencyBinCount,t=new Uint8Array(e);this.contextAnalyser.getByteFrequencyData(t);const i=t.reduce(((e,t)=>e+t),0);this.volume=i/e}else this.volume=0}start(){this.createContextAnalyser(),this.createStreamSource(),this.streamSource&&super.start()}stop(){this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.volume=0,super.stop()}createContextAnalyser(){if(this.context&&this.contextAnalyser)return;if(!window.AudioContext&&!window.webkitAudioContext)return;const e=window.AudioContext||window.webkitAudioContext;this.context=new e,this.contextAnalyser=this.context.createAnalyser(),this.contextAnalyser.fftSize=1024,this.contextAnalyser.smoothingTimeConstant=.5}createStreamSource(){if(this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.context&&this.stream&&this.stream.getAudioTracks().length>0){if(this.streamSource=this.context.createMediaStreamSource(this.stream),!this.contextAnalyser)return;this.streamSource.connect(this.contextAnalyser),"suspended"===this.context.state&&this.context.resume()}}destroy(){this.contextAnalyser&&(this.contextAnalyser.disconnect(),this.contextAnalyser=null),this.context&&(this.context=null),super.destroy()}};const x={autoGainControl:!0,echoCancellation:!0,latency:0,noiseSuppression:!0},V={aspectRatio:16/9,frameRate:30,width:640,height:360},H={width:1920,height:1080,frameRate:5},F=e=>(e.close=e.stop=function(){e.getTracks().forEach((e=>e.stop()))},e.pause=function(){this.getTracks().forEach((e=>e.enabled=!1))},e.play=function(){this.getTracks().forEach((e=>e.enabled=!0))},e.muteAudio=function(e=!0){this.getAudioTracks().forEach((t=>t.enabled=!e))},e.muteVideo=function(e=!0){this.getVideoTracks().forEach((t=>t.enabled=!e))},e),$=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getUserMedia(t);return F(e)})),B=t=>e(void 0,void 0,void 0,(function*(){const e=yield navigator.mediaDevices.getDisplayMedia(t);return F(e)})),G=(e,t,i=!1)=>{if(!e||!t)return!1;const n=e.deviceId===t.deviceId&&e.label===t.label&&e.kind===t.kind;return i?e.groupId===t.groupId&&n:n},q=({deviceList:e,device:t,deviceId:i})=>(t=(t=i?e.find((e=>e.deviceId===i))||null:t&&e.find((e=>G(e,t)))||null)||(e[0]||null))&&t.deviceId?t.deviceId:"",Y=(e,t)=>{if(!e||!t||e.length!==t.length)return!1;let i=!0;for(let n=0;n<e.length;n++){if(!G(e[n],t[n])){i=!1;break}}return i},z=(e,t)=>{e.removeEventListener("inactive",t);(e.getVideoTracks()||[]).forEach((e=>{e.removeEventListener("ended",t)}))};var X;!function(e){e[e.kAudio=0]="kAudio",e[e.kVideo=1]="kVideo",e[e.kData=2]="kData"}(X||(X={}));class J{constructor(e,i){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_streamState",{enumerable:!0,configurable:!0,writable:!0,value:{state:o.NULL}}),Object.defineProperty(this,"_inputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_outputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_outputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_inputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_outputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_mediaTrackConstraints",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"queue",{enumerable:!0,configurable:!0,writable:!0,value:Promise.resolve(null)}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:t()}),Object.defineProperty(this,"analyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"volumeAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"onStreamInactive",{enumerable:!0,configurable:!0,writable:!0,value:this.streamInactive.bind(this)}),this.type=e,this.ctx=i,this.setup()}get mediaTrackConstraints(){return this._mediaTrackConstraints}set mediaTrackConstraints(e){this._mediaTrackConstraints=e,this.streamState.state!==o.NULL&&this.createStream()}get inputDevices(){return this._inputDevices||[]}set inputDevices(e){Y(e,this._inputDevices)||(this._inputDevices=e,this.ctx.state===s.INITED&&this.emitter.emit(a.INPUT_DEVICES_UPDATED,{deviceList:e}))}get outputDevices(){return this._outputDevices||[]}set outputDevices(e){Y(e,this._outputDevices)||(this._outputDevices=e,this.ctx.state===s.INITED&&this.emitter.emit(a.OUTPUT_DEVICES_UPDATED,{deviceList:e}))}get inputDeviceId(){return this._inputDeviceId||""}set inputDeviceId(e){if(this._inputDeviceId&&this._inputDeviceId===e)return;const{inputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.inputDevice=i,this._inputDeviceId=i?i.deviceId:"",this.streamState.state!==o.NULL&&this.createStream()}get outputDeviceId(){return this._outputDeviceId||""}set outputDeviceId(e){if(this._outputDeviceId&&this._outputDeviceId===e)return;const{outputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.outputDevice=i,this._outputDeviceId=i?i.deviceId:""}get inputDevice(){return this._inputDevice}set inputDevice(e){const t=this._inputDevice&&!G(this._inputDevice,e),i=!this._inputDevice&&!!e;(i||t)&&(this._inputDevice=e,!i&&t&&this.emitter.emit(a.INPUT_DEVICE_CHANGED,{device:e}))}get outputDevice(){return this._outputDevice}set outputDevice(e){const t=this._outputDevice&&!G(this._outputDevice,e),i=!this._outputDevice&&!!e;(i||t)&&(this._outputDevice=e,!i&&t&&this.emitter.emit(a.OUTPUT_DEVICE_CHANGED,{device:e}))}get streamState(){return this._streamState}set streamState(e){const{_streamState:t}=this;t.state===e.state&&t.detail===e.detail||(this._streamState=e,this.emitter.emit(a.STREAM_STATE,this._streamState))}setup(){this.type!==X.kData&&(this.type===X.kAudio?(this.analyser=new L(this.stream),this.volumeAnalyser=new U(this.stream)):this.analyser=new j(this.stream),this.analyser.on(M.AUDIO_STATE_CHANGED,(({state:e})=>{!e.hasStream||e.track&&e.active||(this.streamState={state:o.FAILED,detail:c.OTHER_EXCEPTIONS})})))}cleanup(){this.closeStream(),this.inputDevices=[],this.inputDeviceId="",this.outputDevices=[],this.outputDeviceId=""}streamInactive(){this.stream&&(this.stream.close(),this.stream=null,this.streamState={state:o.NULL},this.emitter.emit(a.STREAM,{stream:this.stream}))}getMediaStream(t){return e(this,void 0,void 0,(function*(){let e=null;switch(this.type){case X.kAudio:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:n,groupId:r}=e||{deviceId:"",groupId:""};return i.audio=!!e&&(t&&p?{deviceId:{exact:n},groupId:{exact:r}}:{deviceId:n,groupId:r}),i.audio&&!v&&Object.assign(i.audio,x),i})(this.inputDevice,t),e.audio||(e=null);break;case X.kVideo:e=((e,t)=>{const i={audio:!1,video:!1},{deviceId:n,groupId:r}=e||{deviceId:"",groupId:""};return i.video=t||!!e&&(p?{deviceId:{exact:n},groupId:{exact:r}}:{deviceId:n,groupId:r}),i.video&&Object.assign(i.video,V),i})(this.inputDevice,this.mediaTrackConstraints),e.video||(e=null);break;case X.kData:e={video:H}}let i=this.streamState;if(!e)return i={state:o.FAILED,detail:c.NO_DEVICE},{stream:null,streamState:i};let n,r=null;try{r=yield(this.type===X.kData?B:$)(e)}catch(s){n=s}if(r)i={state:o.CAPTURING};else{n=n||new Error("Stream is null");i={state:o.FAILED,detail:(this.type===X.kAudio?K:this.type===X.kVideo?W:Z).get(n.message)||c.OTHER_EXCEPTIONS}}return{stream:r,streamState:i}}))}closeStream(){this.stream&&(this.type===X.kData&&z(this.stream,this.onStreamInactive),this.stream.close()),this.stream=null,this.switchAnalyserEnable(this.stream,{enable:!1}),this.streamState={state:o.NULL},this.emitter.emit(a.STREAM,{stream:this.stream})}createStream(){return this.ctx.throwIfNotState(s.INITED),this.queue=this.queue.then((()=>e(this,void 0,void 0,(function*(){this.switchAnalyserEnable(this.stream,{enable:!1});const e=!(this.streamState.state!==o.CAPTURING||!this.stream),{stream:t,streamState:i}=yield this.getMediaStream(e);if(this.streamState.state===o.CAPTURING&&this.stream&&(this.type===X.kData&&z(this.stream,this.onStreamInactive),this.stream.close(),this.stream=null),this.ctx.state!==s.INITED)return t&&t.close(),this.emitter.emit(a.STREAM,{stream:this.stream}),Promise.resolve(this.stream);this.type===X.kData&&((e,t)=>{e&&e.addEventListener("inactive",t),p&&e&&(e.getVideoTracks()||[]).forEach((e=>{e.addEventListener("ended",t)}))})(t,this.onStreamInactive),this.stream=t,this.streamState=i,this.emitter.emit(a.STREAM,{stream:this.stream});let n=!0;return t||i.state!==o.FAILED||(n=!1),this.switchAnalyserEnable(t,{enable:n}),Promise.resolve(this.stream)}))))}getMicVolume(){return this.volumeAnalyser?this.volumeAnalyser.volume:0}switchAnalyserEnable(e,{enable:t=!1}){this.type!==X.kData&&(this.analyser?(this.analyser.stream=e,this.analyser.enable=t,this.type===X.kAudio&&this.volumeAnalyser&&(this.volumeAnalyser.stream=e,this.volumeAnalyser.enable=t)):console.error(""))}}const K=new Map([["No Device",c.NO_DEVICE],["Permission denied",c.PERMISSION_DENIED],["Permission dismissed",c.PERMISSION_DENIED],["Could not start video source",c.OTHER_EXCEPTIONS],["The request is not allowed by the user agent or the platform in the current context.",c.PERMISSION_DENIED],["Failed to allocate videosource",c.OTHER_EXCEPTIONS],["Stream is null",c.OTHER_EXCEPTIONS]]),W=new Map([["No Device",c.NO_DEVICE],["Permission denied",c.PERMISSION_DENIED],["Permission dismissed",c.PERMISSION_DENIED],["Could not start video source",c.COULD_NOT_START_VIDEO_SOURCE],["The request is not allowed by the user agent or the platform in the current context.",c.PERMISSION_DENIED],["Failed to allocate videosource",c.COULD_NOT_START_VIDEO_SOURCE],["Stream is null",c.OTHER_EXCEPTIONS]]),Z=new Map([["Permission denied by system",c.PERMISSION_DENIED_BY_SYSTEM],["The object can not be found here.",c.PERMISSION_DENIED_BY_SYSTEM],["The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.",c.PERMISSION_DENIED_BY_SYSTEM]]),Q=()=>{const i={state:s.NULL,emitter:t(),deviceList:[],throwIfState:(e,t)=>{if(i.state===e)throw new Error(t||"Invalid State")},throwIfNotState:(e,t)=>{if(i.state!==e)throw new Error(t||"Invalid State")}},n=new J(X.kAudio,i),a=new J(X.kVideo,i),o=new J(X.kData,i),c=t=>e(void 0,void 0,void 0,(function*(){if(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)return void console.error("mediaDevices or enumerateDevices is miss");const e=yield navigator.mediaDevices.enumerateDevices().catch((e=>{console.error("enumerate devices error: ",e)}));i.deviceList=e&&e.map((e=>e.toJSON()))||[],n.inputDevices=i.deviceList.filter((e=>"audioinput"===e.kind)),n.inputDeviceId=q({deviceList:n.inputDevices,device:n.inputDevice,deviceId:t&&t.audioInputDeviceId||""}),n.outputDevices=i.deviceList.filter((e=>"audiooutput"===e.kind)),n.outputDeviceId=q({deviceList:n.outputDevices,device:n.outputDevice,deviceId:t&&t.audioOutputDeviceId||""}),a.inputDevices=i.deviceList.filter((e=>"videoinput"===e.kind)),a.inputDeviceId=q({deviceList:a.inputDevices,device:a.inputDevice,deviceId:t&&t.videoInputDeviceId||""})}));return{ctx:i,get state(){return i.state},on:i.emitter.on,off:i.emitter.off,init:t=>e(void 0,void 0,void 0,(function*(){if(window.ActiveXObject||"ActiveXObject"in window)throw new Error("Not compatible with this browser yet, please use other browsers instead.");i.throwIfState(s.INITED),navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=function(){c()}),yield c(t),i.state=s.INITED,i.emitter.emit(r.STATE,{state:i.state})})),destroy:()=>{try{n.cleanup(),a.cleanup(),o.cleanup()}catch(e){}i.state=s.NULL,i.emitter.emit(r.STATE,{state:i.state})},audioMedia:n,videoMedia:a,dataMedia:o}};export{i as CHANNEL_EVENT,n as CHANNEL_STATE,N as Channel,a as MEDIA_EVENT,r as MEDIA_MANAGER_EVENT,s as MEDIA_MANAGER_STATE,c as MEDIA_STREAM_DETAIL,o as MEDIA_STREAM_STATE,J as MediaInterface,X as MediaType,R as createChannel,Q as createMediaManager}; |
@@ -1,1 +0,1 @@ | ||
var YlinkSDKStream=function(e){"use strict";function t(e,t,i,r){return new(i||(i=Promise))((function(n,s){function a(e){try{l(r.next(e))}catch(t){s(t)}}function o(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}l((r=r.apply(e,t||[])).next())}))}function i(e){return{all:e=e||new Map,on:function(t,i){var r=e.get(t);r?r.push(i):e.set(t,[i])},off:function(t,i){var r=e.get(t);r&&(i?r.splice(r.indexOf(i)>>>0,1):e.set(t,[]))},emit:function(t,i){var r=e.get(t);r&&r.slice().map((function(e){e(i)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,i)}))}}}var r,n,s,a,o,l;e.CHANNEL_EVENT=void 0,(r=e.CHANNEL_EVENT||(e.CHANNEL_EVENT={})).STATE="streamState",r.CHANNEL_REFRESH="channelRefresh",r.CHANNEL_BUSY="channelBusy",r.AUDIO_CHANNEL_OPENED="audioChannelOpened",r.VIDEO_CHANNEL_OPENED="videoChannelOpened",r.DATA_CHANNEL_OPENED="dataChannelOpened",r.MESSAGE_CHANNEL_OPENED="messageChannelOpened",r.VOICE_ACTIVE_SSRC="voiceActiveSsrc",r.AUDIO_PLAYER_CHANGE="audioPlayerChange",e.CHANNEL_STATE=void 0,(n=e.CHANNEL_STATE||(e.CHANNEL_STATE={}))[n.STARTED=1]="STARTED",n[n.STOPPED=0]="STOPPED",e.MEDIA_MANAGER_EVENT=void 0,(e.MEDIA_MANAGER_EVENT||(e.MEDIA_MANAGER_EVENT={})).STATE="state",e.MEDIA_MANAGER_STATE=void 0,(s=e.MEDIA_MANAGER_STATE||(e.MEDIA_MANAGER_STATE={}))[s.NULL=0]="NULL",s[s.INITED=1]="INITED",e.MEDIA_EVENT=void 0,(a=e.MEDIA_EVENT||(e.MEDIA_EVENT={})).STREAM_STATE="streamState",a.STREAM="stream",a.INPUT_DEVICES_UPDATED="inputDevicesUpdated",a.OUTPUT_DEVICES_UPDATED="outputDevicesUpdated",a.INPUT_DEVICE_CHANGED="inputDeviceChanged",a.OUTPUT_DEVICE_CHANGED="outputDeviceChanged",e.MEDIA_STREAM_STATE=void 0,(o=e.MEDIA_STREAM_STATE||(e.MEDIA_STREAM_STATE={}))[o.NULL=0]="NULL",o[o.CAPTURING=1]="CAPTURING",o[o.FAILED=2]="FAILED",e.MEDIA_STREAM_DETAIL=void 0,(l=e.MEDIA_STREAM_DETAIL||(e.MEDIA_STREAM_DETAIL={}))[l.NO_DEVICE=0]="NO_DEVICE",l[l.PERMISSION_DENIED=1]="PERMISSION_DENIED",l[l.COULD_NOT_START_VIDEO_SOURCE=2]="COULD_NOT_START_VIDEO_SOURCE",l[l.PERMISSION_DENIED_BY_SYSTEM=3]="PERMISSION_DENIED_BY_SYSTEM",l[l.OTHER_EXCEPTIONS=4]="OTHER_EXCEPTIONS";const c=(e,t)=>{const i=t.match(e);return i&&i.length>0&&i[1]||""},d=/version\/(\d+(\.?_?\d+)+)/i,h=[{test:[/\sedg\//i],describe(e){const t={name:"Microsoft Edge"},i=c(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/edg([ea]|ios)/i],describe(e){const t={name:"Microsoft Edge"},i=((e,t)=>{const i=t.match(e);return i&&i.length>1&&i[2]||""})(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/firefox|iceweasel|fxios/i],describe(e){const t={name:"Firefox"},i=c(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/chromium/i],describe(e){const t={name:"Chromium"},i=c(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||c(d,e);return i&&(t.version=i),t}},{test:[/chrome|crios|crmo/i],describe(e){const t={name:"Chrome"},i=c(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/safari|applewebkit/i],describe(e){const t={name:"Safari"},i=c(d,e);return i&&(t.version=i),t}}];let u;const E=h.find((e=>{if(e.test instanceof Array)return e.test.some((e=>e.test(navigator.userAgent)));throw new Error("Browser's test function is not valid")}));E&&(u=E.describe(navigator.userAgent));const m=u&&"Safari"===u.name,v=u&&"Firefox"===u.name,p=u&&"Chrome"===u.name,A=u&&"Microsoft Edge"===u.name,T=e=>/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e),f=(e,t)=>t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e,S=({src:e,id:t})=>new Promise(((i,r)=>{let n=document.querySelector(`#${t}`);if(n)return n.src=e,void i(n);n=document.createElement("script"),n.src=e,n.id=t,n.onload=()=>{i(n)},n.onerror=e=>{r(e)},document.head.appendChild(n)}));var b=class{constructor({namespace:e,debug:t}){Object.defineProperty(this,"initialized",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isDebugging",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useColors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"backend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"namespace",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.initialized=!0,this.isDebugging=t,this.backend=D(),this.namespace=e,this.useColors=this.backend.useColors,this.color=this.selectColor(e)}logger(e){e[0]=this.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let t=0;return e[0]=e[0].replace(/%([a-zA-Z%])/g,((i,r)=>{if("%%"===i)return i;t++;const n=this.backend.formatters[r];if("function"==typeof n){i=n(e[t]),e.splice(t,1),t--}return i})),this.backend.formatArgs(e,this)}coerce(e){return e instanceof Error?e.stack||e.message:e}selectColor(e){const t=Array.from(e).reduce(((e,t)=>(e=(e<<5)-e+t.charCodeAt(0),e|=0)),0);return this.backend.colors[Math.abs(t)%this.backend.colors.length]}switchDebug(e){this.isDebugging=e}log(...e){e=this.logger(e),this.backend.log.apply(this,e)}debug(...e){this.isDebugging&&(e=this.logger(e),this.backend.debug.apply(this,e))}warn(...e){this.backend.warn.apply(this,e)}error(...e){this.backend.error.apply(this,e)}};const D=()=>({colors:["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],formatters:{j:e=>{try{return JSON.stringify(e)}catch(t){return`[UnexpectedJSONParseError]: ${t.message}`}}},log:(...e)=>"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,e),debug:(...e)=>"object"==typeof console&&console.debug&&Function.prototype.apply.call(console.debug,console,e),warn:(...e)=>"object"==typeof console&&console.warn&&Function.prototype.apply.call(console.warn,console,e),error:(...e)=>"object"==typeof console&&console.error&&Function.prototype.apply.call(console.error,console,e),formatArgs:(e,t)=>{const{useColors:i,namespace:r,color:n}=t;if(e[0]=`${(i?"%c":"")+r+(i?" %c":" ")+e[0]+(i?"%c ":" ")}+${function(e){const t=Math.abs(e);if(t>=N)return`${Math.round(e/N)}d`;if(t>=C)return`${Math.round(e/C)}h`;if(t>=_)return`${Math.round(e/_)}m`;if(t>=I)return`${Math.round(e/I)}s`;return`${e}ms`}(0)}`,!i)return[];const s=`color: ${n}`;e.splice(1,0,s,"color: inherit");let a=0,o=0;return e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(a++,"%c"===e&&(o=a))})),e.splice(o,0,s),e},useColors:g()}),I=1e3,_=60*I,C=60*_,N=24*C;const g=()=>!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.webkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)),y=new b({namespace:"STREAM:Store",debug:!1});class w{constructor({baseURL:t,videoSDKLibDir:r,debug:n}){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:e.CHANNEL_STATE.STOPPED}),Object.defineProperty(this,"SFUTransportType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEndpoint",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEngine",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audioChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"videoChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"messageChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"remoteControlStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"subtitleStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"videoSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dataSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioReceiver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"voiceActiveSsrc",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"audioChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"videoChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"dataChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"messageChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"baseURL",{enumerable:!0,configurable:!0,writable:!0,value:"https://meetings.ylyun.com"}),Object.defineProperty(this,"videoSDKLibDir",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:i()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"_audioPlayer",{enumerable:!0,configurable:!0,writable:!0,value:null}),t=t||"https://meetings.ylyun.com",r=r||"",y.switchDebug(n=n||!1),this.setBaseUrl(t),this.setVideoSDKLibDir(r),this.setup()}get audioPlayer(){return this._audioPlayer}set audioPlayer(t){this._audioPlayer=t,this.emitter.emit(e.CHANNEL_EVENT.AUDIO_PLAYER_CHANGE,t)}setup(){return t(this,void 0,void 0,(function*(){}))}cleanup(){return t(this,void 0,void 0,(function*(){const{videoChannel:e,audioChannel:t,messageChannel:i,dataChannel:r,mediaEndpoint:n,remoteControlStream:s}=this;try{t&&(yield t.close()),e&&(yield e.close()),r&&(yield r.close()),s&&i&&(yield i.closeStream(s)),i&&(yield i.close()),n&&(n.stop(),n.destroy())}catch(a){y.error(a)}this.mediaEndpoint=null,this.mediaEngine=null,this.videoChannel=null,this.audioChannel=null,this.dataChannel=null,this.messageChannel=null,this.videoSender=null,this.audioSender=null,this.dataSender=null,this.audioReceiver=null,this.audioPlayer=null,this.audioChannelOpened=!1,this.videoChannelOpened=!1,this.dataChannelOpened=!1,this.messageChannelOpened=!1}))}getMss(e){return t(this,void 0,void 0,(function*(){const{mediaContent:t,userID:i,role:r,meetingID:n}=e,s=yield O.getMss(this.baseURL,{accessMCs:t.accessMCs,topMC:t.topMC,confId:n,ccid:i,userType:"audience"===r?"Broadcast":"Interactive"}).catch((e=>{y.error(e)}));if(y.debug(`response ${JSON.stringify(s)}`),!s||!s.data||!s.data.MssInfo)return y.error("getMss response error ",s),[];const a=s.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),o=s.data.MssInfo.map((e=>e.IntranetUri)).flat();return a.concat(o).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const{baseURL:t}=this,i=T(t)?(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[2]})(t):t,r=`${T(t)&&"http:"===(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[1]})(t)?"ws":"wss"}://${i}`,n=window.btoa(e.replace(/\w+:\/\//,""));return f(r,`/webapp/socket/${n}`)}))}))}mssRequest(e,i){return t(this,void 0,void 0,(function*(){const{mediaContent:r,userID:n,role:s,meetingID:a}=i,o=(i,o)=>new Promise(((l,c)=>{const d=new URL(i),h=d.searchParams.get("webapp");h&&(i=`https://${h}?mc=${d.host}`),O.mssRequest(i,{accessMCs:r.accessMCs,topMC:r.topMC,confId:a,ccid:n,userType:"audience"===s?"Broadcast":"Interactive"}).then((i=>t(this,void 0,void 0,(function*(){return console.log("result: ",i),i&&i.data?i.state&&300001===i.state?(console.log("getMss() wait 300ms"),e.splice(o,1),yield(t=300,new Promise((e=>setTimeout((()=>e(t)),t)))),c(i)):l(i):(e.splice(o,1),c(i));var t})))).catch((e=>{console.error(e),c()}))})),l=()=>t(this,void 0,void 0,(function*(){let t=null;try{t=yield Promise.race(e.map(o))}catch(i){console.error("request/mss ",i)}return t}));let c=[];const d=e.length;for(let e=0;e<d;e++){const e=yield l();if(e&&e.state&&3e5===e.state){const t=e.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),i=e.data.MssInfo.map((e=>e.IntranetUri)).flat();c=t.concat(i).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const t=new URL(e),i=t.searchParams.get("webapp");return i&&(e=`wss://${i}?mss=${t.host}`),e}));break}}return c}))}start(i){return t(this,void 0,void 0,(function*(){this.throwIfState(e.CHANNEL_STATE.STARTED),yield M(this.videoSDKLibDir,!!i.develop).catch((e=>{y.error(e)}));const{LIBRTC:r}=window,{NativeMediaEndpoint:n,NativeMediaEngine:s,SFUTransportType:a}=r;this.SFUTransportType=a,i.config&&(r.config=i.config);const{mediaContent:o,user:l,meetingID:c,ctrlID:d,meetingNum:h,account:u}=i,E=new s;yield E.init();const m=new n;m.onrefresh=()=>t(this,void 0,void 0,(function*(){this.emitter.emit(e.CHANNEL_EVENT.CHANNEL_REFRESH);const t=l.userID,i=l.role;let r=[];for(let e=0;e<o.accessMCs.length;e++){let s=[];try{s=JSON.parse(o.accessMCs[e])}catch(n){console.error(n)}const a=s.some((e=>(!e.extranet||!e.extranet.length)&&e.intranet&&e.intranet.length)),l=s.map((e=>{const t=e.extranet||[];return t.push(...e.intranet),t})).flat(),d={mediaContent:{accessMCs:[o.accessMCs[e]],topMC:o.topMC,crypto:o.crypto},meetingID:c,userID:t,role:i};if(-1!==l.findIndex((e=>new URL(e).searchParams.get("webapp")))){if(console.log("urls",l),r=yield this.mssRequest(l,d),r.length)break}else{if(a)break;if(r=yield this.getMss(d),r.length)break}}return r})),yield m.init(),yield m.start({meeting_number:h||"",user_account:u||"",confid:c,ccid:l.userID,role:1,encrypt:o.crypto,token:d}),this.mediaEndpoint=m,this.mediaEngine=E,this.state=e.CHANNEL_STATE.STARTED,this.emitter.emit(e.CHANNEL_EVENT.STATE,{state:this.state})}))}stop(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),yield this.cleanup(),this.state=e.CHANNEL_STATE.STOPPED,this.emitter.emit(e.CHANNEL_EVENT.STATE,{state:this.state})}))}destroy(){return t(this,void 0,void 0,(function*(){yield this.stop()}))}getChannelState(){return{audioChannelOpened:this.audioChannelOpened,videoChannelOpened:this.videoChannelOpened,dataChannelOpened:this.dataChannelOpened,messageChannelOpened:this.messageChannelOpened}}setBaseUrl(t){this.throwIfState(e.CHANNEL_STATE.STARTED),t&&this.baseURL!==t&&("/"===t&&(t=window.location.origin),this.baseURL=t)}setVideoSDKLibDir(t){this.throwIfState(e.CHANNEL_STATE.STARTED),t&&this.videoSDKLibDir!==t&&(this.videoSDKLibDir=t)}createAudioChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:r}=this,n=t.audio.createChannel(i.createTransport(r.kAudio));this.audioChannel=n,n.onopen=()=>{y.debug("audioChannel onopen()"),this.audioChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.AUDIO_CHANNEL_OPENED)},yield n.open()}))}closeAudioChannel(){return t(this,void 0,void 0,(function*(){const{audioChannel:e}=this;e?(yield e.close(),this.audioChannel=null,this.audioSender=null,this.audioReceiver=null,this.audioChannelOpened=!1):y.error("audioChannel is miss")}))}createVideoChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:r}=this,n=t.video.createChannel(i.createTransport(r.kVideo));this.videoChannel=n,n.onopen=()=>{y.debug("videoChannel onopen()"),this.videoChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.VIDEO_CHANNEL_OPENED)},yield n.open()}))}createDataChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:r}=this,n=t.video.createChannel(i.createTransport(r.kData));this.dataChannel=n,n.onopen=()=>{y.debug("dataChannel onopen()")},yield n.open(),this.dataChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.DATA_CHANNEL_OPENED)}))}createMessageChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:r}=this,n=t.video.createDataChannel(i.createTransport(r.kMessage));this.messageChannel=n,n.onopen=()=>{y.debug("messageChannel onopen()")};try{yield n.open()}catch(s){console.error(s)}this.messageChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.MESSAGE_CHANNEL_OPENED)}))}closeMessageChannel(){return t(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?yield e.close():y.error("messageChannel is miss")}))}closeMessageStream(e){return t(this,void 0,void 0,(function*(){const{messageChannel:t}=this;t?e&&(yield t.closeStream(e)):y.error("messageChannel is miss")}))}setupRemoteControl({element:i,remote:r}){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message"),i.setAttribute("tabIndex","-1"),i.style.outline="0";const{LIBRTC:t}=window,{messageChannel:n}=this,s=yield n.createStream(t.DataType.kRemoteControl);return this.remoteControlStream=s,t.setupRemoteControl(s,i,r)}))}createSubtitleStream(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:t}=this,i=yield t.createSubtitleStream();return i.subscribe([-1]),this.subtitleStream=i,i}))}closeSubtitleStream(i){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:t}=this;yield t.closeSubtitleStream(i),this.subtitleStream=null}))}createAudioSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;if(!t)return y.error("audioChannel is miss"),null;const i=this.audioSender?this.audioSender:t.createSender();return this.audioSender=i,i}))}removeAudioSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioSender:t}=this;if(t)try{t.stop(),this.audioChannel&&this.audioChannel.removeSender(t.ssrc)}catch(i){y.error("audioChannel removeSender() error: ",i)}else y.error("audioSender is miss")}))}createVideoSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:t}=this;if(!t)return y.error("videoChannel is miss"),null;const i=this.videoSender?this.videoSender:t.createSender();return this.videoSender=i,i.onbusy=()=>{y.debug("onbusy"),this.emitter.emit(e.CHANNEL_EVENT.CHANNEL_BUSY);const{audioChannel:t}=this;t&&t.ans(!1)},i}))}removeVideoSender(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoSender:t}=this;if(t)try{t.stop(),this.videoChannel&&this.videoChannel.removeSender(t.ssrc)}catch(i){y.error("videoChannel removeSender() error: ",i)}else y.error("videoSender is miss")}createDataSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:t}=this;if(!t)return y.error("dataChannel is miss"),null;const i=this.dataSender?this.dataSender:t.createSender();return this.dataSender=i,i}))}removeDataSender(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataSender:t}=this;t?(t.stop(),this.dataChannel&&this.dataChannel.removeSender(t.ssrc),this.dataSender=null):y.error("dataSender is miss")}createAudioReceiver(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:i}=this;if(!i)return y.error("audioChannel is miss"),null;const r=i.createReceiver();return this.audioReceiver=r,t?(r.setSink(t),this.audioPlayer=t,i.audioElement&&(i.audioElement.srcObject=null),r):(y.error("audioPlayer is miss"),null)}createVideoReceiver(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{ccid:i}=t;if(y.debug("createVideoReceiver ccid: ",i),!i)return y.error("params is missing or params error"),null;const{videoChannel:r}=this;if(!r)return y.error("videoChannel is miss"),null;return r.createReceiver(i)}createDataReceiver(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{ccid:i}=t;if(y.debug("createDataReceiver ccid: ",i),!i)return y.error("params is missing or params error"),null;const{dataChannel:r}=this;if(!r)return y.error("dataChannel is miss"),null;return r.createReceiver(i)}removeVideoReceiver(t){return this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video"),t?(t.stop(),this.videoChannel&&this.videoChannel.removeReceiver(t.ssrc),null):t}removeDataReceiver(t){return this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data"),t?(t.stop(),this.dataChannel&&this.dataChannel.removeReceiver(t.ssrc),null):t}loadVideoRenderer(i,r=!0){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:t}=this;if(!t||!i)return y.error("videoChannel or el is miss"),null;return(p||A)&&void 0!==i.transferControlToOffscreen?yield t.offscreen.load(i.transferControlToOffscreen(),r):i}))}unloadVideoRenderer(i){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:t}=this;t&&i?(p||A)&&(yield t.offscreen.unload(i)):y.error("videoChannel or renderer is miss")}))}loadDataRenderer(i,r=!0){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:t}=this;if(!t||!i)return y.error("dataChannel or el is miss"),null;return(p||A)&&void 0!==i.transferControlToOffscreen?yield t.offscreen.load(i.transferControlToOffscreen(),r):i}))}unloadDataRenderer(i){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:t}=this;t&&i?(p||A)&&(yield t.offscreen.unload(i)):y.error("dataChannel or renderer is miss")}))}bindAudioChannelEvent(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;t?t.onfocusing=t=>{if(this.voiceActiveSsrc.length&&t.length){if(this.voiceActiveSsrc[0]===t[0])return}else if(0===this.voiceActiveSsrc.length&&0===t.length)return;this.voiceActiveSsrc=t,this.emitter.emit(e.CHANNEL_EVENT.VOICE_ACTIVE_SSRC,{ssrc:t})}:y.error("audioChannel is miss")}offAudioChannelEvent(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;t?t.onfocusing=null:y.error("audioChannel is miss")}setAudioPlayerVolume(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:i}=this;i?i.volume=t=t>=0&&t<1?t:t>=1&&t<=100?t/100:t:y.error("audioPlayer is miss")}getAudioPlayerVolume(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:t}=this;return t?t.volume:(y.error("audioPlayer is miss"),0)}getAudioChannelStats(){return t(this,void 0,void 0,(function*(){return this.state===e.CHANNEL_STATE.STARTED&&this.audioChannelOpened&&this.audioChannel?yield this.audioChannel.getStats():{}}))}throwIfState(e,t){if(this.state===e)throw new Error(t||"Invalid State")}throwIfNotState(e,t){if(this.state!==e)throw new Error(t||"Invalid State")}throwIfChannelNotOpened(e,t=""){switch(e){case"audio":if(!this.audioChannelOpened)throw new Error(t||"Channel is not open");break;case"video":if(!this.videoChannelOpened)throw new Error(t||"Channel is not open");break;case"data":if(!this.dataChannelOpened)throw new Error(t||"Channel is not open");break;case"message":if(!this.messageChannelOpened)throw new Error(t||"Channel is not open")}}}const M=(e,t)=>Promise.all([S({src:`${e}/libsfu${t?"":".prod"}.js`,id:"ylink-sdk-stream-libsfu"}),S({src:`${e}/librtc.global${t?"":".prod"}.js`,id:"ylink-sdk-stream-librtc"})]),O={getMss:(e,i)=>"function"!=typeof fetch?Promise.reject():fetch(f(e,"/webapp/front/getMss"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify(i)}).then((e=>t(void 0,void 0,void 0,(function*(){return yield e.json()})))),mssRequest:(e,i)=>"function"!=typeof fetch?Promise.reject():fetch(f(e,"/api/v1/mss/request"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify({ConfId:i.confId,CCID:i.ccid,Rlp:{UpRlp:56,DownRlp:56},UserType:i.userType,TopMc:i.topMC})}).then((e=>t(void 0,void 0,void 0,(function*(){return yield e.json()}))))};class R{constructor(e){Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_enable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:i()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),this.stream=e}analyse(){}start(){this.stream&&(this.timer&&(clearInterval(this.timer),this.timer=null),this.analyse(),this.timer=setInterval((()=>this.analyse()),this.interval))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}destroy(){this.stop()}}var L;!function(e){e.AUDIO_STATE_CHANGED="audioStateChanged",e.VIDEO_STATE_CHANGED="videoStateChanged"}(L||(L={}));var P=class extends R{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(L.AUDIO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getAudioTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var k=class extends R{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(L.VIDEO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getVideoTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var H=class extends R{constructor(e){super(e),Object.defineProperty(this,"volume",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"contextAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"streamSource",{enumerable:!0,configurable:!0,writable:!0,value:null})}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.context&&this.contextAnalyser&&this.streamSource){const e=this.contextAnalyser.frequencyBinCount,t=new Uint8Array(e);this.contextAnalyser.getByteFrequencyData(t);const i=t.reduce(((e,t)=>e+t),0);this.volume=i/e}else this.volume=0}start(){this.createContextAnalyser(),this.createStreamSource(),this.streamSource&&super.start()}stop(){this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.volume=0,super.stop()}createContextAnalyser(){if(this.context&&this.contextAnalyser)return;if(!window.AudioContext&&!window.webkitAudioContext)return;const e=window.AudioContext||window.webkitAudioContext;this.context=new e,this.contextAnalyser=this.context.createAnalyser(),this.contextAnalyser.fftSize=1024,this.contextAnalyser.smoothingTimeConstant=.5}createStreamSource(){if(this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.context&&this.stream&&this.stream.getAudioTracks().length>0){if(this.streamSource=this.context.createMediaStreamSource(this.stream),!this.contextAnalyser)return;this.streamSource.connect(this.contextAnalyser),"suspended"===this.context.state&&this.context.resume()}}destroy(){this.contextAnalyser&&(this.contextAnalyser.disconnect(),this.contextAnalyser=null),this.context&&(this.context=null),super.destroy()}};const j={autoGainControl:!0,echoCancellation:!0,latency:0,noiseSuppression:!0},V={aspectRatio:16/9,frameRate:30,width:640,height:360},U={width:1920,height:1080,frameRate:5},x=e=>(e.close=e.stop=function(){e.getTracks().forEach((e=>e.stop()))},e.pause=function(){this.getTracks().forEach((e=>e.enabled=!1))},e.play=function(){this.getTracks().forEach((e=>e.enabled=!0))},e.muteAudio=function(e=!0){this.getAudioTracks().forEach((t=>t.enabled=!e))},e.muteVideo=function(e=!0){this.getVideoTracks().forEach((t=>t.enabled=!e))},e),G=e=>t(void 0,void 0,void 0,(function*(){const t=yield navigator.mediaDevices.getUserMedia(e);return x(t)})),F=e=>t(void 0,void 0,void 0,(function*(){const t=yield navigator.mediaDevices.getDisplayMedia(e);return x(t)})),$=(e,t,i=!1)=>{if(!e||!t)return!1;const r=e.deviceId===t.deviceId&&e.label===t.label&&e.kind===t.kind;return i?e.groupId===t.groupId&&r:r},B=({deviceList:e,device:t,deviceId:i})=>(t=(t=i?e.find((e=>e.deviceId===i))||null:t&&e.find((e=>$(e,t)))||null)||(e[0]||null))&&t.deviceId?t.deviceId:"",q=(e,t)=>{if(!e||!t||e.length!==t.length)return!1;let i=!0;for(let r=0;r<e.length;r++){if(!$(e[r],t[r])){i=!1;break}}return i},Y=(e,t)=>{e.removeEventListener("inactive",t);(e.getVideoTracks()||[]).forEach((e=>{e.removeEventListener("ended",t)}))};var z;e.MediaType=void 0,(z=e.MediaType||(e.MediaType={}))[z.kAudio=0]="kAudio",z[z.kVideo=1]="kVideo",z[z.kData=2]="kData";class X{constructor(t,r){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_streamState",{enumerable:!0,configurable:!0,writable:!0,value:{state:e.MEDIA_STREAM_STATE.NULL}}),Object.defineProperty(this,"_inputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_outputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_outputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_inputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_outputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_mediaTrackConstraints",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"queue",{enumerable:!0,configurable:!0,writable:!0,value:Promise.resolve(null)}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:i()}),Object.defineProperty(this,"analyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"volumeAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"onStreamInactive",{enumerable:!0,configurable:!0,writable:!0,value:this.streamInactive.bind(this)}),this.type=t,this.ctx=r,this.setup()}get mediaTrackConstraints(){return this._mediaTrackConstraints}set mediaTrackConstraints(t){this._mediaTrackConstraints=t,this.streamState.state!==e.MEDIA_STREAM_STATE.NULL&&this.createStream()}get inputDevices(){return this._inputDevices||[]}set inputDevices(t){q(t,this._inputDevices)||(this._inputDevices=t,this.ctx.state===e.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(e.MEDIA_EVENT.INPUT_DEVICES_UPDATED,{deviceList:t}))}get outputDevices(){return this._outputDevices||[]}set outputDevices(t){q(t,this._outputDevices)||(this._outputDevices=t,this.ctx.state===e.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(e.MEDIA_EVENT.OUTPUT_DEVICES_UPDATED,{deviceList:t}))}get inputDeviceId(){return this._inputDeviceId||""}set inputDeviceId(t){if(this._inputDeviceId&&this._inputDeviceId===t)return;const{inputDevices:i=[]}=this,r=i.find((e=>e.deviceId===t))||i[0]||null;this.inputDevice=r,this._inputDeviceId=r?r.deviceId:"",this.streamState.state!==e.MEDIA_STREAM_STATE.NULL&&this.createStream()}get outputDeviceId(){return this._outputDeviceId||""}set outputDeviceId(e){if(this._outputDeviceId&&this._outputDeviceId===e)return;const{outputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.outputDevice=i,this._outputDeviceId=i?i.deviceId:""}get inputDevice(){return this._inputDevice}set inputDevice(t){const i=this._inputDevice&&!$(this._inputDevice,t),r=!this._inputDevice&&!!t;(r||i)&&(this._inputDevice=t,!r&&i&&this.emitter.emit(e.MEDIA_EVENT.INPUT_DEVICE_CHANGED,{device:t}))}get outputDevice(){return this._outputDevice}set outputDevice(t){const i=this._outputDevice&&!$(this._outputDevice,t),r=!this._outputDevice&&!!t;(r||i)&&(this._outputDevice=t,!r&&i&&this.emitter.emit(e.MEDIA_EVENT.OUTPUT_DEVICE_CHANGED,{device:t}))}get streamState(){return this._streamState}set streamState(t){const{_streamState:i}=this;i.state===t.state&&i.detail===t.detail||(this._streamState=t,this.emitter.emit(e.MEDIA_EVENT.STREAM_STATE,this._streamState))}setup(){this.type!==e.MediaType.kData&&(this.type===e.MediaType.kAudio?(this.analyser=new P(this.stream),this.volumeAnalyser=new H(this.stream)):this.analyser=new k(this.stream),this.analyser.on(L.AUDIO_STATE_CHANGED,(({state:t})=>{!t.hasStream||t.track&&t.active||(this.streamState={state:e.MEDIA_STREAM_STATE.FAILED,detail:e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS})})))}cleanup(){this.closeStream(),this.inputDevices=[],this.inputDeviceId="",this.outputDevices=[],this.outputDeviceId=""}streamInactive(){this.stream&&(this.stream.close(),this.stream=null,this.streamState={state:e.MEDIA_STREAM_STATE.NULL},this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream}))}getMediaStream(i){return t(this,void 0,void 0,(function*(){let t=null;switch(this.type){case e.MediaType.kAudio:t=((e,t)=>{const i={audio:!1,video:!1},{deviceId:r,groupId:n}=e||{deviceId:"",groupId:""};return i.audio=!!e&&(t&&v?{deviceId:{exact:r},groupId:{exact:n}}:{deviceId:r,groupId:n}),i.audio&&!m&&Object.assign(i.audio,j),i})(this.inputDevice,i),t.audio||(t=null);break;case e.MediaType.kVideo:t=((e,t)=>{const i={audio:!1,video:!1},{deviceId:r,groupId:n}=e||{deviceId:"",groupId:""};return i.video=t||!!e&&(v?{deviceId:{exact:r},groupId:{exact:n}}:{deviceId:r,groupId:n}),i.video&&Object.assign(i.video,V),i})(this.inputDevice,this.mediaTrackConstraints),t.video||(t=null);break;case e.MediaType.kData:t={video:U}}let r=this.streamState;if(!t)return r={state:e.MEDIA_STREAM_STATE.FAILED,detail:e.MEDIA_STREAM_DETAIL.NO_DEVICE},{stream:null,streamState:r};let n,s=null;try{s=yield(this.type===e.MediaType.kData?F:G)(t)}catch(a){n=a}if(s)r={state:e.MEDIA_STREAM_STATE.CAPTURING};else{n=n||new Error("Stream is null");r={state:e.MEDIA_STREAM_STATE.FAILED,detail:(this.type===e.MediaType.kAudio?K:this.type===e.MediaType.kVideo?J:W).get(n.message)||e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS}}return{stream:s,streamState:r}}))}closeStream(){this.stream&&(this.type===e.MediaType.kData&&Y(this.stream,this.onStreamInactive),this.stream.close()),this.stream=null,this.switchAnalyserEnable(this.stream,{enable:!1}),this.streamState={state:e.MEDIA_STREAM_STATE.NULL},this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream})}createStream(){return this.ctx.throwIfNotState(e.MEDIA_MANAGER_STATE.INITED),this.queue=this.queue.then((()=>t(this,void 0,void 0,(function*(){this.switchAnalyserEnable(this.stream,{enable:!1});const t=!(this.streamState.state!==e.MEDIA_STREAM_STATE.CAPTURING||!this.stream),{stream:i,streamState:r}=yield this.getMediaStream(t);if(this.streamState.state===e.MEDIA_STREAM_STATE.CAPTURING&&this.stream&&(this.type===e.MediaType.kData&&Y(this.stream,this.onStreamInactive),this.stream.close(),this.stream=null),this.ctx.state!==e.MEDIA_MANAGER_STATE.INITED)return i&&i.close(),this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream}),Promise.resolve(this.stream);this.type===e.MediaType.kData&&((e,t)=>{e&&e.addEventListener("inactive",t),v&&e&&(e.getVideoTracks()||[]).forEach((e=>{e.addEventListener("ended",t)}))})(i,this.onStreamInactive),this.stream=i,this.streamState=r,this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream});let n=!0;return i||r.state!==e.MEDIA_STREAM_STATE.FAILED||(n=!1),this.switchAnalyserEnable(i,{enable:n}),Promise.resolve(this.stream)}))))}getMicVolume(){return this.volumeAnalyser?this.volumeAnalyser.volume:0}switchAnalyserEnable(t,{enable:i=!1}){this.type!==e.MediaType.kData&&(this.analyser?(this.analyser.stream=t,this.analyser.enable=i,this.type===e.MediaType.kAudio&&this.volumeAnalyser&&(this.volumeAnalyser.stream=t,this.volumeAnalyser.enable=i)):console.error(""))}}const K=new Map([["No Device",e.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["The request is not allowed by the user agent or the platform in the current context.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["Stream is null",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),J=new Map([["No Device",e.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",e.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["The request is not allowed by the user agent or the platform in the current context.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",e.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["Stream is null",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),W=new Map([["Permission denied by system",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The object can not be found here.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM]]);return e.Channel=w,e.MediaInterface=X,e.createChannel=e=>new w(e),e.createMediaManager=()=>{const r={state:e.MEDIA_MANAGER_STATE.NULL,emitter:i(),deviceList:[],throwIfState:(e,t)=>{if(r.state===e)throw new Error(t||"Invalid State")},throwIfNotState:(e,t)=>{if(r.state!==e)throw new Error(t||"Invalid State")}},n=new X(e.MediaType.kAudio,r),s=new X(e.MediaType.kVideo,r),a=new X(e.MediaType.kData,r),o=e=>t(void 0,void 0,void 0,(function*(){if(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)return void console.error("mediaDevices or enumerateDevices is miss");const t=yield navigator.mediaDevices.enumerateDevices().catch((e=>{console.error("enumerate devices error: ",e)}));r.deviceList=t&&t.map((e=>e.toJSON()))||[],n.inputDevices=r.deviceList.filter((e=>"audioinput"===e.kind)),n.inputDeviceId=B({deviceList:n.inputDevices,device:n.inputDevice,deviceId:e&&e.audioInputDeviceId||""}),n.outputDevices=r.deviceList.filter((e=>"audiooutput"===e.kind)),n.outputDeviceId=B({deviceList:n.outputDevices,device:n.outputDevice,deviceId:e&&e.audioOutputDeviceId||""}),s.inputDevices=r.deviceList.filter((e=>"videoinput"===e.kind)),s.inputDeviceId=B({deviceList:s.inputDevices,device:s.inputDevice,deviceId:e&&e.videoInputDeviceId||""})}));return{ctx:r,get state(){return r.state},on:r.emitter.on,off:r.emitter.off,init:i=>t(void 0,void 0,void 0,(function*(){if(window.ActiveXObject||"ActiveXObject"in window)throw new Error("Not compatible with this browser yet, please use other browsers instead.");r.throwIfState(e.MEDIA_MANAGER_STATE.INITED),navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=function(){o()}),yield o(i),r.state=e.MEDIA_MANAGER_STATE.INITED,r.emitter.emit(e.MEDIA_MANAGER_EVENT.STATE,{state:r.state})})),destroy:()=>{try{n.cleanup(),s.cleanup(),a.cleanup()}catch(t){}r.state=e.MEDIA_MANAGER_STATE.NULL,r.emitter.emit(e.MEDIA_MANAGER_EVENT.STATE,{state:r.state})},audioMedia:n,videoMedia:s,dataMedia:a}},Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var YlinkSDKStream=function(e){"use strict";function t(e,t,i,n){return new(i||(i=Promise))((function(r,a){function s(e){try{l(n.next(e))}catch(t){a(t)}}function o(e){try{l(n.throw(e))}catch(t){a(t)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,o)}l((n=n.apply(e,t||[])).next())}))}function i(e){return{all:e=e||new Map,on:function(t,i){var n=e.get(t);n?n.push(i):e.set(t,[i])},off:function(t,i){var n=e.get(t);n&&(i?n.splice(n.indexOf(i)>>>0,1):e.set(t,[]))},emit:function(t,i){var n=e.get(t);n&&n.slice().map((function(e){e(i)})),(n=e.get("*"))&&n.slice().map((function(e){e(t,i)}))}}}var n,r,a,s,o,l;e.CHANNEL_EVENT=void 0,(n=e.CHANNEL_EVENT||(e.CHANNEL_EVENT={})).STATE="streamState",n.CHANNEL_REFRESH="channelRefresh",n.CHANNEL_BUSY="channelBusy",n.AUDIO_CHANNEL_OPENED="audioChannelOpened",n.VIDEO_CHANNEL_OPENED="videoChannelOpened",n.DATA_CHANNEL_OPENED="dataChannelOpened",n.MESSAGE_CHANNEL_OPENED="messageChannelOpened",n.VOICE_ACTIVE_SSRC="voiceActiveSsrc",n.AUDIO_PLAYER_CHANGE="audioPlayerChange",e.CHANNEL_STATE=void 0,(r=e.CHANNEL_STATE||(e.CHANNEL_STATE={}))[r.STARTED=1]="STARTED",r[r.STOPPED=0]="STOPPED",e.MEDIA_MANAGER_EVENT=void 0,(e.MEDIA_MANAGER_EVENT||(e.MEDIA_MANAGER_EVENT={})).STATE="state",e.MEDIA_MANAGER_STATE=void 0,(a=e.MEDIA_MANAGER_STATE||(e.MEDIA_MANAGER_STATE={}))[a.NULL=0]="NULL",a[a.INITED=1]="INITED",e.MEDIA_EVENT=void 0,(s=e.MEDIA_EVENT||(e.MEDIA_EVENT={})).STREAM_STATE="streamState",s.STREAM="stream",s.INPUT_DEVICES_UPDATED="inputDevicesUpdated",s.OUTPUT_DEVICES_UPDATED="outputDevicesUpdated",s.INPUT_DEVICE_CHANGED="inputDeviceChanged",s.OUTPUT_DEVICE_CHANGED="outputDeviceChanged",e.MEDIA_STREAM_STATE=void 0,(o=e.MEDIA_STREAM_STATE||(e.MEDIA_STREAM_STATE={}))[o.NULL=0]="NULL",o[o.CAPTURING=1]="CAPTURING",o[o.FAILED=2]="FAILED",e.MEDIA_STREAM_DETAIL=void 0,(l=e.MEDIA_STREAM_DETAIL||(e.MEDIA_STREAM_DETAIL={}))[l.NO_DEVICE=0]="NO_DEVICE",l[l.PERMISSION_DENIED=1]="PERMISSION_DENIED",l[l.COULD_NOT_START_VIDEO_SOURCE=2]="COULD_NOT_START_VIDEO_SOURCE",l[l.PERMISSION_DENIED_BY_SYSTEM=3]="PERMISSION_DENIED_BY_SYSTEM",l[l.OTHER_EXCEPTIONS=4]="OTHER_EXCEPTIONS";const c=(e,t)=>{const i=t.match(e);return i&&i.length>0&&i[1]||""},d=/version\/(\d+(\.?_?\d+)+)/i,h=[{test:[/\sedg\//i],describe(e){const t={name:"Microsoft Edge"},i=c(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/edg([ea]|ios)/i],describe(e){const t={name:"Microsoft Edge"},i=((e,t)=>{const i=t.match(e);return i&&i.length>1&&i[2]||""})(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/firefox|iceweasel|fxios/i],describe(e){const t={name:"Firefox"},i=c(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/chromium/i],describe(e){const t={name:"Chromium"},i=c(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||c(d,e);return i&&(t.version=i),t}},{test:[/chrome|crios|crmo/i],describe(e){const t={name:"Chrome"},i=c(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return i&&(t.version=i),t}},{test:[/safari|applewebkit/i],describe(e){const t={name:"Safari"},i=c(d,e);return i&&(t.version=i),t}}];let u;const E=h.find((e=>{if(e.test instanceof Array)return e.test.some((e=>e.test(navigator.userAgent)));throw new Error("Browser's test function is not valid")}));E&&(u=E.describe(navigator.userAgent));const m=u&&"Safari"===u.name,v=u&&"Firefox"===u.name,p=u&&"Chrome"===u.name,A=u&&"Microsoft Edge"===u.name,T=e=>/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e),f=(e,t)=>t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e,S=({src:e,id:t})=>new Promise(((i,n)=>{let r=document.querySelector(`#${t}`);if(r)return r.src=e,void i(r);r=document.createElement("script"),r.src=e,r.id=t,r.onload=()=>{i(r)},r.onerror=e=>{n(e)},document.head.appendChild(r)}));var b=class{constructor({namespace:e,debug:t}){Object.defineProperty(this,"initialized",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isDebugging",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"useColors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"backend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"namespace",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.initialized=!0,this.isDebugging=t,this.backend=D(),this.namespace=e,this.useColors=this.backend.useColors,this.color=this.selectColor(e)}logger(e){e[0]=this.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let t=0;return e[0]=e[0].replace(/%([a-zA-Z%])/g,((i,n)=>{if("%%"===i)return i;t++;const r=this.backend.formatters[n];if("function"==typeof r){i=r(e[t]),e.splice(t,1),t--}return i})),this.backend.formatArgs(e,this)}coerce(e){return e instanceof Error?e.stack||e.message:e}selectColor(e){const t=Array.from(e).reduce(((e,t)=>(e=(e<<5)-e+t.charCodeAt(0),e|=0)),0);return this.backend.colors[Math.abs(t)%this.backend.colors.length]}switchDebug(e){this.isDebugging=e}log(...e){e=this.logger(e),this.backend.log.apply(this,e)}debug(...e){this.isDebugging&&(e=this.logger(e),this.backend.debug.apply(this,e))}warn(...e){this.backend.warn.apply(this,e)}error(...e){this.backend.error.apply(this,e)}};const D=()=>({colors:["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],formatters:{j:e=>{try{return JSON.stringify(e)}catch(t){return`[UnexpectedJSONParseError]: ${t.message}`}}},log:(...e)=>"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,e),debug:(...e)=>"object"==typeof console&&console.debug&&Function.prototype.apply.call(console.debug,console,e),warn:(...e)=>"object"==typeof console&&console.warn&&Function.prototype.apply.call(console.warn,console,e),error:(...e)=>"object"==typeof console&&console.error&&Function.prototype.apply.call(console.error,console,e),formatArgs:(e,t)=>{const{useColors:i,namespace:n,color:r}=t;if(e[0]=`${(i?"%c":"")+n+(i?" %c":" ")+e[0]+(i?"%c ":" ")}+${function(e){const t=Math.abs(e);if(t>=C)return`${Math.round(e/C)}d`;if(t>=N)return`${Math.round(e/N)}h`;if(t>=_)return`${Math.round(e/_)}m`;if(t>=I)return`${Math.round(e/I)}s`;return`${e}ms`}(0)}`,!i)return[];const a=`color: ${r}`;e.splice(1,0,a,"color: inherit");let s=0,o=0;return e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(s++,"%c"===e&&(o=s))})),e.splice(o,0,a),e},useColors:g()}),I=1e3,_=60*I,N=60*_,C=24*N;const g=()=>!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.webkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)),y=new b({namespace:"STREAM:Store",debug:!1});class w{constructor({baseURL:t,videoSDKLibDir:n,clientID:r,debug:a}){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:e.CHANNEL_STATE.STOPPED}),Object.defineProperty(this,"clientID",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"SFUTransportType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEndpoint",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaEngine",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"audioChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"videoChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"messageChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"remoteControlStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"subtitleStream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"videoSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dataSender",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"audioReceiver",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"voiceActiveSsrc",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"audioChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"videoChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"dataChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"messageChannelOpened",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"baseURL",{enumerable:!0,configurable:!0,writable:!0,value:"https://meetings.ylyun.com"}),Object.defineProperty(this,"videoSDKLibDir",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:i()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"_audioPlayer",{enumerable:!0,configurable:!0,writable:!0,value:null}),t=t||"https://meetings.ylyun.com",n=n||"",y.switchDebug(a=a||!1),this.clientID=r,this.setBaseUrl(t),this.setVideoSDKLibDir(n),this.setup()}get audioPlayer(){return this._audioPlayer}set audioPlayer(t){this._audioPlayer=t,this.emitter.emit(e.CHANNEL_EVENT.AUDIO_PLAYER_CHANGE,t)}setup(){return t(this,void 0,void 0,(function*(){}))}cleanup(){return t(this,void 0,void 0,(function*(){const{videoChannel:e,audioChannel:t,messageChannel:i,dataChannel:n,mediaEndpoint:r,remoteControlStream:a}=this;try{t&&(yield t.close()),e&&(yield e.close()),n&&(yield n.close()),a&&i&&(yield i.closeStream(a)),i&&(yield i.close()),r&&(r.stop(),r.destroy())}catch(s){y.error(s)}this.mediaEndpoint=null,this.mediaEngine=null,this.videoChannel=null,this.audioChannel=null,this.dataChannel=null,this.messageChannel=null,this.videoSender=null,this.audioSender=null,this.dataSender=null,this.audioReceiver=null,this.audioPlayer=null,this.audioChannelOpened=!1,this.videoChannelOpened=!1,this.dataChannelOpened=!1,this.messageChannelOpened=!1}))}getMss(e){return t(this,void 0,void 0,(function*(){const{mediaContent:t,userID:i,role:n,meetingID:r,appId:a,meetingNumber:s,meetingParam:o,userAccount:l}=e,c=yield O.getMss(this.baseURL,{appId:a,meetingNumber:s,meetingParam:o,userAccount:l,accessMCs:t.accessMCs,topMC:t.topMC,confId:r,ccid:i,userType:"audience"===n?"Broadcast":"Interactive"}).catch((e=>{y.error(e)}));if(y.debug(`response ${JSON.stringify(c)}`),!c||!c.data||!c.data.MssInfo)return y.error("getMss response error ",c),[];const d=c.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),h=c.data.MssInfo.map((e=>e.IntranetUri)).flat();return d.concat(h).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const{baseURL:t}=this,i=T(t)?(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[2]})(t):t,n=`${T(t)&&"http:"===(e=>{if(!e)return"";const t=/^([a-z][a-z\d+\-.]*:)?\/\/(\S+)/.exec(e);return!t||t.length<3?"":t[1]})(t)?"ws":"wss"}://${i}`,r=window.btoa(e.replace(/\w+:\/\//,""));return f(n,`/webapp/socket/${r}`)}))}))}mssRequest(e,i){return t(this,void 0,void 0,(function*(){const{mediaContent:n,userID:r,role:a,meetingID:s,appId:o,meetingNumber:l,meetingParam:c,userAccount:d}=i,h=(i,h)=>new Promise(((u,E)=>{const m=new URL(i),v=m.searchParams.get("webapp");v&&(i=`https://${v}?mc=${m.host}`),O.mssRequest(i,{appId:o,meetingNumber:l,meetingParam:c,userAccount:d,accessMCs:n.accessMCs,topMC:n.topMC,confId:s,ccid:r,userType:"audience"===a?"Broadcast":"Interactive"}).then((i=>t(this,void 0,void 0,(function*(){return console.log("result: ",i),i&&i.data?i.state&&300001===i.state?(console.log("getMss() wait 300ms"),e.splice(h,1),yield(t=300,new Promise((e=>setTimeout((()=>e(t)),t)))),E(i)):u(i):(e.splice(h,1),E(i));var t})))).catch((e=>{console.error(e),E()}))})),u=()=>t(this,void 0,void 0,(function*(){let t=null;try{t=yield Promise.race(e.map(h))}catch(i){console.error("request/mss ",i)}return t}));let E=[];const m=e.length;for(let e=0;e<m;e++){const e=yield u();if(e&&e.state&&3e5===e.state){const t=e.data.MssInfo.map((e=>e.ExtranetlUri)).flat(),i=e.data.MssInfo.map((e=>e.IntranetUri)).flat();E=t.concat(i).filter((e=>e.startsWith("ws")||e.startsWith("wss"))).map((e=>{const t=new URL(e),i=t.searchParams.get("webapp");return i&&(e=`wss://${i}?mss=${t.host}`),e}));break}}return E}))}start(i){return t(this,void 0,void 0,(function*(){this.throwIfState(e.CHANNEL_STATE.STARTED),yield M(this.videoSDKLibDir,!!i.develop).catch((e=>{y.error(e)}));const{LIBRTC:n}=window,{NativeMediaEndpoint:r,NativeMediaEngine:a,SFUTransportType:s}=n;this.SFUTransportType=s,i.config&&(n.config=i.config);const{mediaContent:o,user:l,meetingID:c,ctrlID:d,meetingNum:h="",account:u=""}=i,E=new a;yield E.init();const m=new r;m.onrefresh=()=>t(this,void 0,void 0,(function*(){this.emitter.emit(e.CHANNEL_EVENT.CHANNEL_REFRESH);const t=l.userID,i=l.role;let n=[];for(let e=0;e<o.accessMCs.length;e++){let a=[];try{a=JSON.parse(o.accessMCs[e])}catch(r){console.error(r)}const s=a.some((e=>(!e.extranet||!e.extranet.length)&&e.intranet&&e.intranet.length)),l=a.map((e=>{const t=e.extranet||[];return t.push(...e.intranet),t})).flat(),d={appId:this.clientID,mediaContent:{accessMCs:[o.accessMCs[e]],topMC:o.topMC,crypto:o.crypto,meetingParam:o.meetingParam},meetingID:c,userID:t,role:i,meetingParam:o.meetingParam,meetingNumber:h,userAccount:u};if(-1!==l.findIndex((e=>new URL(e).searchParams.get("webapp")))){if(console.log("urls",l),n=yield this.mssRequest(l,d),n.length)break}else{if(s)break;if(n=yield this.getMss(d),n.length)break}}return n})),yield m.init(),yield m.start({meeting_number:h||"",user_account:u||"",meeting_param:o.meetingParam,client_type:"WebApp",confid:c,ccid:l.userID,role:1,encrypt:o.crypto,token:d}),this.mediaEndpoint=m,this.mediaEngine=E,this.state=e.CHANNEL_STATE.STARTED,this.emitter.emit(e.CHANNEL_EVENT.STATE,{state:this.state})}))}stop(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),yield this.cleanup(),this.state=e.CHANNEL_STATE.STOPPED,this.emitter.emit(e.CHANNEL_EVENT.STATE,{state:this.state})}))}destroy(){return t(this,void 0,void 0,(function*(){yield this.stop()}))}getChannelState(){return{audioChannelOpened:this.audioChannelOpened,videoChannelOpened:this.videoChannelOpened,dataChannelOpened:this.dataChannelOpened,messageChannelOpened:this.messageChannelOpened}}setBaseUrl(t){this.throwIfState(e.CHANNEL_STATE.STARTED),t&&this.baseURL!==t&&("/"===t&&(t=window.location.origin),this.baseURL=t)}setVideoSDKLibDir(t){this.throwIfState(e.CHANNEL_STATE.STARTED),t&&this.videoSDKLibDir!==t&&(this.videoSDKLibDir=t)}createAudioChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:n}=this,r=t.audio.createChannel(i.createTransport(n.kAudio));this.audioChannel=r,r.onopen=()=>{y.debug("audioChannel onopen()"),this.audioChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.AUDIO_CHANNEL_OPENED)},yield r.open()}))}closeAudioChannel(){return t(this,void 0,void 0,(function*(){const{audioChannel:e}=this;e?(yield e.close(),this.audioChannel=null,this.audioSender=null,this.audioReceiver=null,this.audioChannelOpened=!1):y.error("audioChannel is miss")}))}createVideoChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:n}=this,r=t.video.createChannel(i.createTransport(n.kVideo));this.videoChannel=r,r.onopen=()=>{y.debug("videoChannel onopen()"),this.videoChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.VIDEO_CHANNEL_OPENED)},yield r.open()}))}createDataChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:n}=this,r=t.video.createChannel(i.createTransport(n.kData));this.dataChannel=r,r.onopen=()=>{y.debug("dataChannel onopen()")},yield r.open(),this.dataChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.DATA_CHANNEL_OPENED)}))}createMessageChannel(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED);const{mediaEngine:t,mediaEndpoint:i,SFUTransportType:n}=this,r=t.video.createDataChannel(i.createTransport(n.kMessage));this.messageChannel=r,r.onopen=()=>{y.debug("messageChannel onopen()")};try{yield r.open()}catch(a){console.error(a)}this.messageChannelOpened=!0,this.emitter.emit(e.CHANNEL_EVENT.MESSAGE_CHANNEL_OPENED)}))}closeMessageChannel(){return t(this,void 0,void 0,(function*(){const{messageChannel:e}=this;e?yield e.close():y.error("messageChannel is miss")}))}closeMessageStream(e){return t(this,void 0,void 0,(function*(){const{messageChannel:t}=this;t?e&&(yield t.closeStream(e)):y.error("messageChannel is miss")}))}setupRemoteControl({element:i,remote:n}){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message"),i.setAttribute("tabIndex","-1"),i.style.outline="0";const{LIBRTC:t}=window,{messageChannel:r}=this,a=yield r.createStream(t.DataType.kRemoteControl);return this.remoteControlStream=a,t.setupRemoteControl(a,i,n)}))}createSubtitleStream(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:t}=this,i=yield t.createSubtitleStream();return i.subscribe([-1]),this.subtitleStream=i,i}))}closeSubtitleStream(i){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("message");const{messageChannel:t}=this;yield t.closeSubtitleStream(i),this.subtitleStream=null}))}createAudioSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;if(!t)return y.error("audioChannel is miss"),null;const i=this.audioSender?this.audioSender:t.createSender();return this.audioSender=i,i}))}removeAudioSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioSender:t}=this;if(t)try{t.stop(),this.audioChannel&&this.audioChannel.removeSender(t.ssrc)}catch(i){y.error("audioChannel removeSender() error: ",i)}else y.error("audioSender is miss")}))}createVideoSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:t}=this;if(!t)return y.error("videoChannel is miss"),null;const i=this.videoSender?this.videoSender:t.createSender();return this.videoSender=i,i.onbusy=()=>{y.debug("onbusy"),this.emitter.emit(e.CHANNEL_EVENT.CHANNEL_BUSY);const{audioChannel:t}=this;t&&t.ans(!1)},i}))}removeVideoSender(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoSender:t}=this;if(t)try{t.stop(),this.videoChannel&&this.videoChannel.removeSender(t.ssrc)}catch(i){y.error("videoChannel removeSender() error: ",i)}else y.error("videoSender is miss")}createDataSender(){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:t}=this;if(!t)return y.error("dataChannel is miss"),null;const i=this.dataSender?this.dataSender:t.createSender();return this.dataSender=i,i}))}removeDataSender(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataSender:t}=this;t?(t.stop(),this.dataChannel&&this.dataChannel.removeSender(t.ssrc),this.dataSender=null):y.error("dataSender is miss")}createAudioReceiver(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:i}=this;if(!i)return y.error("audioChannel is miss"),null;const n=i.createReceiver();return this.audioReceiver=n,t?(n.setSink(t),this.audioPlayer=t,i.audioElement&&(i.audioElement.srcObject=null),n):(y.error("audioPlayer is miss"),null)}createVideoReceiver(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{ccid:i}=t;if(y.debug("createVideoReceiver ccid: ",i),!i)return y.error("params is missing or params error"),null;const{videoChannel:n}=this;if(!n)return y.error("videoChannel is miss"),null;return n.createReceiver(i)}createDataReceiver(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{ccid:i}=t;if(y.debug("createDataReceiver ccid: ",i),!i)return y.error("params is missing or params error"),null;const{dataChannel:n}=this;if(!n)return y.error("dataChannel is miss"),null;return n.createReceiver(i)}removeVideoReceiver(t){return this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video"),t?(t.stop(),this.videoChannel&&this.videoChannel.removeReceiver(t.ssrc),null):t}removeDataReceiver(t){return this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data"),t?(t.stop(),this.dataChannel&&this.dataChannel.removeReceiver(t.ssrc),null):t}loadVideoRenderer(i,n=!0){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:t}=this;if(!t||!i)return y.error("videoChannel or el is miss"),null;return(p||A)&&void 0!==i.transferControlToOffscreen?yield t.offscreen.load(i.transferControlToOffscreen(),n):i}))}unloadVideoRenderer(i){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("video");const{videoChannel:t}=this;t&&i?(p||A)&&(yield t.offscreen.unload(i)):y.error("videoChannel or renderer is miss")}))}loadDataRenderer(i,n=!0){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:t}=this;if(!t||!i)return y.error("dataChannel or el is miss"),null;return(p||A)&&void 0!==i.transferControlToOffscreen?yield t.offscreen.load(i.transferControlToOffscreen(),n):i}))}unloadDataRenderer(i){return t(this,void 0,void 0,(function*(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("data");const{dataChannel:t}=this;t&&i?(p||A)&&(yield t.offscreen.unload(i)):y.error("dataChannel or renderer is miss")}))}bindAudioChannelEvent(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;t?t.onfocusing=t=>{if(this.voiceActiveSsrc.length&&t.length){if(this.voiceActiveSsrc[0]===t[0])return}else if(0===this.voiceActiveSsrc.length&&0===t.length)return;this.voiceActiveSsrc=t,this.emitter.emit(e.CHANNEL_EVENT.VOICE_ACTIVE_SSRC,{ssrc:t})}:y.error("audioChannel is miss")}offAudioChannelEvent(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioChannel:t}=this;t?t.onfocusing=null:y.error("audioChannel is miss")}setAudioPlayerVolume(t){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:i}=this;i?i.volume=t=t>=0&&t<1?t:t>=1&&t<=100?t/100:t:y.error("audioPlayer is miss")}getAudioPlayerVolume(){this.throwIfNotState(e.CHANNEL_STATE.STARTED),this.throwIfChannelNotOpened("audio");const{audioPlayer:t}=this;return t?t.volume:(y.error("audioPlayer is miss"),0)}getAudioChannelStats(){return t(this,void 0,void 0,(function*(){return this.state===e.CHANNEL_STATE.STARTED&&this.audioChannelOpened&&this.audioChannel?yield this.audioChannel.getStats():{}}))}throwIfState(e,t){if(this.state===e)throw new Error(t||"Invalid State")}throwIfNotState(e,t){if(this.state!==e)throw new Error(t||"Invalid State")}throwIfChannelNotOpened(e,t=""){switch(e){case"audio":if(!this.audioChannelOpened)throw new Error(t||"Channel is not open");break;case"video":if(!this.videoChannelOpened)throw new Error(t||"Channel is not open");break;case"data":if(!this.dataChannelOpened)throw new Error(t||"Channel is not open");break;case"message":if(!this.messageChannelOpened)throw new Error(t||"Channel is not open")}}}const M=(e,t)=>Promise.all([S({src:`${e}/libsfu${t?"":".prod"}.js`,id:"ylink-sdk-stream-libsfu"}),S({src:`${e}/librtc.global${t?"":".prod"}.js`,id:"ylink-sdk-stream-librtc"})]),O={getMss:(e,i)=>"function"!=typeof fetch?Promise.reject():fetch(f(e,"/webapp/front/getMss"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify(i)}).then((e=>t(void 0,void 0,void 0,(function*(){return yield e.json()})))),mssRequest:(e,i)=>"function"!=typeof fetch?Promise.reject():fetch(f(e,"/api/v1/mss/request"),{headers:{"content-type":"application/json"},method:"POST",body:JSON.stringify({ConfId:i.confId,CCID:i.ccid,Rlp:{UpRlp:56,DownRlp:56},ClientType:"WebApp",TimeStamp:(new Date).getTime(),MeetingParam:i.meetingParam,VideoParam:{Width:1920,Height:1080,Fr:30},MeetingNumber:i.meetingNumber,UserAccount:i.userAccount,UserType:i.userType,TopMc:i.topMC})}).then((e=>t(void 0,void 0,void 0,(function*(){return yield e.json()}))))};class R{constructor(e){Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_enable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:i()}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),this.stream=e}analyse(){}start(){this.stream&&(this.timer&&(clearInterval(this.timer),this.timer=null),this.analyse(),this.timer=setInterval((()=>this.analyse()),this.interval))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}destroy(){this.stop()}}var P;!function(e){e.AUDIO_STATE_CHANGED="audioStateChanged",e.VIDEO_STATE_CHANGED="videoStateChanged"}(P||(P={}));var L=class extends R{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(P.AUDIO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getAudioTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var k=class extends R{constructor(e){super(e),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:{active:!1,hasStream:!1,track:!1}}),this.interval=3e3}get state(){return this._state}set state(e){const{_state:t}=this;t.active===e.active&&t.hasStream===e.hasStream&&t.track===e.track||(this._state=e,this.emitter.emit(P.VIDEO_STATE_CHANGED,{state:this._state}))}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.stream){const e=this.stream.getVideoTracks();this.state.active=void 0===this.stream.active?Boolean(e[0]):this.stream.active,this.state.hasStream=void 0!==this.stream.active&&void 0!==this.stream.id,(this.state.active||this.state.hasStream)&&(this.state.track=this.checkAvariable(e))}else this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}streamInactive(){this.state.active=!1,this.state.hasStream=!1,this.state.track=!1}checkAvariable(e=[]){return e.some((e=>!("readyState"in e&&"live"!==e.readyState||"muted"in e&&!0===e.muted)))}destroy(){this.stream&&this.stream.removeEventListener("inactive",this.streamInactive),super.destroy()}};var H=class extends R{constructor(e){super(e),Object.defineProperty(this,"volume",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"contextAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"streamSource",{enumerable:!0,configurable:!0,writable:!0,value:null})}get enable(){return this._enable}set enable(e){this._enable=e,e&&this.stream?this.start():this.stop()}analyse(){if(this.context&&this.contextAnalyser&&this.streamSource){const e=this.contextAnalyser.frequencyBinCount,t=new Uint8Array(e);this.contextAnalyser.getByteFrequencyData(t);const i=t.reduce(((e,t)=>e+t),0);this.volume=i/e}else this.volume=0}start(){this.createContextAnalyser(),this.createStreamSource(),this.streamSource&&super.start()}stop(){this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.volume=0,super.stop()}createContextAnalyser(){if(this.context&&this.contextAnalyser)return;if(!window.AudioContext&&!window.webkitAudioContext)return;const e=window.AudioContext||window.webkitAudioContext;this.context=new e,this.contextAnalyser=this.context.createAnalyser(),this.contextAnalyser.fftSize=1024,this.contextAnalyser.smoothingTimeConstant=.5}createStreamSource(){if(this.streamSource&&(this.streamSource.disconnect(),this.streamSource=null),this.context&&this.stream&&this.stream.getAudioTracks().length>0){if(this.streamSource=this.context.createMediaStreamSource(this.stream),!this.contextAnalyser)return;this.streamSource.connect(this.contextAnalyser),"suspended"===this.context.state&&this.context.resume()}}destroy(){this.contextAnalyser&&(this.contextAnalyser.disconnect(),this.contextAnalyser=null),this.context&&(this.context=null),super.destroy()}};const j={autoGainControl:!0,echoCancellation:!0,latency:0,noiseSuppression:!0},V={aspectRatio:16/9,frameRate:30,width:640,height:360},U={width:1920,height:1080,frameRate:5},x=e=>(e.close=e.stop=function(){e.getTracks().forEach((e=>e.stop()))},e.pause=function(){this.getTracks().forEach((e=>e.enabled=!1))},e.play=function(){this.getTracks().forEach((e=>e.enabled=!0))},e.muteAudio=function(e=!0){this.getAudioTracks().forEach((t=>t.enabled=!e))},e.muteVideo=function(e=!0){this.getVideoTracks().forEach((t=>t.enabled=!e))},e),G=e=>t(void 0,void 0,void 0,(function*(){const t=yield navigator.mediaDevices.getUserMedia(e);return x(t)})),F=e=>t(void 0,void 0,void 0,(function*(){const t=yield navigator.mediaDevices.getDisplayMedia(e);return x(t)})),$=(e,t,i=!1)=>{if(!e||!t)return!1;const n=e.deviceId===t.deviceId&&e.label===t.label&&e.kind===t.kind;return i?e.groupId===t.groupId&&n:n},B=({deviceList:e,device:t,deviceId:i})=>(t=(t=i?e.find((e=>e.deviceId===i))||null:t&&e.find((e=>$(e,t)))||null)||(e[0]||null))&&t.deviceId?t.deviceId:"",q=(e,t)=>{if(!e||!t||e.length!==t.length)return!1;let i=!0;for(let n=0;n<e.length;n++){if(!$(e[n],t[n])){i=!1;break}}return i},Y=(e,t)=>{e.removeEventListener("inactive",t);(e.getVideoTracks()||[]).forEach((e=>{e.removeEventListener("ended",t)}))};var z;e.MediaType=void 0,(z=e.MediaType||(e.MediaType={}))[z.kAudio=0]="kAudio",z[z.kVideo=1]="kVideo",z[z.kData=2]="kData";class X{constructor(t,n){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_streamState",{enumerable:!0,configurable:!0,writable:!0,value:{state:e.MEDIA_STREAM_STATE.NULL}}),Object.defineProperty(this,"_inputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_outputDevice",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_outputDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_inputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_outputDevices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_mediaTrackConstraints",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"queue",{enumerable:!0,configurable:!0,writable:!0,value:Promise.resolve(null)}),Object.defineProperty(this,"emitter",{enumerable:!0,configurable:!0,writable:!0,value:i()}),Object.defineProperty(this,"analyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"volumeAnalyser",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"on",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.on}),Object.defineProperty(this,"off",{enumerable:!0,configurable:!0,writable:!0,value:this.emitter.off}),Object.defineProperty(this,"onStreamInactive",{enumerable:!0,configurable:!0,writable:!0,value:this.streamInactive.bind(this)}),this.type=t,this.ctx=n,this.setup()}get mediaTrackConstraints(){return this._mediaTrackConstraints}set mediaTrackConstraints(t){this._mediaTrackConstraints=t,this.streamState.state!==e.MEDIA_STREAM_STATE.NULL&&this.createStream()}get inputDevices(){return this._inputDevices||[]}set inputDevices(t){q(t,this._inputDevices)||(this._inputDevices=t,this.ctx.state===e.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(e.MEDIA_EVENT.INPUT_DEVICES_UPDATED,{deviceList:t}))}get outputDevices(){return this._outputDevices||[]}set outputDevices(t){q(t,this._outputDevices)||(this._outputDevices=t,this.ctx.state===e.MEDIA_MANAGER_STATE.INITED&&this.emitter.emit(e.MEDIA_EVENT.OUTPUT_DEVICES_UPDATED,{deviceList:t}))}get inputDeviceId(){return this._inputDeviceId||""}set inputDeviceId(t){if(this._inputDeviceId&&this._inputDeviceId===t)return;const{inputDevices:i=[]}=this,n=i.find((e=>e.deviceId===t))||i[0]||null;this.inputDevice=n,this._inputDeviceId=n?n.deviceId:"",this.streamState.state!==e.MEDIA_STREAM_STATE.NULL&&this.createStream()}get outputDeviceId(){return this._outputDeviceId||""}set outputDeviceId(e){if(this._outputDeviceId&&this._outputDeviceId===e)return;const{outputDevices:t=[]}=this,i=t.find((t=>t.deviceId===e))||t[0]||null;this.outputDevice=i,this._outputDeviceId=i?i.deviceId:""}get inputDevice(){return this._inputDevice}set inputDevice(t){const i=this._inputDevice&&!$(this._inputDevice,t),n=!this._inputDevice&&!!t;(n||i)&&(this._inputDevice=t,!n&&i&&this.emitter.emit(e.MEDIA_EVENT.INPUT_DEVICE_CHANGED,{device:t}))}get outputDevice(){return this._outputDevice}set outputDevice(t){const i=this._outputDevice&&!$(this._outputDevice,t),n=!this._outputDevice&&!!t;(n||i)&&(this._outputDevice=t,!n&&i&&this.emitter.emit(e.MEDIA_EVENT.OUTPUT_DEVICE_CHANGED,{device:t}))}get streamState(){return this._streamState}set streamState(t){const{_streamState:i}=this;i.state===t.state&&i.detail===t.detail||(this._streamState=t,this.emitter.emit(e.MEDIA_EVENT.STREAM_STATE,this._streamState))}setup(){this.type!==e.MediaType.kData&&(this.type===e.MediaType.kAudio?(this.analyser=new L(this.stream),this.volumeAnalyser=new H(this.stream)):this.analyser=new k(this.stream),this.analyser.on(P.AUDIO_STATE_CHANGED,(({state:t})=>{!t.hasStream||t.track&&t.active||(this.streamState={state:e.MEDIA_STREAM_STATE.FAILED,detail:e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS})})))}cleanup(){this.closeStream(),this.inputDevices=[],this.inputDeviceId="",this.outputDevices=[],this.outputDeviceId=""}streamInactive(){this.stream&&(this.stream.close(),this.stream=null,this.streamState={state:e.MEDIA_STREAM_STATE.NULL},this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream}))}getMediaStream(i){return t(this,void 0,void 0,(function*(){let t=null;switch(this.type){case e.MediaType.kAudio:t=((e,t)=>{const i={audio:!1,video:!1},{deviceId:n,groupId:r}=e||{deviceId:"",groupId:""};return i.audio=!!e&&(t&&v?{deviceId:{exact:n},groupId:{exact:r}}:{deviceId:n,groupId:r}),i.audio&&!m&&Object.assign(i.audio,j),i})(this.inputDevice,i),t.audio||(t=null);break;case e.MediaType.kVideo:t=((e,t)=>{const i={audio:!1,video:!1},{deviceId:n,groupId:r}=e||{deviceId:"",groupId:""};return i.video=t||!!e&&(v?{deviceId:{exact:n},groupId:{exact:r}}:{deviceId:n,groupId:r}),i.video&&Object.assign(i.video,V),i})(this.inputDevice,this.mediaTrackConstraints),t.video||(t=null);break;case e.MediaType.kData:t={video:U}}let n=this.streamState;if(!t)return n={state:e.MEDIA_STREAM_STATE.FAILED,detail:e.MEDIA_STREAM_DETAIL.NO_DEVICE},{stream:null,streamState:n};let r,a=null;try{a=yield(this.type===e.MediaType.kData?F:G)(t)}catch(s){r=s}if(a)n={state:e.MEDIA_STREAM_STATE.CAPTURING};else{r=r||new Error("Stream is null");n={state:e.MEDIA_STREAM_STATE.FAILED,detail:(this.type===e.MediaType.kAudio?K:this.type===e.MediaType.kVideo?J:W).get(r.message)||e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS}}return{stream:a,streamState:n}}))}closeStream(){this.stream&&(this.type===e.MediaType.kData&&Y(this.stream,this.onStreamInactive),this.stream.close()),this.stream=null,this.switchAnalyserEnable(this.stream,{enable:!1}),this.streamState={state:e.MEDIA_STREAM_STATE.NULL},this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream})}createStream(){return this.ctx.throwIfNotState(e.MEDIA_MANAGER_STATE.INITED),this.queue=this.queue.then((()=>t(this,void 0,void 0,(function*(){this.switchAnalyserEnable(this.stream,{enable:!1});const t=!(this.streamState.state!==e.MEDIA_STREAM_STATE.CAPTURING||!this.stream),{stream:i,streamState:n}=yield this.getMediaStream(t);if(this.streamState.state===e.MEDIA_STREAM_STATE.CAPTURING&&this.stream&&(this.type===e.MediaType.kData&&Y(this.stream,this.onStreamInactive),this.stream.close(),this.stream=null),this.ctx.state!==e.MEDIA_MANAGER_STATE.INITED)return i&&i.close(),this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream}),Promise.resolve(this.stream);this.type===e.MediaType.kData&&((e,t)=>{e&&e.addEventListener("inactive",t),v&&e&&(e.getVideoTracks()||[]).forEach((e=>{e.addEventListener("ended",t)}))})(i,this.onStreamInactive),this.stream=i,this.streamState=n,this.emitter.emit(e.MEDIA_EVENT.STREAM,{stream:this.stream});let r=!0;return i||n.state!==e.MEDIA_STREAM_STATE.FAILED||(r=!1),this.switchAnalyserEnable(i,{enable:r}),Promise.resolve(this.stream)}))))}getMicVolume(){return this.volumeAnalyser?this.volumeAnalyser.volume:0}switchAnalyserEnable(t,{enable:i=!1}){this.type!==e.MediaType.kData&&(this.analyser?(this.analyser.stream=t,this.analyser.enable=i,this.type===e.MediaType.kAudio&&this.volumeAnalyser&&(this.volumeAnalyser.stream=t,this.volumeAnalyser.enable=i)):console.error(""))}}const K=new Map([["No Device",e.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["The request is not allowed by the user agent or the platform in the current context.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS],["Stream is null",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),J=new Map([["No Device",e.MEDIA_STREAM_DETAIL.NO_DEVICE],["Permission denied",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Permission dismissed",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Could not start video source",e.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["The request is not allowed by the user agent or the platform in the current context.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED],["Failed to allocate videosource",e.MEDIA_STREAM_DETAIL.COULD_NOT_START_VIDEO_SOURCE],["Stream is null",e.MEDIA_STREAM_DETAIL.OTHER_EXCEPTIONS]]),W=new Map([["Permission denied by system",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The object can not be found here.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM],["The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.",e.MEDIA_STREAM_DETAIL.PERMISSION_DENIED_BY_SYSTEM]]);return e.Channel=w,e.MediaInterface=X,e.createChannel=e=>new w(e),e.createMediaManager=()=>{const n={state:e.MEDIA_MANAGER_STATE.NULL,emitter:i(),deviceList:[],throwIfState:(e,t)=>{if(n.state===e)throw new Error(t||"Invalid State")},throwIfNotState:(e,t)=>{if(n.state!==e)throw new Error(t||"Invalid State")}},r=new X(e.MediaType.kAudio,n),a=new X(e.MediaType.kVideo,n),s=new X(e.MediaType.kData,n),o=e=>t(void 0,void 0,void 0,(function*(){if(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)return void console.error("mediaDevices or enumerateDevices is miss");const t=yield navigator.mediaDevices.enumerateDevices().catch((e=>{console.error("enumerate devices error: ",e)}));n.deviceList=t&&t.map((e=>e.toJSON()))||[],r.inputDevices=n.deviceList.filter((e=>"audioinput"===e.kind)),r.inputDeviceId=B({deviceList:r.inputDevices,device:r.inputDevice,deviceId:e&&e.audioInputDeviceId||""}),r.outputDevices=n.deviceList.filter((e=>"audiooutput"===e.kind)),r.outputDeviceId=B({deviceList:r.outputDevices,device:r.outputDevice,deviceId:e&&e.audioOutputDeviceId||""}),a.inputDevices=n.deviceList.filter((e=>"videoinput"===e.kind)),a.inputDeviceId=B({deviceList:a.inputDevices,device:a.inputDevice,deviceId:e&&e.videoInputDeviceId||""})}));return{ctx:n,get state(){return n.state},on:n.emitter.on,off:n.emitter.off,init:i=>t(void 0,void 0,void 0,(function*(){if(window.ActiveXObject||"ActiveXObject"in window)throw new Error("Not compatible with this browser yet, please use other browsers instead.");n.throwIfState(e.MEDIA_MANAGER_STATE.INITED),navigator.mediaDevices&&(navigator.mediaDevices.ondevicechange=function(){o()}),yield o(i),n.state=e.MEDIA_MANAGER_STATE.INITED,n.emitter.emit(e.MEDIA_MANAGER_EVENT.STATE,{state:n.state})})),destroy:()=>{try{r.cleanup(),a.cleanup(),s.cleanup()}catch(t){}n.state=e.MEDIA_MANAGER_STATE.NULL,n.emitter.emit(e.MEDIA_MANAGER_EVENT.STATE,{state:n.state})},audioMedia:r,videoMedia:a,dataMedia:s}},Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
{ | ||
"name": "@ylink-sdk/stream", | ||
"version": "0.2.0-beta.13", | ||
"version": "0.2.0-beta.14", | ||
"description": "Media processing of yealink's conference", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155117
1575