@ceeblue/web-utils 7.2.0 → 7.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- const t=new TextDecoder;class e{constructor(t){this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._view=new DataView(this._data.buffer,this._data.byteOffset,this._size)}data(){return this._data}size(){return this._size}available(){return this._size-this._position}value(t=this._position){return this._data[t]}position(){return this._position}reset(t=0){this._position=Math.max(0,t>this._size?this._size:t)}shrink(t){const e=this._size-this._position;return t>e?e:(this._size=this._position+t,t)}next(t=1){const e=this._size-this._position;return t>e&&(t=e),this._position=Math.max(0,this._position+t),t}read8(){return 1===this.next(1)?this._view.getUint8(this._position-1):0}read16(){return 2===this.next(2)?this._view.getUint16(this._position-2):0}read24(){return 3===this.next(3)?this._view.getUint16(this._position-3)<<8|255&this._view.getUint8(this._position-1):0}read32(){return 4===this.next(4)?this._view.getUint32(this._position-4):0}read64(){return 8!==this.next(8)?0:4294967296*this._view.getUint32(this._position-8)+this._view.getUint32(this._position-4)}readFloat(){return 4===this.next(4)?this._view.getFloat32(this._position-4):0}readDouble(){return 8===this.next(8)?this._view.getFloat64(this._position-8):0}read7Bit(t=5){let e=0,i=1;for(;this.available();){const t=this.read8();if(e+=(127&t)*i,!(128&t))break;i*=128}return e}readString(){let e=this._position;for(;e<this._size&&this._data[e];)++e;const i=this.read(e-this._position);return this.next(),t.decode(i)}readHex(t){let e="";for(;t-- >0;)e+=("0"+this.read8().toString(16)).slice(-2);return e}read(t=this.available()){if(this.available()<t)return new Uint8Array(t);const e=this._position;return this._data.subarray(e,Math.max(e,this._position+=t))}}function i(t,e,i,s){return new(i||(i=Promise))((function(r,n){function o(t){try{h(s.next(t))}catch(t){n(t)}}function a(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=new TextDecoder,r=new TextEncoder,n=performance,o=()=>{};function a(){return Math.floor(n.now())}function h(t=("undefined"==typeof location?void 0:location)){if(!t)return{};try{t=new URL(t).searchParams}catch(e){"string"==typeof t&&(t.startsWith("?")&&(t=t.substring(1)),t=new URLSearchParams(t))}return l(t,{withType:!0,noEmptyString:!0})}function l(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const i={};if(!t)return i;for(const[s,r]of u(t)){if(t=r,e.withType&&null!=t&&t.substring)if(t){const e=Number(t);if(isNaN(e))switch(t.toLowerCase()){case"true":t=!0;break;case"false":t=!1;break;case"null":t=null;break;case"undefined":t=void 0}else t=e}else e.noEmptyString&&(t=!0);i[s]?(Array.isArray(i[s])||(i[s]=new Array(i[s])),i[s].push(t)):i[s]=t}return i}function u(t){return t?("function"==typeof t.entries&&(t=t.entries()),"function"==typeof t[Symbol.iterator]?t:function*(){for(const e in t)yield[e.toString(),t[e]]}()):function*(){}()}function c(t){return r.encode(t)}function _(t,e){return i(this,void 0,void 0,(function*(){const i=yield self.fetch(t,e);return i.ok||(i.body&&(i.error=yield i.text()),i.error||(i.error=i.statusText||i.status.toString()||"Unknown error")),i}))}function d(t){const e=t.lastIndexOf(".");return e>=0&&e>t.lastIndexOf("/")?t.substring(e):""}function g(t){return t.substring(t.lastIndexOf("/")+1)}function f(t){const e=t.lastIndexOf("."),i=t.lastIndexOf("/")+1;return e>=0&&e>=i?t.substring(i,e):t.substring(i)}function p(t){const e=[];for(let i=0;i<t.length;++i)e.push(t.charCodeAt(i));return e}function m(t,e=" "){const i=p(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;return t.substring(s)}var b,y=Object.freeze({__proto__:null,EMPTY_FUNCTION:o,caseInsensitive:function(t){return new Proxy(t,{get(t,e,i){if("string"==typeof e){const s=Object.keys(t).find((t=>t.toLowerCase()===e.toLowerCase()));if(void 0!==s)return Reflect.get(t,s,i)}return Reflect.get(t,e,i)}})},equal:function t(e,i,s=new WeakMap){if(e===i)return!0;if(Number.isNaN(e)&&Number.isNaN(i))return!0;if(Object(e)!==e||Object(i)!==i)return!1;if(s.has(e))return s.get(e)===i;s.set(e,i);const r=Object.prototype.toString.call(e);if(r!==Object.prototype.toString.call(i))return!1;switch(r){case"[object Date]":return e.getTime()===i.getTime();case"[object RegExp]":return e.source===i.source&&e.flags===i.flags;case"[object Set]":case"[object Map]":{if(e.size!==i.size)return!1;const s=e.keys(),r=e.keys(),n=e.values(),o=i.values();let a;for(;!(a=s.next()).done;){if(!t(a.value,r.next().value))return!1;const e=n.next().value,i=o.next().value;if(e!==a&&!t(e,i))return!1}return!0}}if(Array.isArray(e)){if(!Array.isArray(i)||e.length!==i.length)return!1;for(let r=0;r<e.length;r++)if(!t(e[r],i[r],s))return!1;return!0}const n=[...Object.keys(e),...Object.getOwnPropertySymbols(e)];if(n.length!==Object.keys(i).length+Object.getOwnPropertySymbols(i).length)return!1;for(const r of n)if(!t(e[r],i[r],s))return!1;return!0},fetch:_,fetchWithRTT:function(t,e){return i(this,void 0,void 0,(function*(){yield _(t,Object.assign(Object.assign({},e),{method:"OPTIONS"}));const i=a(),s=yield _(t,e);s.rtt=a()-i;let r=Number(s.headers.get("Response-Delay"))||0;if(!r){const t=s.headers.get("cmsd-dynamic");if(t)for(const e of t.split(";")){const[t,i]=e.split("=");"rd"===t.trim().toLowerCase()&&(r=Number(i)||r)}}return s.rtt=Math.max(1,s.rtt-r),s}))},getBaseFile:f,getExtension:d,getFile:g,iterableEntries:u,objectFrom:l,options:h,safePromise:function(t,e){let i;return Promise.race([e instanceof Promise?e:new Promise(e),new Promise(((e,s)=>i=setTimeout((()=>s("timed out in "+t+"ms")),t)))]).finally((()=>clearTimeout(i)))},sleep:function(t){return i(this,void 0,void 0,(function*(){return new Promise((e=>{setTimeout(e,t)}))}))},stringify:function t(e,i={}){if(i=Object.assign({space:" ",decimal:2,recursion:1,noBin:!1},i),null==e)return String(e);const r=e.error||e.message;if(r&&(e=r),e.toFixed)return e.toFixed(Number(i.decimal)||0);if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return i.noBin?"["+e.byteLength+"#bytes]":s.decode(e);if("boolean"==typeof e||e.substring||!i.recursion)return String(e);const n=i.space||"";if(Array.isArray(e)){let s="";for(const r of e)s+=(s?",":"[")+n,s+=t(r,Object.assign(Object.assign({},i),{recursion:i.recursion-1}));return s+=n+"]"}let o="{";for(const s in e)o.length>1&&(o+=","),o+=n+s+":",o+=t(e[s],Object.assign(Object.assign({},i),{recursion:i.recursion-1}))+n;return o+"}"},time:a,toBin:c,trim:function(t,e=" "){const i=p(e);let s=0;for(;s<t.length&&i.includes(t.charCodeAt(s));)++s;let r=t.length;for(;r>0&&i.includes(t.charCodeAt(r-1));)--r;return t.substring(s,r)},trimEnd:function(t,e=" "){const i=p(e);let s=t.length;for(;s>0&&i.includes(t.charCodeAt(s-1));)--s;return t.substring(0,s)},trimStart:m,unixTime:function(){return Math.floor(n.timeOrigin+n.now())}});class v{get view(){return this._view||(this._view=new DataView(this._data.buffer,this._data.byteOffset,this._data.byteLength)),this._view}get capacity(){return this._data.byteLength}constructor(t=64,e=0,i){"number"==typeof t?(this._data=new Uint8Array(t),this._size=0):"buffer"in t?(this._data=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this._size=t.byteLength):(this._isConst=!0,null==i&&(i=t.byteLength),this._data=new Uint8Array(t,e,i),this._size=0)}data(){return new Uint8Array(this._data.buffer,this._data.byteOffset,this._size)}size(){return this._size||0}next(t=1){return this.reserve(this._size+=t)}clear(t=0){return this.reserve(this._size=t)}write(t){var e;let i;return i="string"==typeof t?c(t):t instanceof ArrayBuffer?new Uint8Array(t):"buffer"in t?new Uint8Array(t.buffer,null!==(e=t.byteOffset)&&void 0!==e?e:0,t.byteLength):t,this.reserve(this._size+i.length),this._data.set(i,this._size),this._size+=i.length,this}write8(t){return t>255&&(t=255),this.reserve(this._size+1),this._data[this._size++]=t,this}write16(t){return t>65535&&(t=65535),this.reserve(this._size+2),this.view.setUint16(this._size,t),this._size+=2,this}write24(t){return t>16777215&&(t=16777215),this.reserve(this._size+3),this.view.setUint16(this._size,t>>8),this.view.setUint8(this._size+=2,255&t),++this._size,this}write32(t){return t>4294967295&&(t=4294967295),this.reserve(this._size+4),this.view.setUint32(this._size,t),this._size+=4,this}write64(t){return this.write32(t/4294967296),this.write32(4294967295&t)}writeFloat(t){return this.reserve(this._size+4),this.view.setFloat32(this._size,t),this._size+=4,this}writeDouble(t){return this.reserve(this._size+8),this.view.setFloat64(this._size,t),this._size+=8,this}write7Bit(t){let e=127&t;for(;t=Math.floor(t/128);)this.write8(128|e),e=127&t;return this.write8(e)}writeString(t){return this.write(c(t)).write8(0)}writeHex(t){for(let e=0;e<t.length;e+=2)this.write8(parseInt(t.substring(e,e+2),16));return this}reserve(t){if(!this._data)throw Error("buffer not writable");if(t<=this._data.byteLength)return this;if(this._isConst)throw Error("writing exceeds maximum "+this._data.byteLength+" bytes limit");--t,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t;const e=new Uint8Array(t);return e.set(this._data),this._data=e,this._view=void 0,this}}!function(t){t.ERROR="error",t.WARN="warn",t.INFO="info",t.DEBUG="debug"}(b||(b={}));let w=0;setInterval((()=>{console.assert(0===w,w.toFixed(),"calls to log was useless")}),1e4);const x=h()["!cb-override-log-level"],S=new Array(128);S[101]=S[69]=1,S[119]=S[87]=2,S[105]=S[73]=3,S[100]=S[68]=4;class z{get error(){return this._bind(b.ERROR)}get warn(){return this._bind(b.WARN)}get info(){return this._bind(b.INFO)}get debug(){return this._bind(b.DEBUG)}constructor(t,...e){e.length||e.push(void 0),this._args=e,this._log=t,++w}_onLog(t,e){var i,s;const r=null!==(s=null!==(i=null!=x?x:t.level)&&void 0!==i?i:O.level)&&void 0!==s?s:b.INFO;return!1!==r&&(!(!0!==r&&S[e.charCodeAt(0)]>S[r.charCodeAt(0)])&&(t.on&&t.on(e,this._args),!!this._args.length))}_bind(t){return this._done||(this._done=!0,--w),this._onLog(O,t)&&(this._log===O||this._onLog(this._log,t))?console[t].bind(console,...this._args):o}}class A{constructor(){this.log=(...t)=>new z(this.log,...t)}}const O=(...t)=>new z(O,...t);class E extends A{constructor(t){super(),this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._bit=0}data(){return this._data}size(){return this._size}available(){return 8*(this._size-this._position)-this._bit}next(t=1){let e=0;for(;this._position!==this._size&&t--;)++e,8==++this._bit&&(this._bit=0,++this._position);return e}read(t=1){let e=0;for(;this._position!==this._size&&t--;)e<<=1,this._data[this._position]&128>>this._bit++&&(e|=1),8===this._bit&&(this._bit=0,++this._position);return e}read8(){return this.read(8)}read16(){return this.read(16)}read24(){return this.read(24)}read32(){return this.read(32)}readExpGolomb(){let t=0;for(;!this.read();){if(!this.available())return 0;++t}const e=this.read(t);return t>15?(this.log("Exponential-Golomb code exceeding unsigned 16 bits").warn(),0):e+(1<<t)-1}}class M{onBytes(t){}get interval(){return this._interval}set interval(t){this._interval=t,this.updateSamples()}constructor(t=1e3){this._interval=t,this.clear()}value(){return Math.round(this.exact())}exact(){this.updateSamples();const t=a()-this._time;return t?this._bytes/t*1e3:0}addBytes(t){var e;const i=a(),s=this.updateSamples(i)[this._samples.length-1];if(i>(null!==(e=null==s?void 0:s.time)&&void 0!==e?e:this._time))this._samples.push({bytes:t,time:i,clip:!1});else{if(!s)return this;s.bytes+=t}return this._bytes+=t,this.onBytes(t),this}clear(){return this._bytes=0,this._time=a(),this._samples=[],this._clip=!1,this}clip(){if(this._clip){this._clip=!1;let t=0;for(const e of this._samples)if(this._bytes-=e.bytes,++t,this._time=e.time,e.clip)break;this._samples.splice(0,t)}const t=this._samples[this._samples.length-1];return t&&(t.clip=!0,this._clip=!0),this}updateSamples(t=a()){const e=t-this._interval;let i,s=0;for(;this._time<e&&(i=this._samples[s]);){if(this._bytes-=i.bytes,i.clip&&(this._clip=i.clip=!1),i.time>e){i.bytes*=(i.time-e)/(i.time-this._time),this._time=e,this._bytes+=i.bytes;break}++s,this._time=i.time}return this._samples.splice(0,s),this._samples}}class T{static fixProtocol(t,e){const i=(e=e.replace(/^[\/]+/,"")).indexOf("://");return i>=0&&(i>2&&"s"===e.charAt(i-1).toLowerCase()?(t.length<=2||!t.endsWith("s"))&&(t+="s"):t.length>2&&t.endsWith("s")&&(t=t.slice(0,-1)),e=e.substring(i+3)),t+"://"+e}get host(){return this._host}get domain(){return this._domain}get port(){return this._port}toString(){return this._address}valueOf(){return this._address}constructor(t,e){this._address=t;let i=t.indexOf("/");i>=0&&(47===t.charCodeAt(i+1)?i>0?58===t.charCodeAt(i-1)&&(t=t.substring(i+2)):t=t.substring(2):i||(t=t.substring(1))),i=t.indexOf("/"),i>=0&&(t=t.substring(0,i)),this._host=t,this._domain=t,this._port=e;const s=this._host.match(/^(?:\[([0-9a-fA-F:]+)\]|([^:/?#]+))(?::(\d+))?(?=[/#?]|$)/);if(s&&(this._domain=s[1]||s[2],s[3])){const t=parseInt(s[3]);t>=0&&t<=65535&&(this._port=t)}}}var k;function N(t,e){var i;if(!e.mediaExt)try{const t=new URL(e.endPoint);e.mediaExt=null!==(i=t.searchParams.get("ext"))&&void 0!==i?i:d(g(t.pathname))}catch(t){e.mediaExt=""}switch(e.mediaExt=m(e.mediaExt,".").toLowerCase(),t){case k.HESP:e.mediaExt="mp4";break;case k.WEBRTC:e.mediaExt="rtp";break;case k.WRTS:e.mediaExt&&"json"!==e.mediaExt||(e.mediaExt="rts");break;case k.META:e.mediaExt="js";break;case k.DATA:e.mediaExt="json";break;default:O("Unknown params type "+t).warn()}}!function(t){t.HESP="HESP",t.WRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(k||(k={}));var C=Object.freeze({__proto__:null,get Type(){return k},buildURL:function(t,e,i="wss"){var s;N(t,e);const r=new URL(T.fixProtocol(i,e.endPoint));if(r.pathname.length<=1)switch(t){case k.HESP:r.pathname="/hesp/"+e.streamName+"/index.json";break;case k.WEBRTC:r.pathname="/webrtc/"+e.streamName;break;case k.WRTS:r.pathname="/wrts/"+e.streamName+"."+e.mediaExt;break;case k.META:r.pathname="/json_"+e.streamName+".js";break;case k.DATA:r.pathname="/"+e.streamName+".json";break;default:O("Unknown url type "+t).warn()}else if(!e.streamName){const t=r.pathname.split("/");e.streamName=f(t[2]||t[1]||t[0])}e.accessToken&&r.searchParams.set("id",e.accessToken);for(const[t,i]of null!==(s=e.query)&&void 0!==s?s:[])r.searchParams.set(t,i);return r},defineMediaExt:N});class U extends A{constructor(){super(),this._events=new Map;let t=Object.getPrototypeOf(this);for(;t&&t!==Object.prototype;){for(const e of Object.getOwnPropertyNames(t)){if(e.length<3||!e.startsWith("on"))continue;let i=t[e];if(i instanceof Function){const t=new Set;this._events.set(e.substring(2).toLowerCase(),t);const s=(...e)=>{const s=i?i.call(this,...e):void 0;for(const i of t)i(...e);return s};Object.defineProperties(this,{[e]:{get:()=>s,set:t=>{i=t}}})}}t=Object.getPrototypeOf(t)}}on(t,e,i){var s;if("function"!=typeof e)throw Error("event callback must be a function");const r=this._event(t);r.add(e),null===(s=null==i?void 0:i.signal)||void 0===s||s.addEventListener("abort",(()=>r.delete(e)),{once:!0})}once(t,e,i){var s;if("function"!=typeof e)throw Error("event callback must be a function");const r=this._event(t),n=(...t)=>{r.delete(n),e(...t)};r.add(n),null===(s=null==i?void 0:i.signal)||void 0===s||s.addEventListener("abort",(()=>r.delete(n)),{once:!0})}off(t,e){if(!e)throw Error("event to unsubscribe cannot be null");return this._event(t).delete(e)}_event(t){const e=this._events.get(t.toLowerCase());if(!e)throw Error("No event on"+t+" on class "+this.constructor.name);return e}}class I{[Symbol.iterator](){return this._map[Symbol.iterator]()}get size(){return this._map.size}constructor(t){this._initValue=t,this._map=new Map}get(t){let e=this.find(t);return void 0===e&&this._map.set(t,e=this._initValue()),e}find(t){return this._map.get(t)}has(t){return this._map.has(t)}clear(){this._map.clear()}delete(t){return this._map.delete(t)}set(t,e){return this._map.set(t,e),e}forEach(t,e){this._map.forEach(t,e)}}class L{get size(){return this._queue.length}get capacity(){return this._capacity}set capacity(t){this._capacity=t,null!=t&&this._queue.length>t&&this._queue.splice(0,this._queue.length-t)}get front(){return this._queue[0]}get back(){return this._queue[this._queue.length-1]}[Symbol.iterator](){return this._queue[Symbol.iterator]()}constructor(t){this._capacity=t,this._queue=new Array}push(t){return null!=this._capacity&&this._queue.push(t)>this._capacity&&this.pop(),this}pop(){return this._queue.shift()}clear(){return this._queue.length=0,this}}class j extends L{get minimum(){return this._min}get maximum(){return this._max}get average(){return null==this._average&&(this._average=this.size?this._sum/this.size:0),this._average}constructor(t){super(t),this._sum=0,this._min=0,this._max=0}push(t){return t>this._max?this._max=t:t<this._min&&(this._min=t),this._average=void 0,this._sum+=t,super.push(t),this}pop(){const t=super.pop();return t===this._max?this._max=Math.max(0,...this):t===this._min&&(this._min=Math.min(0,...this)),this._average=void 0,this._sum-=t||0,t}clear(){return this._min=this._max=this._sum=0,super.clear(),this}}const R={fromString(t){if(Array.isArray(t))return t;const e=new Array;let i,s=e;for(let r of t.toString().split("\n")){if(r=r.trim(),!r)continue;let t=r[0];const n=r.substring(r.indexOf("=")+1).trim();switch(t.toLowerCase()){case"a":if(!n)continue;t=this.addAttribute(s,n),e===s&&"fingerprint"===t.toLowerCase()&&(i=s.fingerprint);break;case"m":e.length&&i&&!e[e.length-1].fingerprint&&(s.fingerprint=i),e.push(s={m:n});break;default:s[t]=n}}return e.length&&i&&!e[e.length-1].fingerprint&&(s.fingerprint=i),e},toString(t){if("string"==typeof t)return t;const e=[];let i="v"in t?"v="+t.v+"\n":"";"o"in t&&(i+="o="+t.o+"\n"),"s"in t&&(i+="s="+t.s+"\n");const s=t;for(const r of Object.keys(t)){if("v"===r||"o"===r||"s"===r)continue;const t=s[r];if(null==t)continue;const n=parseInt(r);if(!isNaN(n)){e[n]=t;continue}const o=Array.isArray(t)&&t.length||1;for(let e=0;e<o;++e){const s=Array.isArray(t)&&t.length?t[e]:t;r.length>1?(i+="a="+r,s&&(i+=":")):i+=r+"=",i+=s+"\n"}}for(const t of e)i+=this.toString(t);return i},addAttribute(t,e){var i;const s=R.parseAttribute(e),r=null!==(i=s.value)&&void 0!==i?i:"",n=t,o=n[s.key];return o?Array.isArray(o)?o.push(r):r!==o&&(n[s.key]=[o,r]):n[s.key]=r,s.key},removeAttribute(t,e){const i=R.parseAttribute(e),s=t;if(void 0===i.value)return delete s[e],e;const r=s[e];if(Array.isArray(i.value)){const t=r.findIndex((t=>t===i.value));t>=0&&r.splice(t,1)}else r===i.value&&delete s[e];return i.key},parseAttribute(t){const e=t.indexOf(":");return{key:(e>=0?t.substring(0,e):t).trim(),value:e>=0?t.substring(e+1).trim():void 0}}};Object.freeze(R);class F extends U{onOpen(){}onMessage(t){}onClose(t){t?this.log("onClose",t).error():this.log("onClose").info()}get binaryType(){return"arraybuffer"}get recvByteRate(){return this._recvByteRate.value()}get sendByteRate(){return this._sendByteRate.value()}get url(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.url)&&void 0!==e?e:""}get extensions(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.extensions)&&void 0!==e?e:""}get protocol(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.protocol)&&void 0!==e?e:""}get opened(){return this._opened}get readyState(){return this._ws?this._ws.readyState:3}get closed(){return this._closed}get bufferedAmount(){var t;return this._queueingBytes+((null===(t=this._ws)||void 0===t?void 0:t.bufferedAmount)||0)}get queueing(){return this._queueing}constructor(t,e){super(),this._queueing=[],this._queueingBytes=0,this._opened=!1,this._closed=!0,this._recvByteRate=new M,this._sendByteRate=new M,t&&this.open(t,e)}open(t,e){this._closed=!1;const i=this._ws=new WebSocket(t,e);return i.binaryType=this.binaryType,i.onmessage=t=>{var e;this._recvByteRate.addBytes(null!==(e=t.data.byteLength)&&void 0!==e?e:t.data.length),this.onMessage(t.data)},i.onclose=e=>{this._opened?1e3===e.code||1005===e.code?this.close({type:"WebSocketReliableError",name:"Server shutdown",url:t.toString()}):this.close({type:"WebSocketReliableError",name:"Socket disconnection",url:t.toString(),reason:String(e.reason||e.code)}):this.close({type:"WebSocketReliableError",name:"Connection failed",url:t.toString(),reason:String(e.reason||e.code)})},i.onopen=t=>{this._opened=!0,this.flush(),this.onOpen()},this}send(t,e=!1){if(this._closed)throw Error("Open socket before to send data");return e||!this._opened?(this._queueing.push(t),this._queueingBytes+="string"==typeof t?t.length:t.byteLength):this._send(t),this}flush(){if(this._ws)for(const t of this._queueing)this._send(t);this._queueing.length=0,this._queueingBytes=0}close(t){this._ws&&!this._closed&&(this._closed=!0,this._ws.onopen=this._ws.onclose=this._ws.onmessage=null,this._ws.close(),this._queueing.length=0,this._queueingBytes=0,this.onClose(t),this._opened=!1)}_send(t){this._ws&&(this._sendByteRate.addBytes("string"==typeof t?t.length:t.byteLength),this._ws.send(t))}}const W=32;function P(t,e,i=.2){const s=Math.floor(e/W);let r="";if(s<1)return null;const n=s*W,o=Math.floor(s/2),a=t.getImageData(0,o,n,1).data,h=new Uint32Array(a.buffer),l=255*i,u=255*(1-i);for(let t=0;t<n;t+=s){const e=16777215&h[t+o],i=.299*(e>>16&255)+.587*(e>>8&255)+.114*(255&e);if(i<l)r+="1";else{if(!(i>u))return null;r+="0"}}const c=parseInt(r.slice(0,5),2),_=parseInt(r.slice(5,10),2),d=parseInt(r.slice(10,16),2),g=parseInt(r.slice(16,22),2),f=parseInt(r.slice(22,32),2);if(c<1||c>31||_>23||d>59||g>59||f>999)return null;const p=new Date;return new Date(Date.UTC(p.getUTCFullYear(),p.getUTCMonth(),c,_,d,g,f))}var B=Object.freeze({__proto__:null,decodeTimestamp:P,encodeTimestamp:function(t,e,i=32,s=new Date){const r=Math.floor(e/i),n=s.getUTCDate(),o=s.getUTCHours(),a=s.getUTCMinutes(),h=s.getUTCSeconds(),l=s.getUTCMilliseconds(),u=n.toString(2).padStart(5,"0")+o.toString(2).padStart(5,"0")+a.toString(2).padStart(6,"0")+h.toString(2).padStart(6,"0")+l.toString(2).padStart(10,"0");for(let e=0;e<u.length;e++){const s=e%i*r,n=Math.floor(e/i)*r;t.fillStyle="1"===u[e]?"black":"white",t.fillRect(s,n,r,r)}},getLatency:function(t,e,i,s=new Date,r=.2){if(e.width=t.videoWidth,e.height=Math.floor(e.width/W),!e.width||!e.height)return 0;i.drawImage(t,0,0,e.width,e.height,0,0,e.width,e.height);const n=P(i,e.width,r);return null==n?0:s.getTime()-n.getTime()}});class q{get graphMargin(){return this._graphMargin}set graphMargin(t){this._graphMargin=t}get textMargin(){return this._textMargin}set textMargin(t){this._textMargin=t}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight=t}get labelWidth(){return this._labelWidth}set labelWidth(t){this._labelWidth=t}get legendFontSize(){return this._legendFontSize}set legendFontSize(t){this._legendFontSize=t}get stepSize(){return this._stepSize}set stepSize(t){this._stepSize=t}get averageDisplayWidth(){return this._legendFontSize/2*7}get displayableCount(){const t=this._ui.clientWidth-this.averageDisplayWidth;return Math.ceil((t-this._labelWidth)/this._stepSize)}constructor(t){this._ui=t,t.addEventListener("mousemove",(t=>{this._mouseX=t.offsetX})),t.addEventListener("mouseleave",(t=>{this._mouseX=void 0})),this._lineHeight=40,this._labelWidth=170,this._graphMargin=5,this._textMargin=5,this._legendFontSize=13,this._stepSize=10,this._ranges={}}reset(){this._ranges={}}display(t){if(null!=this._html)return;this._html="";const e=this.averageDisplayWidth,i=e/2,s=this._ui.clientWidth-e,r=this._lineHeight-2*this._graphMargin,n=Math.round(this._lineHeight/2),o=Math.round(this._lineHeight/2+this._textMargin),a=this._labelWidth-2*this._textMargin;for(const[e,h]of t){const t=Math.ceil((s-this._labelWidth)/this._stepSize),l=h.slice(Math.max(0,h.length-t));if(!l.length)continue;let u=this._labelWidth+l.length*this._stepSize;this._html+='<svg class="list-group-item p-0" style="height: '+this._lineHeight+'px" xmlns="http://www.w3.org/2000/svg">',this._html+='<text x="'+this._textMargin+'" y="'+o+'">'+e+"</text>",this._html+='<text x="'+a+'" y="'+o+'" text-anchor="end">'+l[l.length-1].toString()+"</text>",this._html+='<path fill="none" d="M'+this._labelWidth+" "+n,this._html+="H"+(s+i),this._html+='" stroke-width="1" stroke="lightgray" stroke-dasharray="10,10"/>',this._html+='<path fill="none" stroke-width="1" stroke="brown" d="M';let c=Number.POSITIVE_INFINITY,_=Number.NEGATIVE_INFINITY;for(let t=0;t<l.length;++t){const e=parseFloat(l[t].toString());e<c&&(c=e),e>_&&(_=e)}let d=this._ranges[e];d||(this._ranges[e]=d={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}),d.min=Math.min(d.min,c),d.max=Math.max(d.max,_);const g=d.max-d.min;let f="",p="",m=null==this._mouseX||this._mouseX>u?null:"";for(let t=0;t<l.length;++t){u-=this._stepSize;const e=parseFloat(l[t].toString()),i=n+(g?Math.round((.5-(e-d.min)/g)*r):0);this._html+=u+" "+i+" ",e===c?p=p||this._drawCircle(u,i,e):e===_&&(f=f||this._drawCircle(u,i,e)),""===m&&u<=(this._mouseX||0)&&(m=this._drawCircle(u,i,e,"blue",""))}this._html+='" />';const b=Math.round((_-c)/2);this._html+='<text text-anchor="middle" font-size="'+this._legendFontSize+'" y="'+o+'">',this._html+='<tspan x="'+(s+i)+'" dy="-0.5em">'+(c!==_?"≈":"=")+(c+b)+"</tspan>",this._html+='<tspan x="'+(s+i)+'" dy="1em">±'+b+"</tspan>",this._html+="</text>",this._html+=f+p+(null!=m?m:""),m&&(this._html+=m),this._html+="</svg>"}requestAnimationFrame((()=>{null!=this._html&&(this._ui.innerHTML=this._html,this._html=void 0)}))}_drawCircle(t,e,i,s="green",r="italic"){let n='<circle cx="'+t+'" cy="'+e+'" r="2" fill="'+s+'" />';const o=.7*this._legendFontSize;return e<Math.round(this._lineHeight/2)?e+=this.textMargin+o:e-=this.textMargin,n+='<text font-style="'+r+'" font-size="'+this._legendFontSize+'" x="'+(t-this._legendFontSize)+'" y="'+e+'">'+i+"</text>",n}}const D="7.2.0";export{e as BinaryReader,v as BinaryWriter,E as BitReader,M as ByteRate,C as Connect,B as EpochTime,U as EventEmitter,I as FixMap,z as Log,b as LogLevel,A as Loggable,T as NetAddress,j as Numbers,L as Queue,R as SDP,q as UIMetrics,y as Util,D as VERSION,F as WebSocketReliable,O as log};//# sourceMappingURL=web-utils.min.js.map
1
+ const t=new TextDecoder;class e{constructor(t){this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._view=new DataView(this._data.buffer,this._data.byteOffset,this._size)}data(){return this._data}size(){return this._size}available(){return this._size-this._position}value(t=this._position){return this._data[t]}position(){return this._position}reset(t=0){this._position=Math.max(0,t>this._size?this._size:t)}shrink(t){const e=this._size-this._position;return t>e?e:(this._size=this._position+t,t)}next(t=1){const e=this._size-this._position;return t>e&&(t=e),this._position=Math.max(0,this._position+t),t}read8(){return 1===this.next(1)?this._view.getUint8(this._position-1):0}read16(){return 2===this.next(2)?this._view.getUint16(this._position-2):0}read24(){return 3===this.next(3)?this._view.getUint16(this._position-3)<<8|255&this._view.getUint8(this._position-1):0}read32(){return 4===this.next(4)?this._view.getUint32(this._position-4):0}read64(){return 8!==this.next(8)?0:4294967296*this._view.getUint32(this._position-8)+this._view.getUint32(this._position-4)}readFloat(){return 4===this.next(4)?this._view.getFloat32(this._position-4):0}readDouble(){return 8===this.next(8)?this._view.getFloat64(this._position-8):0}read7Bit(t=5){let e=0,n=1;for(;this.available();){const t=this.read8();if(e+=(127&t)*n,!(128&t))break;n*=128}return e}readString(){let e=this._position;for(;e<this._size&&this._data[e];)++e;const n=this.read(e-this._position);return this.next(),t.decode(n)}readHex(t){let e="";for(;t-- >0;)e+=("0"+this.read8().toString(16)).slice(-2);return e}read(t=this.available()){if(this.available()<t)return new Uint8Array(t);const e=this._position;return this._data.subarray(e,Math.max(e,this._position+=t))}}function n(t,e,n,r){return new(n||(n=Promise))(function(i,s){function o(t){try{u(r.next(t))}catch(t){s(t)}}function a(t){try{u(r.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(o,a)}u((r=r.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const r=new TextDecoder,i=new TextEncoder,s=performance,o=()=>{};function a(){return Math.floor(s.now())}function u(t=("undefined"==typeof location?void 0:location)){if(!t)return{};try{t=new URL(t).searchParams}catch(e){"string"==typeof t&&(t.startsWith("?")&&(t=t.substring(1)),t=new URLSearchParams(t))}return l(t,{withType:!0,noEmptyString:!0})}function l(t,e){e=Object.assign({withType:!1,noEmptyString:!1},e);const n={};if(!t)return n;for(const[r,i]of c(t)){if(t=i,e.withType&&null!=t&&t.substring)if(t){const e=Number(t);if(isNaN(e))switch(t.toLowerCase()){case"true":t=!0;break;case"false":t=!1;break;case"null":t=null;break;case"undefined":t=void 0}else t=e}else e.noEmptyString&&(t=!0);n[r]?(Array.isArray(n[r])||(n[r]=new Array(n[r])),n[r].push(t)):n[r]=t}return n}function c(t){return t?("function"==typeof t.entries&&(t=t.entries()),"function"==typeof t[Symbol.iterator]?t:function*(){for(const e in t)yield[e.toString(),t[e]]}()):function*(){}()}function h(t){return i.encode(t)}function d(t,e){return n(this,void 0,void 0,function*(){const n=yield self.fetch(t,e);return n.ok||(n.body&&(n.error=yield n.text()),n.error||(n.error=n.statusText||n.status.toString()||"Unknown error")),n})}function f(t){const e=t.lastIndexOf(".");return e>=0&&e>t.lastIndexOf("/")?t.substring(e):""}function g(t){return t.substring(t.lastIndexOf("/")+1)}function p(t){const e=t.lastIndexOf("."),n=t.lastIndexOf("/")+1;return e>=0&&e>=n?t.substring(n,e):t.substring(n)}function m(t){const e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n));return e}function y(t,e=" "){const n=m(e);let r=0;for(;r<t.length&&n.includes(t.charCodeAt(r));)++r;return t.substring(r)}var v,b=Object.freeze({__proto__:null,EMPTY_FUNCTION:o,caseInsensitive:function(t){return new Proxy(t,{get(t,e,n){if("string"==typeof e){const r=Object.keys(t).find(t=>t.toLowerCase()===e.toLowerCase());if(void 0!==r)return Reflect.get(t,r,n)}return Reflect.get(t,e,n)}})},equal:function t(e,n,r=new WeakMap){if(e===n)return!0;if(Number.isNaN(e)&&Number.isNaN(n))return!0;if(Object(e)!==e||Object(n)!==n)return!1;if(r.has(e))return r.get(e)===n;r.set(e,n);const i=Object.prototype.toString.call(e);if(i!==Object.prototype.toString.call(n))return!1;switch(i){case"[object Date]":return e.getTime()===n.getTime();case"[object RegExp]":return e.source===n.source&&e.flags===n.flags;case"[object Set]":case"[object Map]":{if(e.size!==n.size)return!1;const r=e.keys(),i=e.keys(),s=e.values(),o=n.values();let a;for(;!(a=r.next()).done;){if(!t(a.value,i.next().value))return!1;const e=s.next().value,n=o.next().value;if(e!==a&&!t(e,n))return!1}return!0}}if(Array.isArray(e)){if(!Array.isArray(n)||e.length!==n.length)return!1;for(let i=0;i<e.length;i++)if(!t(e[i],n[i],r))return!1;return!0}const s=[...Object.keys(e),...Object.getOwnPropertySymbols(e)];if(s.length!==Object.keys(n).length+Object.getOwnPropertySymbols(n).length)return!1;for(const i of s)if(!t(e[i],n[i],r))return!1;return!0},fetch:d,fetchWithRTT:function(t,e){return n(this,void 0,void 0,function*(){yield d(t,Object.assign(Object.assign({},e),{method:"OPTIONS"}));const n=a(),r=yield d(t,e);r.rtt=a()-n;let i=Number(r.headers.get("Response-Delay"))||0;if(!i){const t=r.headers.get("cmsd-dynamic");if(t)for(const e of t.split(";")){const[t,n]=e.split("=");"rd"===t.trim().toLowerCase()&&(i=Number(n)||i)}}return r.rtt=Math.max(1,r.rtt-i),r})},getBaseFile:p,getExtension:f,getFile:g,iterableEntries:c,objectFrom:l,options:u,safePromise:function(t,e){let n;return Promise.race([e instanceof Promise?e:new Promise(e),new Promise((e,r)=>n=setTimeout(()=>r("timed out in "+t+"ms"),t))]).finally(()=>clearTimeout(n))},sleep:function(t){return n(this,void 0,void 0,function*(){return new Promise(e=>{setTimeout(e,t)})})},stringify:function t(e,n={}){if(n=Object.assign({space:" ",decimal:2,recursion:1,noBin:!1},n),null==e)return String(e);const i=e.error||e.message;if(i&&(e=i),e.toFixed)return e.toFixed(Number(n.decimal)||0);if(null!=e.byteLength&&(null==e?void 0:e[Symbol.iterator]))return n.noBin?"["+e.byteLength+"#bytes]":r.decode(e);if("boolean"==typeof e||e.substring||!n.recursion)return String(e);const s=n.space||"";if(Array.isArray(e)){let r="";for(const i of e)r+=(r?",":"[")+s,r+=t(i,Object.assign(Object.assign({},n),{recursion:n.recursion-1}));return r+=s+"]"}let o="{";for(const r in e)o.length>1&&(o+=","),o+=s+r+":",o+=t(e[r],Object.assign(Object.assign({},n),{recursion:n.recursion-1}))+s;return o+"}"},time:a,toBin:h,trim:function(t,e=" "){const n=m(e);let r=0;for(;r<t.length&&n.includes(t.charCodeAt(r));)++r;let i=t.length;for(;i>0&&n.includes(t.charCodeAt(i-1));)--i;return t.substring(r,i)},trimEnd:function(t,e=" "){const n=m(e);let r=t.length;for(;r>0&&n.includes(t.charCodeAt(r-1));)--r;return t.substring(0,r)},trimStart:y,unixTime:function(){return Math.floor(s.timeOrigin+s.now())}});class w{get view(){return this._view||(this._view=new DataView(this._data.buffer,this._data.byteOffset,this._data.byteLength)),this._view}get capacity(){return this._data.byteLength}constructor(t=64,e=0,n){"number"==typeof t?(this._data=new Uint8Array(t),this._size=0):"buffer"in t?(this._data=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),this._size=t.byteLength):(this._isConst=!0,null==n&&(n=t.byteLength),this._data=new Uint8Array(t,e,n),this._size=0)}data(){return new Uint8Array(this._data.buffer,this._data.byteOffset,this._size)}size(){return this._size||0}next(t=1){return this.reserve(this._size+=t)}clear(t=0){return this.reserve(this._size=t)}write(t){var e;let n;return n="string"==typeof t?h(t):t instanceof ArrayBuffer?new Uint8Array(t):"buffer"in t?new Uint8Array(t.buffer,null!==(e=t.byteOffset)&&void 0!==e?e:0,t.byteLength):t,this.reserve(this._size+n.length),this._data.set(n,this._size),this._size+=n.length,this}write8(t){return t>255&&(t=255),this.reserve(this._size+1),this._data[this._size++]=t,this}write16(t){return t>65535&&(t=65535),this.reserve(this._size+2),this.view.setUint16(this._size,t),this._size+=2,this}write24(t){return t>16777215&&(t=16777215),this.reserve(this._size+3),this.view.setUint16(this._size,t>>8),this.view.setUint8(this._size+=2,255&t),++this._size,this}write32(t){return t>4294967295&&(t=4294967295),this.reserve(this._size+4),this.view.setUint32(this._size,t),this._size+=4,this}write64(t){return this.write32(t/4294967296),this.write32(4294967295&t)}writeFloat(t){return this.reserve(this._size+4),this.view.setFloat32(this._size,t),this._size+=4,this}writeDouble(t){return this.reserve(this._size+8),this.view.setFloat64(this._size,t),this._size+=8,this}write7Bit(t){let e=127&t;for(;t=Math.floor(t/128);)this.write8(128|e),e=127&t;return this.write8(e)}writeString(t){return this.write(h(t)).write8(0)}writeHex(t){for(let e=0;e<t.length;e+=2)this.write8(parseInt(t.substring(e,e+2),16));return this}reserve(t){if(!this._data)throw Error("buffer not writable");if(t<=this._data.byteLength)return this;if(this._isConst)throw Error("writing exceeds maximum "+this._data.byteLength+" bytes limit");--t,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t;const e=new Uint8Array(t);return e.set(this._data),this._data=e,this._view=void 0,this}}!function(t){t.ERROR="error",t.WARN="warn",t.INFO="info",t.DEBUG="debug"}(v||(v={}));let S=0;setInterval(()=>{console.assert(0===S,S.toFixed(),"calls to log was useless")},1e4);const _=u()["!cb-override-log-level"],E=new Array(128);E[101]=E[69]=1,E[119]=E[87]=2,E[105]=E[73]=3,E[100]=E[68]=4;class T{get error(){return this._bind(v.ERROR)}get warn(){return this._bind(v.WARN)}get info(){return this._bind(v.INFO)}get debug(){return this._bind(v.DEBUG)}constructor(t,...e){e.length||e.push(void 0),this._args=e,this._log=t,++S}_onLog(t,e){var n,r;const i=null!==(r=null!==(n=null!=_?_:t.level)&&void 0!==n?n:U.level)&&void 0!==r?r:v.INFO;return!1!==i&&(!(!0!==i&&E[e.charCodeAt(0)]>E[i.charCodeAt(0)])&&(t.on&&t.on(e,this._args),!!this._args.length))}_bind(t){return this._done||(this._done=!0,--S),this._onLog(U,t)&&(this._log===U||this._onLog(this._log,t))?console[t].bind(console,...this._args):o}}class C{constructor(){this.log=(...t)=>new T(this.log,...t)}}const U=(...t)=>new T(U,...t);class A extends C{constructor(t){super(),this._data="buffer"in t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this._size=this._data.byteLength,this._position=0,this._bit=0}data(){return this._data}size(){return this._size}available(){return 8*(this._size-this._position)-this._bit}next(t=1){let e=0;for(;this._position!==this._size&&t--;)++e,8===++this._bit&&(this._bit=0,++this._position);return e}read(t=1){let e=0;for(;this._position!==this._size&&t--;)e<<=1,this._data[this._position]&128>>this._bit++&&(e|=1),8===this._bit&&(this._bit=0,++this._position);return e}read8(){return this.read(8)}read16(){return this.read(16)}read24(){return this.read(24)}read32(){return this.read(32)}readExpGolomb(){let t=0;for(;!this.read();){if(!this.available())return 0;++t}const e=this.read(t);return t>15?(this.log("Exponential-Golomb code exceeding unsigned 16 bits").warn(),0):e+(1<<t)-1}}class R{onBytes(t){}get interval(){return this._interval}set interval(t){this._interval=t,this.updateSamples()}constructor(t=1e3){this._interval=t,this.clear()}value(){return Math.round(this.exact())}exact(){this.updateSamples();const t=a()-this._time;return t?this._bytes/t*1e3:0}addBytes(t){var e;const n=a(),r=this.updateSamples(n)[this._samples.length-1];if(n>(null!==(e=null==r?void 0:r.time)&&void 0!==e?e:this._time))this._samples.push({bytes:t,time:n,clip:!1});else{if(!r)return this;r.bytes+=t}return this._bytes+=t,this.onBytes(t),this}clear(){return this._bytes=0,this._time=a(),this._samples=[],this._clip=!1,this}clip(){if(this._clip){this._clip=!1;let t=0;for(const e of this._samples)if(this._bytes-=e.bytes,++t,this._time=e.time,e.clip)break;this._samples.splice(0,t)}const t=this._samples[this._samples.length-1];return t&&(t.clip=!0,this._clip=!0),this}updateSamples(t=a()){const e=t-this._interval;let n,r=0;for(;this._time<e&&(n=this._samples[r]);){if(this._bytes-=n.bytes,n.clip&&(this._clip=n.clip=!1),n.time>e){n.bytes*=(n.time-e)/(n.time-this._time),this._time=e,this._bytes+=n.bytes;break}++r,this._time=n.time}return this._samples.splice(0,r),this._samples}}class M{static fixProtocol(t,e){const n=(e=e.replace(/^[\/]+/,"")).indexOf("://");return n>=0&&(n>2&&"s"===e.charAt(n-1).toLowerCase()?(t.length<=2||!t.endsWith("s"))&&(t+="s"):t.length>2&&t.endsWith("s")&&(t=t.slice(0,-1)),e=e.substring(n+3)),t+"://"+e}get host(){return this._host}get domain(){return this._domain}get port(){return this._port}toString(){return this._address}valueOf(){return this._address}constructor(t,e){this._address=t;let n=t.indexOf("/");n>=0&&(47===t.charCodeAt(n+1)?n>0?58===t.charCodeAt(n-1)&&(t=t.substring(n+2)):t=t.substring(2):n||(t=t.substring(1))),n=t.indexOf("/"),n>=0&&(t=t.substring(0,n)),this._host=t,this._domain=t,this._port=e;const r=this._host.match(/^(?:\[([0-9a-fA-F:]+)\]|([^:/?#]+))(?::(\d+))?(?=[/#?]|$)/);if(r&&(this._domain=r[1]||r[2],r[3])){const t=parseInt(r[3]);t>=0&&t<=65535&&(this._port=t)}}}var D;function I(t,e){var n;if(!e.mediaExt)try{const t=new URL(e.endPoint);e.mediaExt=null!==(n=t.searchParams.get("ext"))&&void 0!==n?n:f(g(t.pathname))}catch(t){e.mediaExt=""}switch(e.mediaExt=y(e.mediaExt,".").toLowerCase(),t){case D.HESP:e.mediaExt="mp4";break;case D.WEBRTC:e.mediaExt="rtp";break;case D.WRTS:e.mediaExt&&"json"!==e.mediaExt||(e.mediaExt="rts");break;case D.META:e.mediaExt="js";break;case D.DATA:e.mediaExt="json";break;default:U("Unknown params type "+t).warn()}}!function(t){t.HESP="HESP",t.WRTS="WebRTS",t.WEBRTC="WebRTC",t.META="Meta",t.DATA="Data"}(D||(D={}));var O=Object.freeze({__proto__:null,get Type(){return D},buildURL:function(t,e,n="wss"){var r;I(t,e);const i=new URL(M.fixProtocol(n,e.endPoint));if(i.pathname.length<=1)switch(t){case D.HESP:i.pathname="/hesp/"+e.streamName+"/index.json";break;case D.WEBRTC:i.pathname="/webrtc/"+e.streamName;break;case D.WRTS:i.pathname="/wrts/"+e.streamName+"."+e.mediaExt;break;case D.META:i.pathname="/json_"+e.streamName+".js";break;case D.DATA:i.pathname="/"+e.streamName+".json";break;default:U("Unknown url type "+t).warn()}else if(!e.streamName){const t=i.pathname.split("/");e.streamName=p(t[2]||t[1]||t[0])}e.accessToken&&i.searchParams.set("id",e.accessToken);for(const[t,n]of null!==(r=e.query)&&void 0!==r?r:[])i.searchParams.set(t,n);return i},defineMediaExt:I});class x extends C{constructor(){super(),this._events=new Map;let t=Object.getPrototypeOf(this);for(;t&&t!==Object.prototype;){for(const e of Object.getOwnPropertyNames(t)){if(e.length<3||!e.startsWith("on"))continue;let n=t[e];if(n instanceof Function){const t=new Set;this._events.set(e.substring(2).toLowerCase(),t);const r=(...e)=>{const r=n?n.call(this,...e):void 0;for(const n of t)n(...e);return r};Object.defineProperties(this,{[e]:{get:()=>r,set:t=>{n=t}}})}}t=Object.getPrototypeOf(t)}}on(t,e,n){var r;if("function"!=typeof e)throw Error("event callback must be a function");const i=this._event(t);i.add(e),null===(r=null==n?void 0:n.signal)||void 0===r||r.addEventListener("abort",()=>i.delete(e),{once:!0})}once(t,e,n){var r;if("function"!=typeof e)throw Error("event callback must be a function");const i=this._event(t),s=(...t)=>{i.delete(s),e(...t)};i.add(s),null===(r=null==n?void 0:n.signal)||void 0===r||r.addEventListener("abort",()=>i.delete(s),{once:!0})}off(t,e){if(!e)throw Error("event to unsubscribe cannot be null");return this._event(t).delete(e)}_event(t){const e=this._events.get(t.toLowerCase());if(!e)throw Error("No event on"+t+" on class "+this.constructor.name);return e}}class N{[Symbol.iterator](){return this._map[Symbol.iterator]()}get size(){return this._map.size}constructor(t){this._initValue=t,this._map=new Map}get(t){let e=this.find(t);return void 0===e&&this._map.set(t,e=this._initValue()),e}find(t){return this._map.get(t)}has(t){return this._map.has(t)}clear(){this._map.clear()}delete(t){return this._map.delete(t)}set(t,e){return this._map.set(t,e),e}forEach(t,e){this._map.forEach(t,e)}}class L{get size(){return this._queue.length}get capacity(){return this._capacity}set capacity(t){this._capacity=t,null!=t&&this._queue.length>t&&this._queue.splice(0,this._queue.length-t)}get front(){return this._queue[0]}get back(){return this._queue[this._queue.length-1]}[Symbol.iterator](){return this._queue[Symbol.iterator]()}constructor(t){this._capacity=t,this._queue=new Array}push(t){return null!=this._capacity&&this._queue.push(t)>this._capacity&&this.pop(),this}pop(){return this._queue.shift()}clear(){return this._queue.length=0,this}}class $ extends L{get minimum(){return this._min}get maximum(){return this._max}get average(){return null==this._average&&(this._average=this.size?this._sum/this.size:0),this._average}constructor(t){super(t),this._sum=0,this._min=0,this._max=0}push(t){return t>this._max?this._max=t:t<this._min&&(this._min=t),this._average=void 0,this._sum+=t,super.push(t),this}pop(){const t=super.pop();return t===this._max?this._max=Math.max(0,...this):t===this._min&&(this._min=Math.min(0,...this)),this._average=void 0,this._sum-=t||0,t}clear(){return this._min=this._max=this._sum=0,super.clear(),this}}const k={fromString(t){if(Array.isArray(t))return t;const e=new Array;let n,r=e;for(let i of t.toString().split("\n")){if(i=i.trim(),!i)continue;let t=i[0];const s=i.substring(i.indexOf("=")+1).trim();switch(t.toLowerCase()){case"a":if(!s)continue;t=this.addAttribute(r,s),e===r&&"fingerprint"===t.toLowerCase()&&(n=r.fingerprint);break;case"m":e.length&&n&&!e[e.length-1].fingerprint&&(r.fingerprint=n),e.push(r={m:s});break;default:r[t]=s}}return e.length&&n&&!e[e.length-1].fingerprint&&(r.fingerprint=n),e},toString(t){if("string"==typeof t)return t;const e=[];let n="v"in t?"v="+t.v+"\n":"";"o"in t&&(n+="o="+t.o+"\n"),"s"in t&&(n+="s="+t.s+"\n");const r=t;for(const i of Object.keys(t)){if("v"===i||"o"===i||"s"===i)continue;const t=r[i];if(null==t)continue;const s=parseInt(i);if(!isNaN(s)){e[s]=t;continue}const o=Array.isArray(t)&&t.length||1;for(let e=0;e<o;++e){const r=Array.isArray(t)&&t.length?t[e]:t;i.length>1?(n+="a="+i,r&&(n+=":")):n+=i+"=",n+=r+"\n"}}for(const t of e)n+=this.toString(t);return n},addAttribute(t,e){var n;const r=k.parseAttribute(e),i=null!==(n=r.value)&&void 0!==n?n:"",s=t,o=s[r.key];return o?Array.isArray(o)?o.push(i):i!==o&&(s[r.key]=[o,i]):s[r.key]=i,r.key},removeAttribute(t,e){const n=k.parseAttribute(e),r=t;if(void 0===n.value)return delete r[e],e;const i=r[e];if(Array.isArray(n.value)){const t=i.findIndex(t=>t===n.value);t>=0&&i.splice(t,1)}else i===n.value&&delete r[e];return n.key},parseAttribute(t){const e=t.indexOf(":");return{key:(e>=0?t.substring(0,e):t).trim(),value:e>=0?t.substring(e+1).trim():void 0}}};Object.freeze(k);class P extends x{onOpen(){}onMessage(t){}onClose(t){t?this.log("onClose",t).error():this.log("onClose").info()}get binaryType(){return"arraybuffer"}get recvByteRate(){return this._recvByteRate.value()}get sendByteRate(){return this._sendByteRate.value()}get url(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.url)&&void 0!==e?e:""}get extensions(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.extensions)&&void 0!==e?e:""}get protocol(){var t,e;return null!==(e=null===(t=this._ws)||void 0===t?void 0:t.protocol)&&void 0!==e?e:""}get opened(){return this._opened}get readyState(){return this._ws?this._ws.readyState:3}get closed(){return this._closed}get bufferedAmount(){var t;return this._queueingBytes+((null===(t=this._ws)||void 0===t?void 0:t.bufferedAmount)||0)}get queueing(){return this._queueing}constructor(t,e){super(),this._queueing=[],this._queueingBytes=0,this._opened=!1,this._closed=!0,this._recvByteRate=new R,this._sendByteRate=new R,t&&this.open(t,e)}open(t,e){this._closed=!1;const n=this._ws=new WebSocket(t,e);return n.binaryType=this.binaryType,n.onmessage=t=>{var e;this._recvByteRate.addBytes(null!==(e=t.data.byteLength)&&void 0!==e?e:t.data.length),this.onMessage(t.data)},n.onclose=e=>{this._opened?1e3===e.code||1005===e.code?this.close({type:"WebSocketReliableError",name:"Server shutdown",url:t.toString()}):this.close({type:"WebSocketReliableError",name:"Socket disconnection",url:t.toString(),reason:String(e.reason||e.code)}):this.close({type:"WebSocketReliableError",name:"Connection failed",url:t.toString(),reason:String(e.reason||e.code)})},n.onopen=t=>{this._opened=!0,this.flush(),this.onOpen()},this}send(t,e=!1){if(this._closed)throw Error("Open socket before to send data");return e||!this._opened?(this._queueing.push(t),this._queueingBytes+="string"==typeof t?t.length:t.byteLength):this._send(t),this}flush(){if(this._ws)for(const t of this._queueing)this._send(t);this._queueing.length=0,this._queueingBytes=0}close(t){this._ws&&!this._closed&&(this._closed=!0,this._ws.onopen=this._ws.onclose=this._ws.onmessage=null,this._ws.close(),this._queueing.length=0,this._queueingBytes=0,this.onClose(t),this._opened=!1)}_send(t){this._ws&&(this._sendByteRate.addBytes("string"==typeof t?t.length:t.byteLength),this._ws.send(t))}}function F(t,e,n=.2){const r=Math.floor(e/32);let i="";if(r<1)return null;const s=32*r,o=Math.floor(r/2),a=t.getImageData(0,o,s,1).data,u=new Uint32Array(a.buffer),l=255*n,c=255*(1-n);for(let t=0;t<s;t+=r){const e=16777215&u[t+o],n=.299*(e>>16&255)+.587*(e>>8&255)+.114*(255&e);if(n<l)i+="1";else{if(!(n>c))return null;i+="0"}}const h=parseInt(i.slice(0,5),2),d=parseInt(i.slice(5,10),2),f=parseInt(i.slice(10,16),2),g=parseInt(i.slice(16,22),2),p=parseInt(i.slice(22,32),2);if(h<1||h>31||d>23||f>59||g>59||p>999)return null;const m=new Date;return new Date(Date.UTC(m.getUTCFullYear(),m.getUTCMonth(),h,d,f,g,p))}var B=Object.freeze({__proto__:null,decodeTimestamp:F,encodeTimestamp:function(t,e,n=32,r=new Date){const i=Math.floor(e/n),s=r.getUTCDate(),o=r.getUTCHours(),a=r.getUTCMinutes(),u=r.getUTCSeconds(),l=r.getUTCMilliseconds(),c=s.toString(2).padStart(5,"0")+o.toString(2).padStart(5,"0")+a.toString(2).padStart(6,"0")+u.toString(2).padStart(6,"0")+l.toString(2).padStart(10,"0");for(let e=0;e<c.length;e++){const r=e%n*i,s=Math.floor(e/n)*i;t.fillStyle="1"===c[e]?"black":"white",t.fillRect(r,s,i,i)}},getLatency:function(t,e,n,r=new Date,i=.2){if(e.width=t.videoWidth,e.height=Math.floor(e.width/32),!e.width||!e.height)return 0;n.drawImage(t,0,0,e.width,e.height,0,0,e.width,e.height);const s=F(n,e.width,i);return null==s?0:r.getTime()-s.getTime()}});const z={ERROR:0,TEXT:1,WARNING:2,INFO:2,DEBUG:3,DATA:3};class V{constructor(){this.time=null,this.verboseLevel=z.ERROR}log(t,e){if(this.verboseLevel>=t){const n="function"==typeof e?e():e;console.log(`${this.time} [${t}] ${n}`)}}}class H{constructor(){this.foreground="white",this.underline=!1,this.italics=!1,this.background="black",this.flash=!1}reset(){this.foreground="white",this.underline=!1,this.italics=!1,this.background="black",this.flash=!1}setStyles(t){const e=["foreground","underline","italics","background","flash"];for(let n=0;n<e.length;n++){const r=e[n];Object.prototype.hasOwnProperty.call(t,r)&&(this[r]=t[r])}}isDefault(){return"white"===this.foreground&&!this.underline&&!this.italics&&"black"===this.background&&!this.flash}equals(t){return this.foreground===t.foreground&&this.underline===t.underline&&this.italics===t.italics&&this.background===t.background&&this.flash===t.flash}copy(t){this.foreground=t.foreground,this.underline=t.underline,this.italics=t.italics,this.background=t.background,this.flash=t.flash}}class W{constructor(){this.uchar=" ",this.penState=new H}reset(){this.uchar=" ",this.penState.reset()}setChar(t,e){this.uchar=t,this.penState.copy(e)}setPenState(t){this.penState.copy(t)}equals(t){return this.uchar===t.uchar&&this.penState.equals(t.penState)}copy(t){this.uchar=t.uchar,this.penState.copy(t.penState)}isEmpty(){return" "===this.uchar&&this.penState.isDefault()}}const Y=100,j={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608,128:174,129:176,130:189,131:191,132:8482,133:162,134:163,135:9834,136:224,137:32,138:232,139:226,140:234,141:238,142:244,143:251,144:193,145:201,146:211,147:218,148:220,149:252,150:8216,151:161,152:42,153:8217,154:9473,155:169,156:8480,157:8226,158:8220,159:8221,160:192,161:194,162:199,163:200,164:202,165:203,166:235,167:206,168:207,169:239,170:212,171:217,172:249,173:219,174:171,175:187,176:195,177:227,178:205,179:204,180:236,181:210,182:242,183:213,184:245,185:123,186:125,187:92,188:94,189:95,190:124,191:8764,192:196,193:228,194:214,195:246,196:223,197:165,198:164,199:9475,200:197,201:229,202:216,203:248,204:9487,205:9491,206:9495,207:9499};function X(t){return String.fromCharCode(j[t]||t)}class q{constructor(t=new V){this.chars=[],this.cueStartTime=null,this.pos=0,this.currPenState=new H;for(let t=0;t<Y;t++)this.chars.push(new W);this.logger=t}equals(t){for(let e=0;e<Y;e++)if(!this.chars[e].equals(t.chars[e]))return!1;return!0}copy(t){for(let e=0;e<Y;e++)this.chars[e].copy(t.chars[e])}isEmpty(){let t=!0;for(let e=0;e<Y;e++)if(!this.chars[e].isEmpty()){t=!1;break}return t}setCursor(t){this.pos!==t&&(this.pos=t),this.pos<0?(this.logger.log(z.DEBUG,"Negative cursor position "+this.pos),this.pos=0):this.pos>Y&&(this.logger.log(z.DEBUG,"Too large cursor position "+this.pos),this.pos=Y)}moveCursor(t){const e=this.pos+t;if(t>1)for(let t=this.pos+1;t<e+1;t++)this.chars[t].setPenState(this.currPenState);this.setCursor(e)}backSpace(){this.moveCursor(-1),this.chars[this.pos].setChar(" ",this.currPenState)}insertChar(t){t>=144&&this.backSpace();const e=X(t);this.pos>=Y?this.logger.log(z.ERROR,()=>"Cannot insert "+t.toString(16)+" ("+e+") at position "+this.pos+". Skipping it!"):(this.chars[this.pos].setChar(e,this.currPenState),this.moveCursor(1))}clearFromPos(t){let e;for(e=t;e<Y;e++)this.chars[e].reset()}clear(){this.clearFromPos(0),this.pos=0,this.currPenState.reset()}clearToEndOfRow(){this.clearFromPos(this.pos)}getTextString(){const t=[];let e=!0;for(let n=0;n<Y;n++){const r=this.chars[n].uchar;" "!==r&&(e=!1),t.push(r)}return e?"":t.join("")}setPenStyles(t){this.currPenState.setStyles(t);this.chars[this.pos].setPenState(this.currPenState)}}const G=15;class K{constructor(t=new V){this.rows=[],this.currRow=14,this.nrRollUpRows=null,this.lastOutputScreen=null;for(let e=0;e<G;e++)this.rows.push(new q(t));this.logger=t}reset(){for(let t=0;t<G;t++)this.rows[t].clear();this.currRow=14}equals(t){let e=!0;for(let n=0;n<G;n++)if(!this.rows[n].equals(t.rows[n])){e=!1;break}return e}copy(t){for(let e=0;e<G;e++)this.rows[e].copy(t.rows[e])}isEmpty(){let t=!0;for(let e=0;e<G;e++)if(!this.rows[e].isEmpty()){t=!1;break}return t}backSpace(){this.rows[this.currRow].backSpace()}clearToEndOfRow(){this.rows[this.currRow].clearToEndOfRow()}insertChar(t){this.rows[this.currRow].insertChar(t)}setPen(t){this.rows[this.currRow].setPenStyles(t)}moveCursor(t){this.rows[this.currRow].moveCursor(t)}setCursor(t){this.logger.log(z.INFO,"setCursor: "+t);this.rows[this.currRow].setCursor(t)}setPAC(t){this.logger.log(z.INFO,()=>"pacData = "+JSON.stringify(t));let e=t.row-1;if(this.nrRollUpRows&&e<this.nrRollUpRows-1&&(e=this.nrRollUpRows-1),this.nrRollUpRows&&this.currRow!==e){for(let t=0;t<G;t++)this.rows[t].clear();const t=this.currRow+1-this.nrRollUpRows,n=this.lastOutputScreen;if(n){const r=n.rows[t].cueStartTime,i=this.logger.time;if(null!==r&&null!==i&&r<i)for(let r=0;r<this.nrRollUpRows;r++)this.rows[e-this.nrRollUpRows+r+1].copy(n.rows[t+r])}}this.currRow=e;const n=this.rows[this.currRow];if(null!==t.indent){const e=t.indent,r=Math.max(e-1,0);n.setCursor(t.indent),t.color=n.chars[r].penState.foreground}const r={foreground:t.color,underline:t.underline,italics:t.italics,background:"black",flash:!1};this.setPen(r)}setBkgData(t){this.logger.log(z.INFO,()=>"bkgData = "+JSON.stringify(t)),this.backSpace(),this.setPen(t),this.insertChar(32)}setRollUpRows(t){this.nrRollUpRows=t}rollUp(){if(null===this.nrRollUpRows)return void this.logger.log(z.DEBUG,"roll_up but nrRollUpRows not set yet");this.logger.log(z.TEXT,()=>this.getDisplayText());const t=this.currRow+1-this.nrRollUpRows,e=this.rows.splice(t,1)[0];e.clear(),this.rows.splice(this.currRow,0,e),this.logger.log(z.INFO,"Rolling up")}getDisplayText(t){t=t||!1;const e=[];let n="",r=-1;for(let n=0;n<G;n++){const i=this.rows[n].getTextString();i&&(r=n+1,t?e.push("Row "+r+": '"+i+"'"):e.push(i.trim()))}return e.length>0&&(n=t?"["+e.join(" | ")+"]":e.join("\n")),n}getTextAndFormat(){return this.rows}}class Q{constructor(t,e,n=new V){this.chNr=t,this.outputFilter=e,this.mode=null,this.displayedMemory=new K(n),this.nonDisplayedMemory=new K(n),this.lastOutputScreen=new K(n),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.logger=n,this.logger.log(z.INFO,"new Cea608Channel("+this.chNr+")")}reset(){var t,e;this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),null===(e=null===(t=this.outputFilter)||void 0===t?void 0:t.reset)||void 0===e||e.call(t),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null}getHandler(){return this.outputFilter}setHandler(t){this.outputFilter=t}setPAC(t){this.writeScreen.setPAC(t)}setBkgData(t){this.writeScreen.setBkgData(t)}setMode(t){t!==this.mode&&(this.mode=t,this.logger.log(z.INFO,()=>"MODE="+t),"MODE_POP-ON"===this.mode?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),"MODE_ROLL-UP"!==this.mode&&(this.displayedMemory.setRollUpRows(null),this.nonDisplayedMemory.setRollUpRows(null)),this.mode=t)}insertChars(t){for(let e=0;e<t.length;e++)this.writeScreen.insertChar(t[e]);const e=this.writeScreen===this.displayedMemory?"DISP":"NON_DISP";this.logger.log(z.INFO,()=>e+": "+this.writeScreen.getDisplayText(!0)),"MODE_PAINT-ON"!==this.mode&&"MODE_ROLL-UP"!==this.mode||(this.logger.log(z.TEXT,()=>"DISPLAYED: "+this.displayedMemory.getDisplayText(!0)),this.outputDataUpdate())}ccRCL(){this.logger.log(z.INFO,"RCL - Resume Caption Loading"),this.setMode("MODE_POP-ON")}ccBS(){this.logger.log(z.INFO,"BS - BackSpace"),"MODE_TEXT"!==this.mode&&(this.writeScreen.backSpace(),this.writeScreen===this.displayedMemory&&this.outputDataUpdate())}ccAOF(){}ccAON(){}ccDER(){this.logger.log(z.INFO,"DER- Delete to End of Row"),this.writeScreen.clearToEndOfRow(),this.outputDataUpdate()}ccRU(t){this.logger.log(z.INFO,"RU("+t+") - Roll Up"),this.writeScreen=this.displayedMemory,this.setMode("MODE_ROLL-UP"),this.writeScreen.setRollUpRows(t)}ccFON(){this.logger.log(z.INFO,"FON - Flash On"),this.writeScreen.setPen({flash:!0})}ccRDC(){this.logger.log(z.INFO,"RDC - Resume Direct Captioning"),this.setMode("MODE_PAINT-ON")}ccTR(){this.logger.log(z.INFO,"TR"),this.setMode("MODE_TEXT")}ccRTD(){this.logger.log(z.INFO,"RTD"),this.setMode("MODE_TEXT")}ccEDM(){this.logger.log(z.INFO,"EDM - Erase Displayed Memory"),this.displayedMemory.reset(),this.outputDataUpdate(!0)}ccCR(){this.logger.log(z.INFO,"CR - Carriage Return"),this.writeScreen.rollUp(),this.outputDataUpdate(!0)}ccENM(){this.logger.log(z.INFO,"ENM - Erase Non-displayed Memory"),this.nonDisplayedMemory.reset()}ccEOC(){if(this.logger.log(z.INFO,"EOC - End Of Caption"),"MODE_POP-ON"===this.mode){const t=this.displayedMemory;this.displayedMemory=this.nonDisplayedMemory,this.nonDisplayedMemory=t,this.writeScreen=this.nonDisplayedMemory,this.logger.log(z.TEXT,()=>"DISP: "+this.displayedMemory.getDisplayText())}this.outputDataUpdate(!0)}ccTO(t){this.logger.log(z.INFO,"TO("+t+") - Tab Offset"),this.writeScreen.moveCursor(t)}ccMIDROW(t){const e={flash:!1};if(e.underline=t%2==1,e.italics=t>=46,e.italics)e.foreground="white";else{const n=Math.floor(t/2)-16,r=["white","green","blue","cyan","red","yellow","magenta"];e.foreground=r[n]}this.logger.log(z.INFO,"MIDROW: "+JSON.stringify(e)),this.writeScreen.setPen(e)}outputDataUpdate(t=!1){const e=this.logger.time;null!==e&&this.outputFilter&&(null!==this.cueStartTime||this.displayedMemory.isEmpty()?this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue(this.cueStartTime,e,this.lastOutputScreen),t&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:e):this.cueStartTime=e,this.lastOutputScreen.copy(this.displayedMemory))}cueSplitAtTime(t){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,t,this.displayedMemory),this.cueStartTime=t))}}const J=["white","green","blue","cyan","red","yellow","magenta","black","transparent"];function Z(t,e,n){return n.a===t&&n.b===e}function tt(t){const e=[];for(let n=0;n<t.length;n++)e.push(t[n].toString(16));return e}const et={17:2,18:4,21:6,22:8,23:10,19:13,20:15},nt={25:2,26:4,29:6,30:8,31:10,27:13,28:15},rt={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},it={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14};function st(t,e,n){n.a=t,n.b=e}let ot,at,ut;function lt(t){return t?ut(t):(console.error("Can't parse empty HLS Manifest"),{})}function ct(t,e){var n,r,i,s;if(t.$.contentType)return t.$.contentType;if(null===(n=t.ContentComponent)||void 0===n?void 0:n.at(0))return t.ContentComponent.at(0).$.contentType;if(t.$.mimeType||(null==e?void 0:e.$.mimeType)){const n=(null===(r=t.$.mimeType)||void 0===r?void 0:r.split("/")[0])||(null===(i=null==e?void 0:e.$.mimeType)||void 0===i?void 0:i.split("/")[0]);if("audio"===n||"video"===n||"text"===n)return n;if("application"===n)return"text"}if(t.$.maxHeight)return"video";const o=null!==(s=t.$.id)&&void 0!==s?s:`group: ${t.$.group}, lang: ${t.$.lang}`;return console.error(`Could not find contentType from adaptationSet ${o}`),console.info('Using "text" as default contentType'),"text"}function ht(t,e){return t&&e?+(null!=t?t:1)/+(null!=e?e:1):1}function dt(t,e,n){return e.$.media.replace(/\$(.*?)\$/g,e=>e.includes("RepresentationID")?t.$.id:e.includes("Number%04d")?n.toString().padStart(4,"0"):e.includes("Number")?n:(console.error(`Unknown property ${e} from the SegmentTemplate on representation ${t.$.id}`),e))}function ft(t,e,n){var r;const i=function(t,e){return Math.round(e/ht(t.$.duration,t.$.timescale))}(n,e),s=+(null!==(r=n.$.startNumber)&&void 0!==r?r:0),o=[];for(let e=s;e<i+s;e++)o.push({duration:ht(n.$.duration,n.$.timescale),url:dt(t,n,e)});return o}function gt(t,e,n){var r,i,s,o;const a=null!==(i=null===(r=t.SegmentTemplate)||void 0===r?void 0:r.at(0))&&void 0!==i?i:null===(s=e.SegmentTemplate)||void 0===s?void 0:s.at(0),u=null!==(o=t.SegmentList)&&void 0!==o?o:e.SegmentList;return e.SegmentBase?function(t,e){return t.SegmentBase.map(n=>{var r;return{duration:e,url:null!==(r=t.BaseURL[0])&&void 0!==r?r:"",byteRange:n.$.indexRange}})}(e,n):u?function(t){const e=[];return t.map(t=>{if(t.SegmentURL)return t.SegmentURL.forEach(n=>{var r;e.push({duration:ht(t.$.duration,t.$.timescale),url:null!==(r=n.$.media)&&void 0!==r?r:""})})}),e}(u):a?ft(e,n,a):(console.error(`Representation ${e.$.id} has no segments`),[])}function pt(t,e){var n,r,i,s,o,a;const u=+(null!==(a=null!==(i=null===(r=null===(n=t.AudioChannelConfiguration)||void 0===n?void 0:n.at(0))||void 0===r?void 0:r.$.value)&&void 0!==i?i:null===(o=null===(s=e.AudioChannelConfiguration)||void 0===s?void 0:s.at(0))||void 0===o?void 0:o.$.value)&&void 0!==a?a:0);return u||console.error(`Representation ${e.$.id} has no channels`),u}function mt(t,e){var n,r;const i=null!==(r=null!==(n=e.$.codecs)&&void 0!==n?n:t.$.codecs)&&void 0!==r?r:"";return i||console.error(`Representation ${e.$.id} has no codecs`),i}const yt="@";function vt(t,e){var n,r,i,s;const o=null!==(r=null!==(n=e.$.frameRate)&&void 0!==n?n:t.$.frameRate)&&void 0!==r?r:"";o||console.error(`Representation ${e.$.id} has no frame rate`);const a=o.split("/"),u=parseInt(null!==(i=a.at(0))&&void 0!==i?i:""),l=parseInt(null!==(s=a.at(1))&&void 0!==s?s:"");return{frameRateNumerator:isNaN(u)?30:u,frameRateDenominator:isNaN(l)?0:l}}function bt(t){let e=t.$.lang;return e||(console.info(`AdaptationSet ${t.$.id} has no lang, using "und" as default`),e="und"),e}function wt(t,e){var n,r;const i=+(null!==(r=null!==(n=e.$.audioSamplingRate)&&void 0!==n?n:t.$.audioSamplingRate)&&void 0!==r?r:0);return i||console.error(`Representation ${e.$.id} has no audioSamplingRate`),i}function St(t,e){var n,r;const i=null!==(r=null!==(n=e.$.sar)&&void 0!==n?n:t.$.sar)&&void 0!==r?r:"";return i||console.error(`Representation ${e.$.id} has no sar`),i}function _t(t){return t.reduce((t,e)=>t+e.duration,0)}function Et(t){return t.MPD.Period.map(t=>{const e=function(t){const e=/(?:([.,\d]+)H)/.exec(t),n=/(?:([.,\d]+)M)/.exec(t),r=/(?:([.,\d]+)S)/.exec(t);let i=0;return e&&(i+=60*+e[1]*60),n&&(i+=60*+n[1]),r&&(i+=+r[1]),i}(t.$.duration),n=function(t,e){var n;return null!==(n=t.$.id)&&void 0!==n?n:`presentation-id-${e}`}(t,e),r={};t.AdaptationSet.map(t=>{var n,i,s,o;const a=t.Representation.map(n=>{const r=gt(t,n,e);return function(t,e,n,r){var i,s,o,a,u,l,c,h,d,f;if(!t)throw new Error("Error: AdaptationSet is undefined");const g=ct(t,e);return"video"===g?{bandwidth:+(null!==(i=e.$.bandwidth)&&void 0!==i?i:0),codec:mt(t,e),duration:_t(n),frameRate:vt(t,e),height:+(null!==(s=e.$.height)&&void 0!==s?s:0),id:null!==(o=e.$.id)&&void 0!==o?o:"",language:bt(t),par:null!==(a=t.$.par)&&void 0!==a?a:"",sar:St(t,e),scanType:null!==(u=e.$.scanType)&&void 0!==u?u:"",segments:n,type:g,width:+(null!==(l=e.$.width)&&void 0!==l?l:0),urlInitialization:r}:"audio"===g?{bandwidth:+(null!==(c=e.$.bandwidth)&&void 0!==c?c:0),channels:pt(t,e),codec:mt(t,e),duration:_t(n),id:null!==(h=e.$.id)&&void 0!==h?h:"",language:bt(t),sampleRate:wt(t,e),segments:n,type:g,urlInitialization:r}:{bandwidth:+(null!==(d=e.$.bandwidth)&&void 0!==d?d:0),codec:mt(t,e),duration:_t(n),id:null!==(f=e.$.id)&&void 0!==f?f:"",language:bt(t),segments:n,type:g,urlInitialization:r}}(t,n,r,function(t,e){var n,r,i,s,o,a,u,l,c,h;let d;return e.SegmentBase?d=null!==(n=e.BaseURL[0])&&void 0!==n?n:"":(t.SegmentList||e.SegmentList)&&(d=(null===(i=null===(r=e.SegmentList)||void 0===r?void 0:r.at(0))||void 0===i?void 0:i.Initialization[0].$.sourceURL)||(null===(o=null===(s=t.SegmentList)||void 0===s?void 0:s.at(0))||void 0===o?void 0:o.Initialization[0].$.sourceURL)),(t.SegmentTemplate||e.SegmentTemplate)&&(d=(null===(u=null===(a=t.SegmentTemplate)||void 0===a?void 0:a.at(0))||void 0===u?void 0:u.$.initialization)||(null===(c=null===(l=e.SegmentTemplate)||void 0===l?void 0:l.at(0))||void 0===c?void 0:c.$.initialization),(null==d?void 0:d.includes("$RepresentationID$"))&&(d=d.replace("$RepresentationID$",null!==(h=e.$.id)&&void 0!==h?h:""))),d}(t,n))}),u=function(t){var e;return null!==(e=t.$.group)&&void 0!==e?e:ct(t)}(t);r[u]||(r[u]={id:u,switchingSets:[]}),r[u].switchingSets.push({id:null!==(o=null!==(n=t.$.id)&&void 0!==n?n:null===(s=null===(i=t.ContentComponent)||void 0===i?void 0:i.at(0))||void 0===s?void 0:s.$.id)&&void 0!==o?o:u,tracks:a})});return{id:n,selectionSets:Object.values(r)}})}function Tt(t){var e;const n=[];if(t.segments.length>0&&t.byteRange&&t.segments[0].byteRange&&t.segments[0].byteRange.includes("@")){let r;const i=t.byteRange.includes("-")?t.byteRange.split("-")[1]:t.byteRange.includes("@")?t.byteRange.split("@")[0]:"",s=+i-1;if(r={$:{indexRange:`${i}-${+(t.segments[0].byteRange.includes("-")?t.segments[0].byteRange.split("-")[1]:t.segments[0].byteRange.includes("@")?t.segments[0].byteRange.split("@")[1]:"")-1}`},Initialization:[{$:{range:`0-${s}`}}]},r&&"audio"===t.type){const n=t;r.$.timescale=null!==(e=n.sampleRate.toString())&&void 0!==e?e:""}r&&n.push(r)}else t.segments.forEach(e=>{var r;let i;if(e.byteRange){const t=+e.byteRange.split("-")[0]-1;i={$:{indexRange:e.byteRange},Initialization:[{$:{range:`0-${t}`}}]}}if(i&&"audio"===t.type){const e=t;i.$.timescale=null!==(r=e.sampleRate.toString())&&void 0!==r?r:""}i&&n.push(i)});return n}function Ct(t){var e;const n=[],r=[];if(t.segments.forEach(t=>{r.push({$:{media:t.url}})}),!(null===(e=t.segments.at(0))||void 0===e?void 0:e.byteRange)){const e=function(t){if("audio"===(null==t?void 0:t.type)){const e=t;return 0!==e.sampleRate?e.sampleRate:48e3}return"video"===(null==t?void 0:t.type)?9e4:"text"===(null==t?void 0:t.type)?1e3:9e4}(t);n.push({$:{duration:(t.duration*e/r.length).toString(),timescale:e.toString()},Initialization:[{$:{sourceURL:t.urlInitialization}}],SegmentURL:r})}return n}function Ut(t){var e;let n;if("video"===(null==t?void 0:t.type)){const r=t;n=`${null!==(e=r.frameRate.frameRateNumerator)&&void 0!==e?e:30}`,n=0!==r.frameRate.frameRateDenominator?`${n}/${r.frameRate.frameRateDenominator}`:n}return n}function At(t){const e=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return e>0?`PT${e}H${n}M${r}S`:n>0?`PT${n}M${r}S`:`PT${r}S`}function Rt(t){const e=t.map(t=>{return{$:{duration:At(t.selectionSets[0].switchingSets[0].tracks[0].duration),id:t.id,start:"PT0S"},AdaptationSet:(e=t.selectionSets,e.flatMap(t=>t.switchingSets.map(e=>{const n=e.tracks[0];return{$:{id:e.id,group:t.id,contentType:null==n?void 0:n.type,mimeType:`${null==n?void 0:n.type}/mp4`,frameRate:Ut(n),lang:null==n?void 0:n.language,codecs:null==n?void 0:n.codec},Representation:(r=e.tracks,r.map(t=>{var e,n;const r={$:{id:t.id,bandwidth:t.bandwidth.toString()},SegmentBase:Tt(t),SegmentList:Ct(t)};if(r.$.mimeType=`${t.type}/mp4`,"video"===t.type){const e=t;r.$={...r.$,frameRate:Ut(t),width:e.width.toString(),height:e.height.toString(),codecs:e.codec},e.scanType&&(r.$.scanType=e.scanType)}if("audio"===t.type){const n=t;r.$={...r.$,audioSamplingRate:n.sampleRate.toString(),codecs:n.codec},r.AudioChannelConfiguration=[{$:{schemeIdUri:"urn:mpeg:dash:23003:3:audio_channel_configuration:2011",value:null!==(e=n.channels.toString())&&void 0!==e?e:""}}]}return(null===(n=t.segments[0])||void 0===n?void 0:n.byteRange)&&(r.BaseURL=[t.segments[0].url]),r}))};var r})))};var e});const n=e[0].$.duration;return at({MPD:{$:{mediaPresentationDuration:n,type:"static"},Period:e}})}function Mt(t){const e=null==t?void 0:t.metadata;return JSON.parse(JSON.stringify(e))}class Dt{getManifestMetadata(){return Mt(this.manifest)}toHam(t){const e=(n=t.manifest,ot(n));var n;return e?(function(t,e){e.metadata||(e.metadata=new Map),t.MPD.$&&t.MPD.$.profiles&&e.metadata.set("profiles",t.MPD.$.profiles),t.MPD.$&&t.MPD.$.type&&e.metadata.set("type",t.MPD.$.type)}(e,t),Et(e)):[]}toManifest(t){return{manifest:Rt(t),ancillaryManifests:[],type:"dash"}}}class It{constructor(){}static getInstance(){return It.instance||(It.instance=new It),It.instance}setStrategy(t){this.strategy=t}getHamFormat(t){return this.strategy.toHam(t)}getManifestFormat(t){return this.strategy.toManifest(t)}getManifestMetadata(){return this.strategy.getManifestMetadata()}}function Ot(t){return`#EXT-X-MAP:URI="${function(t){var e,n;return null!==(n=null===(e=t.urlInitialization)||void 0===e?void 0:e.replaceAll(" ","%20"))&&void 0!==n?n:""}(t)}",${function(t){var e,n,r,i;return t.byteRange?`BYTERANGE:${t.byteRange.replace("-",yt)}\n`:(null===(n=null===(e=t.segments)||void 0===e?void 0:e.at(0))||void 0===n?void 0:n.byteRange)?`BYTERANGE:0@${Number(null===(i=null===(r=t.segments.at(0))||void 0===r?void 0:r.byteRange)||void 0===i?void 0:i.replace("-",yt).split(yt)[0])-1}\n`:""}(t)}\n`}function xt(t){var e;const n=null!==(e=t.fileName)&&void 0!==e?e:`${t.id}.m3u8`;let r="",i=`#EXTM3U\n#EXT-X-TARGETDURATION:${t.duration/t.segments.length}\n#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-MEDIA-SEQUENCE:0\n`;if("video"===t.type.toLowerCase()){const e=t;r+=`#EXT-X-STREAM-INF:BANDWIDTH=${e.bandwidth},CODECS="${e.codec}",RESOLUTION=${e.width}x${e.height}\n${n}\n`,i+=Ot(e)}else if("audio"===t.type.toLowerCase()){const e=t;r+=`#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="${e.id}",LANGUAGE="${e.language}",NAME="${e.id}",URI="${n}"\n`,i+=Ot(e)}else if("text"===t.type.toLowerCase()){const e=t;r+=`#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="${e.id}",NAME="${e.id}",LANGUAGE="${e.language}",URI="${n}"\n`}var s;return i+=`${s=t.segments,s.map(t=>{const e=t.byteRange?`#EXT-X-BYTERANGE:${t.byteRange.replace("-",yt)}\n`:"",n=t.url.replaceAll(" ","%20");return`#EXTINF:${t.duration},\n${e}\n${n}`}).join("\n")}#EXT-X-ENDLIST`,{mainRef:r,playlist:i}}function Nt(t){return t?`${t.length}@${t.offset}`:""}function Lt(t){var e;return null!==(e=null==t?void 0:t.map(t=>{const e=Nt(null==t?void 0:t.byterange);return{duration:t.duration,url:t.uri,...e&&{byteRange:e}}}))&&void 0!==e?e:[]}function $t(t,e){var n;return"audio"===t?"mp4a.40.2":"video"===t&&null!==(n=null==e?void 0:e.split(",").at(0))&&void 0!==n?n:""}function kt(t,e){return(null==t?void 0:t.targetDuration)?(null==t?void 0:t.targetDuration)*e.length:(console.error("Could not calculate duration, manifest is undefined."),null)}function Pt(t){var e,n;const r=lt(t.manifest),i=function(t,e){return t.metadata||(t.metadata=new Map),e.version||t.metadata.set("version",e.version),e.mediaSequence||t.metadata.set("mediaSequence",e.mediaSequence),t}(t,r),s=[],o=i.ancillaryManifests?[...i.ancillaryManifests]:[],a=function(t,e){var n,r;const i=[],s=[];for(const i in t){const o=t[i];for(const t in o){const i=o[t],{language:a,uri:u}=i,l=lt(null===(n=e.shift())||void 0===n?void 0:n.manifest),c=null===(r=null==l?void 0:l.segments[0])||void 0===r?void 0:r.map,h=Lt(null==l?void 0:l.segments),d=Nt(null==c?void 0:c.byterange);s.push({id:t,type:"audio",fileName:u,codec:$t("audio"),duration:kt(l,h),language:a,bandwidth:0,segments:h,sampleRate:0,channels:2,...d&&{byteRange:d},...(null==c?void 0:c.uri)&&{urlInitialization:null==c?void 0:c.uri}})}}return i.push({id:"audio",tracks:s}),i}(null===(e=r.mediaGroups)||void 0===e?void 0:e.AUDIO,o),u=function(t,e){var n;const r=[],i=[];for(const r in t){const s=t[r];for(const t in s){const r=s[t],{language:o,uri:a}=r,u=lt(null===(n=e.shift())||void 0===n?void 0:n.manifest),l=Lt(null==u?void 0:u.segments);i.push({id:t,type:"text",fileName:a,codec:$t("text"),duration:kt(u,l),language:o,bandwidth:0,segments:l})}}return r.push({id:"text",tracks:i}),r}(null===(n=r.mediaGroups)||void 0===n?void 0:n.SUBTITLES,o),l=function(t,e){const n=[],r=[];let i=0;return t.map(t=>{var n,s,o,a;const u=lt(null===(n=e.shift())||void 0===n?void 0:n.manifest),l=Lt(null==u?void 0:u.segments),{LANGUAGE:c,CODECS:h,BANDWIDTH:d}=t.attributes,f=null===(o=null===(s=null==u?void 0:u.segments)||void 0===s?void 0:s.at(0))||void 0===o?void 0:o.map,g=Nt(null==f?void 0:f.byterange);r.push({id:"video-"+i++,type:"video",fileName:t.uri,codec:$t("video",h),duration:kt(u,l),language:null!=c?c:"und",bandwidth:d,segments:l,width:t.attributes.RESOLUTION.width,height:t.attributes.RESOLUTION.height,frameRate:{frameRateNumerator:null!==(a=t.attributes["FRAME-RATE"])&&void 0!==a?a:30,frameRateDenominator:0},par:"",sar:"",scanType:"",...g&&{byteRange:g},...(null==f?void 0:f.uri)&&{urlInitialization:null==f?void 0:f.uri}})}),n.push({id:"video",tracks:r}),n}(r.playlists,o);let c=0;a.length>0&&s.push({id:(c++).toString(),switchingSets:a}),u.length>0&&s.push({id:(c++).toString(),switchingSets:u}),l.length>0&&s.push({id:(c++).toString(),switchingSets:l});let h=0;return[{id:(h++).toString(),selectionSets:s}]}class Ft{getManifestMetadata(){return Mt(this.manifest)}toHam(t){const e=Pt(t);return this.manifest=t,e}toManifest(t){return function(t){let e="#EXTM3U\n#EXT-X-VERSION:7\n\n";const n=[];return t.map(t=>{t.selectionSets.map(t=>{t.switchingSets.map(t=>{t.tracks.map(t=>{var r;const{mainRef:i,playlist:s}=xt(t);e+=i;const o=null!==(r=t.fileName)&&void 0!==r?r:`${t.id}.m3u8`;n.push({manifest:s,type:"hls",fileName:o})})})})}),{manifest:e,ancillaryManifests:n,type:"hls"}}(t)}}function Bt(t,e){const n=t.tracks;return e?n.filter(e):n}function zt(t,e){const n=t.switchingSets.flatMap(t=>Bt(t));return e?n.filter(e):n}function Vt(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the track with id = ${e}`:".";return t.duration||(r.status=!1,r.errorMessages.push(`Segment duration is undefined${i}`)),t.url||(r.status=!1,r.errorMessages.push(`Segment url is undefined${i}`)),r}function Ht(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]};return t.forEach(t=>{Vt(t,e,r)}),r}function Wt(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the switching set with id = ${e}`:".";switch(t.id||(r.status=!1,r.errorMessages.push(`Track id is undefined${i}`)),t.type){case"video":!function(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the switching set with id = ${e}`:".";t.codec||(r.status=!1,r.errorMessages.push(`VideoTrack with id: ${t.id} does not have codec${i}`))}(t,e,r);break;case"audio":!function(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the switching set with id = ${e}`:".";t.codec||(r.status=!1,r.errorMessages.push(`AudioTrack with id: ${t.id} does not have codec${i}`))}(t,e,r);break;case"text":!function(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the switching set with id = ${e}`:".";t.language||(r.status=!1,r.errorMessages.push(`TextTrack with id: ${t.id} does not have codec${i}`))}(t,e,r)}return Ht(t.segments,t.id,r),r}function Yt(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the switching set with id = ${e}`:".";let s;return t.forEach(t=>{s||(s=t.duration),s!==t.duration&&(r.status=!1,r.errorMessages.push(`All the tracks must have the same duration${i}`)),Wt(t,e,r)}),r}function jt(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the selection set with id = ${e}`:".";return t.id||(r.status=!1,r.errorMessages.push(`SwitchingSet id is undefined${i}`)),Yt(t.tracks,t.id,r),r}function Xt(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]};return t.forEach(t=>{jt(t,e,r)}),r}function qt(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]},i=e?` in the presentation with id = ${e}`:".";return t.id||(r.status=!1,r.errorMessages.push(`SelectionSet id is undefined${i}`)),Xt(t.switchingSets,t.id,r),r}function Gt(t,e,n){const r=null!=n?n:{status:!0,errorMessages:[]};return t.forEach(t=>{qt(t,e,r)}),r}class Kt{constructor(t,e){Array.isArray(t)&&(t=t.map(t=>t instanceof Kt?t:new Kt(t))),this.value=t,this.params=e}}const Qt="Dict";function Jt(t,e,n,r){return new Error(`failed to ${t} "${i=e,Array.isArray(i)?JSON.stringify(i):i instanceof Map?"Map{}":i instanceof Set?"Set{}":"object"==typeof i?JSON.stringify(i):String(i)}" as ${n}`,{cause:r});var i}function Zt(t,e,n){return Jt("serialize",t,e,n)}class te{constructor(t){this.description=t}}const ee="Bare Item",ne="Boolean";function re(t){return btoa(String.fromCharCode(...t))}const ie="Byte Sequence";const se="Integer";function oe(t){return t<-999999999999999||999999999999999<t}function ae(t){if(oe(t))throw Zt(t,se);return t.toString()}function ue(t,e){if(t<0)return-ue(-t,e);const n=Math.pow(10,e);if(Math.abs(t*n%1-.5)<Number.EPSILON){const e=Math.floor(t*n);return(e%2==0?e:e+1)/n}return Math.round(t*n)/n}const le="Decimal";const ce="String",he=/[\x00-\x1f\x7f]+/;function de(t){return t.description||t.toString().slice(7,-1)}const fe="Token";function ge(t){const e=de(t);if(!1===/^([a-zA-Z*])([!#$%&'*+\-.^_`|~\w:/]*)$/.test(e))throw Zt(e,fe);return e}function pe(t){switch(typeof t){case"number":if(!Number.isFinite(t))throw Zt(t,ee);return Number.isInteger(t)?ae(t):function(t){const e=ue(t,3);if(Math.floor(Math.abs(e)).toString().length>12)throw Zt(t,le);const n=e.toString();return n.includes(".")?n:`${n}.0`}(t);case"string":return function(t){if(he.test(t))throw Zt(t,ce);return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}(t);case"symbol":return ge(t);case"boolean":return function(t){if("boolean"!=typeof t)throw Zt(t,ne);return t?"?1":"?0"}(t);case"object":if(t instanceof Date)return function(t){return`@${ae(t.getTime()/1e3)}`}(t);if(t instanceof Uint8Array)return function(t){if(!1===ArrayBuffer.isView(t))throw Zt(t,ie);return`:${re(t)}:`}(t);if(t instanceof te)return ge(t);default:throw Zt(t,ee)}}function me(t){if(!1===/^[a-z*][a-z0-9\-_.*]*$/.test(t))throw Zt(t,"Key");return t}function ye(t){return null==t?"":Object.entries(t).map(([t,e])=>!0===e?`;${me(t)}`:`;${me(t)}=${pe(e)}`).join("")}function ve(t){return t instanceof Kt?`${pe(t.value)}${ye(t.params)}`:pe(t)}function be(t){return`(${t.value.map(ve).join(" ")})${ye(t.params)}`}function we(t,e){return function(t,e={whitespace:!0}){if("object"!=typeof t||null==t)throw Zt(t,Qt);const n=t instanceof Map?t.entries():Object.entries(t),r=(null==e?void 0:e.whitespace)?" ":"";return Array.from(n).map(([t,e])=>{e instanceof Kt==0&&(e=new Kt(e));let n=me(t);return!0===e.value?n+=ye(e.params):(n+="=",Array.isArray(e.value)?n+=be(e):n+=ve(e)),n}).join(`,${r}`)}(t,e)}const Se="CMCD-Object",_e="CMCD-Request",Ee="CMCD-Session",Te="CMCD-Status",Ce={br:Se,ab:Se,d:Se,ot:Se,tb:Se,tpb:Se,lb:Se,tab:Se,lab:Se,url:Se,pb:_e,bl:_e,tbl:_e,dl:_e,ltc:_e,mtp:_e,nor:_e,nrr:_e,rc:_e,sn:_e,sta:_e,su:_e,ttfb:_e,ttfbb:_e,ttlb:_e,cmsdd:_e,cmsds:_e,smrt:_e,df:_e,cs:_e,ts:_e,cid:Ee,pr:Ee,sf:Ee,sid:Ee,st:Ee,v:Ee,msd:Ee,bs:Te,bsd:Te,cdn:Te,rtp:Te,bg:Te,pt:Te,ec:Te,e:Te},Ue={OBJECT:Se,REQUEST:_e,SESSION:Ee,STATUS:Te};function Ae(t,e){const n={};if(!t)return n;const r=Object.keys(t),i=e?(s=e,Object.keys(s).reduce((t,e)=>{var n;return null===(n=s[e])||void 0===n||n.forEach(n=>t[n]=e),t},{})):{};var s;return r.reduce((e,n)=>{var r;const s=Ce[n]||i[n]||Ue.REQUEST;return(null!==(r=e[s])&&void 0!==r?r:e[s]={})[n]=t[n],e},n)}function Re(t){return["ot","sf","st","e","sta"].includes(t)}function Me(t){return"number"==typeof t?Number.isFinite(t):null!=t&&""!==t&&!1!==t}const De="event";function Ie(t,e){const n=new URL(t),r=new URL(e);if(n.origin!==r.origin)return t;const i=n.pathname.split("/").slice(1),s=r.pathname.split("/").slice(1,-1),o=Math.min(i.length,s.length);for(let t=0;t<o&&i[t]===s[t];t++)i.shift(),s.shift();for(;s.length;)s.shift(),i.unshift("..");return i.join("/")+n.search+n.hash}const Oe=t=>Math.round(t),xe=(t,e)=>Array.isArray(t)?t.map(t=>xe(t,e)):t instanceof Kt&&"string"==typeof t.value?new Kt(xe(t.value,e),t.params):(e.baseUrl&&(t=Ie(t,e.baseUrl)),1===e.version?encodeURIComponent(t):t),Ne=t=>100*Oe(t/100),Le={br:Oe,d:Oe,bl:Ne,dl:Ne,mtp:Ne,nor:(t,e)=>{let n=t;return e.version>=2&&(t instanceof Kt&&"string"==typeof t.value?n=new Kt([t]):"string"==typeof t&&(n=[t])),xe(n,e)},rtp:Ne,tb:Oe},$e="request",ke="response",Pe=["ab","bg","bl","br","bs","bsd","cdn","cid","cs","df","ec","lab","lb","ltc","msd","mtp","pb","pr","pt","sf","sid","sn","st","sta","tab","tb","tbl","tpb","ts","v"],Fe=["e"],Be=/^[a-zA-Z0-9-.]+-[a-zA-Z0-9-.]+$/;function ze(t){return Be.test(t)}function Ve(t){return Pe.includes(t)||Fe.includes(t)||ze(t)}const He=["d","dl","nor","ot","rtp","su"];function We(t){return Pe.includes(t)||He.includes(t)||ze(t)}const Ye=["cmsdd","cmsds","rc","smrt","ttfb","ttfbb","ttlb","url"];function je(t){return Pe.includes(t)||He.includes(t)||Ye.includes(t)||ze(t)}const Xe=["bl","br","bs","cid","d","dl","mtp","nor","nrr","ot","pr","rtp","sf","sid","st","su","tb","v"];function qe(t){return Xe.includes(t)||ze(t)}const Ge={[ke]:je,[De]:Ve,[$e]:We};function Ke(t,e={}){const n={};if(null==t||"object"!=typeof t)return n;const r=e.version||t.v||1,i=e.reportingMode||$e,s=1===r?qe:Ge[i];let o=Object.keys(t).filter(s);const a=e.filter;"function"==typeof a&&(o=o.filter(a));const u=i===ke||i===De;u&&!o.includes("ts")&&o.push("ts"),r>1&&!o.includes("v")&&o.push("v");const l=Object.assign({},Le,e.formatters),c={version:r,reportingMode:i,baseUrl:e.baseUrl};return o.sort().forEach(e=>{let i=t[e];const s=l[e];if("function"==typeof s&&(i=s(i,c)),"v"===e){if(1===r)return;i=r}"pr"==e&&1===i||(u&&"ts"===e&&!Number.isFinite(i)&&(i=Date.now()),Me(i)&&(Re(e)&&"string"==typeof i&&(i=new te(i)),n[e]=i))}),n}function Qe(t,e={}){const n={};if(!t)return n;const r=Ae(Ke(t,e),null==e?void 0:e.customHeaderMap);return Object.entries(r).reduce((t,[e,n])=>{const r=we(n,{whitespace:!1});return r&&(t[e]=r),t},n)}const Je="CMCD";function Ze(t,e={}){return t?we(Ke(t,e),{whitespace:!1}):""}function tn(t,e={}){if(!t)return"";const n=Ze(t,e);return encodeURIComponent(n)}function en(t,e={}){if(!t)return"";const n=tn(t,e);return`${Je}=${n}`}const nn=/CMCD=[^&#]+/;const rn="headers",sn="json",on=new Set([...Xe,...Pe,...He,...Ye,...Fe]),an=Array.from(on),un="query",ln={JSON:sn,QUERY:un,HEADERS:rn},cn=ln,hn=Le,dn={MANIFEST:"m",AUDIO:"a",VIDEO:"v",MUXED:"av",INIT:"i",CAPTION:"c",TIMED_TEXT:"tt",KEY:"k",OTHER:"o"},fn=dn,gn={REQUEST:$e,RESPONSE:ke,EVENT:De},pn={DASH:"d",HLS:"h",SMOOTH:"s",OTHER:"o"},mn=pn,yn={VOD:"v",LIVE:"l"},vn=yn;function bn(t,e){return{value:t,src:e}}function wn(t,e,n){return Jt("parse",t,e,n)}const Sn="Inner List";function _n(t){return new Uint8Array([...atob(t)].map(t=>t.charCodeAt(0)))}const En="Date",Tn=`${se} or ${le}`;function Cn(t){let e,n=1,r="";const i=wn(t,Tn);if("-"===t[0]&&(n=-1,t=t.substring(1)),t.length<=0)throw i;const s=/^(\d+)?/g,o=s.exec(t);if(0===o[0].length)throw i;if(r+=o[1],"."===(t=t.substring(s.lastIndex))[0]){if(r.length>12)throw i;const s=/^(\.\d+)?/g,o=s.exec(t);if(t=t.substring(s.lastIndex),0===o[0].length||o[1].length>4)throw i;if(r+=o[1],r.length>16)throw i;e=parseFloat(r)*n}else{if(r.length>15)throw i;if(e=parseInt(r)*n,oe(e))throw wn(r,Tn)}return bn(e,t)}function Un(t,e){const n=t[0];if('"'===n)return function(t){let e="",n=0;if('"'!==t[n])throw wn(t,ce);for(n++;t.length>n;){if("\\"===t[n]){if(t.length<=n+1)throw wn(t,ce);if(n++,'"'!==t[n]&&"\\"!==t[n])throw wn(t,ce);e+=t[n]}else{if('"'===t[n])return bn(e,t.substring(++n));if(he.test(t[n]))throw wn(t,ce);e+=t[n]}n++}throw wn(t,ce)}(t);if(/^[-0-9]/.test(n))return Cn(t);if("?"===n)return function(t){let e=0;if("?"!==t[e])throw wn(t,ne);if(e++,"1"===t[e])return bn(!0,t.substring(++e));if("0"===t[e])return bn(!1,t.substring(++e));throw wn(t,ne)}(t);if(":"===n)return function(t){if(":"!==t[0])throw wn(t,ie);if(!1===(t=t.substring(1)).includes(":"))throw wn(t,ie);const e=/(^.*?)(:)/g,n=e.exec(t)[1];return t=t.substring(e.lastIndex),bn(_n(n),t)}(t);if(/^[a-zA-Z*]/.test(n))return function(t,e){if(!1===/^[a-zA-Z*]$/.test(t[0]))throw wn(t,fe);const n=/^([!#$%&'*+\-.^_`|~\w:/]+)/g,r=n.exec(t)[1];return t=t.substring(n.lastIndex),bn(!1===(null==e?void 0:e.useSymbol)?new te(r):Symbol.for(r),t)}(t,e);if("@"===n)return function(t){let e=0;if("@"!==t[e])throw wn(t,En);e++;const n=Cn(t.substring(e));if(!1===Number.isInteger(n.value))throw wn(t,En);return bn(new Date(1e3*n.value),n.src)}(t);throw wn(t,ee)}function An(t){let e=0;if(!1===/^[a-z*]$/.test(t[e]))throw wn(t,"Key");let n="";for(;t.length>e;){if(!1===/^[a-z0-9_\-.*]$/.test(t[e]))return bn(n,t.substring(e));n+=t[e],e++}return bn(n,t.substring(e))}function Rn(t,e){let n;for(;t.length>0&&";"===t[0];){const r=An(t=t.substring(1).trim()),i=r.value;let s=!0;if("="===(t=r.src)[0]){const n=Un(t=t.substring(1),e);s=n.value,t=n.src}null==n&&(n={}),n[i]=s}return bn(n,t)}function Mn(t,e){const n=Un(t,e),r=Rn(t=n.src,e);return t=r.src,bn(new Kt(n.value,r.value),t)}function Dn(t,e){return"("===t[0]?function(t,e){if("("!==t[0])throw wn(t,Sn);t=t.substring(1);const n=[];for(;t.length>0;){if(")"===(t=t.trim())[0]){const r=Rn(t=t.substring(1),e);return bn(new Kt(n,r.value),r.src)}const r=Mn(t,e);if(n.push(r.value)," "!==(t=r.src)[0]&&")"!==t[0])throw wn(t,Sn)}throw wn(t,Sn)}(t,e):Mn(t,e)}function In(t,e){try{const{src:n,value:r}=function(t,e){const n={};for(;t.length>0;){let r;const i=An(t),s=i.value;if("="===(t=i.src)[0]){const n=Dn(t.substring(1),e);r=n.value,t=n.src}else{const n=Rn(t,e);r=new Kt(!0,n.value),t=n.src}if(n[s]=r,0===(t=t.trim()).length)return bn(n,t);if(","!==t[0])throw wn(t,Qt);if(0===(t=t.substring(1).trim()).length||","===t[0])throw wn(t,Qt)}return bn(n,t)}(t.trim(),e);if(""!==n)throw wn(n,Qt);return r}catch(e){throw wn(t,Qt,e)}}function On(t){return Array.isArray(t)?t.map(On):"symbol"==typeof t?de(t):t instanceof Kt&&!t.params?On(t.value):"string"==typeof t?decodeURIComponent(t):t}function xn(t){if(!t)return{};const e=In(t);return Object.entries(e).reduce((t,[e,n])=>(t[e]=On(n.value),t),{})}const Nn=[Se,_e,Ee,Te];const Ln="CMSD-Dynamic",$n="CMSD-Static",kn={STATIC:$n,DYNAMIC:Ln},Pn=dn,Fn=pn,Bn=yn,zn="List";function Vn(t,e){try{const{src:n,value:r}=function(t,e){const n=[];for(;t.length>0;){const r=Dn(t,e);if(n.push(r.value),0===(t=r.src.trim()).length)return bn(n,t);if(","!==t[0])throw wn(t,zn);if(0===(t=t.substring(1).trim()).length||","===t[0])throw wn(t,zn)}return bn(n,t)}(t.trim(),e);if(""!==n)throw wn(n,zn);return r}catch(e){throw wn(t,zn,e)}}function Hn(t,e){return function(t,e={whitespace:!0}){if(!1===Array.isArray(t))throw Zt(t,zn);const n=(null==e?void 0:e.whitespace)?" ":"";return t.map(t=>{t instanceof Kt==0&&(t=new Kt(t));const e=t;return Array.isArray(e.value)?be(e):ve(e)}).join(`,${n}`)}(t,e)}function Wn(t){if("object"!=typeof t||!t)return!1;const{ID:e,"BASE-ID":n,"URI-REPLACEMENT":r}=t;return"string"==typeof e&&"string"==typeof n&&null!=r&&"object"==typeof r}const Yn=/\$(RepresentationID|Number|SubNumber|Bandwidth|Time)?(?:%0([0-9]+)([diouxX]))?\$/g;const jn="cbcs",Xn="cenc",qn="urn:mpeg:dash:mp4protection:2011";function Gn(t){if(!t)return{};const e=new DataView(t instanceof ArrayBuffer?t:t.buffer),n={};let r=0;for(;!(r>=e.byteLength);){const i=r,s=r+e.getUint32(r);if(r+=4,1886614376!==e.getUint32(r)){r=s;continue}r+=4;const o=e.getUint8(r);if(0!==o&&1!==o){r=s;continue}r+=1,r+=3;let a,u="";for(let t=0;t<4;t++)a=e.getUint8(r+t).toString(16),u+=1===a.length?"0"+a:a;r+=4,u+="-";for(let t=0;t<2;t++)a=e.getUint8(r+t).toString(16),u+=1===a.length?"0"+a:a;r+=2,u+="-";for(let t=0;t<2;t++)a=e.getUint8(r+t).toString(16),u+=1===a.length?"0"+a:a;r+=2,u+="-";for(let t=0;t<2;t++)a=e.getUint8(r+t).toString(16),u+=1===a.length?"0"+a:a;r+=2,u+="-";for(let t=0;t<6;t++)a=e.getUint8(r+t).toString(16),u+=1===a.length?"0"+a:a;r+=6,u=u.toLowerCase(),r+=4,n[u]=t.slice(i,s),r=s}return n}function Kn(t,e){const n={};return t&&t.length>0&&(n.audioCapabilities=t),e&&e.length>0&&(n.videoCapabilities=e),n.distinctiveIdentifier="optional",n.persistentState="optional",n.sessionTypes=["temporary"],n}const Qn="undefined"!=typeof MediaKeys&&"function"==typeof MediaKeys.isTypeSupported?MediaKeys.isTypeSupported:void 0;function Jn(t,e){if(!e||void 0===Qn)return{supportedAudio:[],supportedVideo:[]};for(const n of e){const e=n.audioCapabilities||[],r=n.videoCapabilities||[],i=e.filter(e=>{var n;return Qn(t,null!==(n=e.contentType)&&void 0!==n?n:"")}),s=r.filter(e=>{var n;return Qn(t,null!==(n=e.contentType)&&void 0!==n?n:"")}),o=i.length>0,a=s.length>0;if(o||a)return{supportedAudio:i,supportedVideo:s}}return{supportedAudio:[],supportedVideo:[]}}function Zn(t){const e=new ArrayBuffer(2*t.length),n=new DataView(e);for(let e=0;e<t.length;e++)n.setUint16(2*e,t.charCodeAt(e),!0);return new Uint16Array(e)}const tr="utf-16",er="utf-16be",nr="utf-16le",rr="utf-8";function ir(t,e={}){let n;n=t instanceof ArrayBuffer?new DataView(t):new DataView(t.buffer,t.byteOffset,t.byteLength);let r=0,{encoding:i}=e;if(!i){const t=n.getUint8(0),e=n.getUint8(1);239==t&&187==e&&191==n.getUint8(2)?(i=rr,r=3):254==t&&255==e?(i=er,r=2):255==t&&254==e?(i=nr,r=2):i=rr}if("undefined"!=typeof TextDecoder)return new TextDecoder(i).decode(n);const{byteLength:s}=n,o=i!==er;let a,u="";for(;r<s;){switch(i){case rr:if(a=n.getUint8(r),a<128)r++;else if(a>=194&&a<=223)if(r+1<s){const t=n.getUint8(r+1);t>=128&&t<=191?(a=(31&a)<<6|63&t,r+=2):r++}else r++;else if(a>=224&&a<=239)if(r+2<=s-1){const t=n.getUint8(r+1),e=n.getUint8(r+2);t>=128&&t<=191&&e>=128&&e<=191?(a=(15&a)<<12|(63&t)<<6|63&e,r+=3):r++}else r++;else if(a>=240&&a<=244)if(r+3<=s-1){const t=n.getUint8(r+1),e=n.getUint8(r+2),i=n.getUint8(r+3);t>=128&&t<=191&&e>=128&&e<=191&&i>=128&&i<=191?(a=(7&a)<<18|(63&t)<<12|(63&e)<<6|63&i,r+=4):r++}else r++;else r++;break;case er:case tr:case nr:a=n.getUint16(r,o),r+=2}u+=String.fromCodePoint(a)}return u}function sr(t,e=tr){return ir(t,{encoding:e}).split("skd://")[1]||""}function or(t,e,n=[]){if(!t)return n;if(t.nodeName===e&&n.push(t),t.childNodes)for(const r of t.childNodes)or(r,e,n);return n}const ar=/&(?:amp|lt|gt|quot|apos|nbsp|lrm|rlm|#[xX]?[0-9a-fA-F]+);/g;function ur(t){return-1===t.indexOf("&")?t:t.replace(ar,t=>{switch(t){case"&amp;":return"&";case"&lt;":return"<";case"&gt;":return">";case"&quot;":return'"';case"&apos;":return"'";case"&nbsp;":return" ";case"&lrm;":return"‎";case"&rlm;":return"‏";default:if("#"===t[1]){const e="x"===t[2]||"X"===t[2]?parseInt(t.slice(3),16):parseInt(t.slice(2),10);return String.fromCodePoint(e)}return t}})}function lr(t,e={}){let n=e.pos||0;const r=t.length,i=!!e.keepComments,s=!!e.keepWhitespace,o="<".charCodeAt(0),a=">".charCodeAt(0),u="-".charCodeAt(0),l="/".charCodeAt(0),c="?".charCodeAt(0),h="!".charCodeAt(0),d="'".charCodeAt(0),f='"'.charCodeAt(0),g="[".charCodeAt(0),p="]".charCodeAt(0);function m(t,e="#text"){return{nodeName:e,nodeValue:t,attributes:{},childNodes:[]}}function y(e=""){const d=[];for(;t[n];)if(t.charCodeAt(n)==o){if(t.charCodeAt(n+1)===l){const r=n+2;if(n=t.indexOf(">",n),!t.startsWith(e,r)){const e=t.substring(0,n).split("\n");throw new Error("Unexpected close tag\nLine: "+(e.length-1)+"\nColumn: "+(e[e.length-1].length+1)+"\nChar: "+t[n])}return n+1&&(n+=1),d}if(t.charCodeAt(n+1)===c){n=t.indexOf(">",n),n++;continue}if(t.charCodeAt(n+1)===h){if(t.charCodeAt(n+2)==u){const e=n;for(;-1!==n&&(t.charCodeAt(n)!==a||t.charCodeAt(n-1)!=u||t.charCodeAt(n-2)!=u||-1==n);)n=t.indexOf(">",n+1);-1===n&&(n=r),i&&d.push(m(t.substring(e,n+1),"#comment"))}else{if(t.charCodeAt(n+2)===g&&t.charCodeAt(n+8)===g&&t.startsWith("CDATA",n+3)){const e=t.indexOf("]]>",n);-1==e?(d.push(m(t.substr(n+9),"#cdata")),n=r):(d.push(m(t.substring(n+9,e),"#cdata")),n=e+3);continue}{const e=n+1;n+=2;let r=!1;for(;(t.charCodeAt(n)!==a||!0===r)&&t[n];)t.charCodeAt(n)===g?r=!0:!0===r&&t.charCodeAt(n)===p&&(r=!1),n++;d.push(m(t.substring(e,n),"#doctype"))}}n++;continue}const s=w();d.push(s)}else{const t=v();if(s)t.length>0&&d.push(m(t));else{const e=t.trim();e.length>0&&d.push(m(e))}n++}return d}function v(){const e=n;return n=t.indexOf("<",n)-1,-2===n&&(n=r),ur(t.slice(e,n+1))}function b(){const e=n;for(;-1==="\r\n\t>/= ".indexOf(t[n])&&t[n];)n++;return t.slice(e,n)}function w(){n++;const e=b();let r=e,i=null;const s=e.indexOf(":");-1!==s&&(i=e.slice(0,s),r=e.slice(s+1));const o=function(){const e={};for(;t.charCodeAt(n)!==a&&t[n];){const r=t.charCodeAt(n);if(r>64&&r<91||r>96&&r<123){const r=b();let i="",s=t.charCodeAt(n);for(;s!==d&&s!==f;)n++,s=t.charCodeAt(n);if(s===d||s===f){if(i=S(),-1===n)throw new Error("Missing closing quote")}else n--;e[r]=ur(i)}n++}return e}();let u=[];const c=t.charCodeAt(n-1);return n++,c!==l&&(u=y(e)),{nodeName:e,nodeValue:null,attributes:o,childNodes:u,prefix:i,localName:r}}function S(){const e=t[n],r=n+1;return n=t.indexOf(e,r),t.slice(r,n)}return{nodeName:"#document",nodeValue:null,childNodes:y(""),attributes:{}}}const cr="Challenge",hr="PlayReadyKeyMessage";const dr="Content-Type",fr="HttpHeaders",gr="text/xml; charset=utf-8";const pr={CENC:Xn,CBCS:jn},mr="expired",yr="HW_SECURE_ALL",vr="HW_SECURE_CRYPTO",br="HW_SECURE_DECODE",wr="individualization-request",Sr="keyids",_r="webm",Er={CENC:Xn,CBCS:jn,KEYIDS:Sr,WEBM:_r},Tr="internal-error",Cr="license-release",Ur="license-renewal",Ar="license-request",Rr={LICENSE_REQUEST:Ar,LICENSE_RENEWAL:Ur,LICENSE_RELEASE:Cr,INDIVIDUALIZATION_REQUEST:wr},Mr="output-downscaled",Dr="output-restricted",Ir="released",Or="status-pending",xr="usable",Nr={USABLE:xr,EXPIRED:mr,RELEASED:Ir,OUTPUT_RESTRICTED:Dr,OUTPUT_DOWNSCALED:Mr,STATUS_PENDING:Or,INTERNAL_ERROR:Tr},Lr="SW_SECURE_CRYPTO",$r="SW_SECURE_DECODE",kr={SW_SECURE_CRYPTO:Lr,SW_SECURE_DECODE:$r,HW_SECURE_CRYPTO:vr,HW_SECURE_DECODE:br,HW_SECURE_ALL:yr};function Pr(t,e){return e+10<=t.length&&73===t[e]&&68===t[e+1]&&51===t[e+2]&&t[e+3]<255&&t[e+4]<255&&t[e+6]<128&&t[e+7]<128&&t[e+8]<128&&t[e+9]<128}function Fr(t,e){let n=0;return n=(127&t[e])<<21,n|=(127&t[e+1])<<14,n|=(127&t[e+2])<<7,n|=127&t[e+3],n}function Br(t,e){return e+10<=t.length&&51===t[e]&&68===t[e+1]&&73===t[e+2]&&t[e+3]<255&&t[e+4]<255&&t[e+6]<128&&t[e+7]<128&&t[e+8]<128&&t[e+9]<128}function zr(t,e=!1){const n=e?t.indexOf(0):t.length,r=ir(new DataView(t.buffer,t.byteOffset,n),{encoding:rr});return e?r:r.replace(/\0/g,"")}function Vr(t,e=0,n=1/0){return function(t,e,n,r){const i=function(t){return t instanceof ArrayBuffer?t:t.buffer}(t);let s=1;"BYTES_PER_ELEMENT"in r&&(s=r.BYTES_PER_ELEMENT);const o=(h=t,h&&h.buffer instanceof ArrayBuffer&&void 0!==h.byteLength&&void 0!==h.byteOffset?t.byteOffset:0),a=(o+t.byteLength)/s,u=(o+e)/s,l=Math.floor(Math.max(0,Math.min(u,a))),c=Math.floor(Math.min(l+Math.max(n,0),a));var h;return new r(i,l,c-l)}(t,e,n,Uint8Array)}function Hr(t){const e={key:t.type,description:"",data:"",mimeType:null,pictureType:null};if(t.size<2)return;if(3!==t.data[0])return void console.log("Ignore frame with unrecognized character encoding");const n=t.data.subarray(1).indexOf(0);if(-1===n)return;const r=zr(Vr(t.data,1,n)),i=t.data[2+n],s=t.data.subarray(3+n).indexOf(0);if(-1===s)return;const o=zr(Vr(t.data,3+n,s));let a;return a="--\x3e"===r?zr(Vr(t.data,4+n+s)):function(t){return t instanceof ArrayBuffer?t:0==t.byteOffset&&t.byteLength==t.buffer.byteLength?t.buffer:new Uint8Array(t).buffer}(t.data.subarray(4+n+s)),e.mimeType=r,e.pictureType=i,e.description=o,e.data=a,e}function Wr(t){return"PRIV"===t.type?function(t){if(t.size<2)return;const e=zr(t.data,!0),n=new Uint8Array(t.data.subarray(e.length+1));return{key:t.type,info:e,data:n.buffer}}(t):"W"===t.type[0]?function(t){if("WXXX"===t.type){if(t.size<2)return;let e=1;const n=zr(t.data.subarray(e),!0);e+=n.length+1;const r=zr(t.data.subarray(e));return{key:t.type,info:n,data:r}}const e=zr(t.data);return{key:t.type,info:"",data:e}}(t):"APIC"===t.type?Hr(t):function(t){if(t.size<2)return;if("TXXX"===t.type){let e=1;const{data:n}=t,r=zr(n.subarray(e),!0);e+=r.length+1;const i=zr(n.subarray(e));return{key:t.type,info:r,data:i}}const e=zr(t.data.subarray(1));return{key:t.type,info:"",data:e}}(t)}function Yr(t){const e=String.fromCharCode(t[0],t[1],t[2],t[3]),n=Fr(t,4);return{type:e,size:n,data:t.subarray(10,10+n)}}function jr(t){let e=0;const n=[];for(;Pr(t,e);){const r=Fr(t,e+6);t[e+5]>>6&1&&(e+=10),e+=10;const i=e+r;for(;e+10<i;){const r=Yr(t.subarray(e)),i=Wr(r);i&&n.push(i),e+=r.size+10}Br(t,e)&&(e+=10)}return n}function Xr(t){return t&&"PRIV"===t.key&&"com.apple.streaming.transportStreamTimestamp"===t.info}function qr(t){if(8===t.data.byteLength){const e=new Uint8Array(t.data),n=1&e[3];let r=(e[4]<<23)+(e[5]<<15)+(e[6]<<7)+e[7];return r/=45,n&&(r+=47721858.84),Math.round(r)}}const Gr=/^([-])?P(?:([\d.]*)Y)?(?:([\d.]*)M)?(?:([\d.]*)D)?T?(?:([\d.]*)H)?(?:([\d.]*)M)?(?:([\d.]*)S)?$/;const Kr=["dinf","edts","enca","encv","grpl","mdia","meco","meta","mfra","minf","moof","moov","mvex","prsl","schi","sinf","stbl","strk","traf","trak","tref","udta","vttc"],Qr="data",Jr="int",Zr="string",ti="template",ei="uint",ni="utf8";function ri(t,e,n){const r=e-t.byteOffset;let i,s,o=NaN;switch(n){case 1:o=t.getUint8(r);break;case 2:o=t.getUint16(r);break;case 3:i=t.getUint16(r),s=t.getUint8(r+2),o=(i<<8)+s;break;case 4:o=t.getUint32(r);break;case 8:i=t.getUint32(r),s=t.getUint32(r+4),o=i*Math.pow(2,32)+s}return o}function ii(t,e,n){let r="";for(let i=0;i<n;i++){const n=ri(t,e+i,1);r+=String.fromCharCode(n)}return r}class si{constructor(t,e){this.truncated=!1,this.slice=t=>{const e=new DataView(this.dataView.buffer,this.offset,t);return this.offset+=t,new si(e,this.config)},this.read=(t,e=0)=>{const{dataView:n,offset:r}=this;let i,s=e;switch(t){case ei:i=ri(n,r,e);break;case Jr:i=function(t,e,n){let r=NaN;const i=e-t.byteOffset;switch(n){case 1:r=t.getInt8(i);break;case 2:r=t.getInt16(i);break;case 4:r=t.getInt32(i);break;case 8:const e=t.getInt32(i),n=t.getInt32(i+4);r=e*Math.pow(2,32)+n}return r}(n,r,e);break;case ti:i=function(t,e,n){const r=n/2;return ri(t,e,r)+ri(t,e+r,r)/Math.pow(2,r)}(n,r,e);break;case Zr:-1===e?(i=function(t,e){let n="",r=e;for(;r-t.byteOffset<t.byteLength;){const e=ri(t,r,1);if(0===e)break;n+=String.fromCharCode(e),r++}return n}(n,r),s=i.length+1):i=ii(n,r,e);break;case Qr:i=function(t,e,n){const r=n>0?n:t.byteLength-(e-t.byteOffset);return new Uint8Array(t.buffer,e,Math.max(r,0))}(n,r,e),s=i.length;break;case ni:-1===e?(i=function(t,e){const n=t.byteLength-(e-t.byteOffset);let r="";if(n>0){const i=new DataView(t.buffer,e,n);let s=0;for(;s<n&&0!==i.getUint8(s);s++);r=ir(new DataView(t.buffer,e,s),{encoding:rr})}return r}(n,r),s=i.length+1):i=function(t,e){const n=t.byteLength-(e-t.byteOffset);return n>0?ir(new DataView(t.buffer,e,n),{encoding:rr}):""}(n,r);break;default:i=-1}return this.offset+=s,i},this.readUint=t=>this.read(ei,t),this.readInt=t=>this.read(Jr,t),this.readString=t=>this.read(Zr,t),this.readTemplate=t=>this.read(ti,t),this.readData=t=>this.read(Qr,t),this.readUtf8=t=>this.read(ni,t),this.readFullBox=()=>({version:this.readUint(1),flags:this.readUint(3)}),this.readArray=(t,e,n)=>{const r=[];for(let i=0;i<n;i++)r.push(this.read(t,e));return r},this.readBox=()=>{const{dataView:t,offset:e}=this;let n=0;const r={size:ri(t,e,4),type:ii(t,e+4,4)};n+=8,1===r.size&&(r.largesize=ri(t,e+n,8),n+=8);const i=r.largesize||r.size;if(this.cursor+i>t.byteLength)throw this.truncated=!0,new Error("Truncated box");this.offset+=n,"uuid"===r.type&&(r.usertype=this.readArray("uint",1,16));const s=0===r.size?this.bytesRemaining:i-n;return r.data=this.slice(s),r},this.readBoxes=t=>{const e=[];for(const n of this)if(e.push(n),t>0&&e.length>=t)break;return e},this.readEntries=(t,e)=>{const n=[];for(let r=0;r<t;r++)n.push(e());return n},this.dataView=t instanceof ArrayBuffer?new DataView(t):t instanceof Uint8Array?new DataView(t.buffer,t.byteOffset,t.byteLength):t,this.offset=this.dataView.byteOffset,this.config=e||{recursive:!1,parsers:{}}}get cursor(){return this.offset-this.dataView.byteOffset}get done(){return this.cursor>=this.dataView.byteLength||this.truncated}get bytesRemaining(){return this.dataView.byteLength-this.cursor}*[Symbol.iterator](){const{parsers:t={},recursive:e=!1}=this.config;for(;!this.done;)try{const{type:n,data:r,...i}=this.readBox(),s={type:n,...i},o=t[n]||t[n.trim()];if(o&&Object.assign(s,o(r,this.config)),s.view=r,Kr.includes(n)){const t=[];for(const n of r)e&&(yield n),t.push(n);s.boxes=t}yield s}catch(t){break}}}function oi(t,e){return new si(t,e)}function ai(t,e,n,r){for(const i of t){e(i)&&r.push(i);const{boxes:t}=i;n&&Array.isArray(t)&&ai(t,e,n,r)}return r}function ui(t,e,n){var r;(t instanceof DataView||t instanceof Uint8Array||t instanceof ArrayBuffer)&&(t=oi(t,{...n,recursive:!1}));return ai(t,e,null===(r=null==n?void 0:n.recursive)||void 0===r||r,[])}function li(t,e,n){for(const r of t){if(n(r))return r;const{boxes:t}=r;if(e&&Array.isArray(t)){const r=li(t,e,n);if(r)return r}}return null}function ci(t,e,n){var r;const i=null===(r=null==n?void 0:n.recursive)||void 0===r||r;return(t instanceof DataView||t instanceof Uint8Array||t instanceof ArrayBuffer)&&(t=oi(t,{...n,recursive:!1})),li(t,i,e)}function hi(t){const{readArray:e,readUint:n,readInt:r,readTemplate:i,readData:s}=t;return{reserved1:e(ei,1,6),dataReferenceIndex:n(2),preDefined1:n(2),reserved2:n(2),preDefined2:e(ei,4,3),width:n(2),height:n(2),horizresolution:i(4),vertresolution:i(4),reserved3:n(4),frameCount:n(2),compressorName:e(ei,1,32),depth:n(2),preDefined3:r(2),config:s(-1)}}function di(t){const{readArray:e,readUint:n,readTemplate:r,readData:i}=t;return{reserved1:e(ei,1,6),dataReferenceIndex:n(2),reserved2:e(ei,4,2),channelcount:n(2),samplesize:n(2),preDefined:n(2),reserved3:n(2),samplerate:r(4),esds:i(-1)}}function fi(t){return{data:t.readData(-1)}}function gi(t){const e=t.readString(4),n=t.readUint(4),r=t.bytesRemaining/4;return{majorBrand:e,minorVersion:n,compatibleBrands:t.readArray(Zr,4,r)}}const pi="Item";function mi(t){const e=t.duration/1e3;return 8*t.encodedBodySize/e}class yi{constructor(t){this.alpha=t,this.estimate=0,this.totalDuration=0}sample(t,e){const n=Math.pow(this.alpha,t);this.estimate=n*e+(1-n)*this.estimate,this.totalDuration+=t}getEstimate(){const t=1-Math.pow(this.alpha,this.totalDuration);return this.estimate/t}getTotalDuration(){return this.totalDuration}}function vi(t){return new Uint8Array(t).reduce((t,e)=>t+e.toString(16).padStart(2,"0"),"")}const bi={UTF8:rr,UTF16:tr,UTF16BE:er,UTF16LE:nr};function wi(t){const e=new ArrayBuffer(t.length/2),n=new Uint8Array(e);for(let e=0;e<t.length;e+=2)n[e/2]=parseInt(t.slice(e,e+2),16);return e}function Si(){return{id:"",startTime:0,endTime:0,region:null,snapToLines:!0,line:"auto",lineAlign:"start",position:"auto",positionAlign:"auto",size:100,align:"center",vertical:"",pauseOnExit:!1,text:""}}function _i(){return{id:"",width:100,lines:3,regionAnchorX:0,regionAnchorY:100,viewportAnchorX:0,viewportAnchorY:100,scroll:""}}class Ei extends Error{constructor(t){super(t),this.name="WebVttParsingError"}}function Ti(t,e,n,r){const i=r?t.split(r):[t];for(const t in i){if("string"!=typeof i[t])continue;const r=i[t].split(n);if(2!==r.length)continue;e(r[0],r[1].trim())}}function Ci(t,e,n,r){return 3600*(0|t)+60*(0|e)+(0|n)+(0|r)/1e3}function Ui(t){var e;const n=t.match(/^(\d+):(\d{1,2})(:\d{1,2})?\.(\d{3})/);if(!n)return null;const r=parseInt(n[1]),i=parseInt(n[2]),s=parseInt((null===(e=n[3])||void 0===e?void 0:e.replace(":",""))||"0"),o=parseInt(n[4]);return n[3]?Ci(r,i,s,o):r>59?Ci(r,i,0,o):Ci(0,r,i,o)}class Ai{constructor(){this.values=Object.create(null)}set(t,e){this.get(t)||""===e||(this.values[t]=e)}get(t,e){return this.has(t)?this.values[t]:e}has(t){return t in this.values}alt(t,e,n){for(let r=0;r<n.length;++r)if(e===n[r]){this.set(t,e);break}}integer(t,e){/^-?\d+$/.test(e)&&this.set(t,parseInt(e,10))}percent(t,e){if(e.match(/^([\d]{1,3})(\.[\d]*)?%$/)){const n=parseFloat(e);if(n>=0&&n<=100)return this.set(t,n),!0}return!1}}const Ri="Malformed time stamp.";function Mi(t,e,n){const r=t;function i(){const e=Ui(t);if(null===e)throw new Ei(Ri+r);return t=t.replace(/^[^\sa-zA-Z-]+/,""),e}function s(){t=t.replace(/^\s+/,"")}if(s(),e.startTime=i(),s(),"--\x3e"!==t.substr(0,3))throw new Ei(Ri+" (time stamps must be separated by '--\x3e'): ");t=t.substr(3),s(),e.endTime=i(),s(),function(t,e){const r=new Ai;Ti(t,function(t,e){switch(t){case"region":for(let i=n.length-1;i>=0;i--)if(n[i].id===e){r.set(t,n[i]);break}break;case"vertical":r.alt(t,e,["rl","lr"]);break;case"line":{const n=e.split(","),i=n[0];r.integer(t,i),r.percent(t,i)&&r.set("snapToLines",!1),r.alt(t,i,["auto"]),2===n.length&&r.alt("lineAlign",n[1],["start","center","end"]);break}case"position":{const n=e.split(",");r.percent(t,n[0]),2===n.length&&r.alt("positionAlign",n[1],["line-left","center","line-right","auto"]);break}case"size":r.percent(t,e);break;case"align":r.alt(t,e,["start","center","end","left","right"])}},/:/,/\s/),e.region=r.get("region",null),e.vertical=r.get("vertical","");try{e.line=r.get("line","auto")}catch(t){}e.lineAlign=r.get("lineAlign","start"),e.snapToLines=r.get("snapToLines",!0),e.size=r.get("size",100);try{e.align=r.get("align","center")}catch(t){e.align=r.get("align","middle")}try{e.position=r.get("position","auto")}catch(t){const n={start:0,left:0,center:50,middle:50,end:100,right:100};e.position=r.get("position",n[e.align])}e.positionAlign=r.get("positionAlign","auto")}(t,e)}const Di="INITIAL",Ii="HEADER",Oi="REGION",xi="STYLE",Ni="NOTE",Li="BLOCKS",$i="ID",ki="CUE",Pi="CUE_EXT",Fi="BAD_CUE",Bi="BAD_WEBVTT",zi="Malformed WebVTT signature.",Vi=()=>"undefined"!=typeof VTTCue?new VTTCue(0,0,""):{id:"",startTime:0,endTime:0,region:null,snapToLines:!0,line:"auto",lineAlign:"start",position:"auto",positionAlign:"auto",size:100,align:"center",vertical:"",pauseOnExit:!1,text:""},Hi=()=>"undefined"!=typeof VTTRegion?new VTTRegion:{id:"",width:100,lines:3,regionAnchorX:0,regionAnchorY:100,viewportAnchorX:0,viewportAnchorY:100,scroll:""};class Wi{constructor(t={}){var e;this.regionSettings=null,this.cue=null;const n=null===(e=t.useDomTypes)||void 0===e||e;this.createCue=t.createCue||n?Vi:Si,this.createRegion=t.createRegion||n?Hi:_i,this.state=Di,this.buffer="",this.style="",this.regionList=[]}parse(t,e=!1){var n,r,i,s,o,a;t&&(this.buffer+=t);const u=()=>{const t=this.buffer;let e=0;for(;e<t.length&&"\r"!==t[e]&&"\n"!==t[e];)++e;const n=t.substr(0,e);return"\r"===t[e]&&++e,"\n"===t[e]&&++e,this.buffer=t.substr(e),n},l=t=>{var e;const n=new Ai;Ti(t,(t,e)=>{switch(t){case"MPEGT":n.integer(t+"S",e);break;case"LOCA":n.set(t+"L",Ui(e))}},/[^\d]:/,/,/),null===(e=this.ontimestampmap)||void 0===e||e.call(this,{MPEGTS:n.get("MPEGTS"),LOCAL:n.get("LOCAL")})},c=t=>{t.match(/X-TIMESTAMP-MAP/)&&Ti(t,(t,e)=>{if("X-TIMESTAMP-MAP"===t)l(e)},/=/)};try{let t;if(this.state===Di){if(!/\r\n|\n/.test(this.buffer))return this;t=u(),65279===t.charCodeAt(0)&&(t=t.slice(1));const e=t.match(/^WEBVTT([ \t].*)?$/);if(!e||!e[0])throw new Ei(zi);this.state=Ii}let l=!1;var h=e;for(e||(this.cue=null,this.regionSettings=null);this.buffer;){if(!/\r\n|\n/.test(this.buffer))return this;switch(l?l=!1:t=u(),this.state){case Ii:/:/.test(t)?c(t):t||(this.state=Li);continue;case Oi:if(!t&&this.regionSettings){const t=this.createRegion();t.id=this.regionSettings.get("id",""),t.width=this.regionSettings.get("width",100),t.lines=this.regionSettings.get("lines",3),t.regionAnchorX=this.regionSettings.get("regionanchorX",0),t.regionAnchorY=this.regionSettings.get("regionanchorY",100),t.viewportAnchorX=this.regionSettings.get("viewportanchorX",0),t.viewportAnchorY=this.regionSettings.get("viewportanchorY",100),t.scroll=this.regionSettings.get("scroll",""),null===(n=this.onregion)||void 0===n||n.call(this,t),this.regionList.push(t),this.regionSettings=null,this.state=Li;break}null===this.regionSettings&&(this.regionSettings=new Ai);const e=this.regionSettings;Ti(t,(t,n)=>{switch(t){case"id":e.set(t,n);break;case"width":e.percent(t,n);break;case"lines":e.integer(t,n);break;case"regionanchor":case"viewportanchor":const r=n.split(",");if(2!==r.length)break;const i=new Ai;if(i.percent("x",r[0]),i.percent("y",r[1]),!i.has("x")||!i.has("y"))break;e.set(t+"X",i.get("x")),e.set(t+"Y",i.get("y"));break;case"scroll":e.alt(t,n,["up"])}},/:/,/\s/);continue;case xi:if(!t){null===(r=this.onstyle)||void 0===r||r.call(this,this.style),this.style="",this.state=Li;break}this.style+=t+"\n";continue;case Ni:t||(this.state=$i);continue;case Li:if(!t)continue;if(/^NOTE($[ \t])/.test(t)){this.state=Ni;break}if(/^REGION/.test(t)&&!h){this.state=Oi;break}if(/^STYLE/.test(t)&&!h){this.state=xi;break}this.state=$i;case $i:if(/^NOTE($|[ \t])/.test(t)){this.state=Ni;break}if(!t)continue;if(h=!0,this.cue=this.createCue(),null!==(i=(a=this.cue).text)&&void 0!==i||(a.text=""),this.state=ki,-1===t.indexOf("--\x3e")){this.cue.id=t;continue}case ki:try{Mi(t,this.cue,this.regionList)}catch(t){this.reportOrThrowError(t),this.cue=null,this.state=Fi;continue}this.state=Pi;continue;case Pi:const u=-1!==t.indexOf("--\x3e");if(!t||u&&(l=!0)){null===(s=this.oncue)||void 0===s||s.call(this,this.cue),this.cue=null,this.state=$i;continue}(null===(o=this.cue)||void 0===o?void 0:o.text)&&(this.cue.text+="\n"),this.cue.text+=t.replace(/\u2028/g,"\n").replace(/u2029/g,"\n");continue;case Fi:t||(this.state=$i);continue}}}catch(t){this.reportOrThrowError(t),this.state===Pi&&this.cue&&this.oncue&&this.oncue(this.cue),this.cue=null,this.regionSettings=null,this.state=this.state===Di?Bi:Fi}return this}flush(){var t;try{if(this.buffer+="",(this.cue||this.state===Ii)&&(this.buffer+="\n\n",this.parse(void 0,!0)),this.state===Di)throw new Ei(zi)}catch(t){this.reportOrThrowError(t)}return null===(t=this.onflush)||void 0===t||t.call(this),this}reportOrThrowError(t){var e;if(!(t instanceof Ei))throw t;null===(e=this.onparsingerror)||void 0===e||e.call(this,t)}}const Yi="cue",ji="region",Xi="timestampmap",qi="style",Gi="error";class Ki{constructor(){this.results=[],this.parser=new Wi,this.parser.oncue=t=>this.results.push({type:Yi,data:t}),this.parser.onregion=t=>this.results.push({type:ji,data:t}),this.parser.onstyle=t=>this.results.push({type:qi,data:t}),this.parser.ontimestampmap=t=>this.results.push({type:Xi,data:t}),this.parser.onparsingerror=t=>this.results.push({type:Gi,data:t})}enqueueResults(t){for(const e of this.results)t.enqueue(e);this.results=[]}transform(t,e){try{this.parser.parse(t),this.enqueueResults(e)}catch(t){e.error(t)}}flush(t){try{this.parser.flush(),this.enqueueResults(t)}catch(e){t.error(e)}}}class Qi extends TransformStream{constructor(t,e){super(new Ki,t,e)}}var Ji=Object.freeze({__proto__:null,ArithmeticMeanEstimator:class{constructor(){this.samples=[]}sample(t){this.samples.push(t)}getEstimate(){let t=0;for(let e=0;e<this.samples.length;e++)t+=mi(this.samples[e]);return t/this.samples.length}},CBCS:jn,CENC:Xn,CHALLENGE:cr,CLEAR_KEY_SYSTEM:"org.w3.clearkey",CLEAR_KEY_UUID:"e2719d58-a985-b3c9-781a-b030af78d30e",CMCD_COMMON_KEYS:Pe,CMCD_DEFAULT_TIME_INTERVAL:30,CMCD_EVENT_KEYS:Fe,CMCD_EVENT_MODE:De,CMCD_FORMATTER_MAP:Le,CMCD_HEADERS:rn,CMCD_JSON:sn,CMCD_KEYS:an,CMCD_OBJECT:Se,CMCD_PARAM:Je,CMCD_QUERY:un,CMCD_REQUEST:_e,CMCD_REQUEST_KEYS:He,CMCD_REQUEST_MODE:$e,CMCD_RESPONSE_KEYS:Ye,CMCD_RESPONSE_MODE:ke,CMCD_SESSION:Ee,CMCD_STATUS:Te,CMCD_V1:1,CMCD_V1_KEYS:Xe,CMCD_V2:2,CMSD_DYNAMIC:Ln,CMSD_STATIC:$n,CMSD_V1:1,CONTENT_TYPE:dr,CaptionScreen:K,CaptionsLogger:V,CmcdEncoding:cn,CmcdEventType:{PLAY_STATE:"ps",ERROR:"e",TIME_INTERVAL:"t",CONTENT_ID:"c",BACKGROUNDED_MODE:"b",MUTE:"m",UNMUTE:"um",PLAYER_EXPAND:"pe",PLAYER_COLLAPSE:"pc"},CmcdFormatters:hn,CmcdHeaderField:Ue,CmcdObjectType:fn,CmcdPlayerState:{STARTING:"s",PLAYING:"p",SEEKING:"k",REBUFFERING:"r",PAUSED:"a",WAITING:"w",ENDED:"e",FATAL_ERROR:"f",QUIT:"q",PRELOADING:"d"},CmcdReportingMode:gn,CmcdStreamType:vn,CmcdStreamingFormat:mn,CmcdTransmissionMode:ln,CmsdHeaderField:kn,CmsdObjectType:Pn,CmsdStreamType:Bn,CmsdStreamingFormat:Fn,Cta608Channel:Q,Cta608Parser:class{constructor(t,e,n){this.currentChannel=0,this.cmdHistory={a:null,b:null},this.lastTime=null;const r=this.logger=new V;this.channels=[null,new Q(t,e,r),new Q(t+1,n,r)]}addData(t,e){this.lastTime=t,this.logger.time=t;for(let n=0;n<e.length;n+=2){const r=127&e[n],i=127&e[n+1];let s=!1,o=null;if(null!==this.lastTime&&(t=this.lastTime+.5*n*1001/3e4,this.logger.time=t),0===r&&0===i)continue;this.logger.log(z.DATA,()=>"["+tt([e[n],e[n+1]])+"] -> ("+tt([r,i])+")");const a=this.cmdHistory;if(r>=16&&r<=31){if(Z(r,i,a)){st(null,null,a),this.logger.log(z.DEBUG,()=>"Repeated command ("+tt([r,i])+") is dropped");continue}st(r,i,this.cmdHistory),s=this.parseCmd(r,i),s||(s=this.parseMidrow(r,i)),s||(s=this.parsePAC(r,i)),s||(s=this.parseBackgroundAttributes(r,i))}else st(null,null,a);if(!s&&(o=this.parseChars(r,i),o.length)){const t=this.currentChannel;if(t&&t>0){this.channels[t].insertChars(o)}else this.logger.log(z.WARNING,"No channel found yet. TEXT-MODE?")}s||o||this.logger.log(z.WARNING,()=>"Couldn't parse cleaned data "+tt([r,i])+" orig: "+tt([e[n],e[n+1]]))}}parseCmd(t,e){if(!((20===t||28===t||21===t||29===t)&&e>=32&&e<=47)&&!((23===t||31===t)&&e>=33&&e<=35))return!1;const n=20===t||21===t||23===t?1:2,r=this.channels[n];return 20===t||21===t||28===t||29===t?32===e?r.ccRCL():33===e?r.ccBS():34===e?r.ccAOF():35===e?r.ccAON():36===e?r.ccDER():37===e?r.ccRU(2):38===e?r.ccRU(3):39===e?r.ccRU(4):40===e?r.ccFON():41===e?r.ccRDC():42===e?r.ccTR():43===e?r.ccRTD():44===e?r.ccEDM():45===e?r.ccCR():46===e?r.ccENM():47===e&&r.ccEOC():r.ccTO(e-32),this.currentChannel=n,!0}parseMidrow(t,e){let n=0;if((17===t||25===t)&&e>=32&&e<=47){if(n=17===t?1:2,n!==this.currentChannel)return this.logger.log(z.ERROR,"Mismatch channel in midrow parsing"),!1;const r=this.channels[n];return!!r&&(r.ccMIDROW(e),this.logger.log(z.DEBUG,()=>"MIDROW ("+tt([t,e])+")"),!0)}return!1}parsePAC(t,e){let n;if(!((t>=17&&t<=23||t>=25&&t<=31)&&e>=64&&e<=127)&&!((16===t||24===t)&&e>=64&&e<=95))return!1;const r=t<=23?1:2;n=e>=64&&e<=95?1===r?rt[t]:it[t]:1===r?et[t]:nt[t];const i=this.channels[r];return!!i&&(i.setPAC(this.interpretPAC(n,e)),this.currentChannel=r,!0)}interpretPAC(t,e){let n;const r={color:null,italics:!1,indent:null,underline:!1,row:t};return n=e>95?e-96:e-64,r.underline=!(1&~n),n<=13?r.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(n/2)]:n<=15?(r.italics=!0,r.color="white"):r.indent=4*Math.floor((n-16)/2),r}parseChars(t,e){let n,r=[],i=null;if(t>=25?(n=2,i=t-8):(n=1,i=t),i>=17&&i<=19){let t;t=17===i?e+80:18===i?e+112:e+144,this.logger.log(z.INFO,()=>"Special char '"+X(t)+"' in channel "+n),r=[t]}else t>=32&&t<=127&&(r=0===e?[t]:[t,e]);return r&&this.logger.log(z.DEBUG,()=>"Char codes = "+tt(r).join(",")),r}parseBackgroundAttributes(t,e){if(!((16===t||24===t)&&e>=32&&e<=47)&&!((23===t||31===t)&&e>=45&&e<=47))return!1;let n;const r={};16===t||24===t?(n=Math.floor((e-32)/2),r.background=J[n],e%2==1&&(r.background=r.background+"_semi")):45===e?r.background="transparent":(r.foreground="black",47===e&&(r.underline=!0));const i=t<=23?1:2;return this.channels[i].setBkgData(r),!0}reset(){for(let t=0;t<Object.keys(this.channels).length;t++){const e=this.channels[t];e&&e.reset()}st(null,null,this.cmdHistory)}cueSplitAtTime(t){for(let e=0;e<this.channels.length;e++){const n=this.channels[e];n&&n.cueSplitAtTime(t)}}},DATA:Qr,DEFAULT_PATHWAY_PENALTY:3e5,DEFAULT_TTL:300,EXPIRED:mr,Encoding:bi,EncryptionScheme:pr,Ewma:yi,EwmaEstimator:class{constructor(t){this.slowEwma=new yi(t.slowHalfLife),this.fastEwma=new yi(t.fastHalfLife)}sample(t){const e=t.duration/1e3,n=mi(t);this.slowEwma.sample(e,n),this.fastEwma.sample(e,n)}getEstimate(){return Math.min(this.fastEwma.getEstimate(),this.slowEwma.getEstimate())}canEstimate(){return!0}},FAIRPLAY_KEY_SYSTEM:"com.apple.fps.1_0",FAIRPLAY_UUID:"29701fe4-3cc7-4a34-8c5b-ae90c7439a47",HTTP_HEADERS:fr,HW_SECURE_ALL:yr,HW_SECURE_CRYPTO:vr,HW_SECURE_DECODE:br,HarmonicMeanEstimator:class{constructor(){this.samples=[]}sample(t){this.samples.push(t)}getEstimate(){let t=0;for(let e=0;e<this.samples.length;e++)t+=1/mi(this.samples[e]);return this.samples.length/t}},ID3_SCHEME_ID_URI:"https://aomedia.org/emsg/ID3",INDIVIDUALIZATION_REQUEST:wr,INT:Jr,INTERNAL_ERROR:Tr,InitializationDataType:Er,IsoView:si,KEYIDS:Sr,LICENSE_ACQUISITION:"LicenseAcquisition",LICENSE_RELEASE:Cr,LICENSE_RENEWAL:Ur,LICENSE_REQUEST:Ar,MP4_PROTECTION_SCHEME:qn,MediaKeyMessageType:Rr,MediaKeyStatus:Nr,OUTPUT_DOWNSCALED:Mr,OUTPUT_RESTRICTED:Dr,PLAYREADY_KEY_MESSAGE:hr,PLAYREADY_KEY_SYSTEM:"com.microsoft.playready",PLAYREADY_RECOMMENDATION_KEY_SYSTEM:"com.microsoft.playready.recommendation",PLAYREADY_UUID:"9a04f079-9840-4286-ab92-e65be0885f95",PenState:H,RELEASED:Ir,Row:q,STATUS_PENDING:Or,STRING:Zr,SW_SECURE_CRYPTO:Lr,SW_SECURE_DECODE:$r,SccParser:class{constructor(t,e=1){this.hasHeader=!1,this.nrLinesParsed=0,this.processor=t,this.field=e}parse(t){const e=t.split(/\r?\n/);this.nrLinesParsed=0,"Scenarist_SCC V1.0"===e[0]&&(this.hasHeader=!0,this.nrLinesParsed++);for(let t=1;t<e.length&&""===e[t];t+=2){this.nrLinesParsed++;const n=this.parseDataLine(e[t+1]);if(null===n)break;this.nrLinesParsed++,this.processor.addData(n[0],n[1])}}parseDataLine(t){if(!t)return null;const e=t.split(/\s+/),n=e[0],r=[];for(let t=1;t<e.length;t++){const n=e[t],i=parseInt(n.substring(0,2),16),s=parseInt(n.substring(2,4),16);r.push(i,s)}return[this.timeConverter(n),r]}timeConverter(t){const e=t.split(":");if(3===e.length){const t=e[2].split(";");e[2]=t[0];const n=parseInt(t[1],10);return 1001*(30*(60*(60*parseInt(e[0],10)+parseInt(e[1],10))+parseInt(e[2],10))+n)/3e4}return 0}getHeaderStatus(){return this.hasHeader}getField(){return this.field}getLinesParsed(){return this.nrLinesParsed}},SfItem:Kt,SfToken:te,StyledUnicodeChar:W,TEMPLATE:ti,TEXT_XML_UTF8:gr,THUMBNAIL_TILE_SCHEME_ID_URI:"http://dashif.org/guidelines/thumbnail_tile",UINT:ei,USABLE:xr,UTF8:ni,UTF_16:tr,UTF_16_BE:er,UTF_16_LE:nr,UTF_8:rr,VerboseLevel:z,W3C_CLEAR_KEY_UUID:"1077efec-c0b2-4d02-ace3-3c1e52e2fb4b",WEBM:_r,WIDEVINE_KEY_SYSTEM:"com.widevine.alpha",WIDEVINE_UUID:"edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",WebVttParser:Wi,WebVttParsingError:Ei,WebVttTransformStream:Qi,WebVttTransformer:Ki,WidevineRobustness:kr,ZlemaEstimator:class{constructor(){this.samples=[]}sample(t){this.samples.push(t)}getEstimate(){if(0===this.samples.length)return NaN;const t=2/(this.samples.length+1);let e,n;e=n=mi(this.samples[this.samples.length-1]);for(let r=0;r<this.samples.length;r++)e=t*mi(this.samples[r])+(1-t)*e,n=t*e+(1-t)*n;return n}},appendCmcdHeaders:function(t,e,n){return Object.assign(t,Qe(e,n))},appendCmcdQuery:function(t,e,n){const r=en(e,n);if(!r)return t;if(nn.test(t))return t.replace(nn,r);const i=t.includes("?")?"&":"?";return`${t}${i}${r}`},ardi:function(t){return{...t.readFullBox(),audioRenderingIndication:t.readUint(1)}},arrayBufferToHex:vi,arrayBufferToUuid:function(t){return vi(t).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5")},avc1:hi,avc2:function(t){return hi(t)},avc3:function(t){return hi(t)},avc4:function(t){return hi(t)},base64decode:function(t){return _n(t)},base64encode:function(t){return re(t)},canParseId3:function(t,e){return Pr(t,e)&&Fr(t,e+6)+10<=t.length-e},concatInitDataIdAndCertificate:function(t,e,n){"string"==typeof e&&(e=Zn(e));const r=new ArrayBuffer(t.byteLength+4+e.byteLength+4+n.byteLength),i=new DataView(r);let s=0;return new Uint8Array(r,s,t.byteLength).set(t),s+=t.byteLength,i.setUint32(s,e.byteLength,!0),s+=4,new Uint16Array(r,s,e.length).set(e),s+=e.byteLength,i.setUint32(s,n.byteLength,!0),s+=4,new Uint8Array(r,s,n.byteLength).set(n),new Uint8Array(r)},convertUint8ToUint16:function(t){if(t.length%2!=0){const e=new Uint8Array(t.length+1);return e.set(t),new Uint16Array(e.buffer)}return new Uint16Array(t.buffer)},createIsoView:oi,createMediaKeySystemConfiguration:Kn,createWebVttCue:Si,createWebVttRegion:_i,ctts:function(t){const{version:e,flags:n}=t.readFullBox(),r=1===e?t.readInt:t.readUint,i=t.readUint(4);return{version:e,flags:n,entryCount:i,entries:t.readEntries(i,()=>({sampleCount:t.readUint(4),sampleOffset:r(4)}))}},dashToHam:function(t){const e=It.getInstance();return e.setStrategy(new Dt),e.getHamFormat({manifest:t,type:"dash"})},decodeBase64:_n,decodeCmcd:xn,decodeCmsdDynamic:function(t){return t?Vn(t):[]},decodeCmsdStatic:function(t){return t?Object.entries(In(t)).reduce((t,[e,n])=>{const{value:r}=n;return t[e]="symbol"==typeof r?de(r):r,t},{}):{}},decodeFairPlayLicense:function(t){return"string"==typeof t?_n(t):new Uint8Array(t)},decodeIso8601Duration:function(t){const e=Gr.exec(t);if(!e)return NaN;const n=31536e3*Number(e[2]||0)+2592e3*Number(e[3]||0)+86400*Number(e[4]||0)+3600*Number(e[5]||0)+60*Number(e[6]||0)+Number(e[7]||0);return isFinite(n)?void 0===e[1]?n:-n:NaN},decodeSfDict:In,decodeSfItem:function(t,e){try{const{src:n,value:r}=Mn(t.trim(),e);if(""!==n)throw wn(n,pi);return r}catch(e){throw wn(t,pi,e)}},decodeSfList:Vn,decodeText:ir,dref:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4);return{version:e,flags:n,entryCount:r,entries:t.readBoxes(r)}},elng:function(t){return{...t.readFullBox(),extendedLanguage:t.readUtf8(-1)}},elst:function(t){const{version:e,flags:n}=t.readFullBox(),r=1===e?8:4,i=t.readUint(4);return{version:e,flags:n,entryCount:i,entries:t.readEntries(i,()=>({segmentDuration:t.readUint(r),mediaTime:t.readInt(r),mediaRateInteger:t.readInt(2),mediaRateFraction:t.readInt(2)}))}},emsg:function(t){const{readUint:e,readString:n,readData:r}=t,i={...t.readFullBox()};return 1==i.version?(i.timescale=e(4),i.presentationTime=e(8),i.eventDuration=e(4),i.id=e(4),i.schemeIdUri=n(-1),i.value=n(-1)):(i.schemeIdUri=n(-1),i.value=n(-1),i.timescale=e(4),i.presentationTimeDelta=e(4),i.eventDuration=e(4),i.id=e(4)),i.messageData=r(-1),i},enca:function(t){return di(t)},encodeBase64:re,encodeCmcd:Ze,encodeCmsdDynamic:function(t,e){if(!t)return"";if("string"==typeof t){if(!e)return"";t=[new Kt(t,e)]}return Hn(t,{whitespace:!1})},encodeCmsdStatic:function(t,e){return t?we(function(t,e){const n={};if(null==t||"object"!=typeof t)return n;const r=Object.keys(t),i=!1!==(null==e?void 0:e.useSymbol);return r.forEach(e=>{let r=t[e];"v"===e&&1===r||Me(r)&&(Re(e)&&"string"==typeof r&&(r=i?Symbol.for(r):new te(r)),n[e]=r)}),n}(t,e),{whitespace:!1}):""},encodeIso8601Duration:function(t){if(!isFinite(t))return"PT";const e=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return e>0?`PT${e}H${n}M${r}S`:n>0?`PT${n}M${r}S`:`PT${r}S`},encodeSfDict:we,encodeSfItem:function(t,e){return t instanceof Kt||(t=new Kt(t,e)),ve(t)},encodeSfList:Hn,encv:function(t){return hi(t)},extractContentId:sr,extractCta608Data:function(t,e){let n=e[0];const r=[[],[]];n+=8;const i=31&t.getUint8(n);n+=2;for(let e=0;e<i;e++){const e=t.getUint8(n),i=4&e,s=3&e;n++;const o=t.getUint8(n);n++;const a=t.getUint8(n);n++,i&&(127&o)+(127&a)!=0&&(0===s?(r[0].push(o),r[0].push(a)):1===s&&(r[1].push(o),r[1].push(a)))}return r},filterBoxes:ui,filterBoxesByType:function(t,e,n={}){return Array.isArray(e)||(e=[e]),ui(t,t=>e.includes(t.type),n)},findBox:ci,findBoxByType:function(t,e,n={}){return ci(t,t=>t.type===e,n)},findCencContentProtection:function(t){var e;if(!t)return null;for(const n of t)if((null===(e=n.schemeIdUri)||void 0===e?void 0:e.toLowerCase())===qn&&n.value&&(n.value.toLowerCase()===Xn||n.value.toLowerCase()===jn))return n;return null},findCta608Nalus:function(t,e,n){let r=0,i=e,s=0;const o=[],a=(t,e,n,r)=>{if(4!==t||e<8)return null;const i=n.getUint8(r),s=n.getUint16(r+1),o=n.getUint32(r+3),a=n.getUint8(r+7);return 181==i&&49==s&&1195456820==o&&3==a};for(;i<e+n;){if(r=t.getUint32(i),s=31&t.getUint8(i+4),6===s){let e=i+5,n=-1;for(;e<i+4+r-1;){n=0;let r=255;for(;255===r;)r=t.getUint8(e),n+=r,e++;let i=0;for(r=255;255===r;)r=t.getUint8(e),i+=r,e++;a(n,i,t,e)&&o.push([e,i]),e+=i}}i+=r+4}return o},free:fi,frma:function(t){return{dataFormat:t.readUint(4)}},fromCmcdHeaders:function(t){return t instanceof Headers||(t=new Headers(t)),Nn.reduce((e,n)=>{const r=t.get(n);return Object.assign(e,xn(r))},{})},fromCmcdQuery:function(t){return"string"==typeof t&&(t=new URLSearchParams(t)),xn(t.get(Je))},fromCmcdUrl:function(t){return xn(decodeURIComponent(t.replace(/^CMCD=/,"")))},ftyp:gi,getElementsByName:or,getId:function(t,e,n="ContentId"){try{const r=new URL(t);return new URLSearchParams(r.search).get(n)||sr(e)}catch{return sr(e)}},getId3Data:function(t,e){const n=e;let r=0;for(;Pr(t,e);){r+=10;r+=Fr(t,e+6),Br(t,e+10)&&(r+=10),e+=r}if(r>0)return t.subarray(n,n+r)},getId3Frames:jr,getId3Timestamp:function(t){const e=jr(t);for(let t=0;t<e.length;t++){const n=e[t];if(Xr(n))return qr(n)}},getKeySystemAccess:async function(t){for(const{keySystem:e,configurations:n}of t)try{return await navigator.requestMediaKeySystemAccess(e,n)}catch{}return null},getLegacyKeySystemAccess:function(t){for(const{keySystem:e,configurations:n}of t){const t=Jn(e,n);if(t){return{keySystem:e,configurations:[Kn(t.supportedAudio,t.supportedVideo)]}}}return null},getLicenseRequestFromMessage:function(t,e=tr){var n;if(e===tr&&(null==t?void 0:t.byteLength)%2==1)return t;const r=or(lr(ir(t,{encoding:e})),hr)[0];if(!r)return t;const i=or(r,cr)[0],s=null===(n=null==i?void 0:i.childNodes[0])||void 0===n?void 0:n.nodeValue;return s?_n(s).buffer:t},getLicenseServerUrl:function(t){let e="";for(let n=0;n<t.length;n++)0!==t[n]&&(e+=String.fromCharCode(t[n]));const n=e.match(/skd:\/\/([^"\s]+)/);return n?`https://${n[1]}`:""},getLicenseServerUrlFromContentProtection:function(t,e){var n;return(null===(n=t.find(t=>t.schemeIdUri===e))||void 0===n?void 0:n.laUrl)||null},getPsshData:function(t){const e=new DataView(t);let n=28;if(e.getUint8(8)>0){n+=4+16*e.getUint32(n)}return n+=4,t.slice(n)},getPsshForKeySystem:function(t,e){return e&&t&&Gn(e)[t.toLowerCase()]||null},getRequestHeadersFromMessage:function(t,e=tr){var n,r,i,s,o;const a={};if(e===tr&&t&&t.byteLength%2==1)return a[dr]=gr,a;const u=null===(n=or(lr(ir(t,{encoding:e})),fr)[0])||void 0===n?void 0:n.childNodes;if(!u)return a;for(const t of u){const e=null===(i=null===(r=or(t,"name")[0])||void 0===r?void 0:r.childNodes[0])||void 0===i?void 0:i.nodeValue,n=null===(o=null===(s=or(t,"value")[0])||void 0===s?void 0:s.childNodes[0])||void 0===o?void 0:o.nodeValue;e&&n&&(a[e]=n)}return a.hasOwnProperty("Content")&&(a[dr]=a.Content,delete a.Content),a.hasOwnProperty(dr)||(a[dr]=gr),a},getSupportedKeySystemConfiguration:Jn,getTracksFromPresentation:function(t,e){const n=t.selectionSets.flatMap(t=>zt(t));return e?n.filter(e):n},getTracksFromSelectionSet:zt,getTracksFromSwitchingSet:Bt,groupCmcdHeaders:Ae,hamToDash:function(t){const e=It.getInstance();return e.setStrategy(new Dt),e.getManifestFormat(t)},hamToHls:function(t){const e=It.getInstance();return e.setStrategy(new Ft),e.getManifestFormat(t)},hdlr:function(t){return{...t.readFullBox(),preDefined:t.readUint(4),handlerType:t.readString(4),reserved:t.readArray(ei,4,3),name:t.readString(-1)}},hev1:function(t){return hi(t)},hexToArrayBuffer:wi,hlsToHam:function(t,e){const n=It.getInstance();return n.setStrategy(new Ft),n.getHamFormat({manifest:t,ancillaryManifests:e.map(t=>({manifest:t,type:"hls"})),type:"hls"})},hvc1:function(t){return hi(t)},iden:function(t){return{cueId:t.readUtf8(-1)}},imda:function(t){return{imdaIdentifier:t.readUint(4),data:t.readData(-1)}},isCmcdCustomKey:ze,isCmcdEventKey:Ve,isCmcdRequestKey:We,isCmcdResponseKey:je,isCmcdV1Key:qe,isId3TimestampFrame:Xr,isValidPathwayClone:Wn,isValidSteeringManifest:function(t){if(!t)return!1;const{VERSION:e,TTL:n,"PATHWAY-PRIORITY":r,"PATHWAY-CLONES":i}=t;return"number"==typeof e&&1===e&&(!("number"!=typeof n||n<=0)&&(!(!Array.isArray(r)||0===r.length||new Set(r).size!==r.length)&&!(i&&(!Array.isArray(i)||0===i.length||i.some(t=>!Wn(t))))))},kind:function(t){return{...t.readFullBox(),schemeUri:t.readUtf8(-1),value:t.readUtf8(-1)}},labl:function(t){const{version:e,flags:n}=t.readFullBox();return{version:e,flags:n,isGroupLabel:!!(1&n),labelId:t.readUint(2),language:t.readUtf8(-1),label:t.readUtf8(-1)}},mdat:function(t){return{data:t.readData(-1)}},mdhd:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(1==e?8:4),i=t.readUint(1==e?8:4),s=t.readUint(4),o=t.readUint(1==e?8:4),a=t.readUint(2);return{version:e,flags:n,creationTime:r,modificationTime:i,timescale:s,duration:o,language:String.fromCharCode(96+(a>>10&31),96+(a>>5&31),96+(31&a)),preDefined:t.readUint(2)}},mehd:function(t){const{version:e,flags:n}=t.readFullBox();return{version:e,flags:n,fragmentDuration:t.readUint(1===e?8:4)}},meta:function(t){return t.readFullBox()},mfhd:function(t){return{...t.readFullBox(),sequenceNumber:t.readUint(4)}},mfro:function(t){return{...t.readFullBox(),mfraSize:t.readUint(4)}},mp4a:di,mvhd:function(t){const{readUint:e,readTemplate:n,readArray:r}=t,{version:i,flags:s}=t.readFullBox(),o=1==i?8:4;return{version:i,flags:s,creationTime:e(o),modificationTime:e(o),timescale:e(4),duration:e(o),rate:n(4),volume:n(2),reserved1:e(2),reserved2:r(ei,4,2),matrix:r(ei,4,9),preDefined:r(ei,4,6),nextTrackId:e(4)}},parseBoxes:function(t,e){const n=[];for(const r of oi(t,e))n.push(r);return n},parseFrameRate:function(t){const[e,n]=t.split("/").map(t=>parseInt(t,10));return void 0===n?e:isNaN(e)||isNaN(n)||0===n?NaN:e/n},parseInitDataFromContentProtection:function(t,e){if((null==t?void 0:t.pssh)&&t.pssh){const n=t.pssh.replace(/\r?\n|\r/g,"").replace(/\s+/g,"");return e.decodeArray(n).buffer}return null},parsePsshList:Gn,parseWebVtt:async function(t,e){const n=new Wi(e),r=[],i=[],s=[],o=[];return n.oncue=t=>r.push(t),n.onregion=t=>i.push(t),n.onstyle=t=>s.push(t),n.onparsingerror=t=>o.push(t),n.parse(t),n.flush(),{cues:r,regions:i,styles:s,errors:o}},parseXml:lr,payl:function(t){return{cueText:t.readUtf8(-1)}},prepareCmcdData:Ke,prft:function(t){const{version:e,flags:n}=t.readFullBox();return{version:e,flags:n,referenceTrackId:t.readUint(4),ntpTimestampSec:t.readUint(4),ntpTimestampFrac:t.readUint(4),mediaTime:t.readUint(1===e?8:4)}},processUriTemplate:function(t,e,n,r,i,s){const o=t.replace(Yn,(t,o,a,u)=>{let l,c;switch(o){case void 0:return"$";case"RepresentationID":l=e;break;case"Number":l=n;break;case"SubNumber":l=r;break;case"Bandwidth":l=i;break;case"Time":if("string"==typeof s)return s;l=s?Math.round(s):s;break;default:l=null}if(null==l)return t;switch(u){case void 0:case"d":case"i":case"u":c=l.toString();break;case"o":c=l.toString(8);break;case"x":c=l.toString(16);break;case"X":c=l.toString(16).toUpperCase();break;default:c=l.toString()}const h=parseInt(a,10)||1;return c.padStart(h,"0")});return o},prsl:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4),i=t.readUint(4);return{version:e,flags:n,groupId:r,numEntitiesInGroup:i,entities:t.readEntries(i,()=>({entityId:t.readUint(4)})),preselectionTag:4096&n?t.readUtf8(-1):void 0,selectionPriority:8192&n?t.readUint(1):void 0,interleavingTag:16384&n?t.readUtf8(-1):void 0}},pssh:function(t){const{readUint:e,readArray:n}=t,{version:r,flags:i}=t.readFullBox(),s=n(ei,1,16);let o=0,a=[];r>0&&(o=e(4),a=n(ei,1,o));const u=e(4);return{version:r,flags:i,systemId:s,kidCount:o,kid:a,dataSize:u,data:n(ei,1,u)}},roundToEven:ue,schm:function(t){const{version:e,flags:n}=t.readFullBox();return{version:e,flags:n,schemeType:t.readUint(4),schemeVersion:t.readUint(4),schemeUri:1&n?t.readString(-1):void 0}},sdtp:function(t){return{...t.readFullBox(),sampleDependencyTable:t.readArray(ei,1,t.bytesRemaining)}},setDashParser:function(t){ot=t},setDashSerializer:function(t){at=t},setHlsParser:function(t){ut=t},sidx:function(t){const{readUint:e}=t,{version:n,flags:r}=t.readFullBox(),i=1===n?8:4,s=e(4),o=e(4),a=e(i),u=e(i),l=e(2),c=e(2);return{version:n,flags:r,referenceId:s,timescale:o,earliestPresentationTime:a,firstOffset:u,reserved:l,references:t.readEntries(c,()=>{const t={};return t.reference=e(4),t.subsegmentDuration=e(4),t.sap=e(4),t.referenceType=t.reference>>31&1,t.referencedSize=2147483647&t.reference,t.startsWithSap=t.sap>>31&1,t.sapType=t.sap>>28&7,t.sapDeltaTime=268435455&t.sap,t})}},skip:function(t){return fi(t)},smhd:function(t){return{...t.readFullBox(),balance:t.readUint(2),reserved:t.readUint(2)}},ssix:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4);return{version:e,flags:n,subsegmentCount:r,subsegments:t.readEntries(r,()=>{const e=t.readUint(4);return{rangesCount:e,ranges:t.readEntries(e,()=>({level:t.readUint(1),rangeSize:t.readUint(3)}))}})}},sthd:function(t){return t.readFullBox()},stringToUint16:Zn,stsd:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4);return{version:e,flags:n,entryCount:r,entries:t.readBoxes(r)}},stss:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4);return{version:e,flags:n,entryCount:r,entries:t.readEntries(r,()=>({sampleNumber:t.readUint(4)}))}},sttg:function(t){return{settings:t.readUtf8(-1)}},stts:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4);return{version:e,flags:n,entryCount:r,entries:t.readEntries(r,()=>({sampleCount:t.readUint(4),sampleDelta:t.readUint(4)}))}},styp:function(t){return gi(t)},subs:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4),i=t.readEntries(r,()=>{const n=t.readUint(4),r=t.readUint(2);return{sampleDelta:n,subsampleCount:r,subsamples:t.readEntries(r,()=>({subsampleSize:t.readUint(1===e?4:2),subsamplePriority:t.readUint(1),discardable:t.readUint(1),codecSpecificParameters:t.readUint(4)}))}});return{version:e,flags:n,entryCount:r,entries:i}},tenc:function(t){return{...t.readFullBox(),defaultIsEncrypted:t.readUint(3),defaultIvSize:t.readUint(1),defaultKid:t.readArray(ei,1,16)}},tfdt:function(t){const{version:e,flags:n}=t.readFullBox();return{version:e,flags:n,baseMediaDecodeTime:t.readUint(1==e?8:4)}},tfhd:function(t){const{version:e,flags:n}=t.readFullBox();return{version:e,flags:n,trackId:t.readUint(4),baseDataOffset:1&n?t.readUint(8):void 0,sampleDescriptionIndex:2&n?t.readUint(4):void 0,defaultSampleDuration:8&n?t.readUint(4):void 0,defaultSampleSize:16&n?t.readUint(4):void 0,defaultSampleFlags:32&n?t.readUint(4):void 0}},tfra:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4),i=t.readUint(4),s=(48&i)>>4,o=(12&i)>>2,a=3&i,u=t.readUint(4),l=t.readEntries(u,()=>({time:t.readUint(1===e?8:4),moofOffset:t.readUint(1===e?8:4),trafNumber:t.readUint(s+1),trunNumber:t.readUint(o+1),sampleNumber:t.readUint(a+1)}));return{version:e,flags:n,trackId:r,reserved:i,lengthSizeOfTrafNum:s,lengthSizeOfTrunNum:o,lengthSizeOfSampleNum:a,numberOfEntry:u,entries:l}},tkhd:function(t){const{version:e,flags:n}=t.readFullBox(),r=1===e?8:4;return{version:e,flags:n,creationTime:t.readUint(r),modificationTime:t.readUint(r),trackId:t.readUint(4),reserved1:t.readUint(4),duration:t.readUint(r),reserved2:t.readArray(ei,4,2),layer:t.readUint(2),alternateGroup:t.readUint(2),volume:t.readTemplate(2),reserved3:t.readUint(2),matrix:t.readArray(ti,4,9),width:t.readTemplate(4),height:t.readTemplate(4)}},toBigEndianKeyId:function(t){if(16!==t.byteLength)return t;const e=t.slice(0),n=new DataView(e);return n.setUint32(0,n.getUint32(0,!0),!1),n.setUint16(4,n.getUint16(4,!0),!1),n.setUint16(6,n.getUint16(6,!0),!1),e},toCmcdHeaders:Qe,toCmcdJson:function(t,e){const n=Ke(t,e);return JSON.stringify(n,(t,e)=>"symbol"==typeof e||e instanceof te?de(e):e)},toCmcdQuery:en,toCmcdReport:function(t,e){if(!e||!e.url)return null;const n=new URL(e.url),r=e.method||"GET",i={},s=e.transmissionMode||un,o={version:e.version,reportingMode:e.reportingMode};switch(e.enabledKeys&&(o.filter=t=>e.enabledKeys.includes(t)),s){case un:const e=Ze(t,o);e&&n.searchParams.set(Je,e);break;case rn:Object.assign(i,Qe(t,o))}return{url:n.toString(),method:r,headers:i}},toCmcdUrl:tn,toVttCue:function(t){const e=new VTTCue(t.startTime,t.endTime,t.text);e.id=t.id,e.region=t.region,e.vertical=t.vertical,e.snapToLines=t.snapToLines,e.line=t.line,e.lineAlign=t.lineAlign,e.position=t.position,e.positionAlign=t.positionAlign,e.size=t.size,e.pauseOnExit=t.pauseOnExit;try{e.align="center"}catch(t){e.align="middle"}return e},toVttRegion:function(t){const e=new VTTRegion;return e.id=t.id,e.width=t.width,e.lines=t.lines,e.regionAnchorX=t.regionAnchorX,e.regionAnchorY=t.regionAnchorY,e.viewportAnchorX=t.viewportAnchorX,e.viewportAnchorY=t.viewportAnchorY,e.scroll=t.scroll,e},trex:function(t){return{...t.readFullBox(),trackId:t.readUint(4),defaultSampleDescriptionIndex:t.readUint(4),defaultSampleDuration:t.readUint(4),defaultSampleSize:t.readUint(4),defaultSampleFlags:t.readUint(4)}},trun:function(t){const{version:e,flags:n}=t.readFullBox(),r=t.readUint(4);let i,s;1&n&&(i=t.readInt(4)),4&n&&(s=t.readUint(4));const o=t.readEntries(r,()=>{const r={};return 256&n&&(r.sampleDuration=t.readUint(4)),512&n&&(r.sampleSize=t.readUint(4)),1024&n&&(r.sampleFlags=t.readUint(4)),2048&n&&(r.sampleCompositionTimeOffset=1===e?t.readInt(4):t.readUint(4)),r});return{version:e,flags:n,sampleCount:r,dataOffset:i,firstSampleFlags:s,samples:o}},unescapeHtml:ur,url:function(t){return{...t.readFullBox(),location:t.readString(-1)}},urlToRelativePath:Ie,urn:function(t){return{...t.readFullBox(),name:t.readString(-1),location:t.readString(-1)}},utf8ArrayToStr:zr,uuid:function(){try{return crypto.randomUUID()}catch(t){try{const t=URL.createObjectURL(new Blob),e=t.toString();return URL.revokeObjectURL(t),e.slice(e.lastIndexOf("/")+1)}catch(t){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:3&n|8).toString(16)})}}},uuidToArrayBuffer:function(t){return wi(t.replace(/-/g,""))},validatePresentation:function(t){const e={status:!0,errorMessages:[]};return t.id||(e.status=!1,e.errorMessages.push("Presentation id is undefined")),Gt(t.selectionSets,t.id,e),e},validateSegment:Vt,validateSegments:Ht,validateSelectionSet:qt,validateSelectionSets:Gt,validateSwitchingSet:jt,validateSwitchingSets:Xt,validateTrack:Wt,validateTracks:Yt,vlab:function(t){return{sourceLabel:t.readUtf8(-1)}},vmhd:function(t){return{...t.readFullBox(),graphicsmode:t.readUint(2),opcolor:t.readArray(ei,2,3)}},vttC:function(t){return{config:t.readUtf8()}},vtte:function(){return{}}});class Zi{toCmcd(t,e,n){var r,i,s,o,a,u,l,c;const h={},d=null!==(r=this.playbackRate)&&void 0!==r?r:this.playbackSpeed;e===this.audioTrackId?h.ot=fn.AUDIO:e===this.videoTrackId?h.ot=fn.VIDEO:h.ot=fn.OTHER,h.st=vn.LIVE,h.cid=t.pathname.split("/").pop(),null!=this.bufferAmount&&null!=d&&(h.dl=this.bufferAmount*d),e===this.videoTrackId?h.br=null!==(i=this.videoTrackBandwidth)&&void 0!==i?i:0:e===this.audioTrackId?h.br=null!==(s=this.audioTrackBandwidth)&&void 0!==s?s:0:h.br=(null!==(o=this.audioTrackBandwidth)&&void 0!==o?o:0)+(null!==(a=this.videoTrackBandwidth)&&void 0!==a?a:0),null!=this.stallCount&&(h.bs=this.stallCount-(null!==(u=null==n?void 0:n.stallCount)&&void 0!==u?u:0)>0),null!=this.bufferAmount&&(h.bl=this.bufferAmount),null!=this.recvByteRate&&(h.mtp=this.recvByteRate),null!=d&&(h.pr=Number(d.toFixed(2)));const f={dash:"d",hls:"h",smooth:"s"},g=null===(l=this.protocol)||void 0===l?void 0:l.toLowerCase();return null!=g&&(h.sf=null!==(c=f[g])&&void 0!==c?c:"o"),null!=this.waitingData&&(h.su=this.waitingData),h}}class ts{get graphMargin(){return this._graphMargin}set graphMargin(t){this._graphMargin=t}get textMargin(){return this._textMargin}set textMargin(t){this._textMargin=t}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight=t}get labelWidth(){return this._labelWidth}set labelWidth(t){this._labelWidth=t}get legendFontSize(){return this._legendFontSize}set legendFontSize(t){this._legendFontSize=t}get stepSize(){return this._stepSize}set stepSize(t){this._stepSize=t}get averageDisplayWidth(){return this._legendFontSize/2*7}get displayableCount(){const t=this._ui.clientWidth-this.averageDisplayWidth;return Math.ceil((t-this._labelWidth)/this._stepSize)}constructor(t){this._ui=t,t.addEventListener("mousemove",t=>{this._mouseX=t.offsetX}),t.addEventListener("mouseleave",t=>{this._mouseX=void 0}),this._lineHeight=40,this._labelWidth=170,this._graphMargin=5,this._textMargin=5,this._legendFontSize=13,this._stepSize=10,this._ranges={}}reset(){this._ranges={}}display(t){if(null!=this._html)return;this._html="";const e=this.averageDisplayWidth,n=e/2,r=this._ui.clientWidth-e,i=this._lineHeight-2*this._graphMargin,s=Math.round(this._lineHeight/2),o=Math.round(this._lineHeight/2+this._textMargin),a=this._labelWidth-2*this._textMargin;for(const[e,u]of t){const t=Math.ceil((r-this._labelWidth)/this._stepSize),l=u.slice(Math.max(0,u.length-t));if(!l.length)continue;let c=this._labelWidth+l.length*this._stepSize;this._html+='<svg class="list-group-item p-0" style="height: '+this._lineHeight+'px" xmlns="http://www.w3.org/2000/svg">',this._html+='<text x="'+this._textMargin+'" y="'+o+'">'+e+"</text>",this._html+='<text x="'+a+'" y="'+o+'" text-anchor="end">'+l[l.length-1].toString()+"</text>",this._html+='<path fill="none" d="M'+this._labelWidth+" "+s,this._html+="H"+(r+n),this._html+='" stroke-width="1" stroke="lightgray" stroke-dasharray="10,10"/>',this._html+='<path fill="none" stroke-width="1" stroke="brown" d="M';let h=Number.POSITIVE_INFINITY,d=Number.NEGATIVE_INFINITY;for(let t=0;t<l.length;++t){const e=parseFloat(l[t].toString());e<h&&(h=e),e>d&&(d=e)}let f=this._ranges[e];f||(this._ranges[e]=f={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}),f.min=Math.min(f.min,h),f.max=Math.max(f.max,d);const g=f.max-f.min;let p="",m="",y=null==this._mouseX||this._mouseX>c?null:"";for(let t=0;t<l.length;++t){c-=this._stepSize;const e=parseFloat(l[t].toString()),n=s+(g?Math.round((.5-(e-f.min)/g)*i):0);this._html+=c+" "+n+" ",e===h?m=m||this._drawCircle(c,n,e):e===d&&(p=p||this._drawCircle(c,n,e)),""===y&&c<=(this._mouseX||0)&&(y=this._drawCircle(c,n,e,"blue",""))}this._html+='" />';const v=Math.round((d-h)/2);this._html+='<text text-anchor="middle" font-size="'+this._legendFontSize+'" y="'+o+'">',this._html+='<tspan x="'+(r+n)+'" dy="-0.5em">'+(h!==d?"≈":"=")+(h+v)+"</tspan>",this._html+='<tspan x="'+(r+n)+'" dy="1em">±'+v+"</tspan>",this._html+="</text>",this._html+=p+m+(null!=y?y:""),y&&(this._html+=y),this._html+="</svg>"}requestAnimationFrame(()=>{null!=this._html&&(this._ui.innerHTML=this._html,this._html=void 0)})}_drawCircle(t,e,n,r="green",i="italic"){let s='<circle cx="'+t+'" cy="'+e+'" r="2" fill="'+r+'" />';const o=.7*this._legendFontSize;return e<Math.round(this._lineHeight/2)?e+=this.textMargin+o:e-=this.textMargin,s+='<text font-style="'+i+'" font-size="'+this._legendFontSize+'" x="'+(t-this._legendFontSize)+'" y="'+e+'">'+n+"</text>",s}}const es="7.3.1";export{e as BinaryReader,w as BinaryWriter,A as BitReader,R as ByteRate,Ji as CML,O as Connect,B as EpochTime,x as EventEmitter,N as FixMap,T as Log,v as LogLevel,C as Loggable,M as NetAddress,$ as Numbers,Zi as PlayerStats,L as Queue,k as SDP,ts as UIMetrics,b as Util,es as VERSION,P as WebSocketReliable,U as log};//# sourceMappingURL=web-utils.min.js.map