UNPKG

@zoom/videosdk

Version:
1 lines 226 kB
(self.webpackChunkJsMediaSDK_Instance=self.webpackChunkJsMediaSDK_Instance||[]).push([[557],{3136:(e,t,i)=>{"use strict";i.r(t),i.d(t,{WMSCManager:()=>mi,eventExt:()=>W});var s={};i.r(s),i.d(s,{TO:()=>I,NS:()=>A,mz:()=>E,GA:()=>b,FK:()=>_,pO:()=>S,fZ:()=>v,Rz:()=>L,r3:()=>w,By:()=>D,ey:()=>M,rF:()=>R,wK:()=>g,LA:()=>B,tT:()=>N,ul:()=>u,j$:()=>m,Y7:()=>p,RJ:()=>h,bl:()=>y,Dz:()=>P,c$:()=>O,lN:()=>C,zk:()=>V,nd:()=>o,ue:()=>k,pg:()=>f,S$:()=>T,tP:()=>a,qe:()=>U});var a,n,o,r,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"}(a||(a={})),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"}(o||(o={})),function(e){e[e.VIDEO=1]="VIDEO",e[e.AUDIO=2]="AUDIO",e[e.SHARE=3]="SHARE"}(r||(r={}));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 M,y,C;!function(e){e.STREAM="STREAM",e.SDP="SDP",e.PC_STATE_CHANGE="PC_STATE_CHANGE",e.UPDATE_BITRATE="UPDATE_BITRATE",e.ERROR="ERROR"}(M||(M={})),function(e){e.LAYERS_UPDATE="LAYERS_UPDATE",e.MIN_BITRATE_UPDATE="MIN_BITRATE_UPDATE",e.ENCODER_RESET="ENCODER_RESET"}(y||(y={})),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 I=1;var T;!function(e){e[e.PLAIN=0]="PLAIN",e[e.GZIP_BASE64=1]="GZIP_BASE64"}(T||(T={}));const R=2,b=100,E=62464,A=17120,w=26,L=w+1,D=16,P=299,O=6;var N,B,V,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"}(N||(N={})),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"}(B||(B={})),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"}(V||(V={})),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 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:s,isMacIntel:a,videoSettings:n,qosOptions:o,iceServers:r}=e;void 0!==t&&(this.confId=t),void 0!==i&&(this.nodeId=i),void 0!==s&&(this.webrtcMode=s),void 0!==a&&(this.isMacIntel=a),void 0!==n&&(this.videoSettings=Object.assign(Object.assign({},this.videoSettings),n)),void 0!==o&&(this.qosOptions=o),null!=r&&(this.iceServers=r||[])}getConfig(){const{confId:e,nodeId:t,webrtcMode:i,isMacIntel:s,videoSettings:a,qosOptions:n,iceServers:o}=this;return{confId:e,nodeId:t,webrtcMode:i,isMacIntel:s,videoSettings:a,qosOptions:n,iceServers:o}}setEnabledLayerIds(e){this._enabledLayerIds=e}get enabledLayerIds(){return this._enabledLayerIds}setLayersSettings(e){this._layersSettings=e}get layersSettings(){return this._layersSettings}};var W,F;!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"}(W||(W={})),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"}(F||(F={}));var z=i(7201),j=i.n(z),G=function(e,t,i,s){return new(i||(i=Promise))((function(a,n){function o(e){try{c(s.next(e))}catch(e){n(e)}}function r(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((s=s.apply(e,t||[])).next())}))};function H(e){return 4294966272&e}function Q(e,t){return G(this,void 0,void 0,(function*(){switch(t){case T.GZIP_BASE64:{const t=yield function(e){return G(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 T.PLAIN:return e;default:return null}}))}function q(e,t){return e.length===t.length&&e.every(((e,i)=>e===t[i]))}function Y(e,t){return e-t}function J(e){var t;let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"|";return e?j()(t=e.toString()).call(t,/[,,]/g,i):""}function K(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,2),16)===b}function X(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,4),16)===E}function Z(){return parseInt((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").substring(0,4),16)===A}const $=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||a.INFO,this.level=this.level<a.ERROR?a.ERROR:this.level,this.level=this.level>a.VERBOSE?a.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:F.MONITOR,data:e})}directSendMonitorLog(e){e&&this._telemetry&&this._telemetry({type:F.DIRECT_MONITOR,data:e})}globalTrace(e){e&&this._telemetry&&this._telemetry({type:F.GLOBAL_TRACE,data:e})}_verbose(){if(this.level>=a.VERBOSE){const e=[...arguments];return e.unshift("[VERBOSE]"),this._trace("log",e),!0}return!1}_debug(){return this.level>=a.DEBUG&&(this._trace("debug",arguments),!0)}_log(){return this.level>=a.INFO&&(this._trace("log",arguments),!0)}_info(){return this.level>=a.INFO&&(this._trace("info",arguments),!0)}_warn(){return this.level>=a.WARN&&(this._trace("warn",arguments),!0)}_error(){return this.level>=a.ERROR&&(this._trace("error",arguments),!0)}};var ee=i(1265),te=i.n(ee),ie=i(8048),se=i.n(ie);function ae(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function ne(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?ae(Object(i),!0).forEach((function(t){(0,c.A)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):ae(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}class oe{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,s,a,n,o]=e.substring(2).split(" ");return{userName:t,sessionId:i,sessionVersion:parseInt(s,10),netType:a,addressType:n,address:o}}static writeOriginLine(e){const{userName:t,sessionId:i,sessionVersion:s,netType:a,addressType:n,address:o}=e;return"o=".concat(t," ").concat(i," ").concat(s," ").concat(a," ").concat(n," ").concat(o)}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,s]=e.substring(2).split(" ");return{netType:t,addressType:i,address:s}}static writeConnectionLine(e){const{netType:t,addressType:i,address:s}=e;return"c=".concat(t," ").concat(i," ").concat(s)}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+) (.*)/),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:s,channels:a}=e;let n="a=rtpmap:".concat(t," ").concat(i,"/").concat(s);return null!=a&&(n+="/"+a),n}static parseFmtpLine(e){const t=e.substring(7).match(/^(\d+) (.*)/),i={payloadType:parseInt(t[1],10)};return t[2].includes("=")?i.params=new Map(t[2].split(";").map((e=>te()(e).call(e).split("=")))):i.plain=t[2],i}static writeFmtpLine(e){const{payloadType:t,params:i,plain:s}=e;let a="a=fmtp:".concat(t," ");return i?(i.forEach(((e,t)=>{null!=e&&(a+="".concat(t,"=").concat(e,";"))})),a=a.slice(0,-1)):a+=s,a}static parseRtcpFbLine(e){const t=e.substring(10).match(/^(\d+) (.*)/);return{payloadType:parseInt(t[1],10),params:t[2].split(" ")}}static writeRtcpFbLine(e){const{payloadType:t,params:i}=e;let s="a=rtcp-fb:".concat(t);return i.forEach((e=>{s+=" "+e})),s}static parseRidLine(e){const t=e.substring(6).match(/^(\S+) (send|recv)/);return{rid:t[1],direction:t[2]}}static writeRidLine(e){const{rid:t,direction:i}=e;return"a=rid:".concat(t," ").concat(i)}static parseSimulcastLine(e){const t=e.substring(12).match(/^(send|recv) (.*)/);return{direction:t[1],rids:t[2].split(";").map((e=>"~"===e[0]?{id:e.substring(1),paused:!0}:{id:e,paused:!1}))}}static writeSimulcastLine(e){const{direction:t,rids:i}=e;let s="a=simulcast:".concat(t," ");return i.forEach((e=>{const t=e.paused?"~"+e.id:e.id;s+=t+";"})),s.slice(0,-1)}static parseExtensionMapLine(e){var t;const i=e.substring(9).match(/^(\d+)(\/sendrecv|\/sendonly|\/recvonly|\/inactive)? (\S+)(\s\S+)?/);return{id:parseInt(i[1],10),direction:i[2]?i[2].substring(1):null,uri:i[3],attributes:i[4]?se()(t=i[4]).call(t):null}}static writeExtensionMapLine(e){const{id:t,direction:i,uri:s,attributes:a}=e;let n="a=extmap:".concat(t);return null!=i&&(n+="/"+i),n+=" "+s,null!=a&&(n+=" "+a),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 s="a=ssrc-group:".concat(t);return i.forEach((e=>{s+=" "+e})),s}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 s="a=group:".concat(t);return i.forEach((e=>{s+=" "+e})),s}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:s,priority:a,address:n,port:o,candType:r,type:c,relAddress:d,relPort:l,candExtensions:h}=e;let u="a=candidate:".concat(t," ").concat(i," ").concat(s," ").concat(a)+" ".concat(n," ").concat(o," ").concat(r," ").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 s=i[e];s.length&&(s.match(/^v=/)?t.version=this.parseVersionLine(s):s.match(/^o=/)?t.origin=this.parseOriginLine(s):s.match(/^s=/)?t.sessionName=this.parseSessionNameLine(s):s.match(/^i=/)?t.information=this.parseInformationLine(s):s.match(/^c=/)?t.connection=this.parseConnectionLine(s):s.match(/^b=TIAS:/)?t.bandwidth=this.parseBandwidthLine(s):s.match(/^t=/)?t.timing=this.parseTimingLine(s):s.match(/^a=group:/)?t.groups.push(this.parseGroupLine(s)):s.match(/^a=extmap-allow-mixed$/)?t.extMapAllowMixed=!0:t.otherLines.push(s))}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,connection:null,bandwidth:null,mid:null,direction:null,msid:null,rtcpMux:null,rtcpReducedSize:null,icePwd:null,iceUfrag:null,rtcp:null,codecs:[],extensionMap:new Map,rids:[],simulcast:null,ssrcs:[],ssrcGroups:[],candidates:[],otherLines:[]},i=[],s=[],a=this.splitLines(e),n=a[0].split(" ");t.type=n[0].substring(2),t.port=parseInt(n[1],10),t.protocol=n[2],t.payloadTypes=n.slice(3).map((e=>parseInt(e,10)));for(let e=1;e<a.length;e++){let n;const o=a[e];if(o.length)if(o.match(/^c=/))t.connection=this.parseConnectionLine(o);else if(o.match(/^b=TIAS:/))t.bandwidth=this.parseBandwidthLine(o);else if(o.match(/^a=rtpmap:/)){const e=this.parseRtpMapLine(o);t.codecs.push(ne({},e))}else if(o.match(/^a=fmtp:/))i.push(o);else if(o.match(/^a=rtcp-fb:/))s.push(o);else if(o.match(/^a=rid:/))t.rids.push(this.parseRidLine(o));else if(o.match(/^a=simulcast:/))t.simulcast=this.parseSimulcastLine(o);else if(o.match(/^a=ssrc:/))t.ssrcs.push(this.parseSsrcLine(o));else if(o.match(/^a=ssrc-group:/))t.ssrcGroups.push(this.parseSsrcGroupLine(o));else if(o.match(/^a=extmap:/)){const e=this.parseExtensionMapLine(o);t.extensionMap.set(e.id,e)}else o.match(/^a=mid:/)?t.mid=this.parseMidLine(o):(n=o.match(/^a=(sendrecv|sendonly|recvonly|inactive)/))?t.direction=n[1]:o.match(/^a=msid:/)?t.msid=this.parseMsidLine(o):o.match(/^a=rtcp-mux$/)?t.rtcpMux=!0:o.match(/^a=rtcp-rsize$/)?t.rtcpReducedSize=!0:o.match(/^a=candidate:/)?t.candidates.push(this.parseCandidateLine(o)):o.match(/^a=rtcp:/)?t.rtcp=o:o.match(/^a=ice-ufrag:/)?t.iceUfrag=o.substring(12):o.match(/^a=ice-pwd:/)?t.icePwd=o.substring(10):t.otherLines.push(o)}return i.forEach((e=>{const i=this.parseFmtpLine(e),s=t.codecs.find((e=>e.payloadType===i.payloadType));s&&(i.params?(s.codecParams=new Map,i.params.forEach(((e,t)=>{"apt"===t&&(s.associatedPayloadType=parseInt(e,10)),s.codecParams.set(t,e)}))):(s.fmtpLines=[i.plain],"red"===s.codecName&&(s.associatedPayloadType=parseInt(i.plain.split("/")[0],10))))})),s.forEach((e=>{const i=this.parseRtcpFbLine(e),s=t.codecs.find((e=>e.payloadType===i.payloadType));s&&(s.rtcpFbParams=s.rtcpFbParams||[],s.rtcpFbParams.push(i.params))})),t}static writeMediaSection(e){var t,i,s,a;const n=[];let o="m=".concat(e.type," ").concat(e.port," ").concat(e.protocol);return e.payloadTypes.forEach((e=>{o+=" "+e})),n.push(o),e.connection&&n.push(this.writeConnectionLine(e.connection)),e.bandwidth&&n.push(this.writeBandwidthLine(e.bandwidth)),e.rtcp&&n.push(e.rtcp),e.iceUfrag&&n.push("a=ice-ufrag:".concat(e.iceUfrag)),e.icePwd&&n.push("a=ice-pwd:".concat(e.icePwd)),e.otherLines.length&&n.push(...e.otherLines),n.push(this.writeMidLine(e.mid)),e.extensionMap.size&&e.extensionMap.forEach(((e,t)=>{n.push(this.writeExtensionMapLine(e))})),n.push(this.writeDirectionLine(e.direction)),e.msid&&n.push(this.writeMsidLine(e.msid)),e.rtcpMux&&n.push(this.writeRtcpMuxLine()),e.rtcpReducedSize&&n.push(this.writeRtcpReducedSizeLine()),e.codecs.forEach((e=>{const{payloadType:t,codecName:i,clockRate:s,channels:a,codecParams:o,fmtpLines:r,rtcpFbParams:c}=e;n.push(this.writeRtpMapLine({payloadType:t,codecName:i,clockRate:s,channels:a})),null==c||c.forEach((e=>{n.push(this.writeRtcpFbLine({payloadType:t,params:e}))})),null!=o&&o.size&&n.push(this.writeFmtpLine({payloadType:t,params:o})),null==r||r.forEach((e=>{n.push(this.writeFmtpLine({payloadType:t,plain:e}))}))})),null===(t=e.ssrcGroups)||void 0===t||t.forEach((e=>{n.push(this.writeSsrcGroupLine(e))})),null===(i=e.ssrcs)||void 0===i||i.forEach((e=>{n.push(this.writeSsrcLine(e))})),null===(s=e.rids)||void 0===s||s.forEach((e=>{n.push(this.writeRidLine(e))})),null===(a=e.candidates)||void 0===a||a.forEach((e=>{n.push(this.writeCandidateLine(e))})),e.simulcast&&n.push(this.writeSimulcastLine(e.simulcast)),n.join("\r\n")+"\r\n"}static parse(e){const t={session:null,media:[]},i=this.splitSections(e);return t.session=this.parseSessionSection(i.shift()),i.forEach((e=>{const i=this.parseMediaSection(e);t.media.push(i)})),t}static write(e){let t=this.writeSessionSection(e.session);return e.media.forEach((e=>{t+=this.writeMediaSection(e)})),t}}var re=i(8935);class ce{static parseSdp(e){return oe.parse(e)}static writeSdp(e){return oe.write(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,s]=t;return[4,6,8,10].includes(i)?"-".concat(e[s]):e[s]})).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,s]of e.extensionMap)if(s.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,s,a)=>{e.uri===t&&(a.delete(s),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,s,a){e.media.filter((e=>e.type===t&&e.direction===i)).forEach((e=>ce.updateMLineCodecParameters(e,s,a)))}static updateMLineCodecParameters(e,t,i){e.codecs.filter((e=>e.codecName===t)).forEach((e=>{i.forEach(((t,i)=>{e.codecParams.set(i,t)}))}))}static updateCodecParametersByMid(e,t,i,s){e.media.filter((e=>e.mid===t)).forEach((e=>ce.updateMLineCodecParameters(e,i,s)))}static filterCodecs(e,t){e.media.forEach((e=>{const i=[];e.codecs.forEach((s=>{t&&!t(s,e)||i.push(s.payloadType)})),e.codecs.forEach((e=>{i.includes(e.associatedPayloadType)&&i.push(e.payloadType)})),e.payloadTypes=e.payloadTypes.filter((e=>i.includes(e))),e.codecs=e.codecs.filter((e=>i.includes(e.payloadType)))})),e.media=e.media.filter((e=>e.payloadTypes.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 s;const a=parseInt(null===(s=e.codecParams.get("profile-level-id"))||void 0===s?void 0:s.substring(0,2),16);i.includes(a)&&t.push(e.payloadType)})),e.codecs.forEach((e=>{t.includes(e.associatedPayloadType)&&t.push(e.payloadType)})),e.payloadTypes=e.payloadTypes.filter((e=>t.includes(e))),e.codecs=e.codecs.filter((e=>t.includes(e.payloadType)))}))}static getH264ProfileIds(e,t,i){const s=new Set,a=e.media.find((e=>"video"===e.type&&e.direction===t));return null==a||a.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&&s.add(i)}})),Array.from(s.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 s,a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],n=0;if(e.media.forEach((e=>{const{extensionMap:t,type:i,direction:a}=e;t.forEach(((e,t)=>{t>n&&(n=t)})),"video"!==i||"sendonly"!==a||s||(s=e)})),!s)throw new Error("Failed to find a video media section for send");if(t>1&&a){s.rids=[],s.simulcast=null,s.ssrcs=[],s.ssrcGroups=[];const e=s.codecs.some((e=>"rtx"===e.codecName)),a=[],n=ce.generateUuid();let o;if(s.msid){s.msid.streamId=i;const{trackId:e}=s.msid;o="".concat(i," ").concat(e)}else o="".concat(i," ").concat(ce.generateUuid());for(let i=0;i<t;i++){const t=ce.generateSsrc();if(a.push(t),s.ssrcs.push({ssrc:t,attribute:"cname:"+n}),s.ssrcs.push({ssrc:t,attribute:"msid:"+o}),e){const e=ce.generateSsrc();s.ssrcs.push({ssrc:e,attribute:"cname:"+n}),s.ssrcs.push({ssrc:e,attribute:"msid:"+o}),s.ssrcGroups.push({semantics:"FID",ssrcs:[t,e]})}}s.ssrcGroups.push({semantics:"SIM",ssrcs:a})}ce.removeMidRidHeaderExtensions(s),(0,re.n_)()&&(0,re.nr)()&&15===(0,re.Cd)()&&1===(0,re.w_)()||ce.removeHeaderExtensionByUri(s,"urn:3gpp:video-orientation");const o={uri:"http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time"};if(-1===ce.findHeaderExtensionByUri(s,o.uri)&&(o.id=++n,ce.addHeaderExtension(s,o)),t>1){e.session.extMapAllowMixed=!0;const t={uri:"http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00"};-1===ce.findHeaderExtensionByUri(s,t.uri)&&(t.id=++n,ce.addHeaderExtension(s,t))}}static mungeEgressOfferToRemote(e){e.session.timing={startTime:ce.getNtpSeconds(),stopTime:0}}static mungeEgressAnswer(e,t){t&&ce.updateCodecParameters(e,"video","recvonly","H264",t)}static mungeIngressLocalOffer(e,t){t&&ce.updateCodecParameters(e,"video","recvonly","H264",t)}static updateIceCredential(e,t){const{ice_pwd:i,ice_ufrag:s}=t;e.media.forEach((e=>{e&&(e.icePwd=i,e.iceUfrag=s)}))}static getSSRCByMid(e,t){let i;const s=e.media.find((e=>e.mid==t)),{ssrcs:a}=s;return a.length&&(i=a[0].ssrc),i}static getMlineCodecFromLocalOffer(e,t,i){var s;return null===(s=e.media.find((e=>t===e.mid)))||void 0===s?void 0:s.codecs.find((e=>e.codecName===i))}static updateStreamIdByMid(e,t,i){const s=e.media.find((e=>e.mid===t));if(s.msid){const{trackId:e}=s.msid;s.msid.streamId=i,s.ssrcs&&s.ssrcs.forEach((t=>{0===t.attribute.indexOf("msid")&&(t.attribute="msid:".concat(i," ").concat(e))}))}}}const de=[{layerId:4,width:1920,height:1080,maxFramerate:30,minBitrate:25e5,targetBitrate:4e6,maxBitrate:5e6},{layerId:4,width:1600,height:900,maxFramerate:30,minBitrate:15e5,targetBitrate:3e6,maxBitrate:35e5},{layerId:3,width:1280,height:720,maxFramerate:30,minBitrate:8e5,targetBitrate:2e6,maxBitrate:2e6},{layerId:3,width:960,height:540,maxFramerate:30,minBitrate:5e5,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 le(e){x.setLayersSettings(e)}function he(e){x.setEnabledLayerIds(e)}function ue(){return x.layersSettings}function me(){return x.enabledLayerIds}function pe(){return me()[0]}function ge(e){return me().includes(e)}function Se(){const e=me();return e[e.length-1]}function _e(e){var t;return null===(t=ue())||void 0===t?void 0:t[e]}function ve(e){const t=ue();if(!t)return;const i=t.findIndex((t=>t.layerId===e));return i>=0?_e(i):void 0}function fe(e){const t=ue();if(t)for(let i=t.length-1;i>=0;i--)if(t[i].layerId===e)return _e(i)}function Me(e){var t;return(null===(t=ve(e))||void 0===t?void 0:t.maxBitrate)||0}function ye(e){var t;return(null===(t=ve(e))||void 0===t?void 0:t.targetBitrate)||0}function Ce(e,t){const i=ve(e);if(i){const{width:e,height:s,maxBitrate:a}=i;return Math.floor(t.width*t.height/(e*s)*a)}}function Ie(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 Te(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 Re{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 s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function Ee(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}$.getTracer("WmscStats");class Ae{constructor(){this.sendStatsMonitor=new we({cacheSize:Ae.sendStatsCacheSize}),this.recvStatsMonitor=new Le({cacheSize:Ae.recvStatsCacheSize}),this.sendUsageStatsEnabled=!1,this.recvUsageStatsEnabled=!1,this.maxEncodingFramerate=30,this.resourceUsageStatsReportTimestamp=0,this.resourceUsageStatsIntervalId=null,this.outgoingBitrateStatsCallback=null,this.resourceUsageStatsCallback=null}getSendStatsMonitor(){return this.sendStatsMonitor}getRecvStatsMonitor(){return this.recvStatsMonitor}setOptions(e){const{sendUsageStatsEnabled:t,recvUsageStatsEnabled:i,maxEncodingFramerate:s}=e||{};void 0!==t&&(this.sendUsageStatsEnabled=t),void 0!==i&&(this.recvUsageStatsEnabled=i),void 0!==s&&(this.maxEncodingFramerate=s)}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()}),Ae.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(){const e={};let t=0;if(this.sendUsageStatsEnabled){const i=this._getSendResourceUsageStats();i&&(e.send=Ee({},i),t=Math.max(t,i.timestamp))}if(this.recvUsageStatsEnabled){const i=this._getRecvResourceUsageStats();i&&(e.recv=Ee({},i),t=Math.max(t,i.timestamp))}this.resourceUsageStatsReportTimestamp=t,this.resourceUsageStatsCallback(e)}_getSendResourceUsageStats(){if(!this.sendStatsMonitor.isStarted())return;const e=this.sendStatsMonitor.getOutboundRtpStats(),t=1e3/this.maxEncodingFramerate;let i=0,s=0,a=0,n=C.NONE;for(const[o,r]of e){const e=r.back(),o=Math.max(this.resourceUsageStatsReportTimestamp-500,e.timestamp-Ae.resourceUsageCheckInterval-500),c=r.find((e=>e.timestamp>o));if(!c)continue;const d=e.framesEncoded-c.framesEncoded,l=e.timestamp-c.timestamp;if(0===d||l<Ae.resourceUsageMinTimeSlice)continue;const h=e.framesSent-c.framesSent,u=d?1e3*(e.totalEncodeTime-c.totalEncodeTime)/d:0;let m,p,g=C.NONE,S=C.NONE,_=C.NONE;if(S=d>h||d>=Ae.encodeTimeMinFrameCount&&u>=t*Ae.encodeTimeFactorThresholdCritical?C.OVERUSING:d<=h&&d>=Ae.encodeTimeMinFrameCount&&u<t*Ae.encodeTimeFactorThresholdNormal?C.UNDERUSING:C.NORMAL,e.qualityLimitationDurations)if(m=1e3*(e.qualityLimitationDurations.cpu-c.qualityLimitationDurations.cpu)/l,p=1e3*(e.qualityLimitationDurations.other-c.qualityLimitationDurations.other)/l,m>=Ae.qualityLimitationRatioThresholdCritical||p>=Ae.qualityLimitationRatioThresholdCritical){_=C.OVERUSING;const e="WMSC_Perf_Control: cpuLimitationRatio ".concat(m);$.monitorLog(e),$.globalTrace({logLevel:"log",log:e,tags:["WMSC_Perf_Control"]})}else _=m<Ae.qualityLimitationRatioThresholdNormal&&p<Ae.qualityLimitationRatioThresholdNormal?C.UNDERUSING:C.NORMAL;if(g=S,Y(_,g)>0&&(g=_),i+=d,s+=h,a=Math.max(a,e.timestamp),Y(g,n)>0&&(n=g),n===C.OVERUSING)break}return{usageState:n,framesEncoded:i,framesSent:s,timestamp:a}}_getRecvResourceUsageStats(){if(!this.recvStatsMonitor.isStarted())return;const e=this.recvStatsMonitor.getInboundRtpStats();let t=0,i=0,s=0,a=0,n=C.NONE;for(const[o,r]of e){const e=r.back(),o=Math.max(this.resourceUsageStatsReportTimestamp-500,e.timestamp-Ae.resourceUsageCheckInterval-500),c=r.find((e=>e.timestamp>o));if(!c)continue;const d=e.timestamp-c.timestamp,l=e.framesReceived-c.framesReceived;if(0===l||d<Ae.resourceUsageMinTimeSlice)continue;const h=e.framesDropped-c.framesDropped,u=e.framesDecoded-c.framesDecoded,m=d/l;let p=1e3*(e.totalDecodeTime-c.totalDecodeTime);p>=d&&(p=d);const g=u?p/u:0;let S=C.NONE;if(t+=l,i+=h,s+=u,a=Math.max(a,e.timestamp),S=u>=Ae.decodeTimeMinFrameCount&&g>=m*Ae.decodeTimeFactorThresholdCritical&&l>u?C.OVERUSING:u>=Ae.decodeTimeMinFrameCount&&g<m*Ae.decodeTimeFactorThresholdNormal?C.UNDERUSING:C.NORMAL,Y(S,n)>0&&(n=S),n===C.OVERUSING)break}return{usageState:n,framesReceived:t,framesDropped:i,framesDecoded:s,timestamp:a}}}(0,c.A)(Ae,"sendStatsCacheSize",6),(0,c.A)(Ae,"recvStatsCacheSize",6),(0,c.A)(Ae,"resourceUsageMinTimeSlice",4500),(0,c.A)(Ae,"resourceUsageCheckInterval",5e3),(0,c.A)(Ae,"encodeTimeMinFrameCount",20),(0,c.A)(Ae,"encodeTimeFactorThresholdNormal",.9),(0,c.A)(Ae,"encodeTimeFactorThresholdCritical",1.1),(0,c.A)(Ae,"qualityLimitationRatioThresholdNormal",.05),(0,c.A)(Ae,"qualityLimitationRatioThresholdCritical",.95),(0,c.A)(Ae,"decodeTimeMinFrameCount",20),(0,c.A)(Ae,"decodeTimeFactorThresholdNormal",.9),(0,c.A)(Ae,"decodeTimeFactorThresholdCritical",1.1);class we{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}reset(){this.resetCandidateStats(),this.resetOutboundRtpStats()}resetCandidateStats(){this.selectedCandidatePairId=null,this.roundTripTime=0,this.remoteCandidateId=null,this.networkProtocol=null}resetOutboundRtpStats(){this.outboundRtpStatsMap.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}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)}}onTransportStats(e){const{selectedCandidatePairId:t,dtlsState:i}=e;"connected"===i&&(this.selectedCandidatePairId=t)}onCandidatePairStats(e){const{id:t,state:i,nominated:s,availableOutgoingBitrate:a,currentRoundTripTime:n,remoteCandidateId:o,timestamp:r,localCandidateId:c}=e;t===this.selectedCandidatePairId&&"succeeded"===i&&s&&(this.roundTripTime=n,this.remoteCandidateId=o,this.localCandidateId=c,this.outgoingBitrateStatsCallback({availableOutgoingBitrate:a,timestamp:r}))}onRemoteCandidateStats(e){const{id:t,protocol:i,port:s}=e;if(t===this.remoteCandidateId&&!this.networkProtocol){this.networkProtocol=i;const e="WMSC_Network_Change: send|".concat(i,"|").concat(s);$.globalTrace({logLevel:"log",log:e,tags:["WMSC_Network_Change"]}),$.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);$.globalTrace({logLevel:"directReport",log:e,tags:["WMSC_LocalCandidatae_Change"]}),$.monitorLog(e)}}onOutboundRtpStats(e){if(!this.outboundRtpStatsEnabled||"video"!==e.kind)return;const{ssrc:t,framesEncoded:i,framesSent:s,totalEncodeTime:a,qualityLimitationDurations:n,timestamp:o}=e;let r=this.outboundRtpStatsMap.get(t);r||(r=new Re(this.cacheSize),this.outboundRtpStatsMap.set(t,r)),r.push({framesEncoded:i,framesSent:s,totalEncodeTime:a,qualityLimitationDurations:n,timestamp:o})}}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.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:s,currentRoundTripTime:a,remoteCandidateId:n,localCandidateId:o}=e;t===this.selectedCandidatePairId&&"succeeded"===i&&s&&(this.roundTripTime=a,this.remoteCandidateId=n,this.localCandidateId=o)}onRemoteCandidateStats(e){const{id:t,protocol:i,port:s}=e;if(t===this.remoteCandidateId&&!this.networkProtocol){this.networkProtocol=i;const e="WMSC_Network_Change: recv|".concat(i,"|").concat(s);$.globalTrace({logLevel:"log",log:e,tags:["WMSC_Network_Change"]}),$.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);$.globalTrace({logLevel:"directReport",log:e,tags:["WMSC_LocalCandidatae_Change"]}),$.monitorLog(e)}}onInboundRtpStats(e){if(!this.inboundRtpStatsEnabled||"video"!==e.kind||!e.framesReceived)return;const{ssrc:t,framesDecoded:i,framesDropped:s,framesReceived:a,keyFramesDecoded:n,totalDecodeTime:o,pliCount:r,timestamp:c}=e;let d=this.inboundRtpStatsMap.get(t);d||(d=new Re(this.cacheSize),this.inboundRtpStatsMap.set(t,d)),d.push({framesDecoded:i,framesDropped:s,framesReceived:a,keyFramesDecoded:n,totalDecodeTime:o,pliCount:r,timestamp:c})}}const De=new Ae;class Pe{static mean(e){if(e.length)return e.reduce(((e,t)=>e+t),0)/e.length}static median(e){if(!e.length)return;l()(e).call(e,((e,t)=>e-t));const t=Math.floor(e.length/2);return e.length%2!=0?e[t]:(e[t-1]+e[t])/2}static variance(e){if(!e.length)return;const t=e.reduce(((e,t)=>e+t),0)/e.length,i=e.map((e=>Math.pow(e-t,2)));return i.reduce(((e,t)=>e+t),0)/i.length}static expMovingAverage(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5;if(!e.length)return[];const i=[e[0]];for(let s=1;s<e.length;s++)i.push(t*e[s]+(1-t)*i[s-1]);return i}static bestFitSlope(e){if(e.length<2)return;const t=e.length;let i=0,s=0,a=0,n=0;for(let o=0;o<t;o++)i+=o,s+=e[o],a+=o*e[o],n+=o*o;return(t*a-i*s)/(t*n-i*i)}}function Oe(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function Ne(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?Oe(Object(i),!0).forEach((function(t){(0,c.A)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):Oe(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}const Be=$.getTracer("WmscQosMgr"),Ve=e=>{Be.log(e),$.monitorLog("".concat(e))},ke=8e4,Ue=Object.freeze({Hold:0,Increase:1,Decrease:2}),xe=Object.freeze({None:0,Increase:1,Decrease:2}),We=Object.freeze({User:0,OutgoingBandwidth:1,ReceiverBandwidth:2,Other:3});class Fe{constructor(){this.outgoingBandwidthAdaptationEnabled=!0,this.outgoingBandwidthProbingEnabled=!0,this.receiverBandwidthAdaptationEnabled=!0,this.additionalSubLayersEnabled=!0,this.lossDetectionEnabled=!1,this.performanceAdaptationEnabled=!0,this.maxEncodingLayers=3,this.sendActive=!1,this.requestedLayerIds=[],this.additionalSubLayerIds=[],this.layersAllocation=[],this.layersAllocationCache=null,this.layersAllocationUpdateTimeoutId=null,this.isUpdatingLayers=!1,this.outgoingBandwidthProbingScheduledTime=0,this.maxSubVideoSize=-1,this.maxFeasibleSendSize=4,this.sendUsageAdjustments=new Re(Fe.resourceUsageAdjustmentHistorySize),this.sendUsageIncreaseFailedAttempts=0,this.sendUsageIncreaseFailedTime=0,this.encoderRestartedTime=0,this.maxFeasibleRecvSize=R,this.recvUsageAdjustments=new Re(Fe.resourceUsageAdjustmentHistorySize),this.recvUsageIncreaseFailedAttempts=0,this.recvUsageIncreaseFailedTime=0,this.outgoingBitrateStats=new Re(Fe.outgoingBitrateStatsCacheSize),this.minOutgoingBitrate=ke,this.outgoingBandwidth=1/0,this.receiverBandwidthReport=null,this.receiverL3BandwidthEvaluation=null,this.receiverBandwidthUpdatePending=!1,this.receiverBandwidthUpdateTimeoutId=null,this.isDualCall=!0,this.audioBandwidth=0,this.receiverStats=new Re(Fe.receiverStatsCacheSize),this.minOutgoingBitrateAdjustments=new Re(Fe.minOutgoingBitrateAdjustmentHistorySize),this.receiverReport=null,this.residualLossDetectedTimestamp=0,this.inherentLossDetectedTimestamp=0,this.minOutgoingBitrateUpdatedTime=0,this.messageCallback=null,this.maxRecvVideoSizeUpdateCallback=null,this.sendUsageStateUpdateCallback=null,De.registerOutgoingBitrateStatsCallback(this.onOutgoingBandwidthStats.bind(this)),De.registerResourceUsageStatsCallback(this.onResourceUsageStats.bind(this))}static areLayersAllocationsEqual(e,t){return e.length===t.length&&e.every(((e,i)=>{const s=t[i];return e.layerId===s.layerId&&e.maxBitrate===s.maxBitrate&&(a=e.format,n=s.format,a.width===n.width&&a.height===n.height);var a,n}))}static isBitrateChangeAboveRatio(e,t,i){return!e||Math.abs(t-e)/e>i}resetSendStats(){De.getSendStatsMonitor().reset()}resetRecvStats(){De.getRecvStatsMonitor().reset()}_resetLayersAllocation(){this.requestedLayerIds=[],this.additionalSubLayerIds=[],this.layersAllocation=[],this.layersAllocationCache=null,this.isUpdatingLayers=!1}_resetLossDetection(){this.receiverStats.clear(),this.minOutgoingBitrateAdjustments.clear(),this.receiverReport=null,this.residualLossDetectedTimestamp=0,this.inherentLossDetectedTimestamp=0,this.minOutgoingBitrateUpdatedTime=0}_resetBandwidthState(){this._stopReceiverBandwidthUpdateWait(),this._resetReceiverBandwidth(),this.outgoingBitrateStats.clear(),this.minOutgoingBitrate=ke,this.outgoingBandwidth=1/0,this.isDualCall=!0}_resetResourceUsageState(){this.maxFeasibleSendSize=Se(),this.sendUsageAdjustments.clear(),this.sendUsageIncreaseFailedAttempts=0,this.sendUsageIncreaseFailedTime=0,this.maxFeasibleRecvSize=R,this.recvUsageAdjustments.clear(),this.recvUsageIncreaseFailedAttempts=0,this.recvUsageIncreaseFailedTime=0}resetSend(){this._stopPollingLayersAllocation(),this.sendActive=!1,this._resetLayersAllocation(),this._resetLossDetection(),this._resetBandwidthState(),this.resetSendStats()}resetRecv(){this.maxSubVideoSize=-1,this.resetRecvStats()}registerMessageCallback(e){this.messageCallback=e}registerMaxRecvVideoSizeUpdateCallback(e){this.maxRecvVideoSizeUpdateCallback=e}registerSendUsageStateUpdateCallback(e){this.sendUsageStateUpdateCallback=e}setOptions(e){const{outgoingBandwidthAdaptationEnabled:t,outgoingBandwidthProbingEnabled:i,receiverBandwidthAdaptationEnabled:s,lossDetectionEnabled:a,performanceAdaptationEnabled:n}=e||{};void 0!==t&&(this.outgoingBandwidthAdaptationEnabled=t),void 0!==i&&(this.outgoingBandwidthProbingEnabled=i),void 0!==s&&(this.receiverBandwidthAdaptationEnabled=s),void 0!==a&&(this.lossDetectionEnabled=a),void 0!==n&&(this.performanceAdaptationEnabled=n)}setMaxEncodingLayers(e){this.maxEncodingLayers=e}setMaxEncodingFramerate(e){De.setOptions({maxEncodingFramerate:e})}setStartBandwidth(e){Ve("WMSC_Set_Start_Bandwidth: ".concat(e)),this.outgoingBandwidth=e}setAudioBandwidth(e){this.audioBandwidth!==e&&(Ve("WMSC_Set_Audio_Bandwidth: ".concat(e)),this.audioBandwidth=e,this.allocateBitrate(this._getAvailableBitrate(),We.OutgoingBandwidth))}start(e){e&&this.setOptions(e);const t={};this.performanceAdaptationEnabled&&(t.sendUsageStatsEnabled=!0,t.recvUsageStatsEnabled=!0),De.start(t)}stop(){De.stop(),this.resetSend(),this.resetRecv()}updateLayers(e){Be.log("updateLayers, ".concat(e)),this.requestedLayerIds=[...e],this.allocateBitrate(this._getAvailableBitrate(),We.User),this._setSendState(!!e.length)}_setSendState(e){this.sendActive!==e&&(this.sendActive=e,e?this._startPollingLayersAllocation():this.lossDetectionEnabled&&this._resetLossDetection())}async _startPollingLayersAllocation(){await this._sendLastLayersAllocation(),this.sendActive&&(this.layersAllocationUpdateTimeoutId=setTimeout((()=>{this._startPollingLayersAllocation()}),Fe.layersAllocationUpdateInterval))}_stopPollingLayersAllocation(){clearTimeout(this.layersAllocationUpdateTimeoutId),this.layersAllocationUpdateTimeoutId=null}updateMaxSubVideoSize(e){this.maxSubVideoSize=e}getMaxFeasibleRecvVideoSize(){return this.maxFeasibleRecvSize}_resetReceiverBandwidth(){this.receiverBandwidthReport=null,this.receiverL3BandwidthEvaluation=null}_waitBeforeReceiverBandwidthUpdate(){this.receiverBandwidthUpdatePending=!0,clearTimeout(this.receiverBandwidthUpdateTimeoutId),this.receiverBandwidthUpdateTimeoutId=setTimeout((()=>{this.receiverBandwidthUpdatePending=!1}),Fe.receiverBandwidthUpdateDelay)}_stopReceiverBandwidthUpdateWait(){clearTimeout(this.receiverBandwidthUpdateTimeoutId),this.receiverBandwidthUpdateTimeoutId=null,this.receiverBandwidthUpdatePending=!1}getMinBandwidth(){return this.minOutgoingBitrate}onOutgoingBandwidthStats(e){if(!this.outgoingBandwidthAdaptationEnabled||!this.sendActive)return;const{availableOutgoingBitrate:t=1/0,timestamp:i}=e;this.outgoingBitrateStats.push({availableOutgoingBitrate:t,timestamp:i}),this._updateOutgoingBandwidth(t)}onResourceUsageStats(e){this.performanceAdaptationEnabled&&(e.send&&this.sendActive&&this._handleSendUsageStats(e.send),e.recv&&this._handleRecvUsageStats(e.recv))}_handleSendUsageStats(e){const{framesEncoded:t,usageState:i,timestamp:s}=e,a=this._getFeasibleSendLayerIds();this.sendUsageStateUpdateCallback&&this.sendUsageStateUpdateCallback(i);let n=xe.None;i===C.OVERUSING?n=x.isMacIntel?xe.None:xe.Decrease:i===C.UNDERUSING&&(n=xe.Increase);const o=a[a.length-1];this._maybeAdjustMaxSendSize(o,n)&&(Ve("WMSC_VEnc_Cap_Change: ".concat(this.maxFeasibleSendSize)),this.allocateBitrate(this._getAvailableBitrate(),We.Other))}_handleRecvUsageStats(e){const{usageState:t}=e;let i=xe.None;t===C.OVERUSING?i=xe.Decrease:t===C.UNDERUSING&&(i=xe.Increase),this._maybeAdjustMaxRecvSize(this.maxSubVideoSize,i)&&(Ve("WMSC_VDec_Cap_Change: ".concat(this.maxFeasibleRecvSize)),this.maxRecvVideoSizeUpdateCallback&&this.maxRecvVideoSizeUpdateCallback(this.maxFeasibleRecvSize))}_maybeAdjustMaxSendSize(e,t){const i=Date.now();if(t===xe.Decrease){const a=pe();if(this.maxFeasibleSendSize>a){var s;const n=this.sendUsageAdjustments.back();if(this.sendUsageAdjustments.push({layerChange:t,time:i}),(null==n?void 0:n.layerChange)===xe.Increase){this.sendUsageIncreaseFailedAttempts++,this.sendUsageIncreaseFailedTime=n.time;const e="WMSC_Perf_Control: Attempt to increase layer failed ".concat(this.sendUsageIncreaseFailedAttempts," times");Ve(e),$.globalTrace({logLevel:"log",log:e,tags:["WMSC_Perf_Control"]})}return this.maxFeasibleSendSize=null!==(s=me().findLast((t=>t<e)))&&void 0!==s?s:a,!0}}else if(t===xe.Increase){const s=Se();var a;if(this.maxFeasibleSendSize<s&&this.sendUsageIncreaseFailedAttempts<Fe.resourceUsageIncreaseMaxAttempts&&i-this.sendUsageIncreaseFailedTime>=Fe.resourceUsageIncreaseInitialDelay*Math.pow(2,this.sendUsageIncreaseFailedAttempts-1))return this.sendUsageAdjustments.push({layerChange:t,time:i}),this.maxFeasibleSendSize=null!==(a=me().find((t=>t>e)))&&void 0!==a?a:s,!0}return!1}_maybeAdjustMaxRecvSize(e,t){if(e<=R)return!1;const i=Date.now();if(t===xe.Decrease){const e=this.recvUsageAdjustments.back();if(this.recvUsageAdjustments.push({layerChange:t,time:i}),(null==e?void 0:e.l