@zoom/videosdk
Version:
Zoom Web Video SDK
1 lines • 253 kB
JavaScript
(self.__MEDIA_SDK_CHUNK_LOADER__=self.__MEDIA_SDK_CHUNK_LOADER__||[]).push([[557],{763:(e,t,i)=>{"use strict";i.r(t),i.d(t,{WMSCManager:()=>Ii,eventExt:()=>F});var a={};i.r(a),i.d(a,{TO:()=>E,NS:()=>b,mz:()=>A,GA:()=>R,FK:()=>_,pO:()=>S,fZ:()=>v,Rz:()=>D,r3:()=>w,By:()=>L,ey:()=>y,rF:()=>T,wK:()=>g,LA:()=>N,tT:()=>V,ul:()=>u,j$:()=>m,Y7:()=>p,RJ:()=>h,bl:()=>M,Dz:()=>P,c$:()=>O,lN:()=>C,zk:()=>k,nd:()=>r,ue:()=>B,pg:()=>f,S$:()=>I,tP:()=>s,qe:()=>U});var s,n,r,o,c=i(7857),d=i(129),l=i.n(d);!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"}(s||(s={})),function(e){e[e._90P=0]="_90P",e[e._180P=1]="_180P",e[e._360P=2]="_360P",e[e._720P=3]="_720P",e[e._1080P=4]="_1080P",e[e._2160P=5]="_2160P"}(n||(n={})),function(e){e[e.AUDIO=1]="AUDIO",e[e.VIDEO=2]="VIDEO",e[e.SHARE=3]="SHARE"}(r||(r={})),function(e){e[e.VIDEO=1]="VIDEO",e[e.AUDIO=2]="AUDIO",e[e.SHARE=3]="SHARE"}(o||(o={}));const h=0;var u;!function(e){e[e.IDLE=0]="IDLE",e[e.CONNECTING=1]="CONNECTING",e[e.CONNECTED=2]="CONNECTED"}(u||(u={}));const m=6e3,p=2e3,g=1e4,S=3,_=3,v=3,f=15e3;var y,M,C;!function(e){e.STREAM="STREAM",e.SDP="SDP",e.PC_STATE_CHANGE="PC_STATE_CHANGE",e.UPDATE_BITRATE="UPDATE_BITRATE",e.ERROR="ERROR"}(y||(y={})),function(e){e.LAYERS_UPDATE="LAYERS_UPDATE",e.MIN_BITRATE_UPDATE="MIN_BITRATE_UPDATE",e.ENCODER_RESET="ENCODER_RESET"}(M||(M={})),function(e){e[e.NONE=0]="NONE",e[e.UNDERUSING=1]="UNDERUSING",e[e.NORMAL=2]="NORMAL",e[e.OVERUSING=3]="OVERUSING"}(C||(C={}));const E=1;var I;!function(e){e[e.PLAIN=0]="PLAIN",e[e.GZIP_BASE64=1]="GZIP_BASE64"}(I||(I={}));const T=2,R=100,A=62464,b=17120,w=26,D=w+1,L=16,P=299,O=6;var V,N,k,B;!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"}(V||(V={})),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"}(N||(N={})),function(e){e[e.ICE=0]="ICE",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"}(k||(k={})),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"}(B||(B={}));const U="WMSC_DETECT_CANPLAY_VIDEO",x=new class{constructor(){this.confId="",this.nodeId="",this.webrtcMode=0,this.isMacIntel=!1,this.videoSettings={maxCaptureVideoSize:4,maxRecvVideoNum:w,hdVideoEnabled:!1},this._enabledLayerIds=[],this._layersSettings=null,this.iceServers=[]}setConfig(e){const{confId:t,nodeId:i,webrtcMode:a,isMacIntel:s,videoSettings:n,qosOptions:r,iceServers:o,avSyncMode:c}=e;void 0!==t&&(this.confId=t),void 0!==i&&(this.nodeId=i),void 0!==a&&(this.webrtcMode=a),void 0!==s&&(this.isMacIntel=s),void 0!==n&&(this.videoSettings=Object.assign(Object.assign({},this.videoSettings),n)),void 0!==r&&(this.qosOptions=r),null!=o&&(this.iceServers=o||[]),void 0!==c&&(this.avSyncMode=c)}getConfig(){const{confId:e,nodeId:t,webrtcMode:i,isMacIntel:a,videoSettings:s,qosOptions:n,iceServers:r}=this;return{confId:e,nodeId:t,webrtcMode:i,isMacIntel:a,videoSettings:s,qosOptions:n,iceServers:r}}setEnabledLayerIds(e){this._enabledLayerIds=e}get enabledLayerIds(){return this._enabledLayerIds}setLayersSettings(e){this._layersSettings=e}get layersSettings(){return this._layersSettings}};var F,W,z;!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"}(F||(F={})),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.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_VIDEO_SUBSCRIPTION="UPDATE_VIDEO_SUBSCRIPTION",e.UPDATE_VIDEO_UNSUBSCRIPTION="UPDATE_VIDEO_UNSUBSCRIPTION",e.SDP_NEGOTIATION_FAIL="SDP_NEGOTIATION_FAIL",e.PC_FAIL="PC_FAIL",e.VIDEO_FAIL="VIDEO_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"}(W||(W={})),function(e){e[e.None=0]="None",e[e.App_SYNC=1]="App_SYNC",e[e.WEBRTC_SYNC=2]="WEBRTC_SYNC"}(z||(z={}));var j=i(7201),G=i.n(j),H=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 Q(e){return(4294966272&e)>>>0}function q(e,t){return H(this,void 0,void 0,(function*(){switch(t){case I.GZIP_BASE64:{const t=yield function(e){return H(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 I.PLAIN:return e;default:return null}}))}function Y(e,t){return e.length===t.length&&e.every(((e,i)=>e===t[i]))}function K(e,t){return e-t}function J(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 X(e){var t;let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"|";return e?G()(t=e.toString()).call(t,/[,,]/g,i):""}function Z(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,2),16)===R}function $(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,4),16)===A}function ee(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,4),16)===b}const te=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||s.INFO,this.level=this.level<s.ERROR?s.ERROR:this.level,this.level=this.level>s.VERBOSE?s.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:W.MONITOR,data:e})}directSendMonitorLog(e){e&&this._telemetry&&this._telemetry({type:W.DIRECT_MONITOR,data:e})}globalTrace(e){e&&this._telemetry&&this._telemetry({type:W.GLOBAL_TRACE,data:e})}_verbose(){if(this.level>=s.VERBOSE){const e=[...arguments];return e.unshift("[VERBOSE]"),this._trace("log",e),!0}return!1}_debug(){return this.level>=s.DEBUG&&(this._trace("debug",arguments),!0)}_log(){return this.level>=s.INFO&&(this._trace("log",arguments),!0)}_info(){return this.level>=s.INFO&&(this._trace("info",arguments),!0)}_warn(){return this.level>=s.WARN&&(this._trace("warn",arguments),!0)}_error(){return this.level>=s.ERROR&&(this._trace("error",arguments),!0)}};var ie=i(1265),ae=i.n(ie),se=i(8048),ne=i.n(se);function re(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 oe(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?re(Object(i),!0).forEach((function(t){(0,c.A)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):re(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}class ce{static splitSections(e){return e.split("\r\nm=").map(((e,t)=>t>0?"m="+e:e))}static splitLines(e){return e.split("\r\n")}static parseVersionLine(e){return parseInt(e.substring(2),10)}static writeVersionLine(e){return"v=".concat(e)}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"o=".concat(t," ").concat(i," ").concat(a," ").concat(s," ").concat(n," ").concat(r)}static parseSessionNameLine(e){return e.substring(2)}static writeSessionNameLine(e){return"s=".concat(e)}static parseInformationLine(e){return e.substring(2)}static writeInformationLine(e){return"i=".concat(e)}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"c=".concat(t," ").concat(i," ").concat(a)}static parseBandwidthLine(e){return parseInt(e.substring(7),10)}static writeBandwidthLine(e){return"b=TIAS:".concat(e)}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"t=".concat(t," ").concat(i)}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="a=rtpmap:".concat(t," ").concat(i,"/").concat(a);return null!=s&&(n+="/"+s),n}static parseFmtpLine(e){const t=e.substring(7).match(/^(\d+) (.*)/);if(!t)return null;const i={payloadType:parseInt(t[1],10)};return t[2].includes("=")?i.params=new Map(t[2].split(";").map((e=>ae()(e).call(e).split("=")))):i.plain=t[2],i}static writeFmtpLine(e){const{payloadType:t,params:i,plain:a}=e;let s="a=fmtp:".concat(t," ");return i?(i.forEach(((e,t)=>{null!=e&&(s+="".concat(t,"=").concat(e,";"))})),s=s.slice(0,-1)):s+=a,s}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="a=rtcp-fb:".concat(t);return i.forEach((e=>{a+=" "+e})),a}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,a]=e.split("=");i.set(t,a)})),{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"".concat(t,"=").concat(i)})).join(";")),"a=rid:".concat(t," ").concat(i).concat(s?" "+s:"")}static parseSimulcastLine(e){const t=e.substring(12).match(/^(send|recv) (.*)/);return t?{direction:t[1],rids:t[2].split(";").map((e=>"~"===e[0]?{id:e.substring(1),paused:!0}:{id:e,paused:!1}))}:null}static writeSimulcastLine(e){const{direction:t,rids:i}=e;let a="a=simulcast:".concat(t," ");return i.forEach((e=>{const t=e.paused?"~"+e.id:e.id;a+=t+";"})),a.slice(0,-1)}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]?ne()(t=i[4]).call(t):null}:null}static writeExtensionMapLine(e){const{id:t,direction:i,uri:a,attributes:s}=e;let n="a=extmap:".concat(t);return null!=i&&(n+="/"+i),n+=" "+a,null!=s&&(n+=" "+s),n}static parseMidLine(e){return e.substring(6)}static writeMidLine(e){return"a=mid:".concat(e)}static writeDirectionLine(e){return"a=".concat(e)}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"a=msid:".concat(t," ").concat(i)}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"a=ssrc:".concat(t," ").concat(i)}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="a=ssrc-group:".concat(t);return i.forEach((e=>{a+=" "+e})),a}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="a=group:".concat(t);return i.forEach((e=>{a+=" "+e})),a}static writeExtMapAllowMixedLine(){return"a=extmap-allow-mixed"}static writeRtcpMuxLine(){return"a=rtcp-mux"}static writeRtcpReducedSizeLine(){return"a=rtcp-rsize"}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="a=candidate:".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 parseSessionSection(e){const t={version:0,origin:null,sessionName:null,information:null,connection:null,bandwidth:null,timing:null,groups:[],extMapAllowMixed:null,otherLines:[]},i=this.splitLines(e);for(let e=0;e<i.length;e++){const a=i[e];a.length&&(a.match(/^v=/)?t.version=this.parseVersionLine(a):a.match(/^o=/)?t.origin=this.parseOriginLine(a):a.match(/^s=/)?t.sessionName=this.parseSessionNameLine(a):a.match(/^i=/)?t.information=this.parseInformationLine(a):a.match(/^c=/)?t.connection=this.parseConnectionLine(a):a.match(/^b=TIAS:/)?t.bandwidth=this.parseBandwidthLine(a):a.match(/^t=/)?t.timing=this.parseTimingLine(a):a.match(/^a=group:/)?t.groups.push(this.parseGroupLine(a)):a.match(/^a=extmap-allow-mixed$/)?t.extMapAllowMixed=!0:t.otherLines.push(a))}return t}static writeSessionSection(e){const t=[];return t.push(this.writeVersionLine(e.version)),null!=e.origin&&t.push(this.writeOriginLine(e.origin)),null!=e.sessionName&&t.push(this.writeSessionNameLine(e.sessionName)),null!=e.information&&t.push(this.writeInformationLine(e.information)),null!=e.connection&&t.push(this.writeConnectionLine(e.connection)),null!=e.bandwidth&&t.push(this.writeBandwidthLine(e.bandwidth)),null!=e.timing&&t.push(this.writeTimingLine(e.timing)),e.groups.forEach((e=>{t.push(this.writeGroupLine(e))})),e.extMapAllowMixed&&t.push(this.writeExtMapAllowMixedLine()),e.otherLines.length&&t.push(...e.otherLines),t.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,icePwd:null,iceUfrag: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++){let n;const r=s[e];if(r.length)if(r.match(/^c=/))t.connection=this.parseConnectionLine(r);else if(r.match(/^b=TIAS:/))t.bandwidth=this.parseBandwidthLine(r);else if(r.match(/^a=rtpmap:/)){const e=this.parseRtpMapLine(r);e&&t.codecs.push(oe(oe({},e),{},{codecParams:new Map,rtcpFbParams:[]}))}else if(r.match(/^a=fmtp:/))i.push(r);else if(r.match(/^a=rtcp-fb:/))a.push(r);else if(r.match(/^a=rid:/)){const e=this.parseRidLine(r);e&&t.rids.push(e)}else if(r.match(/^a=simulcast:/)){const e=this.parseSimulcastLine(r);e&&(t.simulcast=e)}else if(r.match(/^a=ssrc:/))t.ssrcs.push(this.parseSsrcLine(r));else if(r.match(/^a=ssrc-group:/))t.ssrcGroups.push(this.parseSsrcGroupLine(r));else if(r.match(/^a=extmap:/)){const e=this.parseExtensionMapLine(r);e&&t.extensionMap.set(e.id,e)}else r.match(/^a=mid:/)?t.mid=this.parseMidLine(r):(n=r.match(/^a=(sendrecv|sendonly|recvonly|inactive)/))?t.direction=n[1]:r.match(/^a=msid:/)?t.msid=this.parseMsidLine(r):r.match(/^a=rtcp-mux$/)?t.rtcpMux=!0:r.match(/^a=rtcp-rsize$/)?t.rtcpReducedSize=!0:r.match(/^a=candidate:/)?t.candidates.push(this.parseCandidateLine(r)):r.match(/^a=rtcp:/)?t.rtcp=r:r.match(/^a=ice-ufrag:/)?t.iceUfrag=r.substring(12):r.match(/^a=ice-pwd:/)?t.icePwd=r.substring(10):t.otherLines.push(r)}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;const r=[];let o="m=".concat(e.type," ").concat(e.port," ").concat(e.protocol);return e.formats.forEach((e=>{o+=" "+e})),r.push(o),e.connection&&r.push(this.writeConnectionLine(e.connection)),e.bandwidth&&r.push(this.writeBandwidthLine(e.bandwidth)),e.rtcp&&r.push(e.rtcp),e.iceUfrag&&r.push("a=ice-ufrag:".concat(e.iceUfrag)),e.icePwd&&r.push("a=ice-pwd:".concat(e.icePwd)),e.otherLines.length&&r.push(...e.otherLines),r.push(this.writeMidLine(e.mid)),e.extensionMap.size&&e.extensionMap.forEach(((e,t)=>{r.push(this.writeExtensionMapLine(e))})),e.direction&&r.push(this.writeDirectionLine(e.direction)),e.msid&&r.push(this.writeMsidLine(e.msid)),e.rtcpMux&&r.push(this.writeRtcpMuxLine()),e.rtcpReducedSize&&r.push(this.writeRtcpReducedSizeLine()),e.codecs.forEach((e=>{const{payloadType:t,codecName:i,clockRate:a,channels:s,codecParams:n,fmtpLines:o,rtcpFbParams:c}=e;r.push(this.writeRtpMapLine({payloadType:t,codecName:i,clockRate:a,channels:s})),c.forEach((e=>{r.push(this.writeRtcpFbLine({payloadType:t,params:e}))})),n.size&&r.push(this.writeFmtpLine({payloadType:t,params:n})),null==o||o.forEach((e=>{r.push(this.writeFmtpLine({payloadType:t,plain:e}))}))})),null===(t=e.wildcardRtcpFb)||void 0===t||t.forEach((e=>{r.push(this.writeRtcpFbLine({payloadType:"*",params:e}))})),null===(i=e.ssrcGroups)||void 0===i||i.forEach((e=>{r.push(this.writeSsrcGroupLine(e))})),null===(a=e.ssrcs)||void 0===a||a.forEach((e=>{r.push(this.writeSsrcLine(e))})),null===(s=e.rids)||void 0===s||s.forEach((e=>{r.push(this.writeRidLine(e))})),e.simulcast&&r.push(this.writeSimulcastLine(e.simulcast)),null===(n=e.candidates)||void 0===n||n.forEach((e=>{r.push(this.writeCandidateLine(e))})),r.join("\r\n")+"\r\n"}static parse(e){const t={session:null,media:[],application:[]},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)}})),t}static write(e){let t=this.writeSessionSection(e.session);return e.media.forEach((e=>{t+=this.writeMediaSection(e)})),e.application.forEach((e=>{t+=this.writeMediaSection(e)})),t}}var de=i(8935);class le{static parseSdp(e){return ce.parse(e)}static writeSdp(e){return ce.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 generateIceCredentials(){const e=e=>[...Array(e)].map((()=>Math.random().toString(36).charAt(2))).join("");return{ice_ufrag:e(8),ice_pwd:e(22)}}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 updateCodecParameters(e,t,i,a,s,n){e.media.filter((e=>e.type===t&&e.direction===i)).forEach((e=>le.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=>le.updateMLineCodecParameters(e,i,a)))}static filterCodecs(e,t){e.media.forEach((e=>{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(le.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=le.generateUuid();for(let r=0;r<t;r++){const t=le.generateSsrc();if(i.push(t),a.ssrcs.push({ssrc:t,attribute:"cname:"+n}),a.ssrcs.push({ssrc:t,attribute:"msid:"+s}),e){const e=le.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})}le.removeMidRidHeaderExtensions(a),(0,de.n_)()&&(0,de.nr)()&&15===(0,de.Cd)()&&1===(0,de.w_)()||le.removeHeaderExtensionByUri(a,"urn:3gpp:video-orientation");const o={uri:"http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time"};if(-1===le.findHeaderExtensionByUri(a,o.uri)&&(o.id=++r,le.addHeaderExtension(a,o)),t>1){e.session.extMapAllowMixed=!0;const t={uri:"http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00"};-1===le.findHeaderExtensionByUri(a,t.uri)&&(t.id=++r,le.addHeaderExtension(a,t))}}static mungeEgressOfferToRemote(e){e.session.timing={startTime:le.getNtpSeconds(),stopTime:0};const t=e.media.find((e=>"video"===e.type&&"sendonly"===e.direction));if((0,de.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})}(0,de.gm)()&&e.media.forEach((e=>{"video"===e.type&&"recvonly"===e.direction&&e.codecs.forEach((e=>{"H264"===e.codecName&&"42e01f"===e.codecParams.get("profile-level-id")&&e.codecParams.set("profile-level-id","64001f")}))}))}static mungeEgressAnswer(e,t,i){if((0,de.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}}(0,de.gm)()&&e.media.forEach((e=>{"video"===e.type&&"sendonly"===e.direction&&e.codecs.forEach((e=>{"H264"===e.codecName&&"64001f"===e.codecParams.get("profile-level-id")&&e.codecParams.set("profile-level-id","42e01f")}))})),i&&le.updateCodecParameters(e,"video","recvonly","H264",i)}static mungeIngressLocalOffer(e,t,i){le.updateCodecParameters(e,"video","recvonly","H264",t,i)}static updateIceCredential(e,t){const{ice_pwd:i,ice_ufrag:a}=t;e.media.forEach((e=>{e&&(e.icePwd=i,e.iceUfrag=a)}))}static getSSRCByMid(e,t){let i;const a=e.media.find((e=>e.mid==t)),{ssrcs:s}=a;return s.length&&(i=s[0].ssrc),i}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(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 he=[{layerId:4,width:1920,height:1080,maxFramerate:30,minBitrate:25e5,targetBitrate:5e6,maxBitrate:5e6},{layerId:4,width:1600,height:900,maxFramerate:30,minBitrate:15e5,targetBitrate:3e6,maxBitrate:3e6},{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 ue(e){const t=e.map(((e,t)=>Object.assign(Object.assign({},e),{formatIndex:t})));x.setLayersSettings(t)}function me(e){x.setEnabledLayerIds(e)}function pe(){return x.layersSettings}function ge(){return x.enabledLayerIds}function Se(){return ge()[0]}function _e(e){return ge().includes(e)}function ve(){const e=ge();return e[e.length-1]}function fe(e){var t;return null===(t=pe())||void 0===t?void 0:t[e]}function ye(e){const t=pe();if(!t)return;const i=t.findIndex((t=>t.layerId===e));return i>=0?fe(i):void 0}function Me(e){const t=pe();if(t)for(let i=t.length-1;i>=0;i--)if(t[i].layerId===e)return fe(i)}function Ce(e){const t=pe();if(!t)return;const i=t.findIndex((t=>t.layerId<=e));return i>=0?fe(i):void 0}function Ee(e){var t;return(null===(t=ye(e))||void 0===t?void 0:t.targetBitrate)||0}function Ie(e,t){const i=ye(e);if(i){const{width:e,height:a,maxBitrate:s}=i;return Math.floor(t.width*t.height/(e*a)*s)}}function Te(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 Re(e){var t,i;return!!(null===(i=null===(t=x.videoSettings)||void 0===t?void 0:t.preferSoftwareCodec)||void 0===i?void 0:i[e])}class Ae{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(!(this._count<this._size&&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]}}function be(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 we(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?be(Object(i),!0).forEach((function(t){(0,c.A)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):be(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}te.getTracer("WmscStats");class De{constructor(){this.sendStatsMonitor=new Le({cacheSize:De.sendStatsCacheSize}),this.recvStatsMonitor=new Pe({cacheSize:De.recvStatsCacheSize}),this.sendUsageStatsEnabled=!1,this.recvUsageStatsEnabled=!1,this.maxEncodingFramerate=30,this.resourceUsageStatsReportTimestamp=0,this.resourceUsageStatsIntervalId=null,this.resourceUsageStatsCallback=null}onStats(e){e.forEach((e=>{this.sendStatsMonitor.onStatsReport(e),this.recvStatsMonitor.onStatsReport(e)}))}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(),(this.sendUsageStatsEnabled||this.recvUsageStatsEnabled)&&(this.resourceUsageStatsIntervalId=setInterval((()=>{this._reportResourceUsageStats()}),De.resourceUsageCheckInterval))}stop(){this.sendStatsMonitor.stop(),this.recvStatsMonitor.stop(),clearInterval(this.resourceUsageStatsIntervalId),this.resourceUsageStatsIntervalId=null}reset(){this.sendStatsMonitor.reset(),this.recvStatsMonitor.reset(),this.resourceUsageStatsReportTimestamp=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=we({},e),i=Math.max(i,e.timestamp))}if(this.recvUsageStatsEnabled){const e=this._getRecvResourceUsageStats();(null==e?void 0:e.duration)>0&&(t.recv=we({},e),i=Math.max(i,e.timestamp))}this.resourceUsageStatsReportTimestamp=i,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=Math.max(this.resourceUsageStatsReportTimestamp-500,t.timestamp-De.resourceUsageCheckInterval-500),a=e.find((e=>e.timestamp>i)),s=void 0!==t.frames&&void 0!==(null==a?void 0:a.frames)?t.frames-a.frames:void 0,{NONE:n,UNDERUSING:r,NORMAL:o,OVERUSING:c}=C,d=this.sendStatsMonitor.getOutboundRtpStats(),l=1e3/this.maxEncodingFramerate;let h=0,u=0,m=0,p=0,g=0,S=n,_=-1,v=0,f=null,y=-1;for(const[e,t]of d){const e=t.back();if(p=Math.max(p,e.timestamp),t.count<2)continue;const i=t.unwrap(),a=Math.max(this.resourceUsageStatsReportTimestamp-500,e.timestamp-De.resourceUsageCheckInterval-500);let s=-1;for(let e=1;e<i.length;e++){const t=i[e-1],n=i[e];t.timestamp>a&&(-1===s&&(s=e-1),n.framesEncoded<t.framesEncoded&&(s=e))}if(-1===s)continue;const n=i[s],r=e.framesEncoded-n.framesEncoded,o=e.framesSent-n.framesSent,c=e.timestamp-n.timestamp,d=Te({width:e.frameWidth,height:e.frameHeight});c<De.resourceUsageMinTimeSlice||(r>0&&(d>_&&(_=d,f=i,y=s),g=Math.max(g,e.timestamp)),h+=r,u+=o,m=Math.max(m,c))}if(f&&f.length>0){const e=f[y],t=f[f.length-1],i=t.framesEncoded-e.framesEncoded,a=t.framesSent-e.framesSent,s=t.timestamp-e.timestamp,d=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;v=h;let u,m,p=n,g=n;if(i>=De.encodeTimeMinFrameCount&&(p=d>=l*De.encodeTimeFactorThresholdCritical?c:d<l*De.encodeTimeFactorThresholdNormal?r:o),t.qualityLimitationDurations)if(u=1e3*(t.qualityLimitationDurations.cpu-e.qualityLimitationDurations.cpu)/s,m=1e3*(t.qualityLimitationDurations.other-e.qualityLimitationDurations.other)/s,u>=De.qualityLimitationRatioThresholdCritical||m>=De.qualityLimitationRatioThresholdCritical){g=c;const e="WMSC_Perf_Control: cpuLimitationRatio ".concat(u);te.monitorLog(e),te.globalTrace({logLevel:"log",log:e,tags:["WMSC_Perf_Control"]})}else g=u<De.qualityLimitationRatioThresholdNormal&&m<De.qualityLimitationRatioThresholdNormal?r:o;S=p,K(g,S)>0&&(S=g),"Encoding SSRC ".concat(t.ssrc,", usageState: ").concat(S,", duration: ").concat(Math.round(s)," ms"),", framesEncoded: ".concat(i,", framesSent: ").concat(a,", avgEncodeTime: ").concat(Math.round(d)," ms"),", cpuLimitationRatio: ".concat(u,", otherLimitationRatio: ").concat(m,", avgQp: ").concat(h),", pliCount: ".concat(t.pliCount-e.pliCount,", videoSize: ").concat(_)}return{usageState:S,framesCaptured:s,framesEncoded:h,framesSent:u,duration:m,maxVideoSize:_,maxVideoSizeAvgQp:v,encodeTimestamp:g,timestamp:p}}_getRecvResourceUsageStats(){if(!this.recvStatsMonitor.isStarted())return;const{NONE:e,UNDERUSING:t,NORMAL:i,OVERUSING:a}=C,s=this.recvStatsMonitor.getInboundRtpStats();let n=0,r=0,o=0,c=0,d=0,l=e,h=e,u=-1,m=0,p=0;for(const[M,C]of s){var g,S,_,v,f,y;const s=C.back();if(d=Math.max(d,s.timestamp),C.count<2)continue;const E=C.unwrap(),I=Math.max(this.resourceUsageStatsReportTimestamp-500,s.timestamp-De.resourceUsageCheckInterval-500);let T=-1;for(let e=1;e<E.length;e++){const t=E[e-1],i=E[e];t.timestamp>I&&(-1===T&&(T=e-1),i.framesDecoded<t.framesDecoded&&(T=e))}if(-1===T)continue;const R=E[T],A=s.framesReceived-R.framesReceived,b=(null!==(g=s.framesDropped)&&void 0!==g?g:0)-(null!==(S=R.framesDropped)&&void 0!==S?S:0),w=s.framesDecoded-R.framesDecoded,D=s.timestamp-R.timestamp,L=Te({width:s.frameWidth,height:s.frameHeight});if(n+=A,r+=b,o+=w,c=Math.max(c,D),0===A||D<De.resourceUsageMinTimeSlice||L<u)continue;const P=D/A,O=Math.min(1e3*(s.totalDecodeTime-R.totalDecodeTime),D),V=w?O/w:0,N=A?b/A:0,k=(null!==(_=s.freezeCount)&&void 0!==_?_:0)-(null!==(v=R.freezeCount)&&void 0!==v?v:0),B=1e3*((null!==(f=s.totalFreezesDuration)&&void 0!==f?f:0)-(null!==(y=R.totalFreezesDuration)&&void 0!==y?y:0));let U=e,x=e;L>u?(u=L,m=N,p=B):L===u&&(N>m&&(m=N),B>p&&(p=B)),x=m>=De.decodingFrameDropRateThresholdCritical||p>=D*De.freezesDurationRatioThresholdCritical?a:m<De.decodingFrameDropRateThresholdNormal&&p<D*De.freezesDurationRatioThresholdNormal?t:i,U=w>=De.decodeTimeMinFrameCount&&V>=P*De.decodeTimeFactorThresholdCritical&&A>w?a:w>=De.decodeTimeMinFrameCount&&V<P*De.decodeTimeFactorThresholdNormal?t:i;const F=s.keyFramesDecoded-R.keyFramesDecoded,W=s.pliCount-R.pliCount;"Decoding SSRC ".concat(M,", usageState: ").concat(U,", networkUsageState: ").concat(x,", duration: ").concat(Math.round(D)," ms"),", framesReceived: ".concat(A,", framesDropped: ").concat(b,", framesDecoded: ").concat(w," (").concat(F,")"),", avgDecodeTime: ".concat(Math.round(V)," ms, freezeCount: ").concat(k,", freezesDuration: ").concat(Math.round(B)," ms"),", pliCount: ".concat(W,", videoSize: ").concat(L),K(U,l)>0&&(l=U),K(x,h)>0&&(h=x)}return{usageState:l,networkUsageState:h,framesReceived:n,framesDropped:r,framesDecoded:o,maxVideoSize:u,duration:c,timestamp:d}}}(0,c.A)(De,"sendStatsCacheSize",4),(0,c.A)(De,"recvStatsCacheSize",4),(0,c.A)(De,"resourceUsageMinTimeSlice",1500),(0,c.A)(De,"resourceUsageCheckInterval",3e3),(0,c.A)(De,"encodeTimeMinFrameCount",10),(0,c.A)(De,"encodeTimeFactorThresholdNormal",.9),(0,c.A)(De,"encodeTimeFactorThresholdCritical",1.1),(0,c.A)(De,"qualityLimitationRatioThresholdNormal",.05),(0,c.A)(De,"qualityLimitationRatioThresholdCritical",.95),(0,c.A)(De,"decodeTimeMinFrameCount",10),(0,c.A)(De,"decodeTimeFactorThresholdNormal",.9),(0,c.A)(De,"decodeTimeFactorThresholdCritical",1.1),(0,c.A)(De,"decodingFrameDropRateThresholdNormal",.05),(0,c.A)(De,"decodingFrameDropRateThresholdCritical",.2),(0,c.A)(De,"freezesDurationRatioThresholdNormal",.05),(0,c.A)(De,"freezesDurationRatioThresholdCritical",.25);class Le{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 Ae(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;if(t===this.remoteCandidateId&&!this.networkProtocol){this.networkProtocol=i;const e="WMSC_Network_Change: send|".concat(i,"|").concat(a);te.globalTrace({logLevel:"log",log:e,tags:["WMSC_Network_Change"]}),te.monitorLog(e)}}onLocalCandidateStats(e){const{id:t,candidateType:i}=e;if(t==this.localCandidateId&&this.candidateType!=i){this.candidateType=i;const e="WMSC_LocalCandidatae_Change:send|".concat(i);te.globalTrace({logLevel:"directReport",log:e,tags:["WMSC_LocalCandidatae_Change"]}),te.monitorLog(e)}}onOutboundRtpStats(e){if(!this.outboundRtpStatsEnabled||"video"!==e.kind)return;const{ssrc:t,framesEncoded:i,framesSent:a,totalEncodeTime:s,qualityLimitationDurations:n,pliCount:r,frameWidth:o,frameHeight:c,qpSum:d,timestamp:l}=e;let h=this.outboundRtpStatsMap.get(t);h||(h=new Ae(this.cacheSize),this.outboundRtpStatsMap.set(t,h)),h.push({ssrc:t,framesEncoded:i,framesSent:a,totalEncodeTime:s,qualityLimitationDurations:n,pliCount:r,frameWidth:o,frameHeight:c,qpSum:d,timestamp:l})}onMediaSourceStats(e){if("video"!==e.kind)return;const{frames:t,width:i,height:a,timestamp:s}=e;this.mediaSourceStats.push({frames:t,width:i,height:a,timestamp:s})}}class Pe{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.inboundRtpStatsEnabled=!1,this.inboundRtpStatsMap=new Map}reset(){this.resetCandidateStats(),this.resetInboundRtpStats()}resetCandidateStats(){this.selectedCandidatePairId=null,this.roundTripTime=0,this.remoteCandidateId=null,this.networkProtocol=null}resetInboundRtpStats(){this.inboundRtpStatsMap.clear()}setOptions(e){const{inboundRtpStatsEnabled:t}=e||{};void 0!==t&&(this.inboundRtpStatsEnabled=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}getInboundRtpStats(){return this.inboundRtpStatsMap}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"inbound-rtp":this.onInboundRtpStats(e);break;case"local-candidate":this.onLocalCandidateStats(e)}}onTransportStats(e){const{selectedCandidatePairId:t,dtlsState:i}=e;"connected"===i&&(this.selectedCandidatePairId=t)}onCandidatePairStats(e){const{id:t,state:i,nominated:a,currentRoundTripTime:s,remoteCandidateId:n,localCandidateId:r}=e;t===this.selectedCandidatePairId&&"succeeded"===i&&a&&(this.roundTripTime=s,this.remoteCandidateId=n,this.localCandidateId=r)}onRemoteCandidateStats(e){const{id:t,protocol:i,port:a}=e;if(t===this.remoteCandidateId&&!this.networkProtocol){this.networkProtocol=i;const e="WMSC_Network_Change: recv|".concat(i,"|").concat(a);te.globalTrace({logLevel:"log",log:e,tags:["WMSC_Network_Change"]}),te.monitorLog(e)}}onLocalCandidateStats(e){const{id:t,candidateType:i}=e;if(t==this.localCandidateId&&this.candidateType!=i){this.localCandidateId=t,this.candidateType=i;const e="WMSC_LocalCandidatae_Change:recv|".concat(i);te.globalTrace({logLevel:"directReport",log:e,tags:["WMSC_LocalCandidatae_Change"]}),te.monitorLog(e)}}onInboundRtpStats(e){if(!this.inboundRtpStatsEnabled||"video"!==e.kind||!e.framesReceived)return;const{ssrc:t,framesDecoded:i,framesDropped:a,framesReceived:s,keyFramesDecoded:n,totalDecodeTime:r,totalFreezesDuration:o,freezeCount:c,pliCount:d,frameWidth:l,frameHeight:h,timestamp:u}=e;let m=this.inboundRtpStatsMap.get(t);m||(m=new Ae(this.cacheSize),this.inboundRtpStatsMap.set(t,m)),m.push({ssrc:t,framesDecoded:i,framesDropped:a,framesReceived:s,keyFramesDecoded:n,totalDecodeTime:r,totalFreezesDuration:o,freezeCount:c,pliCount:d,frameWidth:l,frameHeight:h,timestamp:u})}}const Oe=new De;function Ve(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 Ne(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?Ve(Object(i),!0).forEach((function(t){(0,c.A)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):Ve(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}const ke=te.getTracer("WmscQosMgr"),Be=e=>{ke.log(e),te.monitorLog("".concat(e))},Ue=e=>{Be("WMSC_Perf_Control: ".concat(e)),te.globalTrace({logLevel:"log",log:e,tags:["WMSC_Perf_Control"]})},xe=Object.freeze({None:0,Increase:1,Decrease:2}),Fe=Object.freeze({User:0,OutgoingBandwidth:1,ReceiverBandwidth:2,OutgoingBandwidthProbing:3,Other:4}),We=Object.freeze({Low:0,Medium:1,High:2}),ze="NoLayersAllocation";class je{constructor(){this.outgoingBandwidthAdaptationEnabled=!0,this.outgoingBandwidthProbingEnabled=!0,this.outgoingBandwidthFromServer=!1,this.receiverBandwidthAdaptationEnabled=!0,this.additionalSubLayersEnabled=!0,this.reduceTopLayerBitrateEnabled=!0,this.performanceAdaptationEnabled=!0,this.maxEncodingLayers=3,this.sendActive=!1,this.sendActivatedTime=0,this.videoSourceLive=!1,this.videoSourceLiveTime=0,this.pendingLayersUpdate=Promise.resolve(),this.requestedLayerIds=[],this.additionalSubLayerIds=[],this.layersAllocation=[],this.layersAllocationCache=null,this.outgoingBandwidthProbingScheduledTime=0,this.maxSubVideoSize=-1,this.maxFormatIndex=-1,this.feasibleFormatIndex=-1,this.failedEncodings=new Map,this.sendUsageStateHistory=new Ae(je.resourceUsageStateHistorySize),this.sendUsageAdjustments=new Ae(je.resourceUsageAdjustmentHistorySize),this.sendUsageIncreaseFailedAttempts=0,this.sendUsageIncreaseFailedTime=0,this.maxFeasibleRecvSize=T,this.recvUsageStateHistory=new Ae(je.resourceUsageStateHistorySize),this.recvUsageAdjustments=new Ae(je.resourceUsageAdjustmentHistorySize),this.recvUsageIncreaseFailedAttempts=0,this.recvUsageIncreaseFailedTime=0,this.recvNetworkUnderuseStartTime=0,this.outgoingBandwidthReport=null,this.receiverBandwidthReport=null,this.receiverL3BandwidthEvaluation=null,this.receiverBandwidthUpdatePending=!1,this.receiverBandwidthUpdateTimeoutId=null,this.isDualCall=!0,this.audioBandwidth=0,this.videoStartBandwidth=0,this.framingDelayStats=new Ae(je.maxFramingDelayWindowSize),this.decreaseBitrateWindow=5,this.increaseBitrateWindow=5,this.decreaseBitrateRate=.5,this.increaseBitrateRate=.7,this.maxEncodeBitrate=0,this.currentMaxEncodeBitrate=0,this.messageCallback=null,this.maxRecvVideoSizeUpdateCallback=null,this.sendUsageStateUpdateCallback=null,Oe.registerOutgoingBitrateStatsCallback(this.onOutgoingBandwidthStats.bind(this)),Oe.registerResourceUsageStatsCallback(this.onResourceUsageStats.bind(this))}static areLayersAllocationsEqual(e,t){return e.length===t.length&&e.every(((e,i)=>{const a=t[i];return e.layerId===a.layerId&&e.maxBitrate===a.maxBitrate&&(s=e.format,n=a.format,s.width===n.width&&s.height===n.height);var s,n}))}static isBitrateChangeAboveRatio(e,t,i){return!e||Math.abs(t-e)/e>i}static getLayersChangePriority(e){switch(e){case Fe.User:return We.High;case Fe.ReceiverBandwidth:return We.Medium;default:return We.Low}}static getHighestFormatIndex(e){return e.length?e[e.length-1].format.formatIndex:-1}static isBandwidthReason(e){return e===Fe.OutgoingBandwidth||e===Fe.ReceiverBandwidth||e===Fe.OutgoingBandwidthProbing}_resetSendUsageStats(){Oe.getSendStatsMonitor().resetOutboundRtpStats()}_resetRecvUsageStats(){Oe.getRec