@zoom/videosdk
Version:
Zoom Web Video SDK
1 lines • 278 kB
JavaScript
(self.__MEDIA_SDK_CHUNK_LOADER__=self.__MEDIA_SDK_CHUNK_LOADER__||[]).push([[557],{8591:(e,t,i)=>{"use strict";i.r(t),i.d(t,{WMSCManager:()=>Hi,eventExt:()=>s});var a={};i.r(a),i.d(a,{TO:()=>D,NS:()=>k,mz:()=>N,GA:()=>O,Qx:()=>I,hV:()=>A,FK:()=>C,pO:()=>M,fZ:()=>R,Rz:()=>G,r3:()=>x,By:()=>j,ir:()=>W,pg:()=>U,OK:()=>B,ey:()=>w,jE:()=>F,gb:()=>V,S3:()=>v,wK:()=>E,LA:()=>q,tT:()=>Q,ul:()=>_,j$:()=>f,Y7:()=>y,RJ:()=>S,bl:()=>b,Dz:()=>z,c$:()=>H,lN:()=>L,zk:()=>Y,nd:()=>m,ue:()=>K,V$:()=>T,S$:()=>P,tP:()=>p,qe:()=>J});var s,n,r,o=i(7857),c=i(129),d=i.n(c),l=i(1212),h=i.n(l);!function(e){e.NOTIFY_SDK_JOIN_RWG_SUCCESS="NOTIFY_SDK_JOIN_RWG_SUCCESS",e.NOTIFY_SDK_JOIN_RWG_FAILURE="NOTIFY_SDK_JOIN_RWG_FAILURE",e.VIDEO_STREAMS="VIDEO_STREAMS",e.WMSC_MESSAGE_FROM_RWG="WMSC_MESSAGE_FROM_RWG",e.NOTIFY_WMSC_VIDEO_TAG_MAPPING="NOTIFY_WMSC_VIDEO_TAG_MAPPING",e.NOTIFY_SDK_SUBSCRIBE_VIDEO="NOTIFY_SDK_SUBSCRIBE_VIDEO",e.NOTIFY_SDK_UNSUBSCRIBE_VIDEO="NOTIFY_SDK_UNSUBSCRIBE_VIDEO",e.NOTIFY_SDK_ACTIVE_VIDEO_INDICATION="NOTIFY_SDK_ACTIVE_VIDEO_INDICATION",e.UPDATE_WMSC_PARAMS="UPDATE_WMSC_PARAMS",e.UPDATE_VIDEO_SOURCE_SETTINGS="UPDATE_VIDEO_SOURCE_SETTINGS",e.RE_SETUP_PEER_CONNECTION="RE_SETUP_PEER_CONNECTION"}(s||(s={})),function(e){e.ERROR="ERROR",e.WMSC_MESSAGE_TO_RWG_BY_SDK="WMSC_MESSAGE_TO_RWG_BY_SDK",e.WMSC_MAPPING_STREAMID_AND_MID="WMSC_MAPPING_STREAMID_AND_MID",e.GLOBAL_TRACE="GLOBAL_TRACE",e.SNOWPLOW_TRACE="SNOWPLOW_TRACE",e.MONITOR="MONITOR",e.DIRECT_MONITOR="DIRECT_MONITOR",e.CREATE_VIDEO_STREAMS_SUCCESS="CREATE_VIDEO_STREAMS_SUCCESS",e.CREATE_VIDEO_STREAMS_FAIL="CREATE_VIDEO_STREAMS_FAIL",e.PC_CONNECTED="PC_CONNECTED",e.VIDEO_SOURCE_UPDATED="VIDEO_SOURCE_UPDATED",e.VIDEO_TAG_MAPPED="VIDEO_TAG_MAPPED",e.VIDEO_QOS_DATA="VIDEO_QOS_DATA",e.UPDATE_VIDEO_CAPTURE_CONSTRAINTS="UPDATE_VIDEO_CAPTURE_CONSTRAINTS",e.ERROR_MESSAGE="ERROR_MESSAGE",e.NETWORK_QUALITY_CHANGE="NETWORK_QUALITY_CHANGE",e.NETWORK_QUALITY_CHANGE_AUDIO="NETWORK_QUALITY_CHANGE_AUDIO",e.VIDEO_CAPABILITIES_CHANGE="VIDEO_CAPABILITIES_CHANGE",e.UPDATE_MAX_RECV_VIDEO_SIZE="UPDATE_MAX_RECV_VIDEO_SIZE",e.SDP_NEGOTIATION_FAIL="SDP_NEGOTIATION_FAIL",e.PC_FAIL="PC_FAIL",e.VIDEO_DECODE_FAIL="VIDEO_DECODE_FAIL",e.VIDEO_ENCODE_FAIL="VIDEO_ENCODE_FAIL",e.PC_CLOSED="PC_CLOSED",e.AUDIO_RECAPTURE="AUDIO_RECAPTURE",e.CURRENT_DECODE_VIDEO_QUALITY="CURRENT_DECODE_VIDEO_QUALITY",e.CURRENT_DECODE_VIDEO_FPS="CURRENT_DECODE_VIDEO_FPS"}(n||(n={})),function(e){e[e.None=0]="None",e[e.App_SYNC=1]="App_SYNC",e[e.WEBRTC_SYNC=2]="WEBRTC_SYNC"}(r||(r={}));const u=new class{constructor(){this.config={conId:"",webrtcMode:0,nodeId:0,probe:!1,isMacIntel:!1,videoSettings:{},meetingProperties:{isDualCall:!0,isHdMeeting:!1,isFullHdMeeting:!1,keepFullHd:!1,fullHdL3ViewL4:!1},qosOptions:{},iceServers:[],avSyncMode:r.None,dataChannelEnabled:!1},this.enabledLayerIds=[],this.layersSettings=[]}setConfig(e){this.config=Object.assign(Object.assign({},this.config),e)}getConfig(){return this.config}get(e){return this.config[e]}set(e,t){const i=this.config[e],a=typeof i,s=typeof t;if(a!==s)throw new Error('Type mismatch for key "'.concat(e,'": expected ').concat(a,", got ").concat(s));if("object"!==a||null===i||null===t||Array.isArray(i))this.config[e]=t;else{const a=h()(Object.entries(t).filter((e=>{let[,t]=e;return void 0!==t})));this.config[e]=Object.assign(Object.assign({},i),a)}}setEnabledLayerIds(e){this.enabledLayerIds=e}getEnabledLayerIds(){return this.enabledLayerIds}setLayersSettings(e){this.layersSettings=e}getLayersSettings(){return this.layersSettings}};var p,m,g;!function(e){e[e.ERROR=0]="ERROR",e[e.WARN=1]="WARN",e[e.INFO=2]="INFO",e[e.DEBUG=3]="DEBUG",e[e.VERBOSE=4]="VERBOSE"}(p||(p={})),function(e){e[e.AUDIO=1]="AUDIO",e[e.VIDEO=2]="VIDEO",e[e.SHARE=3]="SHARE"}(m||(m={})),function(e){e[e.VIDEO=1]="VIDEO",e[e.AUDIO=2]="AUDIO",e[e.SHARE=3]="SHARE"}(g||(g={}));const S=0;var _,v;!function(e){e[e.IDLE=0]="IDLE",e[e.CONNECTING=1]="CONNECTING",e[e.CONNECTED=2]="CONNECTED"}(_||(_={})),function(e){e[e.IDLE=0]="IDLE",e[e.NEGOTIATING=1]="NEGOTIATING",e[e.WAITING_CONNECTION=2]="WAITING_CONNECTION",e[e.WAITING_ICE_RESPONSE=3]="WAITING_ICE_RESPONSE"}(v||(v={}));const f=6e3,y=2e3,E=1e4,M=3,C=3,I=12e3,R=3,T=1e3,A=100<<20;var w,b,L;!function(e){e.STREAM="STREAM",e.SDP="SDP",e.PC_STATE_CHANGE="PC_STATE_CHANGE",e.UPDATE_BITRATE="UPDATE_BITRATE",e.UPDATE_VIDEO_CONSTRAINTS="UPDATE_VIDEO_CONSTRAINTS",e.ERROR="ERROR"}(w||(w={})),function(e){e.LAYERS_UPDATE="LAYERS_UPDATE",e.MIN_BITRATE_UPDATE="MIN_BITRATE_UPDATE",e.ENCODER_RESET="ENCODER_RESET"}(b||(b={})),function(e){e[e.NONE=0]="NONE",e[e.UNDERUSING=1]="UNDERUSING",e[e.NORMAL=2]="NORMAL",e[e.OVERUSING=3]="OVERUSING"}(L||(L={}));const D=1;var P;!function(e){e[e.PLAIN=0]="PLAIN",e[e.GZIP_BASE64=1]="GZIP_BASE64"}(P||(P={}));const O=100,N=62464,k=17120,V=2,B=4,W=4,U=3,F=4,x=26,G=x+1,j=16,z=299,H=6;var Q,q,Y,K;!function(e){e[e.NET_QUALITY_UNKNOWN=-1]="NET_QUALITY_UNKNOWN",e[e.NET_QUALITY_VERY_BAD=0]="NET_QUALITY_VERY_BAD",e[e.NET_QUALITY_BAD=1]="NET_QUALITY_BAD",e[e.NET_QUALITY_NOT_GOOD=2]="NET_QUALITY_NOT_GOOD",e[e.NET_QUALITY_NORMAL=3]="NET_QUALITY_NORMAL",e[e.NET_QUALITY_GOOD=4]="NET_QUALITY_GOOD",e[e.NET_QUALITY_EXCELLENT=5]="NET_QUALITY_EXCELLENT"}(Q||(Q={})),function(e){e[e.NET_BW_LEVEL_UNKNOWN=-1]="NET_BW_LEVEL_UNKNOWN",e[e.NET_BW_LEVEL_VERY_LOW=0]="NET_BW_LEVEL_VERY_LOW",e[e.NET_BW_LEVEL_LOW=1]="NET_BW_LEVEL_LOW",e[e.NET_BW_LEVEL_NORMAL=2]="NET_BW_LEVEL_NORMAL"}(q||(q={})),function(e){e[e.ICE_RESTART=0]="ICE_RESTART",e[e.MEDIA=1]="MEDIA",e[e.ADD_MLINE=2]="ADD_MLINE",e[e.REMOVE_MLINE=3]="REMOVE_MLINE",e[e.UPDATE_BITRATE=4]="UPDATE_BITRATE",e[e.REQUEST_ICE_RESTART=5]="REQUEST_ICE_RESTART"}(Y||(Y={})),function(e){e[e.HD_VIDEO=2097152]="HD_VIDEO",e[e.FULL_HD_VIDEO=4096]="FULL_HD_VIDEO",e[e.DUAL_CALL=1]="DUAL_CALL",e[e.AV1_CODEC=262144]="AV1_CODEC"}(K||(K={}));const J="WMSC_DETECT_CANPLAY_VIDEO";var X=i(7201),Z=i.n(X),$=function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function r(e){try{c(a.next(e))}catch(e){n(e)}}function o(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}c((a=a.apply(e,t||[])).next())}))};function ee(e){return(4294966272&e)>>>0}function te(e,t){return $(this,void 0,void 0,(function*(){switch(t){case P.GZIP_BASE64:{const t=yield function(e){return $(this,void 0,void 0,(function*(){const t=(new TextEncoder).encode(e);if(window.CompressionStream){const e=new CompressionStream("gzip"),i=e.writable.getWriter();return i.write(t),i.close(),new Response(e.readable).arrayBuffer()}{const{gzip:e}=yield i.e(404).then(i.bind(i,3075));return e(t).buffer}}))}(e);return function(e){let t="";const i=new Uint8Array(e);for(let e=0;e<i.byteLength;e++)t+=String.fromCharCode(i[e]);return btoa(t)}(t)}case P.PLAIN:return e;default:return null}}))}function ie(e,t){return e.length===t.length&&e.every(((e,i)=>e===t[i]))}function ae(e,t){return e-t}function se(e,t){t=t||{};const i=e=>{var t,i;if("number"==typeof e)return e;if(e&&"object"==typeof e){const{exact:a,ideal:s,max:n,min:r}=e;return null!==(i=null!==(t=null!=a?a:s)&&void 0!==t?t:n)&&void 0!==i?i:r}};return{width:(e=e||{}).width||i(t.width),height:e.height||i(t.height),frameRate:e.frameRate||i(t.frameRate)}}function ne(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"|";return e?Z()(e).call(e,",",t):""}function re(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,2),16)===O}function oe(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,4),16)===N}function ce(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,4),16)===k}function de(e){return"string"!=typeof e?e:e.split("\n").filter((e=>!e.includes("ice-pwd"))).join("\n")}const le=new class{constructor(){this.setTrace()}setTrace(e,t){t&&(t.log||t.info)&&t.error&&t.warn?(this.log=t.log||t.info,this.info=t.info||t.log,this.debug=t.debug||t.log,this.verbose=this._verbose,this.error=t.error,this.warn=t.warn):(this.verbose=this._verbose.bind(this),this.log=this._log.bind(this),this.info=this._info.bind(this),this.debug=this._debug.bind(this),this.error=this._error.bind(this),this.warn=this._warn.bind(this)),this.level=e||p.INFO,this.level=this.level<p.ERROR?p.ERROR:this.level,this.level=this.level>p.VERBOSE?p.VERBOSE:this.level,this.getLevel=()=>this.level,this._trace=(e,t)=>{switch(e){case"log":console.log(...t);break;case"debug":console.debug(...t);break;case"info":console.info(...t);break;case"warn":console.warn(...t);break;case"error":console.error(...t)}}}getTracer(e){return{log:()=>{},debug:()=>{},info:()=>{},warn:()=>{},error:()=>{}}}setTelemetry(e){this._telemetry="function"==typeof e?e:null}monitorLog(e){e&&this._telemetry&&this._telemetry({type:n.MONITOR,data:e})}directSendMonitorLog(e){e&&this._telemetry&&this._telemetry({type:n.DIRECT_MONITOR,data:e})}globalTrace(e){e&&this._telemetry&&this._telemetry({type:n.GLOBAL_TRACE,data:e})}snowplowTrace(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];e&&t&&this._telemetry&&this._telemetry({type:n.SNOWPLOW_TRACE,data:{logLevel:e,message:t,errorEvent:i,entitys:a,tags:s}})}_verbose(){if(this.level>=p.VERBOSE){const e=[...arguments];return e.unshift("[VERBOSE]"),this._trace("log",e),!0}return!1}_debug(){return this.level>=p.DEBUG&&(this._trace("debug",arguments),!0)}_log(){return this.level>=p.INFO&&(this._trace("log",arguments),!0)}_info(){return this.level>=p.INFO&&(this._trace("info",arguments),!0)}_warn(){return this.level>=p.WARN&&(this._trace("warn",arguments),!0)}_error(){return this.level>=p.ERROR&&(this._trace("error",arguments),!0)}};var he=i(1265),ue=i.n(he),pe=i(8048),me=i.n(pe);function ge(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,a)}return i}function Se(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?ge(Object(i),!0).forEach((function(t){(0,o.A)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):ge(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}const _e="b=TIAS:",ve="a=ice-ufrag:",fe="a=ice-pwd:",ye="a=ice-options:",Ee="a=ice-lite",Me="a=ice-pacing:",Ce="a=fingerprint:",Ie="a=setup:",Re="a=rtpmap:",Te="a=fmtp:",Ae="a=rtcp-fb:",we="a=rid:",be="a=simulcast:",Le="a=extmap:",De="a=extmap-allow-mixed",Pe="a=mid:",Oe="a=msid:",Ne="a=ssrc:",ke="a=ssrc-group:",Ve="a=group:",Be="a=rtcp-mux",We="a=rtcp-rsize",Ue="a=candidate:",Fe="a=end-of-candidates",xe="a=remote-candidates:",Ge="a=ice-mismatch",je=new Set(["a=sendrecv","a=sendonly","a=recvonly","a=inactive"]);class ze{static splitSections(e){return e.split(/\r?\nm=/).map(((e,t)=>t>0?"".concat("m=").concat(e):e))}static splitLines(e){return e.split("\n").map((e=>e.replace(/\r$/,"")))}static isVersionLine(e){return e.startsWith("v=")}static parseVersionLine(e){return parseInt(e.substring(2),10)}static writeVersionLine(e){return"".concat("v=").concat(e)}static isOriginLine(e){return e.startsWith("o=")}static parseOriginLine(e){const[t,i,a,s,n,r]=e.substring(2).split(" ");return{userName:t,sessionId:i,sessionVersion:parseInt(a,10),netType:s,addressType:n,address:r}}static writeOriginLine(e){const{userName:t,sessionId:i,sessionVersion:a,netType:s,addressType:n,address:r}=e;return"".concat("o=").concat(t," ").concat(i," ").concat(a," ").concat(s," ").concat(n," ").concat(r)}static isSessionNameLine(e){return e.startsWith("s=")}static parseSessionNameLine(e){return e.substring(2)}static writeSessionNameLine(e){return"".concat("s=").concat(e)}static isInformationLine(e){return e.startsWith("i=")}static parseInformationLine(e){return e.substring(2)}static writeInformationLine(e){return"".concat("i=").concat(e)}static isConnectionLine(e){return e.startsWith("c=")}static parseConnectionLine(e){const[t,i,a]=e.substring(2).split(" ");return{netType:t,addressType:i,address:a}}static writeConnectionLine(e){const{netType:t,addressType:i,address:a}=e;return"".concat("c=").concat(t," ").concat(i," ").concat(a)}static isBandwidthLine(e){return e.startsWith(_e)}static parseBandwidthLine(e){return parseInt(e.substring(7),10)}static writeBandwidthLine(e){return"".concat(_e).concat(e)}static isTimingLine(e){return e.startsWith("t=")}static parseTimingLine(e){const[t,i]=e.substring(2).split(" ");return{startTime:parseInt(t,10),stopTime:parseInt(i,10)}}static writeTimingLine(e){const{startTime:t,stopTime:i}=e;return"".concat("t=").concat(t," ").concat(i)}static isIceUfragLine(e){return e.startsWith(ve)}static parseIceUfragLine(e){return e.substring(12)}static writeIceUfragLine(e){return"".concat(ve).concat(e)}static isIcePwdLine(e){return e.startsWith(fe)}static parseIcePwdLine(e){return e.substring(10)}static writeIcePwdLine(e){return"".concat(fe).concat(e)}static isIceOptionsLine(e){return e.startsWith(ye)}static parseIceOptionsLine(e){return e.substring(14).split(/\s+/).filter(Boolean)}static writeIceOptionsLine(e){const t=Array.isArray(e)?e:[e];return"".concat(ye).concat(t.join(" "))}static isIceLiteLine(e){return e===Ee}static parseIceLiteLine(){return!0}static writeIceLiteLine(){return Ee}static isIcePacingLine(e){return e.startsWith(Me)}static parseIcePacingLine(e){return e.substring(13)}static writeIcePacingLine(e){return"".concat(Me).concat(e)}static isFingerprintLine(e){return e.startsWith(Ce)}static parseFingerprintLine(e){const t=e.substring(14),i=t.indexOf(" ");return-1===i?null:{algorithm:t.substring(0,i),value:t.substring(i+1)}}static writeFingerprintLine(e){const{algorithm:t,value:i}=e;return"".concat(Ce).concat(t," ").concat(i)}static isSetupLine(e){return e.startsWith(Ie)}static parseSetupLine(e){return e.substring(8)}static writeSetupLine(e){return"".concat(Ie).concat(e)}static isRtpMapLine(e){return e.startsWith(Re)}static parseRtpMapLine(e){const t=e.substring(9).match(/^(\d+) (.*)/);if(!t)return null;const i=t[2].split("/");return{payloadType:parseInt(t[1],10),codecName:i[0],clockRate:parseInt(i[1],10),channels:i.length>=3?parseInt(i[2],10):null}}static writeRtpMapLine(e){const{payloadType:t,codecName:i,clockRate:a,channels:s}=e;let n="".concat(Re).concat(t," ").concat(i,"/").concat(a);return null!=s&&(n+="/"+s),n}static isFmtpLine(e){return e.startsWith(Te)}static parseFmtpLine(e){const t=e.substring(7).match(/^(\d+) (.*)/);if(!t)return null;const i={payloadType:parseInt(t[1],10)};if(t[2].includes("=")){const e=t[2].split(";").map((e=>{const t=ue()(e).call(e);if(!t)return null;const i=t.indexOf("=");return-1===i?null:[t.substring(0,i),t.substring(i+1)]})).filter((e=>null!==e));e.length?i.params=new Map(e):i.plain=t[2]}else i.plain=t[2];return i}static writeFmtpLine(e){const{payloadType:t,params:i,plain:a}=e;let s="".concat(Te).concat(t," ");return i?(i.forEach(((e,t)=>{null!=e&&(s+="".concat(t,"=").concat(e,";"))})),s=s.slice(0,-1)):s+=a,s}static isRtcpFbLine(e){return e.startsWith(Ae)}static parseRtcpFbLine(e){const t=e.substring(10).match(/^(\*|\d+) (.*)/);return t?{payloadType:"*"===t[1]?"*":parseInt(t[1],10),params:t[2].split(" ")}:null}static writeRtcpFbLine(e){const{payloadType:t,params:i}=e;let a="".concat(Ae).concat(t);return i.forEach((e=>{a+=" "+e})),a}static isRidLine(e){return e.startsWith(we)}static parseRidLine(e){const t=e.substring(6).match(/^(\S+)\s+(send|recv|sendrecv)(?:\s+(.*))?$/);if(!t)return null;const i=new Map;return t[3]&&t[3].split(";").forEach((e=>{const t=ue()(e).call(e);if(!t)return;const a=t.indexOf("=");-1!==a?i.set(t.substring(0,a),t.substring(a+1)):i.set(t,"")})),{rid:t[1],direction:t[2],params:i}}static writeRidLine(e){const{rid:t,direction:i,params:a}=e;let s;return(null==a?void 0:a.size)>0&&(s=Array.from(a.entries()).map((e=>{let[t,i]=e;return null==i||""===i?t:"".concat(t,"=").concat(i)})).join(";")),"".concat(we).concat(t," ").concat(i).concat(s?" "+s:"")}static parseSimulcastRidList(e){return e.split(";").map((e=>{const t=e.split(",").map((e=>ue()(e).call(e))).filter((e=>e.length>0)).map((e=>"~"===e[0]?{id:e.substring(1),paused:!0}:{id:e,paused:!1}));return t.length?1===t.length?t[0]:{alternatives:t}:null})).filter((e=>null!==e))}static writeSimulcastRidList(e){return e.map((e=>(e.alternatives||[e]).map((e=>e.paused?"~"+e.id:e.id)).join(","))).join(";")}static isSimulcastLine(e){return e.startsWith(be)}static parseSimulcastLine(e){var t;const i=ue()(t=e.substring(12)).call(t).split(/\s+/);if(2!==i.length&&4!==i.length)return null;const a=[];for(let e=0;e<i.length;e+=2){const t=i[e];if("send"!==t&&"recv"!==t)return null;const s=this.parseSimulcastRidList(i[e+1]);if(!s.length)return null;a.push({direction:t,rids:s})}return 2===a.length&&a[0].direction===a[1].direction?null:1===a.length?a[0]:{entries:a}}static writeSimulcastLine(e){const t=e.entries||[e];return"".concat(be).concat(t.map((e=>{let{direction:t,rids:i}=e;return"".concat(t," ").concat(this.writeSimulcastRidList(i))})).join(" "))}static isExtensionMapLine(e){return e.startsWith(Le)}static parseExtensionMapLine(e){var t;const i=e.substring(9).match(/^(\d+)(\/sendrecv|\/sendonly|\/recvonly|\/inactive)? (\S+)(\s\S+)?/);return i?{id:parseInt(i[1],10),direction:i[2]?i[2].substring(1):null,uri:i[3],attributes:i[4]?me()(t=i[4]).call(t):null}:null}static writeExtensionMapLine(e){const{id:t,direction:i,uri:a,attributes:s}=e;let n="".concat(Le).concat(t);return null!=i&&(n+="/"+i),n+=" "+a,null!=s&&(n+=" "+s),n}static isMidLine(e){return e.startsWith(Pe)}static parseMidLine(e){return e.substring(6)}static writeMidLine(e){return"".concat(Pe).concat(e)}static isDirectionLine(e){return je.has(e)}static parseDirectionLine(e){return this.isDirectionLine(e)?e.substring(2):null}static writeDirectionLine(e){return"".concat("a=").concat(e)}static isMsidLine(e){return e.startsWith(Oe)}static parseMsidLine(e){const[t,i]=e.substring(7).split(" ");return{streamId:t,trackId:i}}static writeMsidLine(e){const{streamId:t,trackId:i}=e;return"".concat(Oe).concat(t," ").concat(i)}static isSsrcLine(e){return e.startsWith(Ne)}static parseSsrcLine(e){const t=e.indexOf(" ");return{ssrc:parseInt(e.substring(7,t),10),attribute:e.substring(t+1)}}static writeSsrcLine(e){const{ssrc:t,attribute:i}=e;return"".concat(Ne).concat(t," ").concat(i)}static isSsrcGroupLine(e){return e.startsWith(ke)}static parseSsrcGroupLine(e){const t=e.substring(13).split(" ");return{semantics:t.shift(),ssrcs:t}}static writeSsrcGroupLine(e){const{semantics:t,ssrcs:i}=e;let a="".concat(ke).concat(t);return i.forEach((e=>{a+=" "+e})),a}static isGroupLine(e){return e.startsWith(Ve)}static parseGroupLine(e){const t=e.indexOf(" ");return{semantics:e.substring(8,t),ids:e.substring(t+1).split(" ")}}static writeGroupLine(e){const{semantics:t,ids:i}=e;let a="".concat(Ve).concat(t);return i.forEach((e=>{a+=" "+e})),a}static isExtMapAllowMixedLine(e){return e===De}static parseExtMapAllowMixedLine(){return!0}static writeExtMapAllowMixedLine(){return De}static isRtcpMuxLine(e){return e===Be}static parseRtcpMuxLine(){return!0}static writeRtcpMuxLine(){return Be}static isRtcpReducedSizeLine(e){return e===We}static parseRtcpReducedSizeLine(){return!0}static writeRtcpReducedSizeLine(){return We}static isCandidateLine(e){return e.startsWith(Ue)}static parseCandidateLine(e){const t=e.substring(12).split(" "),i={foundation:t[0],componentId:parseInt(t[1],10),transport:t[2],priority:parseInt(t[3],10),address:t[4],port:parseInt(t[5],10),candType:t[6],type:t[7],relAddress:null,relPort:null,candExtensions:[]};return"raddr"===t[8]&&"rport"===t[10]?(i.relAddress=t[9],i.relPort=parseInt(t[11],10),i.candExtensions=t.slice(12)):i.candExtensions=t.slice(8),i}static writeCandidateLine(e){const{foundation:t,componentId:i,transport:a,priority:s,address:n,port:r,candType:o,type:c,relAddress:d,relPort:l,candExtensions:h}=e;let u="".concat(Ue).concat(t," ").concat(i," ").concat(a," ").concat(s)+" ".concat(n," ").concat(r," ").concat(o," ").concat(c);return null!=d&&null!=l&&(u+=" raddr ".concat(d," rport ").concat(l)),h.length&&(u+=" "+h.join(" ")),u}static isRtcpLine(e){return e.startsWith("a=rtcp:")}static parseRtcpLine(e){return e}static writeRtcpLine(e){return e}static isEndOfCandidatesLine(e){return e===Fe}static parseEndOfCandidatesLine(){return!0}static writeEndOfCandidatesLine(){return Fe}static isRemoteCandidatesLine(e){return e.startsWith(xe)}static parseRemoteCandidatesLine(e){return e.substring(20)}static writeRemoteCandidatesLine(e){return"".concat(xe).concat(e)}static isIceMismatchLine(e){return e===Ge}static parseIceMismatchLine(){return!0}static writeIceMismatchLine(){return Ge}static parseSessionSection(e){const t={version:0,origin:null,sessionName:null,information:null,connection:null,bandwidth:null,timing:null,fingerprint:null,setup:null,iceOptions:null,iceLite:null,icePacing:null,icePwd:null,iceUfrag:null,groups:[],extensionMap:new Map,extMapAllowMixed:null,otherLines:[]},i=this.splitLines(e);for(let e=0;e<i.length;e++){const a=i[e];if(a.length)if(this.isVersionLine(a))t.version=this.parseVersionLine(a);else if(this.isOriginLine(a))t.origin=this.parseOriginLine(a);else if(this.isSessionNameLine(a))t.sessionName=this.parseSessionNameLine(a);else if(this.isInformationLine(a))t.information=this.parseInformationLine(a);else if(this.isConnectionLine(a))t.connection=this.parseConnectionLine(a);else if(this.isBandwidthLine(a))t.bandwidth=this.parseBandwidthLine(a);else if(this.isTimingLine(a))t.timing=this.parseTimingLine(a);else if(this.isFingerprintLine(a))t.fingerprint=this.parseFingerprintLine(a);else if(this.isSetupLine(a))t.setup=this.parseSetupLine(a);else if(this.isIceOptionsLine(a))t.iceOptions=this.parseIceOptionsLine(a);else if(this.isIceLiteLine(a))t.iceLite=this.parseIceLiteLine();else if(this.isIcePacingLine(a))t.icePacing=this.parseIcePacingLine(a);else if(this.isIceUfragLine(a))t.iceUfrag=this.parseIceUfragLine(a);else if(this.isIcePwdLine(a))t.icePwd=this.parseIcePwdLine(a);else if(this.isGroupLine(a))t.groups.push(this.parseGroupLine(a));else if(this.isExtensionMapLine(a)){const e=this.parseExtensionMapLine(a);e&&t.extensionMap.set(e.id,e)}else this.isExtMapAllowMixedLine(a)?t.extMapAllowMixed=this.parseExtMapAllowMixedLine():t.otherLines.push(a)}return t}static writeSessionSection(e){var t;const i=[];return i.push(this.writeVersionLine(e.version)),null!=e.origin&&i.push(this.writeOriginLine(e.origin)),null!=e.sessionName&&i.push(this.writeSessionNameLine(e.sessionName)),null!=e.information&&i.push(this.writeInformationLine(e.information)),null!=e.connection&&i.push(this.writeConnectionLine(e.connection)),null!=e.bandwidth&&i.push(this.writeBandwidthLine(e.bandwidth)),null!=e.timing&&i.push(this.writeTimingLine(e.timing)),e.groups.forEach((e=>{i.push(this.writeGroupLine(e))})),e.extensionMap.forEach((e=>{i.push(this.writeExtensionMapLine(e))})),e.extMapAllowMixed&&i.push(this.writeExtMapAllowMixedLine()),null!==(t=e.iceOptions)&&void 0!==t&&t.length&&i.push(this.writeIceOptionsLine(e.iceOptions)),e.iceLite&&i.push(this.writeIceLiteLine()),e.icePacing&&i.push(this.writeIcePacingLine(e.icePacing)),e.fingerprint&&i.push(this.writeFingerprintLine(e.fingerprint)),e.setup&&i.push(this.writeSetupLine(e.setup)),e.iceUfrag&&i.push(this.writeIceUfragLine(e.iceUfrag)),e.icePwd&&i.push(this.writeIcePwdLine(e.icePwd)),e.otherLines.length&&i.push(...e.otherLines),i.join("\r\n")+"\r\n"}static parseMediaSection(e){const t={type:null,port:null,protocol:null,formats:[],connection:null,bandwidth:null,mid:null,direction:null,msid:null,rtcpMux:null,rtcpReducedSize:null,extMapAllowMixed:null,fingerprint:null,setup:null,iceOptions:null,iceMismatch:null,icePwd:null,iceUfrag:null,remoteCandidates:null,endOfCandidates:null,rtcp:null,codecs:[],wildcardRtcpFb:[],extensionMap:new Map,rids:[],simulcast:null,ssrcs:[],ssrcGroups:[],candidates:[],otherLines:[]},i=[],a=[],s=this.splitLines(e),n=s[0].split(" ");t.type=n[0].substring(2),t.port=parseInt(n[1],10),t.protocol=n[2],t.formats=n.slice(3);for(let e=1;e<s.length;e++){const n=s[e];if(n.length)if(this.isConnectionLine(n))t.connection=this.parseConnectionLine(n);else if(this.isBandwidthLine(n))t.bandwidth=this.parseBandwidthLine(n);else if(this.isRtpMapLine(n)){const e=this.parseRtpMapLine(n);e&&t.codecs.push(Se(Se({},e),{},{codecParams:new Map,rtcpFbParams:[]}))}else if(this.isFmtpLine(n))i.push(n);else if(this.isRtcpFbLine(n))a.push(n);else if(this.isRidLine(n)){const e=this.parseRidLine(n);e&&t.rids.push(e)}else if(this.isSimulcastLine(n))t.simulcast=this.parseSimulcastLine(n);else if(this.isSsrcLine(n))t.ssrcs.push(this.parseSsrcLine(n));else if(this.isSsrcGroupLine(n))t.ssrcGroups.push(this.parseSsrcGroupLine(n));else if(this.isExtensionMapLine(n)){const e=this.parseExtensionMapLine(n);e&&t.extensionMap.set(e.id,e)}else this.isExtMapAllowMixedLine(n)?t.extMapAllowMixed=this.parseExtMapAllowMixedLine():this.isMidLine(n)?t.mid=this.parseMidLine(n):this.isDirectionLine(n)?t.direction=this.parseDirectionLine(n):this.isMsidLine(n)?t.msid=this.parseMsidLine(n):this.isRtcpMuxLine(n)?t.rtcpMux=this.parseRtcpMuxLine():this.isRtcpReducedSizeLine(n)?t.rtcpReducedSize=this.parseRtcpReducedSizeLine():this.isCandidateLine(n)?t.candidates.push(this.parseCandidateLine(n)):this.isRtcpLine(n)?t.rtcp=this.parseRtcpLine(n):this.isIceUfragLine(n)?t.iceUfrag=this.parseIceUfragLine(n):this.isIcePwdLine(n)?t.icePwd=this.parseIcePwdLine(n):this.isIceOptionsLine(n)?t.iceOptions=this.parseIceOptionsLine(n):this.isIceMismatchLine(n)?t.iceMismatch=this.parseIceMismatchLine():this.isFingerprintLine(n)?t.fingerprint=this.parseFingerprintLine(n):this.isSetupLine(n)?t.setup=this.parseSetupLine(n):this.isRemoteCandidatesLine(n)?t.remoteCandidates=this.parseRemoteCandidatesLine(n):this.isEndOfCandidatesLine(n)?t.endOfCandidates=this.parseEndOfCandidatesLine():t.otherLines.push(n)}return i.forEach((e=>{const i=this.parseFmtpLine(e);if(!i)return;const a=t.codecs.find((e=>e.payloadType===i.payloadType));a&&(i.params?i.params.forEach(((e,t)=>{"apt"===t&&(a.associatedPayloadType=parseInt(e,10)),a.codecParams.set(t,e)})):(a.fmtpLines=[i.plain],"red"===a.codecName&&(a.associatedPayloadType=parseInt(i.plain.split("/")[0],10))))})),a.forEach((e=>{const i=this.parseRtcpFbLine(e);if(i)if("*"===i.payloadType)t.wildcardRtcpFb.push(i.params);else{const e=t.codecs.find((e=>e.payloadType===i.payloadType));e&&e.rtcpFbParams.push(i.params)}})),t}static writeMediaSection(e){var t,i,a,s,n,r;const o=[];let c="m=".concat(e.type," ").concat(e.port," ").concat(e.protocol);return e.formats.forEach((e=>{c+=" "+e})),o.push(c),e.connection&&o.push(this.writeConnectionLine(e.connection)),e.bandwidth&&o.push(this.writeBandwidthLine(e.bandwidth)),e.rtcp&&o.push(this.writeRtcpLine(e.rtcp)),e.iceUfrag&&o.push(this.writeIceUfragLine(e.iceUfrag)),e.icePwd&&o.push(this.writeIcePwdLine(e.icePwd)),null!==(t=e.iceOptions)&&void 0!==t&&t.length&&o.push(this.writeIceOptionsLine(e.iceOptions)),e.iceMismatch&&o.push(this.writeIceMismatchLine()),e.fingerprint&&o.push(this.writeFingerprintLine(e.fingerprint)),e.setup&&o.push(this.writeSetupLine(e.setup)),e.otherLines.length&&o.push(...e.otherLines),o.push(this.writeMidLine(e.mid)),e.extensionMap.forEach(((e,t)=>{o.push(this.writeExtensionMapLine(e))})),e.extMapAllowMixed&&o.push(this.writeExtMapAllowMixedLine()),e.direction&&o.push(this.writeDirectionLine(e.direction)),e.msid&&o.push(this.writeMsidLine(e.msid)),e.rtcpMux&&o.push(this.writeRtcpMuxLine()),e.rtcpReducedSize&&o.push(this.writeRtcpReducedSizeLine()),e.codecs.forEach((e=>{const{payloadType:t,codecName:i,clockRate:a,channels:s,codecParams:n,fmtpLines:r,rtcpFbParams:c}=e;o.push(this.writeRtpMapLine({payloadType:t,codecName:i,clockRate:a,channels:s})),c.forEach((e=>{o.push(this.writeRtcpFbLine({payloadType:t,params:e}))})),n.size&&o.push(this.writeFmtpLine({payloadType:t,params:n})),null==r||r.forEach((e=>{o.push(this.writeFmtpLine({payloadType:t,plain:e}))}))})),null===(i=e.wildcardRtcpFb)||void 0===i||i.forEach((e=>{o.push(this.writeRtcpFbLine({payloadType:"*",params:e}))})),null===(a=e.ssrcGroups)||void 0===a||a.forEach((e=>{o.push(this.writeSsrcGroupLine(e))})),null===(s=e.ssrcs)||void 0===s||s.forEach((e=>{o.push(this.writeSsrcLine(e))})),null===(n=e.rids)||void 0===n||n.forEach((e=>{o.push(this.writeRidLine(e))})),e.simulcast&&o.push(this.writeSimulcastLine(e.simulcast)),null===(r=e.candidates)||void 0===r||r.forEach((e=>{o.push(this.writeCandidateLine(e))})),e.remoteCandidates&&o.push(this.writeRemoteCandidatesLine(e.remoteCandidates)),e.endOfCandidates&&o.push(this.writeEndOfCandidatesLine()),o.join("\r\n")+"\r\n"}static parse(e){const t={session:null,media:[],application:[],unsupported:[],mids:[]},i=this.splitSections(e);return t.session=this.parseSessionSection(i.shift()),i.forEach((e=>{const i=this.parseMediaSection(e);switch(i.type){case"audio":case"video":t.media.push(i);break;case"application":t.application.push(i);break;default:t.unsupported.push(i)}t.mids.push(i.mid)})),t}static write(e){let t=this.writeSessionSection(e.session);const i=new Map;(e.media||[]).forEach((e=>{e&&i.set(e.mid,e)})),(e.application||[]).forEach((e=>{e&&i.set(e.mid,e)})),(e.unsupported||[]).forEach((e=>{e&&i.set(e.mid,e)}));for(const a of e.mids||[]){const e=i.get(a);e&&(t+=this.writeMediaSection(e))}return t}}var He=i(8935);class Qe{static parseSdp(e){return ze.parse(e)}static writeSdp(e){return ze.write(e)}static cloneSdp(e){return"function"==typeof structuredClone?structuredClone(e):this.parseSdp(this.writeSdp(e))}static generateSsrc(){return Math.floor(4294967294*Math.random())+1}static generateId(){return Math.random().toString(36).substring(2,12)}static generateSessionId(){return Math.random().toString().substring(2,22)}static generateUuid(){const e=Array.from(Array(256).keys()).map((e=>e.toString(16).padStart(2,"0"))),t=crypto.getRandomValues(new Uint8Array(16));return t[6]=15&t[6]|64,t[8]=63&t[8]|128,Array.from(t.entries()).map((t=>{let[i,a]=t;return[4,6,8,10].includes(i)?"-".concat(e[a]):e[a]})).join("")}static getSessionBoilerplate(){return"v=\r\no=- ".concat(this.generateSessionId()," 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n")}static getNtpSeconds(){return Math.floor((Date.now()+(Date.UTC(1970,0,1)-Date.UTC(1900,0,1)))/1e3)}static findHeaderExtensionByUri(e,t){for(const[i,a]of e.extensionMap)if(a.uri===t)return i;return-1}static addHeaderExtension(e,t){const{id:i}=t;return e.extensionMap.set(i,t),!0}static removeHeaderExtensionByUri(e,t){let i=!1;return e.extensionMap.forEach(((e,a,s)=>{e.uri===t&&(s.delete(a),i=!0)})),i}static removeMidRidHeaderExtensions(e){e.extensionMap.forEach(((e,t,i)=>{/^urn:ietf:params:rtp-hdrext:sdes:(?:mid|rtp-stream-id|repaired-rtp-stream-id)$/.test(e.uri)&&i.delete(t)}))}static hasRecvVideoOrientation(e){const t=e.media.find((e=>"video"===e.type&&"recvonly"===e.direction));return!!t&&-1!==Qe.findHeaderExtensionByUri(t,"urn:3gpp:video-orientation")}static updateCodecParameters(e,t,i,a,s,n){e.media.filter((e=>e.type===t&&e.direction===i)).forEach((e=>Qe.updateMLineCodecParameters(e,a,s,n)))}static updateMLineCodecParameters(e,t,i,a){e.codecs.filter((e=>e.codecName===t)).forEach((e=>{null==i||i.forEach(((t,i)=>{e.codecParams.set(i,t)})),null==a||a.forEach((t=>{e.rtcpFbParams.push(t)}))}))}static updateCodecParametersByMid(e,t,i,a){e.media.filter((e=>e.mid===t)).forEach((e=>Qe.updateMLineCodecParameters(e,i,a)))}static filterCodecs(e,t){e.media.forEach((e=>{if(!e.codecs.length)return;const i=[];e.codecs.forEach((a=>{t&&!t(a,e)||i.push(a.payloadType)})),e.codecs.forEach((e=>{i.includes(e.associatedPayloadType)&&i.push(e.payloadType)})),e.formats=e.formats.filter((e=>i.includes(parseInt(e,10)))),e.codecs=e.codecs.filter((e=>i.includes(e.payloadType)))})),e.media=e.media.filter((e=>e.formats.length))}static filterH264Profiles(e,t,i){e.media.filter((e=>e.direction===t)).forEach((e=>{const t=[];e.codecs.filter((e=>"H264"===e.codecName)).forEach((e=>{var a;const s=parseInt(null===(a=e.codecParams.get("profile-level-id"))||void 0===a?void 0:a.substring(0,2),16);i.includes(s)&&t.push(e.payloadType)})),e.codecs.forEach((e=>{t.includes(e.associatedPayloadType)&&t.push(e.payloadType)})),e.formats=e.formats.filter((e=>t.includes(parseInt(e,10)))),e.codecs=e.codecs.filter((e=>t.includes(e.payloadType)))}))}static getH264ProfileIds(e,t,i){const a=new Set,s=e.media.find((e=>"video"===e.type&&e.direction===t));return null==s||s.codecs.forEach((e=>{if("H264"===e.codecName&&(void 0===i||parseInt(e.codecParams.get("packetization-mode"))===i)){var t;const i=parseInt(null===(t=e.codecParams.get("profile-level-id"))||void 0===t?void 0:t.substring(0,2),16);i&&a.add(i)}})),Array.from(a.values())}static getMediaStartBandwidth(e){var t;const i=null==e||null===(t=e.codecs[0])||void 0===t?void 0:t.codecParams.get("x-google-start-bitrate");return 1e3*parseInt(i,10)||void 0}static mungeEgressLocalOffer(e,t,i){let a,s,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],r=0;if(e.media.forEach((e=>{const{extensionMap:t,type:i,direction:s}=e;t.forEach(((e,t)=>{t>r&&(r=t)})),"video"!==i||"sendonly"!==s||a||(a=e)})),!a)throw new Error("Failed to find a video media section for send");if(a.msid){a.msid.streamId=i;const{trackId:e}=a.msid;s="".concat(i," ").concat(e)}else s="".concat(i," ").concat(Qe.generateUuid());if(t>1&&n){a.rids=[],a.simulcast=null,a.ssrcs=[],a.ssrcGroups=[];const e=a.codecs.some((e=>"rtx"===e.codecName)),i=[],n=Qe.generateUuid();for(let r=0;r<t;r++){const t=Qe.generateSsrc();if(i.push(t),a.ssrcs.push({ssrc:t,attribute:"cname:"+n}),a.ssrcs.push({ssrc:t,attribute:"msid:"+s}),e){const e=Qe.generateSsrc();a.ssrcs.push({ssrc:e,attribute:"cname:"+n}),a.ssrcs.push({ssrc:e,attribute:"msid:"+s}),a.ssrcGroups.push({semantics:"FID",ssrcs:[t,e]})}}a.ssrcGroups.push({semantics:"SIM",ssrcs:i})}(0,He.n_)()&&(0,He.nr)()&&15===(0,He.Cd)()&&1===(0,He.w_)()||Qe.removeHeaderExtensionByUri(a,"urn:3gpp:video-orientation");const o={uri:"http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time"};if(-1===Qe.findHeaderExtensionByUri(a,o.uri)&&(o.id=++r,Qe.addHeaderExtension(a,o)),t>1){e.session.extMapAllowMixed=!0;const t={uri:"http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00"};-1===Qe.findHeaderExtensionByUri(a,t.uri)&&(t.id=++r,Qe.addHeaderExtension(a,t))}}static mungeEgressOfferToRemote(e){e.session.timing={startTime:Qe.getNtpSeconds(),stopTime:0};const t=e.media.find((e=>"video"===e.type&&"sendonly"===e.direction));if((0,He.gm)()&&null!=t&&t.simulcast){t.rids=null,t.simulcast=null;const e=[];t.ssrcGroups.forEach((t=>{"FID"===t.semantics&&e.push(t.ssrcs[0])})),t.ssrcGroups.push({semantics:"SIM",ssrcs:e})}}static mungeEgressAnswer(e,t,i){if((0,He.gm)()&&t>1){const i=e.media.find((e=>"video"===e.type&&"recvonly"===e.direction));if(i){const e=[];for(let i=0;i<t;i++)e.push({rid:i.toString(),direction:"recv"});const a={direction:"recv",rids:[]};e.forEach((e=>{a.rids.push({id:e.rid})})),i.rids=e,i.simulcast=a}}i&&Qe.updateCodecParameters(e,"video","recvonly","H264",i)}static mungeIngressLocalOffer(e,t,i){Qe.updateCodecParameters(e,"video","recvonly","H264",t,i)}static getIceCredential(e){const t=e.session||{};if(t.iceUfrag&&t.icePwd)return{iceUfrag:t.iceUfrag,icePwd:t.icePwd};const i=[...e.media||[],...e.application||[]].find((e=>(null==e?void 0:e.iceUfrag)&&(null==e?void 0:e.icePwd)));return i?{iceUfrag:i.iceUfrag,icePwd:i.icePwd}:null}static updateIceCredential(e,t){const{ice_pwd:i,ice_ufrag:a}=t;e.session&&(e.session.icePwd=i,e.session.iceUfrag=a),e.media.forEach((e=>{e&&(e.icePwd=i,e.iceUfrag=a)})),e.application.forEach((e=>{e.icePwd=i,e.iceUfrag=a}))}static getSSRCByMid(e,t){var i;let a;const s=e.media.find((e=>e.mid==t));return null!=s&&null!==(i=s.ssrcs)&&void 0!==i&&i.length&&(a=s.ssrcs[0].ssrc),a}static getMlineCodecFromLocalOffer(e,t,i){var a;return null===(a=e.media.find((e=>t===e.mid)))||void 0===a?void 0:a.codecs.find((e=>e.codecName===i))}static updateStreamIdByMid(e,t,i){const a=e.media.find((e=>e.mid===t));if(null!=a&&a.msid){const{trackId:e}=a.msid;a.msid.streamId=i,a.ssrcs&&a.ssrcs.forEach((t=>{0===t.attribute.indexOf("msid")&&(t.attribute="msid:".concat(i," ").concat(e))}))}}}const qe=[{layerId:4,width:1920,height:1080,maxFramerate:30,minBitrate:2e6,targetBitrate:4e6,maxBitrate:4e6},{layerId:4,width:1600,height:900,maxFramerate:30,minBitrate:15e5,targetBitrate:25e5,maxBitrate:25e5},{layerId:3,width:1280,height:720,maxFramerate:30,minBitrate:8e5,targetBitrate:2e6,maxBitrate:2e6},{layerId:3,width:960,height:540,maxFramerate:30,minBitrate:55e4,targetBitrate:12e5,maxBitrate:12e5},{layerId:2,width:640,height:360,maxFramerate:30,minBitrate:25e4,targetBitrate:5e5,maxBitrate:7e5},{layerId:2,width:480,height:270,maxFramerate:30,minBitrate:18e4,targetBitrate:35e4,maxBitrate:45e4},{layerId:1,width:320,height:180,maxFramerate:30,minBitrate:1e5,targetBitrate:15e4,maxBitrate:2e5},{layerId:1,width:256,height:144,maxFramerate:30,minBitrate:6e4,targetBitrate:1e5,maxBitrate:13e4}];function Ye(e){const t=e.map(((e,t)=>Object.assign(Object.assign({},e),{formatIndex:t})));u.setLayersSettings(t)}function Ke(e){u.setEnabledLayerIds(e)}function Je(){return u.getLayersSettings()}function Xe(){return u.getEnabledLayerIds()}function Ze(){const e=Xe();return e[e.length-1]}function $e(e){return Je().find((t=>t.layerId===e))}function et(e){const t=Je();for(let i=t.length-1;i>=0;i--)if(t[i].layerId===e)return t[i]}function tt(e){return Je().find((t=>t.width<=e.width))}function it(e){var t;return(null===(t=$e(e))||void 0===t?void 0:t.maxBitrate)||0}function at(e){var t;return(null===(t=$e(e))||void 0===t?void 0:t.targetBitrate)||0}function st(e){var t;return(null===(t=et(e))||void 0===t?void 0:t.minBitrate)||0}function nt(e){const t=e.width*e.height;return t>921600?4:t>307200?3:t>76800?2:t>19200?1:t>0?0:-1}function rt(e,t){return e.width===t.width&&e.height===t.height}function ot(e){var t,i;return!!(null===(i=null===(t=u.get("videoSettings"))||void 0===t?void 0:t.preferSoftwareCodec)||void 0===i?void 0:i[e])}class ct{constructor(e){this._array=new Array(e),this._size=e,this._index=0,this._count=0}get size(){return this._size}get count(){return this._count}empty(){return 0===this._count}full(){return this._count===this._size}clear(){this._array=new Array(this._size),this._index=0,this._count=0}fill(e){return this._array.fill(e),this._index=0,this._count=this._size,this}get lastIndex(){return 0===this._index?this._size-1:this._index-1}nextIndex(e){return(e+1)%this._size}push(e){this._array[this._index]=e,this._index=this.nextIndex(this._index),this._count<this._size&&this._count++}pop(){if(this.empty())return;const e=this.lastIndex;return this._index=e,this._count>0&&this._count--,this._array[e]}at(e){if(!(e<0||e>=this._count))return this._array[e]}front(){if(!this.empty())return this._array[this._count<this.size?0:this._index]}back(){if(!this.empty())return this._array[this.lastIndex]}unwrap(){return this._count<this._size?this._array.slice(0,this._count):[...this._array.slice(this._index),...this._array.slice(0,this._index)]}findIndex(e){if(this._count<this._size){for(let t=0;t<this._count;t++)if(e(this._array[t]))return t}else{for(let t=this._index;t<this._size;t++)if(e(this._array[t]))return t;for(let t=0;t<this._index;t++)if(e(this._array[t]))return t}return-1}findLastIndex(e){if(this._count<this._size){for(let t=this._count-1;t>=0;t--)if(e(this._array[t]))return t}else{for(let t=this._size-1;t>=this._index;t--)if(e(this._array[t]))return t;for(let t=this._index-1;t>=0;t--)if(e(this._array[t]))return t}return-1}find(e){const t=this.findIndex(e);return-1===t?void 0:this._array[t]}findLast(e){const t=this.findLastIndex(e);return-1===t?void 0:this._array[t]}}var dt;function lt(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,a)}return i}function ht(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?lt(Object(i),!0).forEach((function(t){(0,o.A)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):lt(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}le.getTracer("WmscStats");class ut{constructor(){this.sendStatsMonitor=new pt({cacheSize:ut.sendStatsCacheSize}),this.recvStatsMonitor=new mt({cacheSize:ut.recvStatsCacheSize}),this.sendUsageStatsEnabled=!1,this.recvUsageStatsEnabled=!1,this.maxEncodingFramerate=30,this.statsCount=0,this.resourceUsageStatsCallback=null}onStats(e){e.forEach((e=>{this.sendStatsMonitor.onStatsReport(e),this.recvStatsMonitor.onStatsReport(e)})),(this.sendUsageStatsEnabled||this.recvUsageStatsEnabled)&&(this.statsCount++,this.statsCount%ut.resourceUsageCheckStatsCount==0&&this._reportResourceUsageStats())}getSendStatsMonitor(){return this.sendStatsMonitor}getRecvStatsMonitor(){return this.recvStatsMonitor}setOptions(e){const{sendUsageStatsEnabled:t,recvUsageStatsEnabled:i,maxEncodingFramerate:a}=e||{};void 0!==t&&(this.sendUsageStatsEnabled=t),void 0!==i&&(this.recvUsageStatsEnabled=i),void 0!==a&&(this.maxEncodingFramerate=a)}start(e){e&&this.setOptions(e),this.sendUsageStatsEnabled&&this.sendStatsMonitor.setOptions({outboundRtpStatsEnabled:!0}),this.sendStatsMonitor.start(),this.recvUsageStatsEnabled&&this.recvStatsMonitor.setOptions({inboundRtpStatsEnabled:!0}),this.recvStatsMonitor.start()}stop(){this.sendStatsMonitor.stop(),this.recvStatsMonitor.stop()}reset(){this.sendStatsMonitor.reset(),this.recvStatsMonitor.reset(),this.statsCount=0}registerOutgoingBitrateStatsCallback(e){this.sendStatsMonitor.outgoingBitrateStatsCallback=e}registerResourceUsageStatsCallback(e){this.resourceUsageStatsCallback=e}_reportResourceUsageStats(){var e;const t={};let i=0;if(this.sendUsageStatsEnabled){const e=this._getSendResourceUsageStats();(null==e?void 0:e.duration)>0&&(t.send=ht({},e),i=Math.max(i,e.timestamp))}if(this.recvUsageStatsEnabled){const e=this._getRecvResourceUsageStats();(null==e?void 0:e.duration)>0&&(t.recv=ht({},e),i=Math.max(i,e.timestamp))}null===(e=this.resourceUsageStatsCallback)||void 0===e||e.call(this,t)}_getSendResourceUsageStats(){const e=this.sendStatsMonitor.getMediaSourceStats();if(!this.sendStatsMonitor.isStarted()||e.empty())return;const t=e.back(),i=e.front(),a=void 0!==t.frames&&void 0!==(null==i?void 0:i.frames)?t.frames-i.frames:void 0,{NONE:s,UNDERUSING:n,NORMAL:r,OVERUSING:o}=L,c=this.sendStatsMonitor.getOutboundRtpStats(),d=1e3/this.maxEncodingFramerate;let l=0,h=0,u=0,p=0,m=0,g=s,S=-1,_=0,v=null,f=-1;for(const[e,t]of c){const e=t.back();if(p=Math.max(p,e.timestamp),t.count<2)continue;const i=t.unwrap();let a=-1;for(let e=1;e<i.length;e++){const t=i[e-1];-1===a&&(a=e-1),i[e].framesEncoded<t.framesEncoded&&(a=e)}if(-1===a)continue;const s=i[a],n=e.framesEncoded-s.framesEncoded,r=e.framesSent-s.framesSent,o=e.timestamp-s.timestamp,c=nt({width:e.frameWidth,height:e.frameHeight});o<ut.resourceUsageMinTimeSlice||(n>0&&(c>S&&(S=c,v=i,f=a),m=Math.max(m,e.timestamp)),l+=n,h+=r,u=Math.max(u,o))}if(v&&v.length>0){const e=v[f],t=v[v.length-1],i=t.framesEncoded-e.framesEncoded,a=t.framesSent-e.framesSent,c=t.timestamp-e.timestamp,l=i>0?1e3*(t.totalEncodeTime-e.totalEncodeTime)/i:0,h=i>0&&void 0!==t.qpSum&&void 0!==e.qpSum?Math.round((t.qpSum-e.qpSum)/i):0;_=h;let u,p,m=s,y=s;if(i>=ut.encodeTimeMinFrameCount&&(m=l>=d*ut.encodeTimeFactorThresholdCritical?o:l<d*ut.encodeTimeFactorThresholdNormal?n:r),t.qualityLimitationDurations)if(u=1e3*(t.qualityLimitationDurations.cpu-e.qualityLimitationDurations.cpu)/c,p=1e3*(t.qualityLimitationDurations.other-e.qualityLimitationDurations.other)/c,u>=ut.qualityLimitationRatioThresholdCritical||p>=ut.qualityLimitationRatioThresholdCritical){y=o;const e="WMSC_Perf_Control: cpuLimitationRatio ".concat(u);le.monitorLog(e),le.globalTrace({logLevel:"log",log:e,tags:["WMSC_Perf_Control"]}),le.snowplowTrace("log","WMSC_Perf_Control: cpuLimitationRatio",null,{wmscEntity:{cpuLimitationRatio:u}},["WMSC_Perf_Control"])}else y=u<ut.qualityLimitationRatioThresholdNormal&&p<ut.qualityLimitationRatioThresholdNormal?n:r;g=m,ae(y,g)>0&&(g=y),"Encoding SSRC ".concat(t.ssrc,", usageState: ").concat(g,", duration: ").concat(Math.round(c)," ms"),", framesEncoded: ".concat(i,", framesSent: ").concat(a,", avgEncodeTime: ").concat(Math.round(l)," ms"),", cpuLimitationRatio: ".concat(u,", otherLimitationRatio: ").concat(p,", avgQp: ").concat(h),", pliCount: ".concat(t.pliCount-e.pliCount,", videoSize: ").concat(S)}return{usageState:g,framesCaptured:a,framesEncoded:l,framesSent:h,duration:u,maxVideoSize:S,maxVideoSizeAvgQp:_,encodeTimestamp:m,timestamp:p}}_getRecvResourceUsageStats(){if(!this.recvStatsMonitor.isStarted())return;const{NONE:e,UNDERUSING:t,NORMAL:i,OVERUSING:a}=L,s=this.recvStatsMonitor.getInboundRtpStats();let n=0,r=0,o=0,c=0,d=0,l=e,h=e,u=-1,p=0,m=0;for(const[E,M]of s){var g,S,_,v,f,y;const s=M.back();if(d=Math.max(d,s.timestamp),M.count<2)continue;const C=M.unwrap();let I=-1;for(let e=1;e<C.length;e++){const t=C[e-1];-1===I&&(I=e-1),C[e].framesDecoded<t.framesDecoded&&(I=e)}if(-1===I)continue;const R=C[I],T=s.framesReceived-R.framesReceived,A=(null!==(g=s.framesDropped)&&void 0!==g?g:0)-(null!==(S=R.framesDropped)&&void 0!==S?S:0),w=s.framesDecoded-R.framesDecoded,b=s.timestamp-R.timestamp,L=nt({width:s.frameWidth,height:s.frameHeight});if(n+=T,r+=A,o+=w,c=Math.max(c,b),0===T||b<ut.resourceUsageMinTimeSlice||L<u)continue;const D=b/T,P=Math.min(1e3*(s.totalDecodeTime-R.totalDecodeTime),b),O=w?P/w:0,N=T?A/T:0,k=(null!==(_=s.freezeCount)&&void 0!==_?_:0)-(null!==(v=R.freezeCount)&&void 0!==v?v:0),V=1e3*((null!==(f=s.totalFreezesDuration)&&void 0!==f?f:0)-(null!==(y=R.totalFreezesDuration)&&void 0!==y?y:0));let B=e,W=e;L>u?(u=L,p=N,m=V):L===u&&(N>p&&(p=N),V>m&&(m=V)),W=p>=ut.decodingFrameDropRateThresholdCritical||m>=b*ut.freezesDurationRatioThresholdCritical?a:p<ut.decodingFrameDropRateThresholdNormal&&m<b*ut.freezesDurationRatioThresholdNormal?t:i,B=w>=ut.decodeTimeMinFrameCount&&O>=D*ut.decodeTimeFactorThresholdCritical&&T>w?a:w>=ut.decodeTimeMinFrameCount&&O<D*ut.decodeTimeFactorThresholdNormal?t:i;const U=s.keyFramesDecoded-R.keyFramesDecoded,F=s.pliCount-R.pliCount;"Decoding SSRC ".concat(E,", usageState: ").concat(B,", networkUsageState: ").concat(W,", duration: ").concat(Math.round(b)," ms"),", framesReceived: ".concat(T,", framesDropped: ").concat(A,", framesDecoded: ").concat(w," (").concat(U,")"),", avgDecodeTime: ".concat(Math.round(O)," ms, freezeCount: ").concat(k,", freezesDuration: ").concat(Math.round(V)," ms"),", pliCount: ".concat(F,", videoSize: ").concat(L),ae(B,l)>0&&(l=B),ae(W,h)>0&&(h=W)}return{usageState:l,networkUsageState:h,framesReceived:n,framesDropped:r,framesDecoded:o,maxVideoSize:u,duration:c,timestamp:d}}}dt=ut,(0,o.A)(ut,"resourceUsageMinTimeSlice",1500),(0,o.A)(ut,"resourceUsageCheckInterval",3e3),(0,o.A)(ut,"resourceUsageCheckStatsCount",Math.floor(dt.resourceUsageCheckInterval/T)),(0,o.A)(ut,"sendStatsCacheSize",dt.resourceUsageCheckStatsCount+1),(0,o.A)(ut,"recvStatsCacheSize",dt.resourceUsageCheckStatsCount+1),(0,o.A)(ut,"encodeTimeMinFrameCount",10),(0,o.A)(ut,"encodeTimeFactorThresholdNormal",.9),(0,o.A)(ut,"encodeTimeFactorThresholdCritical",1.1),(0,o.A)(ut,"qualityLimitationRatioThresholdNormal",.05),(0,o.A)(ut,"qualityLimitationRatioThresholdCritical",.95),(0,o.A)(ut,"decodeTimeMinFrameCount",10),(0,o.A)(ut,"decodeTimeFactorThresholdNormal",.9),(0,o.A)(ut,"decodeTimeFactorThresholdCritical",1.1),(0,o.A)(ut,"decodingFrameDropRateThresholdNormal",.05),(0,o.A)(ut,"decodingFrameDropRateThresholdCritical",.2),(0,o.A)(ut,"freezesDurationRatioThresholdNormal",.05),(0,o.A)(ut,"freezesDurationRatioThresholdCritical",.25);class pt{constructor(e){this.cacheSize=e.cacheSize||10,this.started=!1,this.selectedCandidatePairId=null,this.roundTripTime=0,this.remoteCandidateId=null,this.networkProtocol=null,this.localCandidateId=null,this.candidateType=null,this.outboundRtpStatsEnabled=!1,this.outboundRtpStatsMap=new Map,this.mediaSourceStats=new ct(this.cacheSize),this.outgoingBitrateStatsCallback=null}reset(){this.resetCandidateStats(),this.resetOutboundRtpStats(),this.resetMediaSourceStats()}resetCandidateStats(){this.selectedCandidatePairId=null,this.roundTripTime=0,this.remoteCandidateId=null,this.networkProtocol=null}resetOutboundRtpStats(){this.outboundRtpStatsMap.clear()}resetMediaSourceStats(){this.mediaSourceStats.clear()}setOptions(e){const{outboundRtpStatsEnabled:t}=e||{};void 0!==t&&(this.outboundRtpStatsEnabled=t)}start(e){e&&this.setOptions(e),this.started=!0}stop(){this.started=!1}isStarted(){return this.started}getNetworkProtocol(){return this.networkProtocol}getCurrentRoundTripTime(){return this.roundTripTime}getOutboundRtpStats(){return this.outboundRtpStatsMap}getMediaSourceStats(){return this.mediaSourceStats}onStatsReport(e){if(this.started)switch(e.type){case"transport":this.onTransportStats(e);break;case"candidate-pair":this.onCandidatePairStats(e);break;case"remote-candidate":this.onRemoteCandidateStats(e);break;case"outbound-rtp":this.onOutboundRtpStats(e);break;case"local-candidate":this.onLocalCandidateStats(e);break;case"media-source":this.onMediaSourceStats(e)}}onTransportStats(e){const{selectedCandidatePairId:t,dtlsState:i}=e;"connected"===i&&(this.selectedCandidatePairId=t)}onCandidatePairStats(e){const{id:t,state:i,nominated:a,availableOutgoingBitrate:s,currentRoundTripTime:n,remoteCandidateId:r,timestamp:o,localCandidateId:c}=e;var d;t===this.selectedCandidatePairId&&"succeeded"===i&&a&&(this.roundTripTime=n,this.remoteCandidateId=r,this.localCandidateId=c,null===(d=this.outgoingBitrateStatsCallback)||void 0===d||d.call(this,{availableOutgoingBitrate:s,timestamp:o}))}onRemoteCandidateStats(e){const{id:t,protocol:i,port:a}=e;