UNPKG

rx-player

Version:
1 lines 541 kB
"use strict";(()=>{var kp=Object.defineProperty,Pp=Object.defineProperties;var Cp=Object.getOwnPropertyDescriptors;var Wl=Object.getOwnPropertySymbols;var Mp=Object.prototype.hasOwnProperty,Ap=Object.prototype.propertyIsEnumerable;var ql=(n,e,t)=>e in n?kp(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,oe=(n,e)=>{for(var t in e||(e={}))Mp.call(e,t)&&ql(n,t,e[t]);if(Wl)for(var t of Wl(e))Ap.call(e,t)&&ql(n,t,e[t]);return n},de=(n,e)=>Pp(n,Cp(e));var y={PRODUCTION:0,DEV:1,CURRENT_ENV:0};var S={CURRENT_LEVEL:"NONE"};function Un(){return typeof __RX_PLAYER_DEBUG_MODE__=="boolean"&&__RX_PLAYER_DEBUG_MODE__}function _(n){return n==null}var ae=class{constructor(){this._listeners={}}addEventListener(e,t,r){let i=this._listeners[e];Array.isArray(i)?i.push(t):this._listeners[e]=[t],r!==void 0&&r.register(()=>{this.removeEventListener(e,t)})}removeEventListener(e,t){if(_(e)){this._listeners={};return}let r=this._listeners[e];if(!Array.isArray(r))return;if(_(t)){delete this._listeners[e];return}let i=r.indexOf(t);i!==-1&&r.splice(i,1),r.length===0&&delete this._listeners[e]}trigger(e,t){let r=this._listeners[e];Array.isArray(r)&&r.slice().forEach(i=>{try{i(t)}catch(o){if(y.CURRENT_ENV===y.DEV)throw o instanceof Error?o:new Error("EventEmitter: listener error");console.error("RxPlayer: EventEmitter error",o instanceof Error?o:null)}})}};var Ht=typeof WorkerGlobalScope!="undefined"&&self instanceof WorkerGlobalScope;var Op=typeof window=="undefined"&&!Ht,Wt=Op;var yo;Ht?yo=self:Wt?yo=global:yo=window;var J=yo;var Rt=typeof queueMicrotask=="function"?queueMicrotask:function(e){Promise.resolve().then(e,()=>e())};function Wa(){if(!Wt&&!_(J.WebKitSourceBuffer)&&J.WebKitSourceBuffer.prototype.addEventListener===void 0){let e=J.WebKitSourceBuffer.prototype;for(let t in ae.prototype)Object.prototype.hasOwnProperty.call(ae.prototype,t)&&(e[t]=ae.prototype[t]);e._listeners=[],e._emitUpdate=function(t,r){Rt(()=>{this.trigger(t,r),this.updating=!1,this.trigger("updateend",new Event("updateend"))})},e.appendBuffer=function(t){var r,i;if(this.updating)throw new Error("updating");this.trigger("updatestart",new Event("updatestart")),this.updating=!0;try{this.append(t)}catch(o){(r=this._emitUpdate)==null||r.call(this,"error",o);return}(i=this._emitUpdate)==null||i.call(this,"update",new Event("update"))}}}function pe(n,e,t){if(typeof Array.prototype.findIndex=="function")return n.findIndex(e,t);let r=n.length>>>0;for(let i=0;i<r;i++)if(e.call(t,n[i],i,n))return i;return-1}function Z(){}var Io=class{constructor(e,t){this._value=e,this._listeners=[],this._isFinished=!1,this._onFinishCbs=[],t!==void 0&&(this._deregisterCancellation=t.register(()=>this.finish()))}getValue(){return this._value}setValue(e){if(this._isFinished){y.CURRENT_ENV===y.DEV&&console.error("Finished shared references cannot be updated");return}if(this._value=e,this._listeners.length===0)return;let t=this._listeners.slice();for(let r of t)try{r.hasBeenCleared||r.trigger(e,r.complete)}catch(i){}}setValueIfChanged(e){e!==this._value&&this.setValue(e)}onUpdate(e,t){let r=()=>{if(t.clearSignal!==void 0&&t.clearSignal.deregister(r),i.hasBeenCleared)return;i.hasBeenCleared=!0;let o=this._listeners.indexOf(i);o>=0&&this._listeners.splice(o,1)},i={trigger:e,complete:r,hasBeenCleared:!1};if(this._listeners.push(i),t.emitCurrentValue===!0&&e(this._value,r),this._isFinished||i.hasBeenCleared){r();return}t.clearSignal.register(r)}waitUntilDefined(e,t){this.onUpdate((r,i)=>{r!==void 0&&(i(),e(this._value))},{clearSignal:t.clearSignal,emitCurrentValue:!0})}_onFinished(e,t){if(t.isCancelled())return Z;let r=()=>{let a=pe(this._onFinishCbs,s=>s.trigger===i);a>=0&&(this._onFinishCbs[a].hasBeenCleared=!0,this._onFinishCbs.splice(a,1))},i=()=>{r(),e()},o=t.register(r);return this._onFinishCbs.push({trigger:i,hasBeenCleared:!1}),o}finish(){this._deregisterCancellation!==void 0&&this._deregisterCancellation(),this._isFinished=!0;let e=this._listeners.slice();for(let t of e)try{t.hasBeenCleared||(t.complete(),t.hasBeenCleared=!0)}catch(r){}if(this._listeners.length=0,this._onFinishCbs.length>0){let t=this._onFinishCbs.slice();for(let r of t)try{r.hasBeenCleared||(r.trigger(),r.hasBeenCleared=!0)}catch(i){}this._onFinishCbs.length=0}}};function ln(n,e,t){let r=new Io(e(n.getValue()),t);return n.onUpdate(function(o){r.setValue(e(o))},{clearSignal:t}),n._onFinished(()=>{r.finish()},t),r}var G=Io;var Gl=new G(0);var Dp=typeof performance!="undefined"?()=>performance.now()+Gl.getValue():()=>Date.now()+Gl.getValue(),V=Dp;var Lp="NONE",mr=class extends ae{constructor(){super(),this.error=Z,this.warn=Z,this.info=Z,this.debug=Z,this._levels={NONE:0,ERROR:1,WARNING:2,INFO:3,DEBUG:4},this._currentFormat="standard",this._currentLevel=Lp}setLevel(e,t,r){let i,o=this._levels[e];typeof o=="number"?(i=o,this._currentLevel=e):(i=0,this._currentLevel="NONE");let a;if(t==="standard"||t==="full"?a=t:a="standard",a==="full"&&a!==this._currentFormat){let d=V();console.log(String(d.toFixed(2)),"[Init]",`Local-Date: ${Date.now()}`)}this._currentFormat=a;let s=this._currentFormat==="full"?(d,u)=>(...c)=>{let l=V();return u(String(l.toFixed(2)),`[${d}]`,...c)}:(d,u)=>u;if(r===void 0)this.error=i>=this._levels.ERROR?s("error",console.error.bind(console)):Z,this.warn=i>=this._levels.WARNING?s("warn",console.warn.bind(console)):Z,this.info=i>=this._levels.INFO?s("info",console.info.bind(console)):Z,this.debug=i>=this._levels.DEBUG?s("log",console.log.bind(console)):Z;else{let d=u=>i>=this._levels[u]?(...c)=>r(u,c):Z;this.error=d("ERROR"),this.warn=d("WARNING"),this.info=d("INFO"),this.debug=d("DEBUG")}this.trigger("onLogLevelChange",{level:this._currentLevel,format:this._currentFormat})}getLevel(){return this._currentLevel}getFormat(){return this._currentFormat}hasLevel(e){return this._levels[e]>=this._levels[this._currentLevel]}};var Np=new mr,m=Np;var De=J,jl,Yl,$l,Ql,Xl,kt=(Xl=(Ql=($l=(Yl=(jl=De==null?void 0:De.MediaSource)!=null?jl:De==null?void 0:De.MozMediaSource)!=null?Yl:De==null?void 0:De.WebKitMediaSource)!=null?$l:De==null?void 0:De.MSMediaSource)!=null?Ql:De==null?void 0:De.ManagedMediaSource)!=null?Xl:void 0,Zl=kt!==void 0&&kt===(De==null?void 0:De.ManagedMediaSource);var Up=200,bo=new Map;function qa(n){if(_(kt))return Ht&&m.error("Compat: Cannot request codec support in a worker without MSE."),!1;if(typeof kt.isTypeSupported=="function"){let e=bo.get(n);if(e!==void 0)return e;{let t=kt.isTypeSupported(n);return bo.size>=Up&&bo.clear(),bo.set(n,t),t}}return!0}var pr=!1,cn=!1,qt=!1,fn=!1,Ga=!1,mn=!1,ja=!1,gr=!1,hr=!1,Bp=!1,Fp=!1,Ya=!1,$a=!1,Qa=!1,pn=!1,Kp=!1,Xa=!1;(function(){var e,t,r;Wt||(typeof J.MSInputMethodContext!="undefined"&&typeof document.documentMode!="undefined"?(cn=!0,qt=!0):navigator.appName==="Microsoft Internet Explorer"||navigator.appName==="Netscape"&&/(Trident|Edge)\//.test(navigator.userAgent)?qt=!0:navigator.userAgent.toLowerCase().indexOf("edg/")!==-1?pr=!0:navigator.userAgent.toLowerCase().indexOf("firefox")!==-1?fn=!0:typeof navigator.platform=="string"&&/iPad|iPhone|iPod/.test(navigator.platform)?mn=!0:(Object.prototype.toString.call(J.HTMLElement).indexOf("Constructor")>=0||((t=(e=J.safari)==null?void 0:e.pushNotification)==null?void 0:t.toString())==="[object SafariRemoteNotification]"||/Safari\/(\d+)/.test(navigator.userAgent)&&/Version\/(\d+)/.test(navigator.userAgent)&&((r=navigator.vendor)==null?void 0:r.indexOf("Apple"))!==-1&&!/Chrome\/(\d+)/.test(navigator.userAgent)&&!/Chromium\/(\d+)/.test(navigator.userAgent))&&(Ga=!0),/SamsungBrowser/.test(navigator.userAgent)&&(ja=!0),navigator.userAgent.indexOf("PlayStation 4")!==-1?Qa=!0:navigator.userAgent.indexOf("PlayStation 5")!==-1?pn=!0:/Tizen/.test(navigator.userAgent)?gr=!0:/[Ww]eb[O0]S/.test(navigator.userAgent)?(hr=!0,/[Ww]eb[O0]S.TV-2022/.test(navigator.userAgent)||/[Cc]hr[o0]me\/87/.test(navigator.userAgent)?Fp=!0:(/[Ww]eb[O0]S.TV-2021/.test(navigator.userAgent)||/[Cc]hr[o0]me\/79/.test(navigator.userAgent))&&(Bp=!0)):navigator.userAgent.indexOf("NETTV")!==-1&&navigator.userAgent.indexOf("Philips")!==-1?$a=!0:/[Pp]anasonic/.test(navigator.userAgent)?Ya=!0:navigator.userAgent.indexOf("Xbox")!==-1?Kp=!0:navigator.userAgent.indexOf("Model/a1-kstb40xx")!==-1&&(Xa=!0))})();var Vp=pn,Jl=Vp;function Za(n){return n===void 0||n.indexOf("widevine")<0}var ec={DEFAULT_REQUEST_TIMEOUT:3e4,DEFAULT_CONNECTION_TIMEOUT:15e3,DEFAULT_TEXT_TRACK_MODE:"native",DEFAULT_ENABLE_FAST_SWITCHING:!0,DELTA_POSITION_AFTER_RELOAD:{bitrateSwitch:-.1,trackSwitch:{audio:0,video:0,other:0}},DEFAULT_CODEC_SWITCHING_BEHAVIOR:"continue",DEFAULT_AUTO_PLAY:!1,DEFAULT_WANTED_BUFFER_AHEAD:30,DEFAULT_MAX_BUFFER_AHEAD:1/0,DEFAULT_MAX_BUFFER_BEHIND:1/0,DEFAULT_MAX_VIDEO_BUFFER_SIZE:1/0,MAXIMUM_MAX_BUFFER_AHEAD:{text:18e3},MINIMUM_MAX_BUFFER_AHEAD:{text:120},MAXIMUM_MAX_BUFFER_BEHIND:{text:18e3},DEFAULT_BASE_BANDWIDTH:0,INACTIVITY_DELAY:6e4,DEFAULT_THROTTLE_VIDEO_BITRATE_WHEN_HIDDEN:!1,DEFAULT_VIDEO_RESOLUTION_LIMIT:"none",DEFAULT_LIVE_GAP:{DEFAULT:10,LOW_LATENCY:3.5},BUFFER_DISCONTINUITY_THRESHOLD:.2,BITRATE_REBUFFERING_RATIO:1.5,DEFAULT_MAX_MANIFEST_REQUEST_RETRY:4,DEFAULT_CDN_DOWNGRADE_TIME:60,DEFAULT_MAX_REQUESTS_RETRY_ON_ERROR:4,INITIAL_BACKOFF_DELAY_BASE:{REGULAR:200,LOW_LATENCY:50},MAX_BACKOFF_DELAY_BASE:{REGULAR:3e3,LOW_LATENCY:1e3},SAMPLING_INTERVAL_MEDIASOURCE:1e3,SAMPLING_INTERVAL_LOW_LATENCY:500,SAMPLING_INTERVAL_NO_MEDIASOURCE:500,ABR_ENTER_BUFFER_BASED_ALGO:10,ABR_EXIT_BUFFER_BASED_ALGO:5,ABR_MINIMUM_TOTAL_BYTES:15e4,ABR_MINIMUM_CHUNK_SIZE:16e3,ABR_STARVATION_FACTOR:{DEFAULT:.72,LOW_LATENCY:.72},ABR_REGULAR_FACTOR:{DEFAULT:.72,LOW_LATENCY:.72},ABR_STARVATION_GAP:{DEFAULT:5,LOW_LATENCY:5},OUT_OF_STARVATION_GAP:{DEFAULT:7,LOW_LATENCY:7},ABR_STARVATION_DURATION_DELTA:.1,ABR_FAST_EMA:2,ABR_SLOW_EMA:10,RESUME_GAP_AFTER_SEEKING:{DEFAULT:1.5,LOW_LATENCY:.5},RESUME_GAP_AFTER_NOT_ENOUGH_DATA:{DEFAULT:.5,LOW_LATENCY:.5},RESUME_GAP_AFTER_BUFFERING:{DEFAULT:5,LOW_LATENCY:.5},REBUFFERING_GAP:{DEFAULT:.5,LOW_LATENCY:.2},MINIMUM_BUFFER_AMOUNT_BEFORE_FREEZING:2,UNFREEZING_SEEK_DELAY:6e3,FREEZING_STALLED_DELAY:600,UNFREEZING_DELTA_POSITION:.001,FREEZING_FLUSH_FAILURE_DELAY:{MAXIMUM:2e4,MINIMUM:4e3,POSITION_DELTA:1},SEGMENT_SYNCHRONIZATION_DELAY:1500,MISSING_DATA_TRIGGER_SYNC_DELAY:.1,MAX_TIME_MISSING_FROM_COMPLETE_SEGMENT:.15,MAX_MANIFEST_BUFFERED_START_END_DIFFERENCE:.4,MAX_MANIFEST_BUFFERED_DURATION_DIFFERENCE:.3,MINIMUM_SEGMENT_SIZE:.001,APPEND_WINDOW_SECURITIES:{START:.2,END:.1},MAXIMUM_HTML_TEXT_TRACK_UPDATE_INTERVAL:50,TEXT_TRACK_SIZE_CHECKS_INTERVAL:250,BUFFER_PADDING:{audio:1,video:3,other:1},SEGMENT_PRIORITIES_STEPS:[2,4,8,12,18,25],MAX_HIGH_PRIORITY_LEVEL:1,MIN_CANCELABLE_PRIORITY:3,EME_DEFAULT_VIDEO_CODECS:['video/mp4;codecs="avc1.4d401e"','video/mp4;codecs="avc1.42e01e"','video/mp4;codecs="hvc1.1.6.L93.B0"','video/webm;codecs="vp8"'],EME_DEFAULT_AUDIO_CODECS:['audio/mp4;codecs="mp4a.40.2"','audio/webm;codecs="opus"','audio/mp4;codecs="ec-3"'],EME_DEFAULT_WIDEVINE_ROBUSTNESSES:["HW_SECURE_ALL","HW_SECURE_DECODE","HW_SECURE_CRYPTO","SW_SECURE_DECODE","SW_SECURE_CRYPTO"],EME_DEFAULT_PLAYREADY_RECOMMENDATION_ROBUSTNESSES:["3000","2000"],EME_KEY_SYSTEMS:{clearkey:["webkit-org.w3.clearkey","org.w3.clearkey"],widevine:["com.widevine.alpha"],playready:["com.microsoft.playready.recommendation","com.microsoft.playready","com.chromecast.playready","com.youtube.playready"],fairplay:["com.apple.fps.1_0"]},MAX_CONSECUTIVE_MANIFEST_PARSING_IN_UNSAFE_MODE:10,MIN_MANIFEST_PARSING_TIME_TO_ENTER_UNSAFE_MODE:200,MIN_DASH_S_ELEMENTS_TO_PARSE_UNSAFELY:300,OUT_OF_SYNC_MANIFEST_REFRESH_DELAY:3e3,FAILED_PARTIAL_UPDATE_MANIFEST_REFRESH_DELAY:3e3,DASH_FALLBACK_LIFETIME_WHEN_MINIMUM_UPDATE_PERIOD_EQUAL_0:3,EME_DEFAULT_MAX_SIMULTANEOUS_MEDIA_KEY_SESSIONS:15,EME_MAX_STORED_PERSISTENT_SESSION_INFORMATION:1e3,EME_WAITING_DELAY_LOADED_SESSION_EMPTY_KEYSTATUSES:100,FORCED_ENDED_THRESHOLD:8e-4,ADAP_REP_SWITCH_BUFFER_PADDINGS:{video:{before:5,after:5},audio:{before:2,after:2.5},text:{before:0,after:0}},SOURCE_BUFFER_FLUSHING_INTERVAL:500,CONTENT_REPLACEMENT_PADDING:1.2,CACHE_LOAD_DURATION_THRESHOLDS:{video:50,audio:10},STREAM_EVENT_EMITTER_POLL_INTERVAL:250,DEFAULT_MAXIMUM_TIME_ROUNDING_ERROR:.001,BUFFERED_HISTORY_RETENTION_TIME:6e4,BUFFERED_HISTORY_MAXIMUM_ENTRIES:200,MIN_BUFFER_AHEAD:5,UPTO_CURRENT_POSITION_CLEANUP:5,DEFAULT_VIDEO_REPRESENTATIONS_SWITCHING_MODE:"seamless",DEFAULT_AUDIO_REPRESENTATIONS_SWITCHING_MODE:"seamless",DEFAULT_VIDEO_TRACK_SWITCHING_MODE:"reload",DEFAULT_AUDIO_TRACK_SWITCHING_MODE:"seamless",DEFAULT_MAX_THUMBNAIL_REQUESTS_RETRY_ON_ERROR:1,DEFAULT_THUMBNAIL_REQUEST_TIMEOUT:1e4,DEFAULT_THUMBNAIL_CONNECTION_TIMEOUT:7e3},tc=ec;function zp(n,...e){if(n==null)throw new TypeError("Cannot convert undefined or null to object");let t=Object(n);for(let r of e)for(let i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i]);return t}var Y=typeof Object.assign=="function"?Object.assign:zp;function Ja(n){return n!=null&&!Array.isArray(n)&&typeof n=="object"}function yr(n,...e){if(e.length===0)return n;let t=e.shift();if(Ja(n)&&Ja(t))for(let r in t)if(Ja(t[r])){let i=n[r];i===void 0&&(i={},n[r]=i),yr(i,t[r])}else Y(n,{[r]:t[r]});return yr(n,...e)}var es=class extends ae{constructor(){super(...arguments);this.updated=!1;this._config=tc}update(t){let r=yr(this._config,t);this._config=r,this.updated=!0,this.trigger("update",t)}getCurrent(){return this._config}},Hp=new es,L=Hp;var Wp=.016666666666666666;function nc(n,e){return Math.abs(n-e)<Wp}function ic(n,e){let t=Math.min(n.start,e.start),r=Math.max(n.end,e.end);return{start:t,end:r}}function qp(n){for(let e=0;e<n.length;e++){let t=n[e];t.start===t.end&&n.splice(e--,1)}return n}function Gp(n){for(let e=1;e<n.length;e++){let t=n[e-1],r=n[e];if(ac(t,r)){let i=ic(t,r);n.splice(--e,2,i)}}return n}function ts(n,e){return n.end<=e.start}function rc({start:n,end:e},t){return n<=t&&t<e}function oc(n,e){return rc(n,e.start)||n.start<e.end&&e.end<n.end||rc(e,n.start)}function ac(n,e){return nc(e.start,n.end)||nc(e.end,n.start)}function xe(n){let e=[];for(let t=0;t<n.length;t++)e.push({start:n.start(t),end:n.end(t)});return e}function ns(n,e){for(let t=n.length-1;t>=0;t--){let r=n.start(t);if(e>=r){let i=n.end(t);if(e<i)return{start:r,end:i}}}return null}function jp(n,e){for(let t=n.length-1;t>=0;t--){let r=n[t].start;if(e>=r){let i=n[t].end;if(e<i)return n[t]}}return null}function sc(n,e){let t=n.length;for(let r=0;r<t;r++){let i=n.start(r);if(e<i)return i-e}return 1/0}function dc(n,e){let t=null,r=[];for(let i=0;i<n.length;i++){let o=n[i].start,a=n[i].end;e<o||e>=a?r.push({start:o,end:a}):t={start:o,end:a}}return{outerRanges:r,innerRange:t}}function uc(n,e){let t=ns(n,e);return t!==null?t.end-e:1/0}function So(n,e){let t=jp(n,e);return t!==null?t.end-e:1/0}function Gt(n,e){if(e.start===e.end)return n;let t=e,r=0;for(;r<n.length;r++){let i=n[r],o=oc(t,i),a=ac(t,i);if(o||a)t=ic(t,i),n.splice(r--,1);else if(r===0){if(ts(t,n[0]))break}else if(ts(n[r-1],t)&&ts(t,i))break}return n.splice(r,0,t),Gp(qp(n))}function lc(n,e){let t=[];for(let r=0;r<e.length;r++)oc(n,e[r])&&t.push(e[r]);return t}function cc(n,e){let t=[];for(let r=0;r<n.length;r++){let i=n[r],o=lc(i,e);if(o.length>0)for(let a=0;a<o.length;a++){let s=o[a];t.push({start:Math.max(i.start,s.start),end:Math.min(i.end,s.end)})}}return t}function To(n,e){let t=[];for(let r=0;r<n.length;r++){let i=n[r],o=[],a=lc(i,e);if(a.length>0)for(let s=0;s<a.length;s++){let d=a[s];o.push({start:Math.max(i.start,d.start),end:Math.min(i.end,d.end)})}if(o.length===0)t.push(i);else{let s=i.start;for(let d=0;d<o.length;d++)o[d].start>s&&t.push({start:s,end:o[d].start}),s=o[d].end;s<i.end&&t.push({start:s,end:i.end})}}return t}var _o=class n extends Error{constructor(e){super(e),Object.setPrototypeOf(this,n.prototype),this.name="AssertionError"}};function ee(n,e){if(y.DEV===y.CURRENT_ENV&&!n)throw new _o(e===void 0?"invalid assertion":e)}function fc(n,e,t="object"){ee(!_(n),`${t} should be an object`);for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&ee(typeof n[r]===e[r],`${t} should have property ${r} as a ${e[r]}`)}function He(n){throw new _o("Unreachable path taken")}var U=class{constructor(){let[e,t]=Yp();this._isUsed=!1,this._trigger=e,this.signal=new Ir(t)}isUsed(){return this._isUsed}linkToSignal(e){let t=e.register(()=>{this.cancel()});return this.signal.register(t),t}cancel(e){if(this._isUsed)return;this._isUsed=!0;let t=e!=null?e:new Pe;this._trigger(t)}static isCancellationError(e){return e instanceof Pe}},Ir=class{constructor(e){this._isCancelled=!1,this.cancellationError=null,this._listeners=[],e(t=>{for(this.cancellationError=t,this._isCancelled=!0;this._listeners.length>0;)try{let r=this._listeners.pop();r==null||r(t)}catch(r){m.error("Error while calling clean up listener",r instanceof Error?r.toString():"Unknown error")}})}isCancelled(){return this._isCancelled}register(e){return this._isCancelled?(ee(this.cancellationError!==null),e(this.cancellationError),Z):(this._listeners.push(e),()=>this.deregister(e))}deregister(e){for(let t=this._listeners.length-1;t>=0;t--)this._listeners[t]===e&&this._listeners.splice(t,1)}},Pe=class n extends Error{constructor(){super("This task was cancelled."),Object.setPrototypeOf(this,n.prototype),this.name="CancellationError"}};function Yp(){let n=Z;return[function(t){n(t)},function(t){n=t}]}function rs(n){let e=n.map(a=>Math.log(a/n[0])),t=e.map(a=>a-e[0]+1),r=(t[t.length-1]-1)/(n.length*2+10),i=1/r;return n.map((a,s)=>o(s));function o(a){if(a===0)return 0;let s=Math.min(Math.max(1,a),n.length-1);return n[s]===n[s-1]?o(a-1):i*(r+(n[s]*t[s-1]-n[s-1]*t[s])/(n[s]-n[s-1]))+4}}var rt=class{constructor(e){this._alpha=Math.exp(Math.log(.5)/e),this._lastEstimate=0,this._totalWeight=0}addSample(e,t){let r=Math.pow(this._alpha,e),i=t*(1-r)+r*this._lastEstimate;isNaN(i)||(this._lastEstimate=i,this._totalWeight+=e)}getEstimate(){let e=1-Math.pow(this._alpha,this._totalWeight);return this._lastEstimate/e}};var br=class{constructor(){this._currentRepresentationData=null,this._lastRepresentationWithGoodScore=null}addSample(e,t,r){let i=r/t,o=this._currentRepresentationData,a;o!==null&&o.representation.id===e.id?(a=o.ewma,o.ewma.addSample(t,i),o.loadedDuration+=r,o.loadedSegments++):(a=new rt(5),a.addSample(t,i),this._currentRepresentationData={representation:e,ewma:a,loadedDuration:r,loadedSegments:0}),a.getEstimate()>1&&this._lastRepresentationWithGoodScore!==e&&(m.debug("ABR: New last stable representation",e.bitrate),this._lastRepresentationWithGoodScore=e)}getEstimate(e){if(this._currentRepresentationData===null||this._currentRepresentationData.representation.id!==e.id)return;let{ewma:t,loadedSegments:r,loadedDuration:i}=this._currentRepresentationData,o=t.getEstimate(),a=r>=5&&i>=10?1:0;return{score:o,confidenceLevel:a}}getLastStableRepresentation(){return this._lastRepresentationWithGoodScore}};var mc=6e3,$p=15e3,Qp=3e3,Xp=1e3,Zp=9e3,Sr=class{constructor(e){this._levelsMap=rs(e).map(t=>t+4),this._bitrates=e,this._lastUnsuitableQualityTimestamp=void 0,this._blockRaiseDelay=mc,m.debug("ABR: Steps for buffer based chooser.",this._levelsMap.map((t,r)=>`bufferLevel: ${t}, bitrate: ${e[r]}`).join(" ,"))}onAddedSegment(e){let t=this._levelsMap,r=this._bitrates,{bufferGap:i,currentBitrate:o,currentScore:a,speed:s}=e;if(_(o)){this._currentEstimate=r[0];return}let d=-1;for(let g=0;g<r.length;g++){let b=r[g];if(b===o)d=g;else if(b>o)break}if(d<0||r.length!==t.length){m.info("ABR: Current Bitrate not found in the calculated levels"),this._currentEstimate=r[0];return}let u;a!==void 0&&(u=s===0?a.score:a.score/s);let c=isFinite(i)?i:0,l=V();if(c<t[d]||u!==void 0&&u<1&&(a==null?void 0:a.confidenceLevel)===1){if((this._lastUnsuitableQualityTimestamp===void 0?-1:l-this._lastUnsuitableQualityTimestamp)<this._blockRaiseDelay+Zp){let h=this._blockRaiseDelay+Qp;this._blockRaiseDelay=Math.min(h,$p),m.debug("ABR: Incrementing blocking raise in BufferBasedChooser due to unstable quality",this._blockRaiseDelay)}else{let h=this._blockRaiseDelay-Xp;this._blockRaiseDelay=Math.max(mc,h),m.debug("ABR: Lowering quality in BufferBasedChooser",this._blockRaiseDelay)}this._lastUnsuitableQualityTimestamp=l;let b=pe(r,h=>h===o);for(let h=b-1;h>=0;h--)if(c>=t[h]){this._currentEstimate=r[h];return}this._currentEstimate=r[0];return}if(this._lastUnsuitableQualityTimestamp!==void 0&&l-this._lastUnsuitableQualityTimestamp<this._blockRaiseDelay||u===void 0||u<1.15||(a==null?void 0:a.confidenceLevel)!==1){this._currentEstimate=o;return}let f=t[d],p=(()=>{for(let g=d+1;g<t.length;g++)if(t[g]>f)return g})();if(p!==void 0){let g=t[p];if(i>=g){m.debug("ABR: Raising quality in BufferBasedChooser",r[p]),this._currentEstimate=r[p];return}}this._currentEstimate=o}getLastEstimate(){return this._currentEstimate}};function Q(n,e,t){if(typeof Array.prototype.find=="function")return n.find(e,t);let r=n.length>>>0;for(let i=0;i<r;i++){let o=n[i];if(e.call(t,o,i,n))return o}}function Jp(n,e){let t=-1;for(let a=0;a<n.length;a++){let{segment:s}=n[a].content;if(s.duration<=0)continue;let d=s.time+s.duration;if(!s.complete&&a===n.length-1&&e-s.time>-1.2){t=a;break}if(d>e&&e-s.time>-1.2){t=a;break}}if(t<0)return[];let r=n[t],i=r.content.segment.time,o=[r];for(let a=t+1;a<n.length&&n[a].content.segment.time===i;a++)o.push(n[a]);return o}function Eo(n){if(n.progress.length<5)return;let e=new rt(2),{progress:t}=n;for(let r=1;r<t.length;r++){let i=t[r].size-t[r-1].size,o=t[r].timestamp-t[r-1].timestamp,a=i*8/(o/1e3);e.addSample(o/1e3,a)}return e.getEstimate()}function pc(n,e){let t=(n.totalSize-n.size)*8;return Math.max(t/e,0)}function eg(n,e,t,r,i){if(r)return;let{bufferGap:o,speed:a,position:s}=e,d=isFinite(o)?o:0,u=s.getWanted()+d,c=Jp(n,u);if(c.length!==1)return;let l=c[0],f=V(),p=l.content.segment.duration*1.5;if(p=Math.min(p,3e3),p=Math.max(p,12e3),f-l.requestTimestamp<p)return;let g=l.progress.length>0?l.progress[l.progress.length-1]:void 0,b=Eo(l);if(g!==void 0&&b!==void 0){let v=pc(g,b);if((f-g.timestamp)/1e3<=v&&v-d/a>2500)return b}if(!l.content.segment.complete)return;let h=l.content.segment.duration,I=(f-l.requestTimestamp)/1e3,T=I<=(h*1.5+2)/a;if(_(t)||T)return;let R=h/I,E=t.bitrate*Math.min(.7,R);if(i===void 0||E<i)return E}function tg(n,e,t){if(t)return!0;let r=isFinite(n.bufferGap)?n.bufferGap:0,i=n.position.getWanted()+r,o=Q(e,({content:l})=>l.segment.duration>0&&l.segment.time+l.segment.duration>i);if(o===void 0)return!0;let a=V(),s=o.progress.length>0?o.progress[o.progress.length-1]:void 0,d=Eo(o);if(s===void 0||d===void 0)return!0;let u=pc(s,d);return(a-s.timestamp)/1e3>u*1.2?!0:u-r/n.speed>-1.5}var Tr=class{constructor(e,t){let{ABR_STARVATION_GAP:r,OUT_OF_STARVATION_GAP:i,ABR_STARVATION_FACTOR:o,ABR_REGULAR_FACTOR:a}=L.getCurrent();this._initialBitrate=e,this._inStarvationMode=!1,this._lowLatencyMode=t,t?this._config={starvationGap:r.LOW_LATENCY,outOfStarvationGap:i.LOW_LATENCY,starvationBitrateFactor:o.LOW_LATENCY,regularBitrateFactor:a.LOW_LATENCY}:this._config={starvationGap:r.DEFAULT,outOfStarvationGap:i.DEFAULT,starvationBitrateFactor:o.DEFAULT,regularBitrateFactor:a.DEFAULT}}getBandwidthEstimate(e,t,r,i,o){let a,s,d=this._config,{bufferGap:u,position:c,duration:l}=e,f=isFinite(u)?u:0,{ABR_STARVATION_DURATION_DELTA:p}=L.getCurrent();return isNaN(l)||f+c.getWanted()<l-p?!this._inStarvationMode&&f<=d.starvationGap?(m.info("ABR: enter starvation mode."),this._inStarvationMode=!0):this._inStarvationMode&&f>=d.outOfStarvationGap&&(m.info("ABR: exit starvation mode."),this._inStarvationMode=!1):this._inStarvationMode&&(m.info("ABR: exit starvation mode."),this._inStarvationMode=!1),this._inStarvationMode&&(s=eg(i,e,r,this._lowLatencyMode,o),s!==void 0&&(m.info("ABR: starvation mode emergency estimate:",s),t.reset(),a=_(r)?s:Math.min(s,r.bitrate))),_(a)&&(s=t.getEstimate(),s!==void 0?a=s*(this._inStarvationMode?d.starvationBitrateFactor:d.regularBitrateFactor):o!==void 0?a=o*(this._inStarvationMode?d.starvationBitrateFactor:d.regularBitrateFactor):a=this._initialBitrate),e.speed>1&&(a/=e.speed),{bandwidthEstimate:s,bitrateChosen:a}}isUrgent(e,t,r,i){return t===null?!0:e>=t.bitrate?!1:tg(i,r,this._lowLatencyMode)}};var _r=class{constructor(){this.bandwidth=void 0,this.representation=null,this.algorithmType=3}update(e,t,r){this.representation=e,this.bandwidth=t,this.algorithmType=r}};var Er=class{constructor(e,t){this._scoreCalculator=e,this._lastAbrEstimate=t,this._consecutiveWrongGuesses=0,this._blockGuessesUntil=0,this._lastMaintanableBitrate=null}getGuess(e,t,r,i,o){let{bufferGap:a,speed:s}=t,d=this._lastAbrEstimate.representation;if(d===null)return null;if(i>d.bitrate)return this._lastAbrEstimate.algorithmType===2&&(this._lastAbrEstimate.representation!==null&&(this._lastMaintanableBitrate=this._lastAbrEstimate.representation.bitrate),this._consecutiveWrongGuesses=0),null;let u=this._scoreCalculator.getEstimate(r);if(this._lastAbrEstimate.algorithmType!==2){if(u===void 0)return null;if(this._canGuessHigher(a,s,u)){let l=gc(e,r);if(l!==null)return l}return null}if(this._isLastGuessValidated(d,i,u)&&(m.debug("ABR: Guessed Representation validated",d.bitrate),this._lastMaintanableBitrate=d.bitrate,this._consecutiveWrongGuesses=0),r.id!==d.id)return d;if(this._shouldStopGuess(r,u,a,o))return this._consecutiveWrongGuesses++,this._blockGuessesUntil=V()+Math.min(this._consecutiveWrongGuesses*15e3,12e4),ng(e,r);if(u===void 0)return r;if(this._canGuessHigher(a,s,u)){let l=gc(e,r);if(l!==null)return l}return r}_canGuessHigher(e,t,{score:r,confidenceLevel:i}){return isFinite(e)&&e>=2.5&&V()>this._blockGuessesUntil&&i===1&&r/t>1.01}_shouldStopGuess(e,t,r,i){if(t!==void 0&&t.score<1.01)return!0;if((t===void 0||t.score<1.2)&&r<.6)return!0;let o=i.filter(s=>s.content.representation.id===e.id),a=V();for(let s of o){let d=a-s.requestTimestamp;if(s.content.segment.isInit){if(d>1e3)return!0}else{if(d>s.content.segment.duration*1e3+200)return!0;{let u=Eo(s);if(u!==void 0&&u<e.bitrate*.8)return!0}}}return!1}_isLastGuessValidated(e,t,r){return r!==void 0&&r.confidenceLevel===1&&r.score>1.5?!0:t>=e.bitrate&&(this._lastMaintanableBitrate===null||this._lastMaintanableBitrate<e.bitrate)}};function gc(n,e){let t=n.length,r=pe(n,({id:i})=>i===e.id);if(r<0)return m.error("ABR: Current Representation not found."),null;for(;++r<t;)if(n[r].bitrate>e.bitrate)return n[r];return null}function ng(n,e){let t=pe(n,({id:r})=>r===e.id);if(t<0)return m.error("ABR: Current Representation not found."),null;for(;--t>=0;)if(n[t].bitrate<e.bitrate)return n[t];return null}var vr=class{constructor(){let{ABR_FAST_EMA:e,ABR_SLOW_EMA:t}=L.getCurrent();this._fastEWMA=new rt(e),this._slowEWMA=new rt(t),this._bytesSampled=0}addSample(e,t){let{ABR_MINIMUM_CHUNK_SIZE:r}=L.getCurrent();if(t<r)return;let i=t*8e3/e,o=e/1e3;this._bytesSampled+=t,this._fastEWMA.addSample(o,i),this._slowEWMA.addSample(o,i)}getEstimate(){let{ABR_MINIMUM_TOTAL_BYTES:e}=L.getCurrent();if(!(this._bytesSampled<e))return Math.min(this._fastEWMA.getEstimate(),this._slowEWMA.getEstimate())}reset(){let{ABR_FAST_EMA:e,ABR_SLOW_EMA:t}=L.getCurrent();this._fastEWMA=new rt(e),this._slowEWMA=new rt(t),this._bytesSampled=0}};function is(n,e){if(n.length===0)return[];n.sort((o,a)=>o.bitrate-a.bitrate);let t=n[0].bitrate,r=Math.max(e,t),i=pe(n,o=>o.bitrate>r);return i===-1?n:n.slice(0,i)}function os(n,e){if(e.width===void 0||e.height===void 0)return n;let t=e.width*e.pixelRatio,r=e.height*e.pixelRatio,i=n.slice().sort((s,d)=>{var u,c;return((u=s.width)!=null?u:0)-((c=d.width)!=null?c:0)}),o=Q(i,s=>typeof s.width=="number"&&s.width>=t&&typeof s.height=="number"&&s.height>=r);if(o===void 0)return n;let a=typeof o.width=="number"?o.width:0;return n.filter(s=>typeof s.width=="number"?s.width<=a:!0)}function Rr(n){return Object.keys(n).map(e=>n[e])}var Bn=typeof Object.values=="function"?Object.values:Rr;var kr=class{constructor(){this._currentRequests={}}add(e){let{id:t,requestTimestamp:r,content:i}=e;this._currentRequests[t]={requestTimestamp:r,progress:[],content:i}}addProgress(e){let t=this._currentRequests[e.id];if(_(t)){if(y.CURRENT_ENV===y.DEV)throw new Error("ABR: progress for a request not added");m.warn("ABR: progress for a request not added");return}t.progress.push(e)}remove(e){if(_(this._currentRequests[e])){if(y.CURRENT_ENV===y.DEV)throw new Error("ABR: can't remove unknown request");m.warn("ABR: can't remove unknown request")}delete this._currentRequests[e]}getRequests(){return Bn(this._currentRequests).filter(e=>!_(e)).sort((e,t)=>e.content.segment.time-t.content.segment.time)}};function vo(n,e){let t=pe(n,r=>r.bitrate>e);return t===-1?n[n.length-1]:t===0?n[0]:n[t-1]}var hc=new G(void 0);hc.finish();var yc=new G(1/0);yc.finish();function as(n){let e={},{initialBitrates:t,throttlers:r,lowLatencyMode:i}=n;return function(s,d,u,c,l){var h,I,T;let{type:f}=s.adaptation,p=o(f),g=(h=t[f])!=null?h:0,b={limitResolution:(I=r.limitResolution[f])!=null?I:hc,throttleBitrate:(T=r.throttleBitrate[f])!=null?T:yc};return rg({bandwidthEstimator:p,context:s,currentRepresentation:d,filters:b,initialBitrate:g,playbackObserver:c,representations:u,lowLatencyMode:i},l)};function o(a){let s=e[a];if(_(s)){m.debug("ABR: Creating new BandwidthEstimator for ",a);let d=new vr;return e[a]=d,d}return s}}function rg({bandwidthEstimator:n,context:e,currentRepresentation:t,filters:r,initialBitrate:i,lowLatencyMode:o,playbackObserver:a,representations:s},d){let u=new br,c=new Tr(i!=null?i:0,o),l=new kr,f=Z,p={metrics:T,requestBegin:R,requestProgress:E,requestEnd:v,addedSegment(k){f(k)}},g=new U;g.linkToSignal(d);let b=h(s.getValue(),g.signal);return s.onUpdate(I,{clearSignal:d}),{estimates:b,callbacks:p};function h(k,x){if(k.length<=1)return new G({bitrate:void 0,representation:k[0],urgent:!0,knownStableBitrate:void 0});let P=!1,M=k.sort((K,j)=>K.bitrate-j.bitrate),O=new Sr(M.map(K=>K.bitrate)),B=new _r,D=new Er(u,B),F=a.getReference().getValue(),A=new G(N());return a.listen(K=>{F=K,C()},{includeLastObservation:!1,clearSignal:x}),f=function(K){if(F===null)return;let{position:j,speed:$}=F,z=K.buffered,H=So(z,j.getWanted()),{representation:q}=K.content,ie=u.getEstimate(q),ne=q.bitrate,le={bufferGap:H,currentBitrate:ne,currentScore:ie,speed:$};O.onAddedSegment(le),C()},x.register(()=>{f=Z}),r.throttleBitrate.onUpdate(C,{clearSignal:x}),r.limitResolution.onUpdate(C,{clearSignal:x}),A;function C(){A.setValue(N())}function N(){let{bufferGap:K,position:j,maximumPosition:$}=F,z=r.limitResolution.getValue(),H=r.throttleBitrate.getValue(),q=t.getValue(),ie=ig(M,z,H),ne=l.getRequests(),{bandwidthEstimate:le,bitrateChosen:be}=c.getBandwidthEstimate(F,n,q,ne,B.bandwidth),me=u.getLastStableRepresentation(),W=me===null?void 0:me.bitrate/(F.speed>0?F.speed:1),{ABR_ENTER_BUFFER_BASED_ALGO:Ce,ABR_EXIT_BUFFER_BASED_ALGO:nt}=L.getCurrent();P&&K<=nt?P=!1:!P&&isFinite(K)&&K>=Ce&&(P=!0);let Ae=vo(ie,be),Vt=O.getLastEstimate(),un=Ae.bitrate,mt=null;P&&Vt!==void 0&&Vt>un&&(mt=vo(ie,Vt),un=mt.bitrate);let bt=null;return o&&q!==null&&e.manifest.isDynamic&&$-j.getWanted()<40&&(bt=D.getGuess(M,F,q,un,ne)),bt!==null&&bt.bitrate>un?(m.debug("ABR: Choosing representation with guess-based estimation.",bt.bitrate,bt.id),B.update(bt,le,2),{bitrate:le,representation:bt,urgent:q===null||bt.bitrate<q.bitrate,knownStableBitrate:W}):mt!==null?(m.debug("ABR: Choosing representation with buffer-based estimation.",mt.bitrate,mt.id),B.update(mt,le,0),{bitrate:le,representation:mt,urgent:c.isUrgent(mt.bitrate,q,ne,F),knownStableBitrate:W}):(m.debug("ABR: Choosing representation with bandwidth estimation.",Ae.bitrate,Ae.id),B.update(Ae,le,1),{bitrate:le,representation:Ae,urgent:c.isUrgent(Ae.bitrate,q,ne,F),knownStableBitrate:W})}}function I(){let k=s.getValue();g.cancel(),g=new U,g.linkToSignal(d),h(k,g.signal).onUpdate(function(M){b.setValue(M)},{clearSignal:g.signal,emitCurrentValue:!0})}function T(k){let{requestDuration:x,segmentDuration:P,size:M,content:O}=k;if(n.addSample(x,M),!O.segment.isInit){let{segment:B,representation:D}=O;if(P===void 0&&!B.complete)return;let F=P!=null?P:B.duration;u.addSample(D,x/1e3,F)}}function R(k){l.add(k)}function E(k){l.addProgress(k)}function v(k){l.remove(k.id)}}function ig(n,e,t){let r=n;return t!==void 0&&t<1/0&&(r=is(r,t)),e!==void 0&&(r=os(r,e)),r}var Ic=as;function Ro(){var t;if(typeof((t=J.crypto)==null?void 0:t.randomUUID)=="function")return J.crypto.randomUUID();let n=new Date().getTime(),e=V();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){let i=Math.random()*16;return n>0?(i=(n+i)%16|0,n=Math.floor(n/16)):(i=(e+i)%16|0,e=Math.floor(e/16)),(r==="x"?i:i&3|8).toString(16)})}function w(n){return typeof n=="string"&&n.length>0}function Xe(n,e,t){if(typeof String.prototype.startsWith=="function")return n.startsWith(e,t);let r=typeof t=="number"?Math.max(t,0):0;return n.substring(r,r+e.length)===e}var og=/^(?:[a-z]+:)?\/\//i,ag=/^(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?$/;function Mr(n){let e=n.lastIndexOf("/");if(e<0)return n.length;if(og.test(n)){let r=n.indexOf("/");if(r>=0&&e===r+1)return n.length}let t=n.indexOf("?");return t>=0&&t<e?Mr(n.substring(0,t)):e+1}function bc(n,e){let t=ko(n),r=ko(e);if(t.scheme!==r.scheme||t.authority!==r.authority||t.path[0]!==void 0&&t.path[0]!=="/"&&r.path[0]==="/"||r.path[0]!==void 0&&r.path[0]!=="/"&&t.path[0]==="/")return null;let i=Cr(t.path),o=Cr(r.path),a;if(i===o)a="";else{let d=i.split("/");d.pop();let u=o.split("/");for(;d.length>0&&u.length>0&&d[0]===u[0];)d.shift(),u.shift();for(;d.length>0;)d.shift(),u.unshift("..");let c=u.join("/");(c.endsWith("../")||c.endsWith("./"))&&(c=c.slice(0,c.length-1)),a=c===""?".":c}let s=a;return a===""&&r.query===t.query||w(r.query)&&(s+="?",s+=r.query),w(r.fragment)&&(s+="#",s+=r.fragment),s}function sg(n,e){let t=ko(n),r=ko(e);if(w(r.scheme))return ss(r);let i={scheme:t.scheme,authority:t.authority,path:"",query:r.query,fragment:r.fragment};return w(r.authority)?(i.authority=r.authority,i.path=Cr(r.path),ss(i)):(r.path===""?(i.path=t.path,w(r.query)||(i.query=t.query)):Xe(r.path,"/")?i.path=Cr(r.path):i.path=Cr(ug(t,r.path)),ss(i))}var Pr=new Map,dg=200;function ko(n){var r,i,o,a,s;if(Pr.has(n))return Pr.get(n);let e=n.match(ag),t;return e===null?t={scheme:"",authority:"",path:"",query:"",fragment:""}:t={scheme:(r=e[1])!=null?r:"",authority:(i=e[2])!=null?i:"",path:(o=e[3])!=null?o:"",query:(a=e[4])!=null?a:"",fragment:(s=e[5])!=null?s:""},Pr.size>=dg&&Pr.clear(),Pr.set(n,t),t}function ss(n){let e="";return w(n.scheme)&&(e+=n.scheme+":"),w(n.authority)&&(e+="//"+n.authority),e+=n.path,w(n.query)&&(e+="?"+n.query),w(n.fragment)&&(e+="#"+n.fragment),e}function Cr(n){let e=n.split(/(?=\/)/),t=[];for(let r=0;r<e.length;r++){let i=e[r];if(!(i===".."||i==="."||i==="")){if(i==="/.."){t.pop(),r===e.length-1&&t.push("/");continue}if(i==="/."){r===e.length-1&&t.push("/");continue}t.push(i)}}return t.join("")}function ug(n,e){if(w(n.authority)&&n.path==="")return"/"+e;let t=n.path;return t.substring(0,t.lastIndexOf("/")+1)+e}function gn(...n){var r,i,o;let e=n.filter(a=>a!==""),t=e.length;if(t===0)return"";if(t===1)return(r=e[0])!=null?r:"";{let a=(i=e[0])!=null?i:"",s=(o=e[1])!=null?o:"",d=sg(a,s),u=e.slice(2);return gn(d,...u)}}var lg=4,Ar=class{constructor(e){var t,r;this._sessionId=(t=e.sessionId)!=null?t:Ro(),this._contentId=(r=e.contentId)!=null?r:Ro(),this._typePreference=e.communicationType==="headers"?0:1,this._bufferStarvationToggle=!1,this._playbackObserver=null,this._lastThroughput={},this._canceller=null}startMonitoringPlayback(e){var t;(t=this._canceller)==null||t.cancel(),this._canceller=new U,this._playbackObserver=e,e.listen(r=>{r.rebuffering!==null&&(this._bufferStarvationToggle=!0)},{includeLastObservation:!0,clearSignal:this._canceller.signal})}stopMonitoringPlayback(){var e;(e=this._canceller)==null||e.cancel(),this._canceller=null,this._playbackObserver=null}updateThroughput(e,t){this._lastThroughput[e]=t}_getCommonCmcdData(e){var i;let t={};t.bs=this._bufferStarvationToggle,this._bufferStarvationToggle=!1,t.cid=this._contentId,t.mtp=e!==void 0?Math.floor(Math.round(e/1e3/100)*100):void 0,t.sid=this._sessionId;let r=(i=this._playbackObserver)==null?void 0:i.getReference().getValue();return t.pr=r===void 0||r.speed===1?void 0:r.speed,r!==void 0&&(t.su=r.rebuffering!==null),t}getCmcdDataForManifest(e){var r;let t=this._getCommonCmcdData((r=this._lastThroughput.video)!=null?r:this._lastThroughput.audio);switch(t.ot="m",e){case"dash":t.sf="d";break;case"smooth":t.sf="s";break;default:t.sf="o";break}return this._producePayload(t)}getCmcdDataForSegmentRequest(e){var a,s,d,u;let t=(a=this._playbackObserver)==null?void 0:a.getReference().getValue(),r=this._getCommonCmcdData(this._lastThroughput[e.adaptation.type]);switch(r.br=Math.round(e.representation.bitrate/1e3),r.d=Math.round(e.segment.duration*1e3),e.adaptation.type){case"video":r.ot="v";break;case"audio":r.ot="a";break;case"text":r.ot="c";break}if(e.segment.isInit&&(r.ot="i"),!_(e.nextSegment)&&e.segment.url!==null&&e.nextSegment.url!==null&&(!e.nextSegment.isInit||e.nextSegment.indexRange===void 0)){let c=e.segment.url,l=e.nextSegment.url,f=bc(c,l);f!==null&&(f!=="."&&(r.nor=encodeURIComponent(f)),e.nextSegment.range!==void 0&&(r.nrr=String(e.nextSegment.range[0])+"-",isFinite(e.nextSegment.range[1])&&(r.nrr+=String(e.nextSegment.range[1]))))}let i;if(t!==void 0&&(r.ot==="v"||r.ot==="a"||r.ot==="av")){let c=t.buffered[e.adaptation.type];if(!_(c)){let l=(u=(d=(s=this._playbackObserver)==null?void 0:s.getCurrentTime())!=null?d:t.position.getWanted())!=null?u:t.position.getPolled();for(let f of c)if(l>=f.start&&l<f.end){i=(f.end-l)*1e3,r.bl=Math.floor(Math.round(i/100)*100);break}}}let o=i===void 0||t===void 0?void 0:i/t.speed;if(r.dl=o===void 0?void 0:Math.floor(Math.round(o/100)*100),o!==void 0){let l=e.representation.bitrate*e.segment.duration/1e3/(o/1e3);r.rtp=Math.floor(Math.round(l*lg/100)*100)}switch(e.manifest.transport){case"dash":r.sf="d";break;case"smooth":r.sf="s";break;default:r.sf="o";break}return r.st=e.manifest.isDynamic?"l":"v",r.tb=e.adaptation.representations.reduce((c,l)=>l.isPlayable()!==!0?c:c===void 0?Math.round(l.bitrate/1e3):Math.max(c,Math.round(l.bitrate/1e3)),void 0),this._producePayload(r)}_producePayload(e){let t={object:"",request:"",session:"",status:""},r="",i=(u,c)=>{this._typePreference===0?t[c]+=u:r+=u},o=(u,c)=>{let l=e[u];if(l!==void 0){let f=`${u}=${String(l)},`;i(f,c)}},a=(u,c)=>{if(e[u]===!0){let l=`${u},`;i(l,c)}},s=(u,c)=>{let l=e[u];if(l!==void 0){let p=`prop=${`"${l.replace("\\","\\\\").replace('"','\\"')}"`},`;i(p,c)}},d=(u,c)=>{let l=e[u];if(l!==void 0){let f=`prop=${l},`;i(f,c)}};return o("bl","request"),o("br","object"),a("bs","status"),s("cid","session"),o("d","object"),o("dl","request"),o("mtp","request"),s("nor","request"),s("nrr","request"),d("ot","object"),o("pr","session"),o("rtp","status"),d("sf","session"),s("sid","session"),d("st","session"),a("su","request"),o("tb","object"),this._typePreference===0?(t.object[t.object.length-1]===","&&(t.object=t.object.substring(0,t.object.length-1)),t.request[t.request.length-1]===","&&(t.request=t.request.substring(0,t.request.length-1)),t.session[t.session.length-1]===","&&(t.session=t.session.substring(0,t.session.length-1)),t.status[t.status.length-1]===","&&(t.status=t.status.substring(0,t.status.length-1)),m.debug("CMCD: proposing headers payload"),{type:"headers",value:{"CMCD-Object":t.object,"CMCD-Request":t.request,"CMCD-Session":t.session,"CMCD-Status":t.status}}):(r[r.length-1]===","&&(r=r.substring(0,r.length-1)),r=encodeURIComponent(r),m.debug("CMCD: proposing query string payload",r),{type:"query",value:[["CMCD",r]]})}};var Sc=Ar;var Fn=class extends ae{constructor(e){super(),this._downgradedCdnList={metadata:[],timeouts:[]},e.register(()=>{for(let t of this._downgradedCdnList.timeouts)clearTimeout(t);this._downgradedCdnList={metadata:[],timeouts:[]}})}getCdnPreferenceForResource(e){return e.length<=1?e:this._innerGetCdnPreferenceForResource(e)}downgradeCdn(e){let t=Tc(this._downgradedCdnList.metadata,e);t>=0&&this._removeIndexFromDowngradeList(t);let{DEFAULT_CDN_DOWNGRADE_TIME:r}=L.getCurrent(),i=r;this._downgradedCdnList.metadata.push(e);let o=setTimeout(()=>{let a=Tc(this._downgradedCdnList.metadata,e);a>=0&&this._removeIndexFromDowngradeList(a),this.trigger("priorityChange",null)},i);this._downgradedCdnList.timeouts.push(o),this.trigger("priorityChange",null)}_innerGetCdnPreferenceForResource(e){let[t,r]=e.reduce((i,o)=>(this._downgradedCdnList.metadata.some(a=>a.id===o.id&&a.baseUrl===o.baseUrl)?i[1].push(o):i[0].push(o),i),[[],[]]);return t.concat(r)}_removeIndexFromDowngradeList(e){this._downgradedCdnList.metadata.splice(e,1);let t=this._downgradedCdnList.timeouts.splice(e,1);clearTimeout(t[0])}};function Tc(n,e){return n.length===0?-1:e.id!==void 0?pe(n,t=>t.id===e.id):pe(n,t=>t.baseUrl===e.baseUrl)}var it=class n extends Error{constructor(e,t,r){super(e),Object.setPrototypeOf(this,n.prototype),this.name="CustomLoaderError",this.canRetry=t,this.xhr=r}};var _e=class n extends Error{constructor(e,t,r){let i;switch(r){case"TIMEOUT":i="The request timed out";break;case"ERROR_EVENT":i="An error prevented the request to be performed successfully";break;case"PARSE_ERROR":i="An error happened while formatting the response data";break;case"ERROR_HTTP_CODE":i="An HTTP status code indicating failure was received: "+String(t);break}super(i),Object.setPrototypeOf(this,n.prototype),this.name="RequestError",this.url=e,this.status=t,this.type=r}serialize(){return{url:this.url,status:this.status,type:this.type}}},Fe={TIMEOUT:"TIMEOUT",ERROR_EVENT:"ERROR_EVENT",ERROR_HTTP_CODE:"ERROR_HTTP_CODE",PARSE_ERROR:"PARSE_ERROR"};var ds=typeof Headers=="function"?Headers:null,us=typeof AbortController=="function"?AbortController:null;function Po(n){var f,p;let e;if(!_(n.headers))if(_(ds))e=n.headers;else{e=new ds;let g=Object.keys(n.headers);for(let b=0;b<g.length;b++){let h=g[b];e.append(h,n.headers[h])}}m.debug("Fetch: Called with URL",n.url);let t=null,r=!1,i=!1,o=V(),a=_(us)?null:new us;function s(){if(_(a)){m.warn("Fetch: AbortController API not available.");return}a.abort()}let d;n.timeout!==void 0&&(d=setTimeout(()=>{r=!0,u!==void 0&&clearTimeout(u),s()},n.timeout));let u;n.connectionTimeout!==void 0&&(u=setTimeout(()=>{i=!0,d!==void 0&&clearTimeout(d),s()},n.connectionTimeout));let c=n.cancelSignal.register(function(b){t=b,s()}),l={method:"GET"};if(e!==void 0&&(l.headers=e),l.signal=_(a)?null:a.signal,m.hasLevel("DEBUG")){let g="FETCH: Sending GET "+n.url;n.timeout!==void 0&&(g+=" to="+String(n.timeout/1e3)),n.connectionTimeout!==void 0&&(g+=" cto="+String(n.connectionTimeout/1e3)),((f=n.headers)==null?void 0:f.Range)!==void 0&&(g+=" Range="+((p=n.headers)==null?void 0:p.Range)),m.debug(g)}return fetch(n.url,l).then(g=>{if(u!==void 0&&clearTimeout(u),g.status>=300)throw m.warn("Fetch: Request HTTP Error",g.status,g.url),new _e(g.url,g.status,Fe.ERROR_HTTP_CODE);if(_(g.body))throw new _e(g.url,g.status,Fe.PARSE_ERROR);let b=g.headers.get("Content-Length"),h=!_(b)&&!isNaN(+b)?+b:void 0,I=g.body.getReader(),T=0;return R();async function R(){let E=await I.read();if(!E.done&&!_(E.value)){T+=E.value.byteLength;let v=V(),k={url:g.url,currentTime:v,duration:v-o,sendingTime:o,chunkSize:E.value.byteLength,chunk:E.value.buffer,size:T,totalSize:h};return n.onData(k),R()}else if(E.done){d!==void 0&&clearTimeout(d),c();let v=V();return{requestDuration:v-o,receivedTime:v,sendingTime:o,size:T,status:g.status,url:g.url}}return R()}}).catch(g=>{throw t!==null?t:(c(),r?(m.warn("Fetch: Request timed out."),new _e(n.url,0,Fe.TIMEOUT)):i?(m.warn("Fetch: Request connection timed out."),new _e(n.url,0,Fe.TIMEOUT)):g instanceof _e?g:(m.warn("Fetch: Request Error",g instanceof Error?g.toString():""),new _e(n.url,0,Fe.ERROR_EVENT)))})}function xr(){return typeof J.fetch=="function"&&!_(us)&&!_(ds)}var cg="json";function wr(n){let e={url:n.url,headers:n.headers,responseType:_(n.responseType)?cg:n.responseType,timeout:n.timeout,connectionTimeout:n.connectionTimeout};return new Promise((t,r)=>{let{onProgress:i,cancelSignal:o}=n,{url:a,headers:s,responseType:d,timeout:u,connectionTimeout:c}=e,l=new XMLHttpRequest;l.open("GET",a,!0);let f;u!==void 0&&(l.timeout=u,f=setTimeout(()=>{h(),r(new _e(a,l.status,Fe.TIMEOUT))},u+3e3));let p;if(c!==void 0&&(p=setTimeout(()=>{h(),l.readyState!==XMLHttpRequest.DONE&&l.abort(),r(new _e(a,l.status,Fe.TIMEOUT))},c)),l.responseType=d,l.responseType==="document"&&l.overrideMimeType("text/xml"),!_(s)){let I=s;for(let T in I)Object.prototype.hasOwnProperty.call(I,T)&&l.setRequestHeader(T,I[T])}let g=V(),b=null;if(o!==void 0&&(b=o.register(function(T){h(),l.readyState!==XMLHttpRequest.DONE&&l.abort(),r(T)}),o.isCancelled()))return;if(l.onerror=function(){h(),r(new _e(a,l.status,Fe.ERROR_EVENT))},l.ontimeout=function(){h(),r(new _e(a,l.status,Fe.TIMEOUT))},c!==void 0&&(l.onreadystatechange=function(){l.readyState>=XMLHttpRequest.HEADERS_RECEIVED&&clearTimeout(p)}),i!==void 0&&(l.onprogress=function(T){let R=V();i({url:a,duration:R-g,sendingTime:g,currentTime:R,size:T.loaded,totalSize:T.total})}),l.onload=function(T){if(l.readyState===XMLHttpRequest.DONE)if(h(),l.status>=200&&l.status<300){let R=V(),E=l.response instanceof ArrayBuffer?l.response.byteLength:T.total,v=l.status,k=l.responseType,x=w(l.responseURL)?l.responseURL:a,P;if(k==="json"?P=typeof l.response=="object"?l.response:fg(l.responseText):P=l.response,_(P)){r(new _e(a,l.status,Fe.PARSE_ERROR));return}t({status:v,url:x,responseType:k,sendingTime:g,receivedTime:R,requestDuration:R-g,size:E,responseData:P})}else r(new _e(a,l.status,Fe.ERROR_HTTP_CODE))},m.hasLevel("DEBUG")){let I="XHR: Sending GET "+a;n.responseType!==void 0&&(I+=" type="+n.responseType),u!==void 0&&(I+=" to="+String(u/1e3)),c!==void 0&&(I+=" cto="+String(c/1e3)),(s==null?void 0:s.Range)!==void 0&&(I+=" Range="+(s==null?void 0:s.Range)),m.debug(I)}l.send();function h(){f!==void 0&&clearTimeout(f),p!==void 0&&clearTimeout(p),b!==null&&b()}})}function fg(n){try{return JSON.parse(n)}catch(e){return null}}var Se=wr;var hn=Fe,Ze={NETWORK_ERROR:"NETWORK_ERROR",MEDIA_ERROR:"MEDIA_ERROR",ENCRYPTED_MEDIA_ERROR:"ENCRYPTED_MEDIA_ERROR",OTHER_ERROR:"OTHER_ERROR"},ls={PIPELINE_LOAD_ERROR:"PIPELINE_LOAD_ERROR",PIPELINE_PARSE_ERROR:"PIPELINE_PARSE_ERROR",INTEGRITY_ERROR:"INTEGRITY_ERROR",MANIFEST_PARSE_ERROR:"MANIFEST_PARSE_ERROR",MANIFEST_INCOMPATIBLE_CODECS_ERROR:"MANIFEST_INCOMPATIBLE_CODECS_ERROR",MANIFEST_UPDATE_ERROR:"MANIFEST_UPDATE_ERROR",MANIFEST_UNSUPPORTED_ADAPTATION_TYPE:"MANIFEST_UNSUPPORTED_ADAPTATION_TYPE",MEDIA_STARTING_TIME_NOT_FOUND:"MEDIA_STARTING_TIME_NOT_FOUND",MEDIA_TIME_BEFORE_MANIFEST:"MEDIA_TIME_BEFORE_MANIFEST",MEDIA_TIME_AFTER_MANIFEST:"MEDIA_TIME_AFTER_MANIFEST",MEDIA_TIME_NOT_FOUND:"MEDIA_TIME_NOT_FOUND",NO_PLAYABLE_REPRESENTATION:"NO_PLAYABLE_REPRESENTATION",MEDIA_IS_ENCRYPTED_ERROR:"MEDIA_IS_ENCRYPTED_ERROR",CREATE_MEDIA_KEYS_ERROR:"CREATE_MEDIA_KEYS_ERROR",MEDIA_KEYS_ATTACHMENT_ERROR:"MEDIA_KEYS_ATTACHMENT_ERROR",KEY_ERROR:"KEY_ERROR",KEY_STATUS_CHANGE_ERROR:"KEY_STATUS_CHANGE_ERROR",KEY_UPDATE_ERROR:"KEY_UPDATE_ERROR",KEY_LOAD_ERROR:"KEY_LOAD_ERROR",KEY_LOAD_TIMEOUT:"KEY_LOAD_TIMEOUT",KEY_GENERATE_REQUEST_ERROR:"KEY_GENERATE_REQUEST_ERROR",INCOMPATIBLE_KEYSYSTEMS:"INCOMPATIBLE_KEYSYSTEMS",INVALID_ENCRYPTED_EVENT:"INVALID_ENCRYPTED_EVENT",INVALID_KEY_SYSTEM:"INVALID_KEY_SYSTEM",LICENSE_SERVER_CERTIFICATE_ERROR:"LICENSE_SERVER_CERTIFICATE_ERROR",MULTIPLE_SESSIONS_SAME_INIT_DATA:"MULTIPLE_SESSIONS_SAME_INIT_DATA",BUFFER_APPEND_ERROR:"BUFFER_APPEND_ERROR",BUFFER_FULL_ERROR:"BUFFER_FULL_ERROR",BUFFER_TYPE_UNKNOWN:"BUFFER_TYPE_UNKNOWN",MEDIA_ERR_BLOCKED_AUTOPLAY:"MEDIA_ERR_BLOCKED_AUTOPLAY",MEDIA_ERR_PLAY_NOT_ALLOWED:"MEDIA_ERR_PLAY_NOT_ALLOWED",MEDIA_ERR_NOT_LOADED_METADATA:"MEDIA_ERR_NOT_LOADED_METADATA",MEDIA_ERR_ABORTED:"MEDIA_ERR_ABORTED",MEDIA_ERR_NETWORK:"MEDIA_ERR_NETWORK",MEDIA_ERR_DECODE:"MEDIA_ERR_DECODE",MEDIA_ERR_SRC_NOT_SUPPORTED:"MEDIA_ERR_SRC_NOT_SUPPORTED",MEDIA_ERR_UNKNOWN:"MEDIA_ERR_UNKNOWN",MEDIA_SOURCE_NOT_SUPPORTED:"MEDIA_SOURCE_NOT_SUPPORTED",MEDIA_KEYS_NOT_SUPPORTED:"MEDIA_KEYS_NOT_SUPPORTED",DISCONTINUITY_ENCOUNTERED:"DISCONTINUITY_ENCOUNTERED",NONE:"NONE"};function Je(n,e){return`${n}: ${e}`}var ge=class n extends Error{constructor(e,t,r){super(Je(e,t)),Object.setPrototypeOf(this,n.prototype),this.name="EncryptedMediaError",this.type=Ze.ENCRYPTED_MEDIA_ERROR,this.code=e,this._originalMessage=t,this.fatal=!1,typeof(r==null?void 0:r.keyStatuses)=="string"&&(this.keyStatuses=r.keyStatuses)}serialize(){return{name:this.name,code:this.code,reason:this._originalMessage,keyStatuses:this.keyStatuses}}};var te=class n extends Error{constructor(e,t,r){super(Je(e,t)),Object.setPrototypeOf(this,n.prototype),this.name="MediaError",this.type=Ze.MEDIA_ERROR,this._originalMessage=t,this.code=e,this.fatal=!1,(r==null?void 0:r.tracks)!==void 0&&(r==null?void 0:r.tracks.length)>0&&(this.tracksInfo=r.tracks)}serialize(){return{name:this.name,code:this.code,reason:this._originalMessage,tracks:this.tracksInfo}}};var ot=class n extends Error{constructor(e,t){super(Je(e,t.message)),Object.setPrototypeOf(this,n.prototype),this.name="NetworkError",this.type=Ze.NETWORK_ERROR,this.url=t.url,this.status=t.status,this.errorType=t.type,this._baseError=t,this.code=e,this.fatal=!1}isHttpError(e){return this.errorType===hn.ERROR_HTTP_CODE&&this.status===e}serialize(){return{name:this.name,code:this.code,baseError:this._baseError.serialize()}}};var Ne=class n extends Error{constructor(e,t){super(Je(e,t)),Object.setPrototypeOf(this,n.prototype),this.name="OtherError",this.type=Ze.OTHER_ERROR,this.code=e,this.fatal=!1,this._originalMessage=t}serialize(){return{name:this.name,code:this.code,reason:this._originalMessage}}};function jt(n){return(n instanceof ge||n instanceof te||n instanceof Ne||n instanceof ot)&&Object.keys(Ze).indexOf(n.type)>=0}function Ee(n,{defaultCode:e,defaultReason:t}){if(jt(n))return n;let r=n instanceof Error?n.toString():t;return new Ne(e,r)}var at=class n extends Error{constructor(e,t,r){sup