@vkontakte/videoplayer-core 2.0.38 → 2.0.39
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.
- package/index.cjs.js +4 -4
- package/index.d.ts +2 -2
- package/index.esm.js +4 -4
- package/package.json +1 -1
- package/player/Player.d.ts +1 -1
- package/player/types.d.ts +2 -1
package/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vkontakte/videoplayer-core v2.0.
|
|
3
|
-
*
|
|
4
|
-
* https://st.mycdn.me/static/playersdk/2-0-
|
|
2
|
+
* @vkontakte/videoplayer-core v2.0.39
|
|
3
|
+
* Thu, 03 Feb 2022 12:13:55 GMT
|
|
4
|
+
* https://st.mycdn.me/static/playersdk/2-0-39/doc/
|
|
5
5
|
*/
|
|
6
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@vkontakte/videoplayer-shared");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i,a,n,s,o,u,d=t(require("lodash/debounce"));exports.PlaybackState=void 0,(i=exports.PlaybackState||(exports.PlaybackState={})).STOPPED="stopped",i.PLAYING="playing",i.PAUSED="paused",exports.VideoFormat=void 0,(a=exports.VideoFormat||(exports.VideoFormat={})).MPEG="MPEG",a.DASH="DASH",a.DASH_SEP="DASH_SEP",a.DASH_SEP_VK="DASH_SEP_VK",a.DASH_WEBM="DASH_WEBM",a.DASH_WEBM_VK="DASH_WEBM_VK",a.DASH_ONDEMAND="DASH_ONDEMAND",a.DASH_LIVE="DASH_LIVE",a.DASH_LIVE_WEBM="DASH_LIVE_WEBM",a.HLS="HLS",a.HLS_ONDEMAND="HLS_ONDEMAND",a.HLS_JS="HLS_JS",a.HLS_LIVE="HLS_LIVE",function(e){e.SCREEN="SCREEN",e.CHROMECAST="CHROMECAST"}(n||(n={})),exports.ChromecastState=void 0,(s=exports.ChromecastState||(exports.ChromecastState={})).NOT_AVAILABLE="NOT_AVAILABLE",s.AVAILABLE="AVAILABLE",s.CONNECTING="CONNECTING",s.CONNECTED="CONNECTED",exports.StartStatus=void 0,(o=exports.StartStatus||(exports.StartStatus={})).SuccessWithSound="success_with_sound",o.SuccessWithoutSound="success_without_sound",o.Failed="failed",exports.HttpConnectionType=void 0,(u=exports.HttpConnectionType||(exports.HttpConnectionType={})).HTTP1="http1",u.HTTP2="http2",u.QUIC="quic";var l=function(){return(l=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function c(e,t,r,i){return new(r||(r=Promise))((function(a,n){function s(e){try{u(i.next(e))}catch(e){n(e)}}function o(e){try{u(i.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,o)}u((i=i.apply(e,t||[])).next())}))}function p(e,t){var r,i,a,n,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return n={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function o(n){return function(o){return function(n){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(a=2&n[0]?i.return:n[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,n[1])).done)return a;switch(i=0,a&&(n=[2&n[0],a.value]),n[0]){case 0:case 1:a=n;break;case 4:return s.label++,{value:n[1],done:!1};case 5:s.label++,i=n[1],n=[0];continue;case 7:n=s.ops.pop(),s.trys.pop();continue;default:if(!(a=s.trys,(a=a.length>0&&a[a.length-1])||6!==n[0]&&2!==n[0])){s=0;continue}if(3===n[0]&&(!a||n[1]>a[0]&&n[1]<a[3])){s.label=n[1];break}if(6===n[0]&&s.label<a[1]){s.label=a[1],a=n;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(n);break}a[2]&&s.ops.pop(),s.trys.pop();continue}n=t.call(e,s)}catch(e){n=[6,e],i=0}finally{r=a=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,o])}}}function h(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function f(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,a,n=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(e){a={error:e}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return s}function v(e,t,r){if(r||2===arguments.length)for(var i,a=0,n=t.length;a<n;a++)!i&&a in t||(i||(i=Array.prototype.slice.call(t,0,a)),i[a]=t[a]);return e.concat(i||Array.prototype.slice.call(t))}var m,S,b,g,y={throughputEstimator:{emaAlphaSlow:.2,emaAlphaFast:.7,changeThreshold:.2,useBrowserEstimation:!0,rttPenaltyRequestSize:1048576,streamMinSampleSize:10240,streamMinSampleTime:300},autoTrackSelection:{bitrateFactorAtEmptyBuffer:1.8,bitrateFactorAtFullBuffer:1.2,usePixelRatio:!0,limitByContainer:!0,containerSizeFactor:2,lazyQualitySwitch:!1},dash:{extraInitSize:1e3,forwardBufferTarget:3e4,segmentRequestSize:1048576,representationSwitchForwardBufferGap:3e3},enableTelemetryAtStart:!1,formatsToAvoid:[exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_SEP_VK],disableChromecast:!1,chromecastReceiverId:void 0,useWebmBigRequest:!0,bigRequestMinInitSize:51200,bigRequestMinDataSize:1048576,stripRangeHeader:!0,flushShortLoopedBuffers:!0,insufficientBufferRuleMargin:1e4,dashSeekInSegmentDurationThreshold:18e4,dashSeekInSegmentAlwaysSeekDelta:1e4,endGapTolerance:300,stallIgnoreThreshold:33},T=function(){function t(t){var r,i=this;this.connection$=new e.ValueSubject(void 0),this.castState$=new e.ValueSubject(exports.ChromecastState.NOT_AVAILABLE),this.errorEvent$=new e.Subject,this.realCastState$=new e.ValueSubject(exports.ChromecastState.NOT_AVAILABLE),this.subscription=new e.Subscription,this.params=t,this.log=this.params.dependencies.logger.createComponentLog("ChromecastInitializer");var a,n="chrome"in window;(this.log({message:"[constructor] receiverApplicationId: "+this.params.receiverApplicationId+", isDisabled: "+this.params.isDisabled+", isSupported: "+n}),!t.isDisabled&&n)&&(e.isNonNullable(null===(r=window.chrome)||void 0===r?void 0:r.cast)?this.initializeCastApi():(window.__onGCastApiAvailable=function(e){e&&i.initializeCastApi()},(a="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",new Promise((function(e,t){var r=document.createElement("script");r.setAttribute("src",a),r.onload=function(){return e},r.onerror=function(){return t},document.body.appendChild(r)}))).catch((function(){return i.errorEvent$.next({id:"ChromecastLoading",message:"Script loading failed!"})}))))}return t.prototype.connect=function(){var e;null===(e=cast.framework.CastContext.getInstance())||void 0===e||e.requestSession()},t.prototype.disconnect=function(){var e,t;null===(t=null===(e=cast.framework.CastContext.getInstance())||void 0===e?void 0:e.getCurrentSession())||void 0===t||t.endSession(!0)},t.prototype.stopMedia=function(){return new Promise((function(e,t){var r,i,a;null===(a=null===(i=null===(r=cast.framework.CastContext.getInstance())||void 0===r?void 0:r.getCurrentSession())||void 0===i?void 0:i.getMediaSession())||void 0===a||a.stop(new chrome.cast.media.StopRequest,e,t)}))},t.prototype.toggleConnection=function(){e.isNonNullable(this.connection$.getValue())?this.disconnect():this.connect()},t.prototype.setVolume=function(t){var r=this.connection$.getValue();e.isNullable(r)||(r.remotePlayer.volumeLevel=t,r.remotePlayerController.setVolumeLevel())},t.prototype.setMuted=function(t){var r=this.connection$.getValue();e.isNullable(r)||t!==r.remotePlayer.isMuted&&r.remotePlayerController.muteOrUnmute()},t.prototype.destroy=function(){this.subscription.unsubscribe()},t.prototype.initListeners=function(){var t=this,r=new cast.framework.RemotePlayer,i=new cast.framework.RemotePlayerController(r),a=cast.framework.CastContext.getInstance();this.subscription.add(e.fromEvent(a,cast.framework.CastContextEventType.SESSION_STATE_CHANGED).subscribe((function(r){var i,n;switch(r.sessionState){case cast.framework.SessionState.SESSION_STARTED:case cast.framework.SessionState.SESSION_STARTING:case cast.framework.SessionState.SESSION_RESUMED:t.contentId=null===(n=null===(i=a.getCurrentSession())||void 0===i?void 0:i.getMediaSession())||void 0===n?void 0:n.media.contentId;break;case cast.framework.SessionState.NO_SESSION:case cast.framework.SessionState.SESSION_ENDING:case cast.framework.SessionState.SESSION_ENDED:case cast.framework.SessionState.SESSION_START_FAILED:t.contentId=void 0;break;default:return e.assertNever(r.sessionState)}}))).add(e.merge(e.fromEvent(a,cast.framework.CastContextEventType.CAST_STATE_CHANGED).pipe(e.tap((function(e){t.log({message:"[cast.framework.RemotePlayerEventType.CAST_STATE_CHANGED]: "+JSON.stringify(e)})})),e.map((function(e){return e.castState}))),e.observableFrom([a.getCastState()])).pipe(e.filterChanged(),e.map(E),e.tap((function(e){t.log({message:"realCastState$: "+e})}))).subscribe(this.realCastState$)).add(this.realCastState$.subscribe((function(n){var s,o=n===exports.ChromecastState.CONNECTED,u=e.isNonNullable(t.connection$.getValue());if(o&&!u){var d=a.getCurrentSession();e.assertNonNullable(d);var l=d.getCastDevice(),c=null===(s=d.getMediaSession())||void 0===s?void 0:s.media.contentId;(e.isNullable(c)||c===t.contentId)&&(t.log({message:"connection created"}),t.connection$.next({remotePlayer:r,remotePlayerController:i,session:d,castDevice:l}))}else!o&&u&&(t.log({message:"connection destroyed"}),t.connection$.next(void 0));t.castState$.next(n===exports.ChromecastState.CONNECTED?e.isNonNullable(t.connection$.getValue())?exports.ChromecastState.CONNECTED:exports.ChromecastState.AVAILABLE:n)})))},t.prototype.initializeCastApi=function(){var e,t,r,i;try{t=cast.framework.CastContext.getInstance(),r=chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,i=chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}catch(e){return}try{t.setOptions({receiverApplicationId:null!==(e=this.params.receiverApplicationId)&&void 0!==e?e:r,autoJoinPolicy:i}),this.initListeners()}catch(e){this.errorEvent$.next({id:"ChromecastInitializer",message:"[initializeCastApi] failed",thrown:e})}},t}(),E=function(t){switch(t){case cast.framework.CastState.NO_DEVICES_AVAILABLE:return exports.ChromecastState.NOT_AVAILABLE;case cast.framework.CastState.NOT_CONNECTED:return exports.ChromecastState.AVAILABLE;case cast.framework.CastState.CONNECTING:return exports.ChromecastState.CONNECTING;case cast.framework.CastState.CONNECTED:return exports.ChromecastState.CONNECTED;default:return e.assertNever(t)}};!function(e){e.VIDEO="video",e.AUDIO="audio",e.TEXT="text"}(m||(m={})),function(e){e.WEBM_AS_IN_SPEC="urn:mpeg:dash:profile:webm-on-demand:2012",e.WEBM_AS_IN_FFMPEG="urn:webm:dash:profile:webm-on-demand:2012"}(S||(S={})),function(e){e.NONE="none",e.DOWNLOADING="downloading",e.DOWNLOADED="downloaded",e.FED="fed"}(b||(b={})),function(e){e.MP4="mp4",e.WEBM="webm"}(g||(g={}));var P,k,w=function(e){return c(void 0,void 0,void 0,(function(){var t,r,i;return p(this,(function(a){switch(a.label){case 0:t=e.muted,a.label=1;case 1:return a.trys.push([1,3,,8]),[4,e.play()];case 2:return a.sent(),[3,8];case 3:if((r=a.sent())instanceof DOMException&&(20===r.code||"AbortError"===r.name))return[2,!1];if(t)return console.warn(r),[2,!1];e.muted=!0,a.label=4;case 4:return a.trys.push([4,6,,7]),[4,e.play()];case 5:return a.sent(),[3,7];case 6:return i=a.sent(),e.muted=!1,console.warn(i),[2,!1];case 7:return[3,8];case 8:return[2,!0]}}))}))},x=function(t,r,i,a){var n=void 0===a?{}:a,s=n.equal,o=void 0===s?function(e,t){return e===t}:s,u=n.changed$,d=n.onError,l=t.getState(),c=r(),p=e.isNullable(u),h=new e.Subscription;return u&&h.add(u.subscribe((function(e){var r=t.getState();o(e,r)&&t.setState(e)}),d)),o(c,l)||(i(l),p&&t.setState(l)),h.add(t.stateChangeStarted$.subscribe((function(e){i(e.to),p&&t.setState(e.to)}),d)),h},A=function(t,r,i){return x(r,(function(){return t.loop}),(function(r){e.isNonNullable(r)&&(t.loop=r)}),{onError:i})},$=function(t,r,i,a){return x(r,(function(){return{muted:t.muted,volume:t.volume}}),(function(r){e.isNonNullable(r)&&(t.muted=r.muted,t.volume=r.volume)}),{equal:function(e,t){return e===t||(null==e?void 0:e.muted)===(null==t?void 0:t.muted)&&(null==e?void 0:e.volume)===(null==t?void 0:t.volume)},changed$:i,onError:a})},N=function(e,t){if(e.id===t)return!0;var r=f(t.split("|"),3);r[0];var i=r[1],a=r[2];return e.language===i&&e.label===a},D=function(){function t(){this.available$=new e.Subject,this.current$=new e.ValueSubject(void 0),this.error$=new e.Subject,this.subscription=new e.Subscription,this.externalTracks=new Map}return t.prototype.connect=function(t,r,i){var a=this;this.video=t,this.cueSettings=r.textTrackCuesSettings,this.subscribe();var n=function(e){a.error$.next({id:"TextTracksManager",message:"Generic HtmlVideoTextTrackManager error",thrown:e})};this.subscription.add(this.available$.subscribe(i.availableTextTracks$)),this.subscription.add(this.current$.subscribe(i.currentTextTrack$)),this.subscription.add(this.error$.subscribe(i.error$)),this.subscription.add(x(r.externalTextTracks,(function(){return Object.values(a.externalTracks)}),(function(t){e.isNonNullable(t)&&a.setExternal(t)}),{equal:function(t,r){return e.isNonNullable(t)&&e.isNonNullable(r)&&t.length===r.length&&t.every((function(e,t){return e.id===r[t].id}))},changed$:this.available$.pipe(e.map((function(e){return e.filter((function(e){return"external"===e.type}))}))),onError:n})),this.subscription.add(x(r.currentTextTrack,(function(){if(!a.video){var e=a.htmlTextTracksAsArray().find((function(e){return"showing"===e.mode}));return e&&a.htmlTextTrackToITextTrack(e).id}}),(function(e){return a.select(e)}),{changed$:this.current$,onError:n})),this.subscription.add(x(r.textTrackCuesSettings,(function(){return{}}),(function(){var e,t;if(a.video)try{for(var r=h(a.htmlTextTracksAsArray()),i=r.next();!i.done;i=r.next()){var n=i.value;a.applyCueSettings(n.cues),a.applyCueSettings(n.activeCues)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}})))},t.prototype.subscribe=function(){var t=this;e.assertNonNullable(this.video);var r=this.video.textTracks;this.subscription.add(e.fromEvent(r,"addtrack").subscribe((function(){var e=t.current$.getValue();t.select(e)}))),this.subscription.add(e.merge(e.fromEvent(r,"addtrack"),e.fromEvent(r,"removetrack"),e.observableFrom(["init"])).pipe(e.map((function(){return t.htmlTextTracksAsArray().map((function(e){return t.htmlTextTrackToITextTrack(e)}))})),e.filterChanged((function(e,t){return e.length===t.length&&e.every((function(e,r){return e.id===t[r].id}))}))).subscribe(this.available$)),this.subscription.add(e.merge(e.fromEvent(r,"change"),e.observableFrom(["init"])).pipe(e.map((function(){return t.htmlTextTracksAsArray().find((function(e){return"showing"===e.mode}))})),e.map((function(e){return e&&t.htmlTextTrackToITextTrack(e).id})),e.filterChanged()).subscribe(this.current$));var i=function(e){var r,i;return t.applyCueSettings(null!==(i=null===(r=e.target)||void 0===r?void 0:r.activeCues)&&void 0!==i?i:null)};this.subscription.add(e.fromEvent(r,"addtrack").subscribe((function(e){var r,a;null===(r=e.track)||void 0===r||r.addEventListener("cuechange",i);var n=function(e){var r,i,a,s,o,u=null!==(i=null===(r=e.target)||void 0===r?void 0:r.cues)&&void 0!==i?i:null;u&&u.length&&(t.applyCueSettings(null!==(s=null===(a=e.target)||void 0===a?void 0:a.cues)&&void 0!==s?s:null),null===(o=e.target)||void 0===o||o.removeEventListener("cuechange",n))};null===(a=e.track)||void 0===a||a.addEventListener("cuechange",n)}))),this.subscription.add(e.fromEvent(r,"removetrack").subscribe((function(e){var t;null===(t=e.track)||void 0===t||t.removeEventListener("cuechange",i)})))},t.prototype.applyCueSettings=function(t){var r,i;if(t&&t.length){var a=this.cueSettings.getState();try{for(var n=h(Array.from(t)),s=n.next();!s.done;s=n.next()){var o=s.value;e.isNonNullable(a.align)&&(o.align=a.align),e.isNonNullable(a.position)&&(o.position=a.position),e.isNonNullable(a.size)&&(o.size=a.size),e.isNonNullable(a.line)&&(o.line=a.line)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(i=n.return)&&i.call(n)}finally{if(r)throw r.error}}}},t.prototype.htmlTextTracksAsArray=function(r){void 0===r&&(r=!1),e.assertNonNullable(this.video);var i=v([],f(this.video.textTracks),!1);return r?i:i.filter(t.isHealthyTrack)},t.prototype.htmlTextTrackToITextTrack=function(e){var t=e.language,r=e.label,i=""!==e.id?e.id:function(e){return["__",e.language,e.label].join("|")}(e);return this.externalTracks.has(i)?{id:i,type:"external",language:t,label:r,url:this.externalTracks.get(i).url}:{id:i,type:"internal",language:t,label:r}},t.isHealthyTrack=function(e){return"metadata"!==e.kind&&(""!==e.id||""!==e.label||""!==e.language)},t.prototype.setExternal=function(e){var t=this;e.filter((function(e){var r=e.id;return!t.externalTracks.has(r)})).forEach((function(e){return t.attach(e)})),Array.from(this.externalTracks.keys()).filter((function(t){return!e.find((function(e){return e.id===t}))})).forEach((function(e){return t.detach(e)}))},t.prototype.select=function(t){var r,i;e.assertNonNullable(this.video);try{for(var a=h(this.htmlTextTracksAsArray(!0)),n=a.next();!n.done;n=a.next()){var s=n.value;e.isNonNullable(t)&&N(s,t)?s.mode="showing":s.mode="disabled"}}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}},t.prototype.destroy=function(){var e,t;if(this.subscription.unsubscribe(),this.video)try{for(var r=h(Array.from(this.video.getElementsByTagName("track"))),i=r.next();!i.done;i=r.next()){var a=i.value,n=a.getAttribute("id");n&&this.externalTracks.has(n)&&this.video.removeChild(a)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}this.externalTracks.clear()},t.prototype.attach=function(t){e.assertNonNullable(this.video);var r=document.createElement("track");r.setAttribute("src",t.url),r.setAttribute("id",t.id),t.label&&r.setAttribute("label",t.label),t.language&&r.setAttribute("srclang",t.language),this.externalTracks.set(t.id,t),this.video.appendChild(r)},t.prototype.detach=function(t){e.assertNonNullable(this.video);var r=Array.prototype.find.call(this.video.getElementsByTagName("track"),(function(e){return e.getAttribute("id")===t}));r&&this.video.removeChild(r),this.externalTracks.delete(t)},t}(),_=function(e){var t=document.createElement("video");return t.setAttribute("crossorigin","anonymous"),t.setAttribute("playsinline","playsinline"),e.appendChild(t),t},R=function(t){return new e.Observable((function(r){var i=0;return(new e.Subscription).add(e.fromEvent(t,"loadstart").subscribe((function(){i=Date.now()}))).add(e.fromEvent(t,"loadeddata").subscribe((function(){r.next(Date.now()-i)})))})).pipe(e.once())},I=function(){function e(e){this._buffer=[],this._source=e}return e.prototype.fill=function(){this._buffer=[];for(var e=this._source.currentTime,t=0,r=this._source.buffered.length;t<r;t++){var i=this._source.buffered.start(t),a=this._source.buffered.end(t);i>e&&i-e<3&&(i=e),this._buffer.push({start:i,end:a,i:t})}return this._buffer.sort((function(e,t){return e.start-t.start})),this._buffer},e.prototype.getByTime=function(e){return this._buffer.find((function(t){return e>=t.start&&e<t.end}))},e.prototype.getNextWithGap=function(e,t){var r=this.getNext(e);if(r&&r.start-e.end<(t||3))return r},e.prototype.getNext=function(e){var t=this._buffer.indexOf(e);if(~t&&this._buffer.length-1>t)return this._buffer[++t]},e.prototype.smartRemove=function(e,t,r){this._buffer.forEach((function(i){var a=i.start,n=i.end,s=a>=e&&a<t,o=n>=e&&n<t;s&&o||(s?r(t,n):o?r(a,e):a<e&&n>t?(r(t,n),r(a,e)):r(a,n))}))},e.prototype.destroy=function(){this._buffer=[]},e}(),C=function(e,t,r){void 0===r&&(r=3);for(var i=0,a=0,n=0;n<e.length;n++){var s=e.start(n),o=e.end(n);if(s<=t&&t<=o){if(i=s,a=o,!r)return{start:i,end:a};for(var u=n-1;u>=0;u--)e.end(u)+r>=i&&(i=e.start(u));for(var d=n+1;d<e.length;d++)e.start(d)-r<=a&&(a=e.end(d))}}return{start:i,end:a}},L=function(t){return new e.Observable((function(r){var i=0;return(new e.Subscription).add(e.fromEvent(t,"loadstart").subscribe((function(){i=Date.now()}))).add(e.fromEvent(t,"loadedmetadata").subscribe((function(){r.next(Date.now()-i)})))})).pipe(e.once())},O=function(t){var r=function(r,i){return void 0===i&&(i=function(){}),e.fromEvent(t,r).pipe(e.map(i))},i=e.merge.apply(void 0,v([],f(["waiting","pause","canplay","play","canplaythrough","playing","seeking","seeked","ended"].map((function(r){return e.fromEvent(t,r)}))),!1)).pipe(e.map((function(){return t.readyState<3})),e.filterChanged()),a=e.merge(e.fromEvent(t,"progress"),e.fromEvent(t,"timeupdate")).pipe(e.map((function(){return C(t.buffered,t.currentTime)}))),n=e.fromEvent(t,"volumechange").pipe(e.debounce(0),e.map((function(){return{muted:t.muted,volume:t.volume}}))),s=e.fromEvent(t,"error").pipe(e.map((function(){var e=t.error;return{id:e?"MediaError#"+e.code:"HtmlVideoError",message:e?e.message:"Error event from HTML video element"}})));return{playing$:r("playing"),pause$:r("pause"),canplay$:r("canplay"),ended$:r("ended"),error$:s,seeked$:r("seeked"),seeking$:r("seeking"),progress$:r("progress"),loadedMetadata$:r("loadedmetadata"),loadedData$:r("loadeddata"),timeUpdate$:r("timeupdate",(function(){return t.currentTime})),durationChange$:r("durationchange",(function(){return t.duration})),isBuffering$:i,currentBuffer$:a,volumeState$:n,firstBytes$:L(t),firstFrame$:R(t)}},V=function(e,t,r){void 0===r&&(r=!1);var i=e.getTransition();!r&&i&&i.to!==t||e.setState(t)};exports.VideoQuality=void 0,(P=exports.VideoQuality||(exports.VideoQuality={})).INVARIANT="Invariant quality",P.Q_144P="144p",P.Q_240P="240p",P.Q_360P="360p",P.Q_480P="480p",P.Q_720P="720p",P.Q_1080P="1080p",P.Q_1440P="1440p",P.Q_2160P="2160p",P.Q_4320P="4320p";var M,B=((k={})[exports.VideoQuality.Q_144P]=144,k[exports.VideoQuality.Q_240P]=240,k[exports.VideoQuality.Q_360P]=360,k[exports.VideoQuality.Q_480P]=480,k[exports.VideoQuality.Q_720P]=720,k[exports.VideoQuality.Q_1080P]=1080,k[exports.VideoQuality.Q_1440P]=1440,k[exports.VideoQuality.Q_2160P]=2160,k[exports.VideoQuality.Q_4320P]=4320,k),U=function(e,t){return B[e]>B[t]},F=function(e,t){return B[e]<B[t]},H=Object.keys(B).sort((function(e,t){return F(e,t)?-1:1})),q=function(e,t){var r=e.width,i=e.height;return function(e,t){return void 0===t&&(t=.02),v([],f(H),!1).find((function(r){return B[r]*(1+t)>=e}))}(Math.min(r,i),t)},G=function(e){return e===exports.VideoQuality.INVARIANT},j=!1,Y={},z=function(e){e(Y)},Q=function(e,t){var r;j&&(Y.meta=null!==(r=Y.meta)&&void 0!==r?r:{},Y.meta[e]=t)},W=function(){function e(e){this.name=e}return e.prototype.next=function(e){var t,r;if(j){Y.series=null!==(t=Y.series)&&void 0!==t?t:{};var i=null!==(r=Y.series[this.name])&&void 0!==r?r:[];i.push([Date.now(),e]),Y.series[this.name]=i}},e}(),J=new W("best_bitrate"),K=function(t,r){var i,a,n=r.container,s=r.throughput,o=r.tuning,u=r.forwardBufferHealth,d=r.currentRepresentation,l=o.usePixelRatio&&null!==(i=window.devicePixelRatio)&&void 0!==i?i:1,c=o.limitByContainer&&n&&n.width>0&&n.height>0&&{width:n.width*l*o.containerSizeFactor,height:n.height*l*o.containerSizeFactor},p=c&&q(c,0),h=t.filter((function(e){return!G(e.quality)})).sort((function(e,t){return U(e.quality,t.quality)?-1:1})),f=h.filter((function(t){var r,i,a,n,l=!p||F(t.quality,p),c=!(e.isNonNullable(s)&&isFinite(s)&&e.isNonNullable(t.bitrate))||s>=t.bitrate*(i=null!=u?u:.5,a=o.bitrateFactorAtEmptyBuffer,n=o.bitrateFactorAtFullBuffer,(a-n)*Math.pow(2,-10*i)+n),h=!o.lazyQualitySwitch||!d||(null!=u?u:.5)>=.5||((null===(r=t.size)||void 0===r?void 0:r.height)||0)<=((null==d?void 0:d.height)||0);return l&&c&&h}))[0];return f&&f.bitrate&&J.next(f.bitrate),null!==(a=null!=f?f:h[h.length-1])&&void 0!==a?a:t[0]},X=function(e,t){for(var r=0,i=0;i<e.length;i++){var a=1e3*e.start(i),n=1e3*e.end(i);a<=t&&t<=n&&(r=n)}return Math.max(r-t,0)},Z=function(e){return new URL(e).hostname},ee=function(t,r){return void 0===r&&(r=300),new e.Observable((function(i){var a=t.getBoundingClientRect(),n=a.width,s=a.height;if(i.next({width:n,height:s}),window.ResizeObserver){var o=new ResizeObserver(d.default((function(t){var r,a,n=t[0];n&&(n.contentBoxSize&&n.contentBoxSize[0]?(a=n.contentBoxSize[0].blockSize,r=n.contentBoxSize[0].inlineSize):n.contentRect&&(r=n.contentRect.width,a=n.contentRect.height),e.isNonNullable(r)&&e.isNonNullable(a)&&i.next({width:r,height:a}))}),r));return o.observe(t),function(){return o.disconnect()}}}))},te=function(){function t(t){this.transitionStarted$=new e.Subject,this.transitionEnded$=new e.Subject,this.transitionUpdated$=new e.Subject,this.forceChanged$=new e.Subject,this.stateChangeStarted$=e.merge(this.transitionStarted$,this.transitionUpdated$),this.stateChangeEnded$=e.merge(this.transitionEnded$,this.forceChanged$),this.state=t}return t.prototype.setState=function(e){var t=this.transition,r=this.state;this.transition=void 0,this.state=e,t?t.to===e?this.transitionEnded$.next(t):this.forceChanged$.next({from:t.from,to:e,canceledTransition:t}):this.forceChanged$.next({from:r,to:e,canceledTransition:t})},t.prototype.startTransitionTo=function(t){var r=this.transition,i=this.state;i===t||e.isNonNullable(r)&&r.to===t||(this.state=t,r?(this.transition={from:r.from,to:t,canceledTransition:r},this.transitionUpdated$.next(this.transition)):(this.transition={from:i,to:t},this.transitionStarted$.next(this.transition)))},t.prototype.getTransition=function(){return this.transition},t.prototype.getState=function(){return this.state},t}(),re=function(e){var t,r,i=e.get("X-Delivery-Type"),a=e.get("X-Reused");return{type:null===i?exports.HttpConnectionType.HTTP1:null!==(t=i)&&void 0!==t?t:void 0,reused:null===a?void 0:null!==(r={1:!0,0:!1}[a])&&void 0!==r?r:void 0}};!function(e){e[e.HEADER=0]="HEADER",e[e.PARAM=1]="PARAM"}(M||(M={}));var ie,ae,ne,se=function(){function t(t){var r=this,i=(void 0===t?{}:t).throughputEstimator;this.lastConnectionType$=new e.ValueSubject(void 0),this.lastConnectionReused$=new e.ValueSubject(void 0),this.lastRequestFirstBytes$=new e.ValueSubject(void 0),this.abortAllController=new AbortController,this.subscription=new e.Subscription,this.fetchRepresentation=function(e,t,i){return void 0===i&&(i=0),c(r,void 0,void 0,(function(){var r,a,n,s,o,u,d,l,c,h,f,v,m,S,b;return p(this,(function(p){switch(p.label){case 0:return r=e.initRange,a=r.from,n=r.to,s=a,o=n,u=!1,e.indexRange&&(d=e.indexRange.from,l=e.indexRange.to,(u=n+1===d)&&(s=Math.min(d,a),o=Math.max(l,n))),s=Math.min(s,0),o+=i,[4,this.fetchRange(e.url,s,o,{method:M.PARAM})];case 1:if(!(c=p.sent()))return[2,null];if(h=new DataView(c,a-s,n-s),!t.validateData(h))throw new Error("Invalid media file");return f=t.parseInit(h),u&&void 0!==d&&void 0!==l?(v=new DataView(c,d-s,l-d),[3,4]):[3,2];case 2:return(m=t.getIndexRange(f))?[4,this.fetchRange(e.url,m.from,m.to,{method:M.PARAM})]:[3,4];case 3:if(!(S=p.sent()))return[2,null];v=new DataView(S),p.label=4;case 4:if(!v)throw new ReferenceError("No way to load representation index");return b=t.parseSegments(v,f),[2,{dataView:new DataView(c),segments:b}]}}))}))},this.throughputEstimator=i}return t.prototype.onHeadersReceived=function(e){var t=re(e),r=t.type,i=t.reused;this.lastConnectionType$.next(r),this.lastConnectionReused$.next(i)},t.prototype.fetchManifest=function(e){return c(this,void 0,void 0,(function(){var t;return p(this,(function(r){switch(r.label){case 0:return[4,fetch(e,{signal:this.abortAllController.signal}).catch(oe)];case 1:return(t=r.sent())?(this.onHeadersReceived(t.headers),[2,t.text()]):[2,null]}}))}))},t.prototype.fetchRange=function(t,r,i,a){var n,s,o,u=void 0===a?{}:a,d=u.method,l=void 0===d?M.HEADER:d,h=u.onProgress,v=u.signal;return c(this,void 0,void 0,(function(){var a,u,d,m,S,b,g,y,T,E,P,k,w,x,A,$,N,D,_,R=this;return p(this,(function(I){switch(I.label){case 0:switch(a=t,u=new Headers,l){case M.HEADER:u.append("Range",r+"-"+i);break;case M.PARAM:(d=new URL(a,location.href)).searchParams.append("bytes",r+"-"+i),a=d.toString();break;default:e.assertNever(l)}return m=this.abortAllController.signal,v&&(S=new AbortController,this.subscription.add(e.merge(e.fromEvent(this.abortAllController.signal,"abort"),e.fromEvent(v,"abort")).subscribe((function(){S.abort()}))),(this.abortAllController.signal.aborted||v.aborted)&&S.abort(),m=S.signal),b=e.now(),[4,fetch(a,{headers:u,signal:m}).catch(oe)];case 1:return g=I.sent(),null===(n=this.throughputEstimator)||void 0===n||n.addRawRtt(e.now()-b),g?g.ok&&g.body?(this.onHeadersReceived(g.headers),y=f(g.body.tee(),2),T=y[0],E=y[1],P=T.getReader(),null===(s=this.throughputEstimator)||void 0===s||s.trackStream(E),k=parseInt(null!==(o=g.headers.get("Content-Length"))&&void 0!==o?o:"",10),w=0,x=new ArrayBuffer(k),A=new Uint8Array(x),$=new DataView(x),N=!1,D=function(e){N=!0,oe(e)},_=function(t){var r=t.done,i=t.value;return c(R,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return 0===w&&this.lastRequestFirstBytes$.next(e.now()-b),r?(null==h||h($,w),[3,3]):[3,1];case 1:return i?(A.set(i,w),w+=i.byteLength,null==h||h($,w),[4,null==P?void 0:P.read().then(_,D)]):[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))},[4,null==P?void 0:P.read().then(_,D)]):[2,Promise.reject(new Error("Fetch error "+g.status+": "+g.statusText))]:[2,null];case 2:return I.sent(),[2,N?null:x]}}))}))},t.prototype.destroy=function(){this.abortAllController.abort(),this.subscription.unsubscribe()},t}(),oe=function(e){if(!(e instanceof DOMException)||"AbortError"!==e.name&&20!==e.code)throw e};!function(e){e[e.EBML=440786851]="EBML",e[e.EBMLVersion=17030]="EBMLVersion",e[e.EBMLReadVersion=17143]="EBMLReadVersion",e[e.EBMLMaxIDLength=17138]="EBMLMaxIDLength",e[e.EBMLMaxSizeLength=17139]="EBMLMaxSizeLength",e[e.DocType=17026]="DocType",e[e.DocTypeVersion=17031]="DocTypeVersion",e[e.DocTypeReadVersion=17029]="DocTypeReadVersion",e[e.Void=236]="Void",e[e.Segment=408125543]="Segment",e[e.SeekHead=290298740]="SeekHead",e[e.Seek=19899]="Seek",e[e.SeekID=21419]="SeekID",e[e.SeekPosition=21420]="SeekPosition",e[e.Info=357149030]="Info",e[e.TimestampScale=2807729]="TimestampScale",e[e.Duration=17545]="Duration",e[e.Tracks=374648427]="Tracks",e[e.Chapters=272869232]="Chapters",e[e.Cluster=524531317]="Cluster",e[e.Attachments=423732329]="Attachments",e[e.Tags=307544935]="Tags",e[e.Cues=475249515]="Cues",e[e.CuePoint=187]="CuePoint",e[e.CueTime=179]="CueTime",e[e.CueTrackPositions=183]="CueTrackPositions",e[e.CueTrack=247]="CueTrack",e[e.CueClusterPosition=241]="CueClusterPosition",e[e.CueRelativePosition=240]="CueRelativePosition",e[e.CueDuration=178]="CueDuration",e[e.CueBlockNumber=21368]="CueBlockNumber",e[e.CueCodecState=234]="CueCodecState",e[e.CueReference=219]="CueReference",e[e.CueRefTime=150]="CueRefTime"}(ae||(ae={})),function(e){e.SignedInteger="int",e.UnsignedInteger="uint",e.Float="float",e.String="string",e.UTF8="utf8",e.Date="date",e.Master="master",e.Binary="binary"}(ne||(ne={}));var ue,de=((ie={})[ae.EBML]={type:ne.Master},ie[ae.EBMLVersion]={type:ne.UnsignedInteger},ie[ae.EBMLReadVersion]={type:ne.UnsignedInteger},ie[ae.EBMLMaxIDLength]={type:ne.UnsignedInteger},ie[ae.EBMLMaxSizeLength]={type:ne.UnsignedInteger},ie[ae.DocType]={type:ne.String},ie[ae.DocTypeVersion]={type:ne.UnsignedInteger},ie[ae.DocTypeReadVersion]={type:ne.UnsignedInteger},ie[ae.Void]={type:ne.Binary},ie[ae.Segment]={type:ne.Master},ie[ae.SeekHead]={type:ne.Master},ie[ae.Seek]={type:ne.Master},ie[ae.SeekID]={type:ne.Binary},ie[ae.SeekPosition]={type:ne.UnsignedInteger},ie[ae.Info]={type:ne.Master},ie[ae.TimestampScale]={type:ne.UnsignedInteger},ie[ae.Duration]={type:ne.Float},ie[ae.Tracks]={type:ne.Master},ie[ae.Chapters]={type:ne.Master},ie[ae.Cluster]={type:ne.Master},ie[ae.Attachments]={type:ne.Master},ie[ae.Tags]={type:ne.Master},ie[ae.Cues]={type:ne.Master},ie[ae.CuePoint]={type:ne.Master},ie[ae.CueTime]={type:ne.UnsignedInteger},ie[ae.CueTrackPositions]={type:ne.Master},ie[ae.CueTrack]={type:ne.UnsignedInteger},ie[ae.CueClusterPosition]={type:ne.UnsignedInteger},ie[ae.CueRelativePosition]={type:ne.UnsignedInteger},ie[ae.CueDuration]={type:ne.UnsignedInteger},ie[ae.CueBlockNumber]={type:ne.UnsignedInteger},ie[ae.CueCodecState]={type:ne.UnsignedInteger},ie[ae.CueReference]={type:ne.Master},ie[ae.CueRefTime]={type:ne.UnsignedInteger},ie),le=function(e){var t=e.getUint8(0),r=0;128&t?r=1:64&t?r=2:32&t?r=3:16&t&&(r=4);var i=ce(e,r),a=i in de,n=a?de[i].type:ne.Binary,s=e.getUint8(r),o=0;128&s?o=1:64&s?o=2:32&s?o=3:16&s?o=4:8&s?o=5:4&s?o=6:2&s?o=7:1&s&&(o=8);var u,d=new DataView(e.buffer,e.byteOffset+r+1,o-1),l=((s&255>>o)<<8*(o-1))+ce(d),c=r+o;return u=c+l>e.byteLength?new DataView(e.buffer,e.byteOffset+c):new DataView(e.buffer,e.byteOffset+c,l),{tag:a?i:"0x"+i.toString(16).toUpperCase(),type:n,value:u,valueSize:l}},ce=function(e,t){switch(void 0===t&&(t=e.byteLength),t){case 1:return e.getUint8(0);case 2:return e.getUint16(0);case 3:return e.getUint16(0)<<8|e.getUint8(2);case 4:return e.getUint32(0);case 5:return e.getUint32(0)<<8|e.getUint8(4);case 6:return e.getUint32(0)<<16|e.getUint16(4);case 7:return e.getUint32(0)<<32|e.getUint16(4)<<8|e.getUint8(6);case 8:return e.getUint32(0)<<32|e.getUint32(4)}return 0},pe=function(t,r){switch(r){case ne.SignedInteger:return t.getInt8(0);case ne.UnsignedInteger:return ce(t);case ne.Float:return 4===t.byteLength?t.getFloat32(0):t.getFloat64(0);case ne.String:return new TextDecoder("ascii").decode(t);case ne.UTF8:return new TextDecoder("utf-8").decode(t);case ne.Date:return new Date(Date.UTC(2001,0)+t.getInt8(0)).getTime();case ne.Master:case ne.Binary:return t;default:e.assertNever(r)}},he=function(e,t){for(var r=0;r<e.byteLength;){var i=new DataView(e.buffer,e.byteOffset+r),a=le(i);if(!t(a))return;a.type===ne.Master&&he(a.value,t),r=a.value.byteOffset-e.byteOffset+a.valueSize}},fe=[ae.Info,ae.SeekHead,ae.Tracks,ae.Chapters,ae.Cluster,ae.Cues,ae.Attachments,ae.Tags],ve={validateData:function(e){if(e.getUint32(0)!==ae.EBML)return!1;var t=void 0,r=void 0,i=void 0,a=le(e);return he(a.value,(function(e){var a=e.tag,n=e.type,s=e.value;return a===ae.EBMLReadVersion?t=pe(s,n):a===ae.DocType?r=pe(s,n):a===ae.DocTypeReadVersion&&(i=pe(s,n)),!0})),(void 0===t||t<=1)&&void 0!==r&&"webm"===r&&(void 0===i||i<=2)},parseInit:function(t){var r=void 0,i=void 0,a=void 0,n=void 0,s=!1,o=!1,u=!1,d=void 0,l=void 0;return he(t,(function(e){var t=e.tag,c=e.type,p=e.value,h=e.valueSize;if(t===ae.SeekID){var f=pe(p,c);l=ce(f)}else t!==ae.SeekPosition&&(l=void 0);return t===ae.Segment?(r=p.byteOffset,i=p.byteOffset+h):t===ae.Info?s=!0:t===ae.SeekHead?o=!0:t===ae.TimestampScale?a=pe(p,c):t===ae.Duration?n=pe(p,c):t===ae.SeekPosition&&l===ae.Cues?d=pe(p,c):s&&o&&fe.includes(t)&&(u=!0),!u})),e.assertNonNullable(r,"Failed to parse webm Segment start"),e.assertNonNullable(i,"Failed to parse webm Segment end"),e.assertNonNullable(n,"Failed to parse webm Segment duration"),a=null!=a?a:1e6,{segmentStart:Math.round(r/1e9*a*1e3),segmentEnd:Math.round(i/1e9*a*1e3),timeScale:a,segmentDuration:Math.round(n/1e9*a*1e3),cuesSeekPosition:d}},getIndexRange:function(t){if(!e.isNullable(t.cuesSeekPosition)){var r=t.segmentStart+t.cuesSeekPosition;return{from:r,to:r+1048576}}},parseSegments:function(t,r){var i,a=!1,n=!1,s=function(t){return e.isNonNullable(t.time)&&e.isNonNullable(t.position)},o=[];return he(t,(function(e){var t=e.tag,r=e.type,u=e.value;switch(t){case ae.Cues:a=!0;break;case ae.CuePoint:i&&s(i)&&o.push(i),i={};break;case ae.CueTime:i&&(i.time=pe(u,r));break;case ae.CueTrackPositions:break;case ae.CueClusterPosition:i&&(i.position=pe(u,r));break;default:a&&fe.includes(t)&&(n=!0)}return!(a&&n)})),i&&s(i)&&o.push(i),o.map((function(e,t){var i=e.time,a=e.position,n=o[t+1];return{status:b.NONE,time:{from:i,to:n?n.time:r.segmentDuration},byte:{from:r.segmentStart+a,to:n?r.segmentStart+n.position-1:r.segmentEnd-1}}}))}},me=new TextDecoder("ascii"),Se={validateData:function(e){return"ftyp"===me.decode(new DataView(e.buffer,e.byteOffset+4,4))},parseInit:function(){return null},getIndexRange:function(){},parseSegments:function(e){var t=function(e){var t=0,r=e.getUint32(t);t+=4;var i=new DataView(e.buffer,e.byteOffset+t,4),a=me.decode(i);t+=4,0===r?r=1/0:1===r&&(t+=8,r=1/0);var n=Math.min(r,e.byteLength)-t+1;return{id:a,size:r,contents:new DataView(e.buffer,e.byteOffset+t,n)}}(e),r=[],i=0,a=function(){var e=t.contents.getUint32(i);return i+=4,e};if(0!==(4278190080&a()))throw new SyntaxError("Unsupported sidx version");a();for(var n=a(),s=a(),o=a(),u=255&a(),d=s/n*1e3,l=e.byteOffset+e.byteLength+o+1,c=0;c<u;c++){var p=a(),h=p>>>31,f=p<<1>>>1,v=a();if(a(),0!==h)throw new Error("Unsupported multilevel sidx");var m=v/n*1e3;r.push({status:b.NONE,time:{from:d,to:d+m},byte:{from:l,to:l+f-1}}),d+=m,l+=f}return r}},be=function(){function t(t,r,i,a,n){var s=n.fetcher,o=n.tuning;switch(this.ended$=new e.ValueSubject(!1),this.playingRepresentation$=new e.ValueSubject(void 0),this.error$=new e.Subject,this.subscription=new e.Subscription,this.abortController=new AbortController,this.allInitsLoaded=!1,this.fetcher=s,this.tuning=o,this.container=i,i){case g.MP4:this.containerParser=Se;break;case g.WEBM:this.containerParser=ve;break;default:e.assertNever(i)}this.initData=new Map,this.segments=new Map,this.representations=new Map(a.map((function(e){return[e.id,e]}))),this.kind=t,this.mediaSource=r,this.sourceBuffer=null,this.segmentDownloadPromise=Promise.resolve()}return t.prototype.startWith=function(t){return c(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,c,h=this;return p(this,(function(p){switch(p.label){case 0:return r=this.representations.get(t),e.assertNonNullable(r,"Cannot find representation "+t),i=Math.ceil(1e3*r.bitrate/8*(this.tuning.extraInitSize/1e3)*1.1),this.playingRepresentationId=t,this.downloadingRepresentationId=t,this.sourceBuffer=this.mediaSource.addSourceBuffer(r.mime+'; codecs="'+r.codecs+'"'),this.subscription.add(e.fromEvent(this.sourceBuffer,"updateEnd").subscribe((function(){return h.checkEjectedSegments()}),(function(e){return h.error$.next({id:"SegmentEjection",message:"Error when trying to clear segments ejecte by browser",thrown:e})}))),this.subscription.add(e.fromEvent(this.sourceBuffer,"error").subscribe((function(e){return h.error$.next({id:"SourceBuffer",message:"SourceBuffer Error event fired",thrown:e})}))),[4,this.fetcher.fetchRepresentation(r,this.containerParser,i).catch((function(e){return h.error$.next({id:"LoadInit",message:"Failed to init Representation",thrown:e})}))];case 1:return(a=p.sent())?(n=a.dataView,s=a.segments,o=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength-i),this.initData.set(t,o),u=s.filter((function(e){return e.byte.from>=n.byteOffset&&e.byte.to<n.byteOffset+n.byteLength})),d=u.at(-1),c=new DataView(n.buffer,n.byteOffset,u.length&&d?Math.min(d.byte.to-n.byteOffset+1,n.byteLength):n.byteLength-i),[4,this.appendDataToBuffer(c)]):[2,!1];case 2:return p.sent(),this.segments.set(t,s.map((function(e){return l(l({},e),{status:e.byte.from>=n.byteOffset&&e.byte.to<n.byteOffset+n.byteLength?b.FED:b.NONE})}))),this.maintain(0),[2,!0]}}))}))},t.prototype.switchTo=function(t){var r;return c(this,void 0,void 0,(function(){var i,a,n,s,o,u,d=this;return p(this,(function(l){switch(l.label){case 0:return t===this.downloadingRepresentationId||t===this.switchingToRepresentationId?[2]:(this.switchingToRepresentationId=t,this.initData.has(t)?[3,4]:this.loadAllInitsPromise?[4,this.loadAllInitsPromise]:[3,2]);case 1:return l.sent(),[3,4];case 2:return i=this.representations.get(t),e.assertNonNullable(i),[4,this.fetcher.fetchRepresentation(i,this.containerParser,0).catch((function(e){return d.error$.next({id:"LoadInit",message:"Failed to init Representation",thrown:e})}))];case 3:if(!(a=l.sent()))return[2];n=a.dataView,s=a.segments,o=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),this.initData.set(t,o),this.segments.set(t,s),l.label=4;case 4:u=this.initData.get(t),e.assertNonNullable(u,"No init buffer for "+t),e.assertNonNullable(this.sourceBuffer),this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=t,this.abortController.abort(),this.abortController=new AbortController;try{this.sourceBuffer.abort()}catch(e){this.error$.next({id:"SourceBufferAbort",message:"SourceBuffer.abort() threw",thrown:e})}return[4,this.appendDataToBuffer(u,this.abortController.signal)];case 5:return l.sent(),e.isNonNullable(this.playingRepresentationId)&&(null===(r=this.segments.get(this.playingRepresentationId))||void 0===r||r.forEach((function(e){e.status===b.FED&&(e.status=b.NONE)}))),[2]}}))}))},t.prototype.maintain=function(t){return c(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d=this;return p(this,(function(l){switch(l.label){case 0:return e.isNullable(this.downloadingRepresentationId)||e.isNullable(this.playingRepresentationId)||e.isNullable(this.sourceBuffer)||this.ended$.getValue()?[2]:(r=this.representations.get(this.downloadingRepresentationId),i=this.segments.get(this.downloadingRepresentationId),e.assertNonNullable(r),e.assertNonNullable(i),a=i.find((function(e){return t>=e.time.from&&t<e.time.to})),n=t,this.playingRepresentationId!==this.downloadingRepresentationId&&(s=X(this.sourceBuffer.buffered,t),n=t+Math.min(s,this.tuning.representationSwitchForwardBufferGap)),(o=this.selectForwardBufferSegments(i,n)).length?[4,this.loadSegments(o,r)]:[3,2]);case 1:l.sent(),l.label=2;case 2:return!this.allInitsLoaded&&!this.loadAllInitsPromise&&a&&a.status===b.FED&&!o.length&&X(this.sourceBuffer.buffered,t)>3e3&&this.loadAllInits().catch((function(e){return d.error$.next({id:"InitDownload",message:"Error when trying to load all inits",thrown:e})})),(u=i.at(-1))&&a===u&&u.status===b.FED&&this.ended$.next(!0),[2]}}))}))},t.prototype.destroy=function(){this.initData.clear(),this.segments.clear(),this.representations.clear(),this.subscription.unsubscribe(),this.sourceBuffer&&"open"===this.mediaSource.readyState&&(this.sourceBuffer.abort(),this.mediaSource.removeSourceBuffer(this.sourceBuffer)),this.abortController.abort()},t.prototype.selectForwardBufferSegments=function(e,t){var r=this,i=e.findIndex((function(e){var i=e.status,a=e.time,n=a.from,s=a.to;return i===b.NONE&&(n>t||n<=t&&s>=t)&&s<=t+r.tuning.forwardBufferTarget}));if(-1===i)return[];for(var a=0,n=[],s=i;s<e.length&&a<=this.tuning.segmentRequestSize;s++){var o=e[s];if(a+=o.byte.to+1-o.byte.from,o.status===b.NONE)n.push(o);else if([b.DOWNLOADING,b.DOWNLOADED,b.FED].includes(o.status))break}return n},t.prototype.loadSegments=function(e,t){return c(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,l,f=this;return p(this,(function(v){if(!e.length)return[2];r=e.at(0).byte.from,i=e.at(-1).byte.to;try{for(a=h(e),n=a.next();!n.done;n=a.next())n.value.status=b.DOWNLOADING}catch(e){d={error:e}}finally{try{n&&!n.done&&(l=a.return)&&l.call(a)}finally{if(d)throw d.error}}return s=this.abortController.signal,o=function(e,r){e.status=b.DOWNLOADED,f.appendDataToBuffer(r,s).then((function(r){!r||s.aborted?e.status=b.NONE:(f.playingRepresentationId=t.id,f.playingRepresentation$.next(f.playingRepresentationId),e.status=b.FED)}))},u=function(t,i){var a,n;try{for(var s=h(e),u=s.next();!u.done;u=s.next()){var d=u.value;d.status===b.DOWNLOADING&&d.byte.from-r>=0&&d.byte.to+1-r<=i&&o(d,new DataView(t.buffer,t.byteOffset+d.byte.from-r,d.byte.to+1-d.byte.from))}}catch(e){a={error:e}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(a)throw a.error}}},this.segmentDownloadPromise=this.segmentDownloadPromise.then((function(){return c(f,void 0,void 0,(function(){var a,n,d,l,c,f,v,m,S,g,y,T,E;return p(this,(function(p){switch(p.label){case 0:if(s.aborted){try{for(a=h(e),n=a.next();!n.done;n=a.next())(m=n.value).status===b.DOWNLOADING&&(m.status=b.NONE)}catch(e){S={error:e}}finally{try{n&&!n.done&&(g=a.return)&&g.call(a)}finally{if(S)throw S.error}}return[2]}return[4,this.fetcher.fetchRange(t.url,r,i,{method:M.PARAM,onProgress:u,signal:s})];case 1:if(d=p.sent(),l=e.at(-1),c=null===(E=this.segments.get(t.id))||void 0===E?void 0:E.at(-1),!d)try{for(f=h(e),v=f.next();!v.done;v=f.next())(m=v.value).status===b.DOWNLOADING&&(m.status=b.NONE)}catch(e){y={error:e}}finally{try{v&&!v.done&&(T=f.return)&&T.call(f)}finally{if(y)throw y.error}}return d&&!s.aborted&&l&&c&&l.status===b.DOWNLOADING&&l===c&&o(l,new DataView(d,l.byte.from-r)),[2]}}))}))})).catch((function(e){return f.error$.next({id:"SegmentDownload",message:"Error when fetching segments",thrown:e})})),[2,this.segmentDownloadPromise]}))}))},t.prototype.loadAllInits=function(){return c(this,void 0,void 0,(function(){var e=this;return p(this,(function(t){return this.loadAllInitsPromise||(this.loadAllInitsPromise=Promise.all(Array.from(this.representations.entries()).map((function(t){var r=f(t,2),i=r[0],a=r[1];return e.initData.has(i)?Promise.resolve():e.fetcher.fetchRepresentation(a,e.containerParser).then((function(t){if(t){var r=t.dataView,a=t.segments,n=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);e.initData.set(i,n),e.segments.set(i,a)}}))}))).then((function(){e.allInitsLoaded=!0})).finally((function(){e.loadAllInitsPromise=null}))),[2,this.loadAllInitsPromise]}))}))},t.prototype.appendDataToBuffer=function(r,i){return c(this,void 0,void 0,(function(){return p(this,(function(a){switch(a.label){case 0:if(e.assertNonNullable(this.sourceBuffer),i&&i.aborted)return[2,!1];if(this.sourceBuffer.updating)return[3,2];try{this.sourceBuffer.appendBuffer(r)}catch(e){return this.error$.next({id:"AppendBuffer",message:"Error appending data to buffer",thrown:e}),[2,!1]}return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 1:return a.sent(),[3,4];case 2:return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 3:return a.sent(),[2,this.appendDataToBuffer(r,i)];case 4:return[2,!0]}}))}))},t.prototype.checkEjectedSegments=function(){var t,r;if(!e.isNullable(this.sourceBuffer)&&!e.isNullable(this.playingRepresentationId)){var i=this.segments.get(this.playingRepresentationId);e.assertNonNullable(i);for(var a=[],n=0;n<this.sourceBuffer.buffered.length;n++){var s=1e3*this.sourceBuffer.buffered.start(n),o=this.sourceBuffer.buffered.end(n),u=1e3*(o%1>.9?Math.round(o):o);a.push({from:s,to:u})}var d=function(e){var t=a.some((function(t){return t.from<=e.time.from&&t.to>=e.time.to}));e.status!==b.FED||t||(e.status=b.NONE)};try{for(var l=h(i),c=l.next();!c.done;c=l.next()){d(c.value)}}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}}},t.waitForBufferUpdate=function(e){return c(this,void 0,void 0,(function(){return p(this,(function(t){return[2,new Promise((function(t){return e?e.addEventListener("update",(function(){return t()})):t()}))]}))}))},t}(),ge=["timeupdate","progress","play","seeked","stalled"];!function(e){e.NONE="none",e.MANIFEST_LOADED="manifest_loaded",e.REPRESENTATION_SELECTED="representation_selected"}(ue||(ue={}));var ye,Te=function(){function t(t){var r=this;this.element=null,this.source=null,this.manifest=null,this.subscription=new e.Subscription,this.state$=new te(ue.NONE),this.currentVideoRepresentation$=new e.ValueSubject(void 0),this.error$=new e.Subject,this.lastConnectionType$=new e.ValueSubject(void 0),this.lastConnectionReused$=new e.ValueSubject(void 0),this.lastRequestFirstBytes$=new e.ValueSubject(void 0),this.forceEnded$=new e.Subject,this.tick=function(){var e,t;if(r.element){var i=1e3*r.element.currentTime;null===(e=r.videoBufferManager)||void 0===e||e.maintain(i),null===(t=r.audioBufferManager)||void 0===t||t.maintain(i)}},this.throughputEstimator=t.throughputEstimator,this.tuning=t.tuning,this.fetcher=new se({throughputEstimator:this.throughputEstimator})}return t.prototype.initManifest=function(t,r){return c(this,void 0,void 0,(function(){var i,a,n,s=this;return p(this,(function(o){switch(o.label){case 0:return this.element=t,this.subscription.add(e.fromEvent(t,"waiting").subscribe((function(){t.duration-t.currentTime<s.tuning.endGapTolerance/1e3&&s.forceEnded$.next()}),(function(e){return s.error$.next({id:"ForceEnd",message:"Error when forcing stream end",thrown:e})}))),this.state$.startTransitionTo(ue.MANIFEST_LOADED),[4,this.fetcher.fetchManifest(r)];case 1:return i=o.sent(),a=function(e,t){var r,i,a,n,s,o,u,d,l,c,p,b,y,T,E,P,k,w,x,A,$,N,D,_,R,I,C={video:[],audio:[],text:[]},L=(new DOMParser).parseFromString(e,"application/xml").children[0],O=L.getElementsByTagName("Period")[0].children,V=0,M=null!==(o=null===(s=L.getAttribute("profiles"))||void 0===s?void 0:s.split(","))&&void 0!==o?o:[],B=M.includes(S.WEBM_AS_IN_FFMPEG)||M.includes(S.WEBM_AS_IN_SPEC)?g.WEBM:g.MP4;try{for(var U=h(O),F=U.next();!F.done;F=U.next()){var H=F.value,q=H.getAttribute("mimeType"),G=H.getAttribute("codecs"),j=null!==(u=H.getAttribute("contentType"))&&void 0!==u?u:null==q?void 0:q.split("/")[0],Y=null!==(l=null===(d=H.getAttribute("profiles"))||void 0===d?void 0:d.split(","))&&void 0!==l?l:[],z=H.querySelectorAll("Representation");try{for(var Q=(a=void 0,h(z)),W=Q.next();!W.done;W=Q.next()){var J=W.value,K=null!==(c=J.getAttribute("mimeType"))&&void 0!==c?c:q,X=null!==(b=null!==(p=J.getAttribute("codecs"))&&void 0!==p?p:G)&&void 0!==b?b:"",Z=null!==(T=null!==(y=J.getAttribute("contentType"))&&void 0!==y?y:null==K?void 0:K.split("/")[0])&&void 0!==T?T:j,ee=null!==(P=null===(E=H.getAttribute("profiles"))||void 0===E?void 0:E.split(","))&&void 0!==P?P:[],te=parseInt(null!==(k=J.getAttribute("width"))&&void 0!==k?k:"",10),re=parseInt(null!==(w=J.getAttribute("height"))&&void 0!==w?w:"",10),ie=parseInt(null!==(x=J.getAttribute("bandwidth"))&&void 0!==x?x:"",10)/1e3,ae=(null!==(A=J.getAttribute("id"))&&void 0!==A?A:(V++).toString(10))+"@"+("video"===Z?re+"p":"audio"===Z?ie+"Kbps":X),ne=null!==(D=null===(N=null===($=J.querySelector("BaseURL"))||void 0===$?void 0:$.textContent)||void 0===N?void 0:N.trim())&&void 0!==D?D:"",se=new URL(ne,t).toString(),oe=v(v(v([],f(M),!1),f(Y),!1),f(ee),!1),ue=f((null!==(R=null===(_=J.querySelector("SegmentBase Initialization"))||void 0===_?void 0:_.getAttribute("range"))&&void 0!==R?R:"").split("-").map((function(e){return parseInt(e,10)})),2),de={from:ue[0],to:ue[1]},le=null===(I=J.querySelector("SegmentBase"))||void 0===I?void 0:I.getAttribute("indexRange"),ce=f(le?le.split("-").map((function(e){return parseInt(e,10)})):[],2),pe=ce[0],he=ce[1],fe=le?{from:pe,to:he}:void 0;if(Z&&K){var ve={video:m.VIDEO,audio:m.AUDIO,text:m.TEXT}[Z];ve&&C[ve].push({id:ae,kind:ve,profiles:oe,initRange:de,indexRange:fe,bitrate:ie,mime:K,codecs:X,width:te,height:re,url:se})}}}catch(e){a={error:e}}finally{try{W&&!W.done&&(n=Q.return)&&n.call(Q)}finally{if(a)throw a.error}}}}catch(e){r={error:e}}finally{try{F&&!F.done&&(i=U.return)&&i.call(U)}finally{if(r)throw r.error}}return{container:B,representations:C}}(null!=i?i:"",r),n=function(e){var r,i,a,n=e.mime,s=e.codecs;return Boolean((null===(r=t.canPlayType)||void 0===r?void 0:r.call(t,n))&&(null===(a=null===(i=window.MediaSource)||void 0===i?void 0:i.isTypeSupported)||void 0===a?void 0:a.call(i,n+'; codecs="'+s+'"')))},this.manifest=l(l({},a),{representations:Object.fromEntries(Object.entries(a.representations).map((function(e){var t=f(e,2);return[t[0],t[1].filter(n)]})))}),this.manifest.representations.video.length?this.state$.setState(ue.MANIFEST_LOADED):this.error$.next({id:"NoRepresentations",message:"No playable video representations"}),[2,this.manifest]}}))}))},t.prototype.initRepresentations=function(t,r){return c(this,void 0,void 0,(function(){var i,a=this;return p(this,(function(n){switch(n.label){case 0:return e.assertNonNullable(this.manifest),e.assertNonNullable(this.element),this.state$.startTransitionTo(ue.REPRESENTATION_SELECTED),this.source=new MediaSource,this.element.src=URL.createObjectURL(this.source),i={fetcher:this.fetcher,tuning:this.tuning.dash},this.videoBufferManager=new be(m.VIDEO,this.source,this.manifest.container,this.manifest.representations.video,i),this.audioBufferManager=new be(m.AUDIO,this.source,this.manifest.container,this.manifest.representations.audio,i),this.subscription.add(this.fetcher.lastConnectionType$.subscribe(this.lastConnectionType$)),this.subscription.add(this.fetcher.lastConnectionReused$.subscribe(this.lastConnectionReused$)),this.subscription.add(this.fetcher.lastRequestFirstBytes$.subscribe(this.lastRequestFirstBytes$)),this.subscription.add(e.merge(this.forceEnded$,e.combine({video:this.videoBufferManager.ended$,audio:this.audioBufferManager.ended$}).pipe(e.filter((function(e){return Object.values(e).every((function(e){return!0===e}))})))).subscribe((function(){var e,t;if("open"===(null===(e=a.source)||void 0===e?void 0:e.readyState))try{null===(t=a.source)||void 0===t||t.endOfStream()}catch(e){a.error$.next({id:"EndOfStream",message:"Failed to end MediaSource stream",thrown:e})}}))),this.subscription.add(e.merge(this.videoBufferManager.error$,this.audioBufferManager.error$).subscribe(this.error$)),this.subscription.add(this.videoBufferManager.playingRepresentation$.subscribe(this.currentVideoRepresentation$)),"open"===this.source.readyState?[3,2]:[4,new Promise((function(e){var t;return null===(t=a.source)||void 0===t?void 0:t.addEventListener("sourceopen",e)}))];case 1:n.sent(),n.label=2;case 2:return[4,Promise.all([this.videoBufferManager.startWith(t),this.audioBufferManager.startWith(r)])];case 3:return n.sent().some((function(e){return!e}))||(this.state$.setState(ue.REPRESENTATION_SELECTED),e.assertNonNullable(this.element),this.subscription.add(e.merge.apply(void 0,v(v([],f(ge.map((function(t){return e.fromEvent(a.element,t)}))),!1),[e.fromEvent(window,"online")],!1)).subscribe(this.tick,(function(e){a.error$.next({id:"DashVKPlayer",message:"Internal logic error",thrown:e})}))),this.subscription.add(e.fromEvent(this.element,"progress").subscribe((function(){a.element&&2===a.element.readyState&&!a.element.seeking&&(a.element.currentTime=a.element.currentTime)}))),this.tick()),[2]}}))}))},t.prototype.switchRepresentation=function(t,r){return c(this,void 0,void 0,(function(){var i,a;return p(this,(function(n){return i=(a={},a[m.VIDEO]=this.videoBufferManager,a[m.AUDIO]=this.audioBufferManager,a[m.TEXT]=null,a)[t],e.assertNonNullable(i),[2,i.switchTo(r)]}))}))},t.prototype.seek=function(t){e.assertNonNullable(this.element),e.assertNonNullable(this.videoBufferManager),e.assertNonNullable(this.audioBufferManager),this.videoBufferManager.maintain(t),this.audioBufferManager.maintain(t),this.element.currentTime=t/1e3},t.prototype.stop=function(){var e,t;this.element=null,this.source=null,this.manifest=null,this.currentVideoRepresentation$.next(void 0),null===(e=this.videoBufferManager)||void 0===e||e.destroy(),this.videoBufferManager=null,null===(t=this.audioBufferManager)||void 0===t||t.destroy(),this.audioBufferManager=null,this.state$.setState(ue.NONE)},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.fetcher.destroy(),this.stop(),this.source=null},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(ye||(ye={}));var Ee,Pe=function(e){var t=e.id,r=e.width,i=e.height,a=e.bitrate,n=q({width:r,height:i});return n&&{id:t,quality:n,bitrate:a,size:{width:r,height:i}}},ke=function(e,t,r){var i,a=Array.from(t).sort((function(e,t){return t.bitrate-e.bitrate})).indexOf(r);return null!==(i=e.at(Math.round(e.length*a/t.length)))&&void 0!==i?i:e.at(-1)},we=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(ye.STOPPED),this.elementSize$=new e.ValueSubject(void 0),this.textTracksManager=new D,this.videoTracks=[],this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.seekPosition.getTransition();if(!r.videoState.getTransition()){var s=null==n?void 0:n.to;if((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(s)&&t!==ye.STOPPED&&i!==exports.PlaybackState.STOPPED&&r.seek(s),i!==exports.PlaybackState.STOPPED){if(t===ye.STOPPED)return r.videoState.startTransitionTo(ye.READY),void r.prepare();switch(t){case ye.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(ye.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(ye.PLAYING),r.playIfAllowed()));case ye.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(ye.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case ye.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(ye.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}else t!==ye.STOPPED&&(r.videoState.startTransitionTo(ye.STOPPED),r.player.stop(),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState(ye.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))}},this.params=t,this.video=_(this.params.container),this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(Z(this.params.source.url)),this.params.output.isLive$.next(!1),this.player=new Te({throughputEstimator:this.params.dependencies.throughputEstimator,tuning:this.params.tuning}),this.subscribe()}return t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=O(this.video),s=function(e){i.error$.next({id:"DashVKProvider",message:"DashVKProvider internal logic error",thrown:e})},o=function(e,r){return t.subscription.add(e.subscribe(r,s))};o(n.timeUpdate$,i.position$),o(n.durationChange$,i.duration$),o(n.ended$,i.endedEvent$),o(n.error$,i.error$),o(n.isBuffering$,i.isBuffering$),o(n.currentBuffer$,i.currentBuffer$),o(n.firstFrame$,i.firstFrameEvent$),o(this.player.error$,i.error$),o(this.player.lastConnectionType$,i.httpConnectionType$),o(this.player.lastConnectionReused$,i.httpConnectionReused$),o(this.player.lastRequestFirstBytes$.pipe(e.filter(e.isNonNullable),e.once()),i.firstBytesEvent$),this.subscription.add(n.seeked$.subscribe(i.seekedEvent$,s)),this.subscription.add(A(this.video,a.isLooped,s)),this.subscription.add($(this.video,a.volume,n.volumeState$,s)),this.subscription.add(n.volumeState$.subscribe(this.params.output.volume$,s)),o(ee(this.video),this.elementSize$),this.subscription.add(n.playing$.subscribe((function(){t.videoState.setState(ye.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),s)).add(n.pause$.subscribe((function(){t.videoState.setState(ye.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),s)).add(n.canplay$.subscribe((function(){t.videoState.getState()===ye.PLAYING&&t.playIfAllowed()}),s)),this.subscription.add(this.player.state$.stateChangeEnded$.pipe(e.filter((function(e){return e.to===ue.REPRESENTATION_SELECTED}))).subscribe((function(){t.videoState.setState(ye.READY)}))),this.subscription.add(e.merge(this.player.state$.stateChangeEnded$,a.videoTrack.stateChangeStarted$,a.autoVideoTrackSwitching.transitionStarted$,this.params.dependencies.throughputEstimator.rttAdjustedThroughput$,this.elementSize$,e.fromEvent(this.video,"progress")).subscribe((function(){var r,i,n,s=t.player.state$.getState(),o=t.player.state$.getTransition();if(s!==ue.NONE&&t.videoTracks.length){var u=s===ue.MANIFEST_LOADED&&!o,d=a.autoVideoTrackSwitching.getState(),l=a.videoTrack.getState(),c=null===(r=t.videoTracks.find((function(e){return e.track.id===l})))||void 0===r?void 0:r.track;a.autoVideoTrackSwitching.getTransition()&&a.autoVideoTrackSwitching.setState(d);var p=X(t.video.buffered,1e3*t.video.currentTime),h=Math.min(p/Math.min(t.params.tuning.dash.forwardBufferTarget,(t.video.duration||1/0)-t.video.currentTime),1),f=K(t.videoTracks.map((function(e){return e.track})),{container:t.elementSize$.getValue(),throughput:t.params.dependencies.throughputEstimator.rttAdjustedThroughput$.getValue(),tuning:t.params.tuning.autoTrackSelection,forwardBufferHealth:h}),v=d?null!=f?f:c:null!=c?c:f;if(u){var S=v&&(null===(i=t.videoTracks.find((function(e){return e.track===v})))||void 0===i?void 0:i.representation);e.assertNonNullable(S);var b=ke(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);e.assertNonNullable(b),t.player.initRepresentations(S.id,b.id)}else{if(S=v&&(null===(n=t.videoTracks.find((function(e){return e.track===v})))||void 0===n?void 0:n.representation)){b=ke(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);t.player.switchRepresentation(m.VIDEO,S.id),b&&t.player.switchRepresentation(m.AUDIO,b.id)}}}}))),this.subscription.add(this.player.currentVideoRepresentation$.pipe(e.filterChanged(),e.map((function(e){var r;return e&&(null===(r=t.videoTracks.find((function(t){return t.representation.id===e})))||void 0===r?void 0:r.track)}))).subscribe(i.currentVideoTrack$)),this.textTracksManager.connect(this.video,a,i);var u=e.merge(a.playbackState.stateChangeStarted$,a.videoTrack.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,s))},t.prototype.prepare=function(){return c(this,void 0,void 0,(function(){var e,t,r,i,a,n,s;return p(this,(function(o){switch(o.label){case 0:return[4,this.player.initManifest(this.video,this.params.source.url)];case 1:e=o.sent(),this.videoTracks=[];try{for(t=h(e.representations.video),r=t.next();!r.done;r=t.next())i=r.value,(a=Pe(i))&&this.videoTracks.push({track:a,representation:i})}catch(e){n={error:e}}finally{try{r&&!r.done&&(s=t.return)&&s.call(t)}finally{if(n)throw n.error}}return this.audioRepresentations=Array.from(e.representations.audio).sort((function(e,t){return t.bitrate-e.bitrate})),this.params.output.availableVideoTracks$.next(this.videoTracks.map((function(e){return e.track}))),[2]}}))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.player.seek(1e3*e)},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0),this.player.destroy()},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(ye.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t}();!function(e){e[e.OFFSET_P=0]="OFFSET_P",e[e.PLAYBACK_SHIFT=1]="PLAYBACK_SHIFT"}(Ee||(Ee={}));var xe,Ae=function(t,r,i){switch(void 0===r&&(r=0),void 0===i&&(i=Ee.OFFSET_P),i){case Ee.OFFSET_P:return t.replace("_offset_p",0===r?"":"_"+r.toFixed(0));case Ee.PLAYBACK_SHIFT:if(0===r)return t;var a=new URL(t);return a.searchParams.append("playback_shift",r.toFixed(0)),a.toString();default:e.assertNever(i)}return t};!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(xe||(xe={}));var $e,Ne=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.loadMediaTimeoutSubscription=new e.Subscription,this.videoState=new te(xe.STOPPED),this.syncPlayback=function(){var t=r.videoState.getState(),i=r.videoState.getTransition(),a=r.params.desiredState.playbackState.getState(),n=r.params.desiredState.playbackState.getTransition(),s=r.params.desiredState.seekPosition.getTransition();if(r.log({message:"[syncPlayback] videoState: "+t+"; videoTransition: "+JSON.stringify(i)+"; desiredPlaybackState: "+a+"; desiredPlaybackStateTransition: "+r.params.desiredState.playbackState.getTransition()+"; seekPositionTransition: "+JSON.stringify(s)+";"}),a!==exports.PlaybackState.STOPPED){if(!i){var o=null==s?void 0:s.to;if((null==n?void 0:n.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&t!==xe.STOPPED)r.seek(o);else switch(a){case exports.PlaybackState.PLAYING:switch(t){case xe.PLAYING:break;case xe.PAUSED:case xe.READY:r.videoState.startTransitionTo(xe.PLAYING),r.params.connection.remotePlayerController.playOrPause();break;case xe.STOPPED:r.videoState.startTransitionTo(xe.READY),r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case xe.PLAYING:r.videoState.startTransitionTo(xe.PAUSED),r.params.connection.remotePlayerController.playOrPause();break;case xe.PAUSED:break;case xe.READY:r.videoState.startTransitionTo(xe.PAUSED),r.videoState.setState(xe.PAUSED);break;case xe.STOPPED:r.videoState.startTransitionTo(xe.READY),r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(a)}}}else t!==xe.STOPPED&&(r.videoState.startTransitionTo(xe.STOPPED),r.stop())},this.params=t,this.log=this.params.dependencies.logger.createComponentLog("ChromecastProvider"),this.log({message:"constructor, format: "+t.format}),this.params.output.isLive$.next(function(t){switch(t){case exports.VideoFormat.MPEG:case exports.VideoFormat.DASH:case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_SEP_VK:case exports.VideoFormat.DASH_ONDEMAND:case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_JS:case exports.VideoFormat.HLS_ONDEMAND:return!1;case exports.VideoFormat.HLS_LIVE:case exports.VideoFormat.DASH_LIVE:case exports.VideoFormat.DASH_LIVE_WEBM:return!0;default:return e.assertNever(t)}}(t.format)),this.handleRemoteVolumeChange({volume:this.params.connection.remotePlayer.volumeLevel,muted:this.params.connection.remotePlayer.isMuted});var i=this.params.connection.session.getMediaSession();i&&this.restoreSession(i),this.subscribe()}return t.prototype.destroy=function(){this.log({message:"[destroy]"}),this.subscription.unsubscribe()},t.prototype.subscribe=function(){var t=this;this.subscription.add(this.loadMediaTimeoutSubscription);var r=new e.Subscription;this.subscription.add(r),this.subscription.add(e.merge(this.videoState.stateChangeStarted$.pipe(e.map((function(e){return"stateChangeStarted$ "+JSON.stringify(e)}))),this.videoState.stateChangeEnded$.pipe(e.map((function(e){return"stateChangeEnded$ "+JSON.stringify(e)})))).subscribe((function(e){return t.log({message:"[videoState] "+e})})));var i=function(e,r){return t.subscription.add(e.subscribe(r))};if(this.params.output.isLive$.getValue())this.params.output.position$.next(0),this.params.output.duration$.next(0);else{var a=new e.Subject;r.add(a.pipe(e.debounce(500)).subscribe((function(){t.params.output.seekedEvent$.next()})));var n=NaN;r.add(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.CURRENT_TIME_CHANGED).subscribe((function(r){t.logRemoteEvent(r);var i=r.value;t.params.output.position$.next(i);var s=t.params.desiredState.seekPosition.getTransition();(e.isNonNullable(s)&&e.isNullable(s.to)||Math.abs(i-n)>5)&&a.next(i),n=i}))),r.add(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.DURATION_CHANGED).subscribe((function(e){t.logRemoteEvent(e),t.params.output.duration$.next(e.value)})))}i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MEDIA_LOADED_CHANGED),(function(e){t.logRemoteEvent(e),e.value?t.handleRemoteReady():(t.handleRemoteStop(),r.unsubscribe())})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_PAUSED_CHANGED),(function(e){t.logRemoteEvent(e),e.value?t.handleRemotePause():t.handleRemotePlay()})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.PLAYER_STATE_CHANGED),(function(r){t.logRemoteEvent(r);var i=t.params.connection.remotePlayer,a=r.value,n=t.params.output.isBuffering$.getValue(),s=a===chrome.cast.media.PlayerState.BUFFERING;switch(n!==s&&t.params.output.isBuffering$.next(s),a){case chrome.cast.media.PlayerState.IDLE:!t.params.output.isLive$.getValue()&&i.duration-i.currentTime<5&&t.params.output.endedEvent$.next(),t.handleRemoteStop(),V(t.params.desiredState.playbackState,exports.PlaybackState.STOPPED);break;case chrome.cast.media.PlayerState.PAUSED:t.handleRemotePause();break;case chrome.cast.media.PlayerState.PLAYING:t.handleRemotePlay();break;case chrome.cast.media.PlayerState.BUFFERING:break;default:e.assertNever(a)}})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.VOLUME_LEVEL_CHANGED),(function(e){t.logRemoteEvent(e),t.handleRemoteVolumeChange({volume:e.value})})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MUTED_CHANGED),(function(e){t.logRemoteEvent(e),t.handleRemoteVolumeChange({muted:e.value})})),i(e.merge(this.params.desiredState.playbackState.stateChangeStarted$,this.params.desiredState.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)),this.syncPlayback)},t.prototype.restoreSession=function(e){this.log({message:"restoreSession"});var t=this.params.connection.remotePlayer;if(e.playerState!==chrome.cast.media.PlayerState.IDLE){t.isPaused?(this.videoState.setState(xe.PAUSED),V(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):(this.videoState.setState(xe.PLAYING),V(this.params.desiredState.playbackState,exports.PlaybackState.PLAYING));var r=this.params.output.isLive$.getValue();this.params.output.duration$.next(r?0:t.duration),this.params.output.position$.next(r?0:t.currentTime),this.params.desiredState.seekPosition.setState(void 0)}},t.prototype.prepare=function(){var e=this.params.format;this.log({message:"[prepare] format: "+e});var t=this.createMediaInfo(e),r=this.createLoadRequest(t);this.loadMedia(r)},t.prototype.handleRemotePause=function(){var e=this.videoState.getState(),t=this.videoState.getTransition();(null==t?void 0:t.to)!==xe.PAUSED&&e!==xe.PLAYING||(this.videoState.setState(xe.PAUSED),V(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED))},t.prototype.handleRemotePlay=function(){var e=this.videoState.getState(),t=this.videoState.getTransition();(null==t?void 0:t.to)!==xe.PLAYING&&e!==xe.PAUSED||(this.videoState.setState(xe.PLAYING),V(this.params.desiredState.playbackState,exports.PlaybackState.PLAYING))},t.prototype.handleRemoteReady=function(){var e=this.videoState.getTransition();(null==e?void 0:e.to)===xe.READY&&this.videoState.setState(xe.READY)},t.prototype.handleRemoteStop=function(){this.videoState.getState()!==xe.STOPPED&&this.videoState.setState(xe.STOPPED)},t.prototype.handleRemoteVolumeChange=function(e){var t,r,i=this.params.output.volume$.getValue(),a={volume:null!==(t=e.volume)&&void 0!==t?t:i.volume,muted:null!==(r=e.muted)&&void 0!==r?r:i.muted};a.volume===i.volume&&a.muted==a.muted||this.params.output.volume$.next(a)},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next();var t=this.params.connection,r=t.remotePlayer,i=t.remotePlayerController;r.currentTime=e,i.seek()},t.prototype.stop=function(){this.params.connection.remotePlayerController.stop()},t.prototype.createMediaInfo=function(t){var r,i,a,n,s=this.params.source;switch(t){case exports.VideoFormat.MPEG:var o=s[t];e.assertNonNullable(o);var u=Object.keys(o).sort((function(e,t){return e===t?0:e===exports.VideoQuality.INVARIANT?1:t===exports.VideoQuality.INVARIANT?-1:F(e,t)?1:-1}))[0];e.assertNonNullable(u);var d=o[u];e.assertNonNullable(d),i=d,a="video/mp4",n=chrome.cast.media.StreamType.BUFFERED;break;case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_ONDEMAND:var l=s[t];e.assertNonNullable(l),i=l.url,a="application/x-mpegurl",n=chrome.cast.media.StreamType.BUFFERED;break;case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_SEP_VK:case exports.VideoFormat.DASH_ONDEMAND:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.DASH_WEBM:var c=s[t];e.assertNonNullable(c),i=c.url,a="application/dash+xml",n=chrome.cast.media.StreamType.BUFFERED;break;case exports.VideoFormat.HLS_LIVE:l=s[t];e.assertNonNullable(l),i=Ae(l.url),a="application/x-mpegurl",n=chrome.cast.media.StreamType.LIVE;break;case exports.VideoFormat.DASH_LIVE_WEBM:c=s[t];e.assertNonNullable(c),i=c.url,a="application/dash+xml",n=chrome.cast.media.StreamType.LIVE;break;case exports.VideoFormat.HLS_JS:case exports.VideoFormat.DASH:case exports.VideoFormat.DASH_LIVE:var p="Unsupported format for Chromecast",h=new Error(p);throw this.params.output.error$.next({id:"ChromecastProvider.createMediaInfo()",message:p,thrown:h}),h;default:return e.assertNever(t)}var f=new chrome.cast.media.MediaInfo(null!==(r=this.params.meta.videoId)&&void 0!==r?r:i,a);f.contentUrl=i,f.streamType=n,f.metadata=new chrome.cast.media.GenericMediaMetadata;var v=this.params.meta,m=v.title,S=v.subtitle;return e.isNonNullable(m)&&(f.metadata.title=m),e.isNonNullable(S)&&(f.metadata.subtitle=S),f},t.prototype.createLoadRequest=function(e){var t,r=new chrome.cast.media.LoadRequest(e);r.autoplay=!1;var i=this.params.desiredState.seekPosition.getTransition();return r.currentTime=i?this.params.output.isLive$.getValue()?0:null!==(t=i.to)&&void 0!==t?t:0:0,r},t.prototype.loadMedia=function(t){var r=this,i=this.params.connection.session.loadMedia(t),a=new Promise((function(t,i){r.loadMediaTimeoutSubscription.add(e.timeout(7e3).subscribe((function(){return i("timeout(7000)")})))}));Promise.race([i,a]).then((function(){r.log({message:"[loadMedia] completed, format: "+r.params.format});var e=r.params.desiredState.seekPosition;e.getTransition()&&e.setState(void 0),r.handleRemoteReady()}),(function(e){var t="[prepare] loadMedia failed, format: "+r.params.format+", reason: "+e;r.log({message:t}),r.params.output.error$.next({id:"ChromecastProvider.loadMedia",message:t,thrown:e})})).finally((function(){r.loadMediaTimeoutSubscription.unsubscribe()}))},t.prototype.logRemoteEvent=function(e){this.log({message:"[remoteEvent] "+JSON.stringify(e)})},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}($e||($e={}));var De,_e=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te($e.STOPPED),this.trackUrls={},this.textTracksManager=new D,this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition();if(i!==exports.PlaybackState.STOPPED){if(!r.videoState.getTransition()){var n=r.params.desiredState.videoTrack.getTransition(),s=r.params.desiredState.seekPosition.getTransition();if(t===$e.STOPPED)return r.videoState.startTransitionTo($e.READY),void r.prepare();if(n){var o=r.video.currentTime;return r.prepare(),void(s||r.params.desiredState.seekPosition.startTransitionTo(o))}var u=null==s?void 0:s.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(u)&&r.seek(u),t){case $e.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState($e.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo($e.PLAYING),r.playIfAllowed()));case $e.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo($e.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case $e.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo($e.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==$e.STOPPED&&(r.videoState.startTransitionTo($e.STOPPED),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState($e.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=_(t.container),this.params.output.element$.next(this.video),Object.entries(this.params.source).forEach((function(e,t){var i=f(e,2),a=i[0],n=i[1],s=t.toString(10);r.trackUrls[s]={track:{quality:a,id:s},url:n}})),this.params.output.availableVideoTracks$.next(Object.values(this.trackUrls).map((function(e){return e.track}))),this.params.output.isLive$.next(!1),this.subscribe()}return t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"MpegProvider",message:"MpegProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r,n))};o(s.timeUpdate$,i.position$),o(s.durationChange$,i.duration$),o(s.ended$,i.endedEvent$),o(s.error$,i.error$),o(s.isBuffering$,i.isBuffering$),o(s.currentBuffer$,i.currentBuffer$),o(s.firstBytes$,i.firstBytesEvent$),o(s.firstFrame$,i.firstFrameEvent$),o(s.seeked$,i.seekedEvent$),this.subscription.add(A(this.video,a.isLooped,n)),this.subscription.add($(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState($e.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState($e.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var r;(null===(r=t.videoState.getTransition())||void 0===r?void 0:r.to)===$e.READY&&t.videoState.setState($e.READY);var i=t.params.desiredState.videoTrack.getTransition();i&&e.isNonNullable(i.to)&&(t.params.desiredState.videoTrack.setState(i.to),t.params.output.currentVideoTrack$.next(t.trackUrls[i.to].track)),t.videoState.getState()===$e.PLAYING&&t.playIfAllowed()}),n)),this.subscription.add(a.autoVideoTrackSwitching.stateChangeStarted$.subscribe((function(){return a.autoVideoTrackSwitching.setState(!1)}),n)),this.textTracksManager.connect(this.video,a,i);var u=e.merge(a.playbackState.stateChangeStarted$,a.videoTrack.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.trackUrls={},this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.prepare=function(){var t,r,i=null!==(r=null===(t=this.params.desiredState.videoTrack.getTransition())||void 0===t?void 0:t.to)&&void 0!==r?r:this.params.desiredState.videoTrack.getState();e.assertNonNullable(i,"MpegProvider: track is not selected");var a=this.trackUrls[i].url;e.assertNonNullable(a,"MpegProvider: No url for "+i),this.video.setAttribute("src",a),this.video.load(),this.params.output.hostname$.next(Z(a))},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState($e.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.video.currentTime=e},t}(),Re=function(){function t(e,t,r,i,a,n){void 0===t&&(t=[]),this._failoverIndex=0,this._failoverCount=0,this._xhr=null,this._retryTimeout=0,this._url=e,this._failoverHosts=t,this._completeCb=r,this._progressCb=i,this._headersCb=a,this._errorCb=n,this._request()}return t.prototype._request=function(){var t=this;this._xhr=new XMLHttpRequest,this._xhr.open("GET",this._url,!0),this._xhr.overrideMimeType("text/plain; charset=x-user-defined");var r=!1;this._xhr.onreadystatechange=function(){var i,a,n,s,o,u,d,l;if(e.assertNonNullable(t._xhr),(null===(i=t._xhr)||void 0===i?void 0:i.status)>=400)return null===(a=t._errorCb)||void 0===a||a.call(t,"Http"+(null===(n=t._xhr)||void 0===n?void 0:n.status),"XHR response code "+(null===(s=t._xhr)||void 0===s?void 0:s.status)),void t.abort();if(4!==t._xhr.readyState||0!==t._xhr.status)try{if(t._xhr.readyState>=2&&!r){r=!0;var c=Object.fromEntries(t._xhr.getAllResponseHeaders().trim().split(/[\n\r]+/).map((function(e){return e.split(":").map((function(e){return e.trim()}))})));null===(o=t._headersCb)||void 0===o||o.call(t,new Headers(c))}else 4===t._xhr.readyState?null===(u=t._completeCb)||void 0===u||u.call(t,t._xhr.response):3===t._xhr.readyState&&(null===(d=t._progressCb)||void 0===d||d.call(t,t._xhr.response))}catch(e){throw null===(l=t._errorCb)||void 0===l||l.call(t,"XHR2CallbackError","xhr2 callback threw "+String(e),e),e}},this._xhr.onerror=function(){var e;null===(e=t._xhr)||void 0===e||e.abort(),t._retryTimeout=window.setTimeout((function(){var e;if(t._xhr)if(++t._failoverCount>=30)t._xhr=null,null===(e=t._errorCb)||void 0===e||e.call(t,"XHR2Failover","XHR failed, retrying failover host");else{var r=void 0;t._failoverIndex>=t._failoverHosts.length?(r=t._url,t._failoverIndex=0):(r=t._url.replace(function(e){var t=document.createElement("a");return t.href=e,t.host}(t._url),t._failoverHosts[t._failoverIndex]),t._failoverIndex++),t._xhr.open("GET",r,!0),t._xhr.send(null)}}),500)},this._xhr.send(null)},t.prototype.abort=function(){window.clearTimeout(this._retryTimeout),this._completeCb=this._progressCb=this._errorCb=void 0,this._xhr&&(this._xhr.abort(),this._xhr=null)},t}(),Ie=function(){function e(e){this._maxBufferDuration=Number.POSITIVE_INFINITY,this._isFull=!1,this._params=e,this._mediaSource=e.mediaSource,this._sourceBuffer=e.sourceBuffer,this._onDashCallback=e.onDashCallback}return e.prototype._appendBuffer=function(e,t){try{this._isFull=!1,(this._sourceBuffer.appendBuffer||this._sourceBuffer.append).bind(this._sourceBuffer)(e),null==t||t()}catch(e){if("QuotaExceededError"!==e.name)throw this._params.onError("AppendBuffer","Unknown Buffer error",e),e;this._isFull=!0;for(var r=this._sourceBuffer.buffered,i=0,a=0,n=r.length;a<n;a++)i+=r.end(a)-r.start(a);i&&(this._maxBufferDuration=Math.round(i))}},e.prototype.getMaxBufferDuration=function(){return this._maxBufferDuration},e.prototype.isFull=function(){return this._isFull},e.prototype.load=function(t,r,i,a,n,s,o){var u=this;this.abort((function(){var d=0,l=Date.now(),c=0,p=0,h=0,f=function(t){a(e._str2ua(t.substr(d))),d=t.length};u._lastXhr=new Re(t.baseURL+"&bytes="+r+"-"+i,t.failoverHosts,(function(e){u._lastXhr=void 0,f(e);var t=Date.now()-l;u._params.onBandwidthChange({size:e.length,duration:t,speed:8*e.length/(t/1e3)}),u._onDashCallback("loading",{size:e.length,done:!0}),null==n||n()}),(function(e){if(e.length-d>o&&f(e),0!==p){h=e.length-c;var t=Date.now()-p;h>=102400&&t>=1e3&&(u._params.onBandwidthChange({size:h,duration:t,speed:8*h/(t/1e3)}),h=0,c=e.length,p=Date.now()),u._onDashCallback("loading",{size:e.length,done:!1})}else p=Date.now()}),s,(function(e,t,r){return u._params.onError(e,t,r)}))}))},e.prototype.abort=function(e){var t,r=this;null===(t=this._lastXhr)||void 0===t||t.abort(),this._lastXhr=void 0,this._sbUpdatingStop(this._lastStreamUpdatingCallback),this._lastStreamUpdatingCallback=this._sbUpdatingWatch((function(){r._appendPromiseUint8Array&&(r._appendBuffer(r._appendPromiseUint8Array),r._appendPromiseUint8Array=void 0),r._lastStreamUpdatingCallback=r._sbUpdatingWatch((function(){"open"===r._mediaSource.readyState&&r._sourceBuffer.abort(),null==e||e()}))}))},e.prototype._sbUpdatingWatch=function(e){var t=this;if(this._sourceBuffer.updating){var r=function(){try{t._sbUpdatingStop(r),t._sbUpdatingWatch(e)}catch(e){throw t._params.onError("SourceBuffer","Source Buffer update error",e),e}};return this._sourceBuffer.addEventListener("updateend",r,!1),r}e()},e.prototype._sbUpdatingStop=function(e){e&&this._sourceBuffer.removeEventListener("updateend",e,!1)},e.prototype.append=function(t,r){var i=this;this._appendPromiseUint8Array?this._appendPromiseUint8Array=e._concatUint8(this._appendPromiseUint8Array,t):(this._appendPromiseUint8Array=t,this._lastStreamUpdatingCallback=this._sbUpdatingWatch((function(){i._appendPromiseUint8Array&&i._appendBuffer(i._appendPromiseUint8Array,(function(){i._appendPromiseUint8Array=void 0,r&&i._sbUpdatingWatch(r)}))})))},e.prototype.endOfStream=function(){var e=this;"open"===this._mediaSource.readyState&&this._sbUpdatingWatch((function(){return e._mediaSource.endOfStream()}))},e._concatUint8=function(e,t){var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(e,0),r.set(t,e.byteLength),r},e._str2ua=function(e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t},e.prototype.remove=function(e,t){var r=this;this._sbUpdatingWatch((function(){!r._sourceBuffer.updating&&r._sourceBuffer.remove&&r._sourceBuffer.remove(e,t),r._maxBufferDuration=Number.POSITIVE_INFINITY}))},e.prototype.destroy=function(){var e;null===(e=this._lastXhr)||void 0===e||e.abort(),this._sbUpdatingStop(this._lastStreamUpdatingCallback),"open"===this._mediaSource.readyState&&this._sourceBuffer.abort()},e}(),Ce=function(){function t(e){var t;this._representations=[],this._appendVector={},this._cachingPaused=!1,this._duration=0,this.STREAM_END_THRESHOLD=1,this._params=e,this._video=e.video,this._buffer=e.buffer,this._onDashCallback=null!==(t=e.onDashCallback)&&void 0!==t?t:function(){},this._config=e.config}return t.prototype._parseDurationFromISO8601=function(e){var t=function(e,t){var r=e?parseFloat(e.replace(",",".")):NaN;return(isNaN(r)?0:r)*t},r=/^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/.exec(e),i="-"===(null==r?void 0:r[1])?-1:1;t(null==r?void 0:r[2],i),t(null==r?void 0:r[3],i),t(null==r?void 0:r[4],i),t(null==r?void 0:r[5],i);return 3600*t(null==r?void 0:r[6],i)+60*t(null==r?void 0:r[7],i)+t(null==r?void 0:r[8],i)},t.prototype.getRepresentations=function(){return this._representations},t.prototype.attachSource=function(e,t){var r=this;new Re(e,t,(function(i){r.attachManifest(i,t,function(e){var t=document.createElement("a");return t.href=e,t.origin}(e))}),void 0,(function(e){r._params.onResponseHeaders(e)}),(function(e,t,i){return r._params.onError(e,t,i)}))},t.prototype.attachManifest=function(e,t,r){var i=this,a=(new DOMParser).parseFromString(e,"text/xml").documentElement,n=function(e,t){var r=e.attributes.getNamedItem(t);return r?r.value:null};this._duration=this._parseDurationFromISO8601(String(n(a,"mediaPresentationDuration")));var s=[],o=[];Array.prototype.forEach.call(a.getElementsByTagName("Representation"),(function(e){var i,a,u,d,l,c,p,h,f,v,m,S,b,g,y,T,E,P=e.getElementsByTagName("SegmentBase")[0],k=P&&n(P,"indexRange").split("-"),w=P&&P.getElementsByTagName("Initialization")[0],x=w&&n(w,"range").split("-");if(x&&k){var A=Number(null===(p=e.attributes.getNamedItem("bandwidth"))||void 0===p?void 0:p.value),$=(r?r+"/":"")+e.getElementsByTagName("BaseURL")[0].childNodes[0].data;s.push({width:Number(null===(h=e.attributes.getNamedItem("width"))||void 0===h?void 0:h.value),height:Number(null===(f=e.attributes.getNamedItem("height"))||void 0===f?void 0:f.value),bandwidth:A,baseURL:$,failoverHosts:t,indexFrom:Number(k[0]),indexTo:Number(k[1]),initFrom:Number(x[0]),initTo:Number(x[1]),codecs:null!==(m=null===(v=e.attributes.getNamedItem("codecs"))||void 0===v?void 0:v.value)&&void 0!==m?m:void 0,mimeType:null!==(b=null===(S=e.attributes.getNamedItem("mimeType"))||void 0===S?void 0:S.value)&&void 0!==b?b:void 0,bufferSize:.1*A/8,bufferLength:.1,name:null!==(y=null===(g=e.attributes.getNamedItem("okQuality"))||void 0===g?void 0:g.value)&&void 0!==y?y:void 0,id:null!==(E=null===(T=e.attributes.getNamedItem("id"))||void 0===T?void 0:T.value)&&void 0!==E?E:void 0})}else{var N=e.parentElement;if("text"===(null==N?void 0:N.getAttribute("contentType"))){var D=null!==(i=e.getAttribute("id"))&&void 0!==i?i:void 0,_=(r?r+"/":"")+(null===(l=null===(d=null===(u=null===(a=e.getElementsByTagName("BaseURL"))||void 0===a?void 0:a[0])||void 0===u?void 0:u.childNodes)||void 0===d?void 0:d[0])||void 0===l?void 0:l.data),R=null!==(c=N.getAttribute("lang"))&&void 0!==c?c:void 0;_&&o.push({id:D,url:_,language:R})}}})),s.length?(this._representations=s,o.forEach((function(e){var t=e.id,r=e.language,a=e.url,n=document.createElement("track");n.setAttribute("src",a),t&&n.setAttribute("id",t),r&&n.setAttribute("srclang",r),i._video.appendChild(n)})),this._representations.sort((function(e,t){return t.bandwidth-e.bandwidth})),this._params.onManifestReady(this._representations)):this._onDashCallback("error")},t.prototype._loadInitAndSidx=function(e,t){var r=this;if(e!==this._currentRepresentation)if(e.refs)this._stream.abort((function(){r._stream.append(e.initMessage,t)}));else{var i=Date.now();this._stream.load(e,e.initFrom,e.indexTo,(function(i){var a=e.initTo-e.initFrom+1;if(i.byteLength){e.initMessage=new Uint8Array(i.buffer,0,a);var n=new DataView(i.buffer);a+=12;var s=n.getUint32(a+4,!1);a+=8;var o=n.getUint32(a,!1),u=n.getUint32(a+4,!1)+(e.indexTo+1);a+=8;var d=n.getUint16(a+2,!1);a+=4,e.refs=[];for(var l=0;l<d;l+=1){var c=u+(2147483647&n.getUint32(a,!1)),p=o+n.getUint32(a+4,!1);a+=12,e.refs.push({fromTime:o/s,toTime:p/s,fromOffset:u,toOffset:c-1}),u=c,o=p}var h=e.refs[e.refs.length-1];h.toTime-h.fromTime<.3&&e.refs.pop(),r._stream.append(e.initMessage,t)}else r._params.onError("EmptyResponse","Empty response")}),void 0,(function(e){r._params.onResponseHeaders(e),r._params.onIdxRequestPing(Date.now()-i)}),e.indexTo-e.initFrom+1)}else t&&t()},t.prototype.startPlay=function(e){var t=this,r=window.MediaSource||window.WebKitMediaSource;if(r){var i=new r,a=void 0,n=void 0,s=function(){t._loopTimeout=window.setTimeout((function(){try{!function(){var r=t._findRef(t._video.currentTime);if(r&&!t._video.paused){if(!t._cachingPaused&&void 0!==t._lastLoadOffset&&t._lastLoadOffset-t._video.currentTime<t._config.FRONT_CACHE_DURATION&&t._lastLoadOffset-t._video.currentTime<t._stream.getMaxBufferDuration()){var i=t._stream.isFull()?t._findBufferRangeEnd(t._video.currentTime):t._lastLoadOffset;t._loadRef(t._params.selectRepresentation(t._representations),i)}var s,o=t._appendVector[String(r.fromTime)];if(o!==a&&(a=o,t._params.onRepresentationPlay(o)),t._findRef(r.toTime)){var u=t._buffer.getByTime(t._video.currentTime);if(!u)return void t._onDashCallback("buffering");(s=u.end-t._video.currentTime)<e.bufferLength&&(t._onDashCallback("buffering"),n!==u.end&&(n=u.end,window.setTimeout((function(){try{var e=t._buffer.getNextWithGap(u);e&&(t._video.currentTime=e.start)}catch(e){throw t._params.onError("GapSyncError","Seek Error "+String(e),e),e}}),1e3*s)))}}}()}catch(e){throw t._params.onError("LoopError","Dash Loop exception "+String(e),e),e}s()}),250)},o=function(){if(!t._stream)try{var r=i.addSourceBuffer(e.mimeType+'; codecs="'+e.codecs+'"');t._stream=new Ie({mediaSource:i,sourceBuffer:r,onBandwidthChange:t._params.onBandwidthChange,onError:t._params.onError,onDashCallback:t._onDashCallback})}catch(e){throw t._params.onError("DashSourceOpen","Source open exception "+String(e),e),e}t._loadInitAndSidx(e),i.duration||(i.duration=t._duration),t._loopTimeout||s(),i.removeEventListener("sourceopen",o),i.removeEventListener("webkitsourceopen",o)};i.addEventListener("sourceopen",o,!1),i.addEventListener("webkitsourceopen",o,!1),this._video&&(this._video.src=window.URL.createObjectURL(i),this._video.addEventListener("waiting",(function(){var e=t._video&&t._video.played.length;e&&!t._video.currentTime&&t._video.loop?t._video.duration-t._video.played.end(e-1)<t.STREAM_END_THRESHOLD&&t.seek(0):t._video.duration-t._video.currentTime<t.STREAM_END_THRESHOLD&&t._stream.endOfStream()})))}else this._params.onError("MediaSourceNotSupported","MediaSource is not supported")},t.prototype._loadRef=function(e,t,r){var i=this;void 0===r&&(r=!1),this._lastLoadOffset=void 0,this._loadInitAndSidx(e,(function(){i._currentRepresentation=e;var a=i._findRef(t);if(a){if(r){i._isLastRef(a)&&t>=a.toTime&&(t=a.fromTime);var n=i._findRef(i._video.currentTime),s=Math.abs(i._video.currentTime-t),o=i._video.duration<i._config.SEEK_IN_SEGMENT_THRESHOLD/1e3||a===n||s<=i._config.SEEK_IN_SEGMENT_DELTA/1e3;i._video.currentTime=o?t:a.fromTime}i._appendVector[String(a.fromTime)]=e,i._stream.load(e,a.fromOffset,a.toOffset,(function(e,t){return i._stream.append(e,t)}),(function(){i._lastLoadOffset=a.toTime,i._video.duration-i._lastLoadOffset<i.STREAM_END_THRESHOLD&&i._stream.endOfStream()}),(function(e){return i._params.onResponseHeaders(e)}),e.bufferSize)}}))},t.prototype.setQualityByRepresentation=function(e,t){var r=this;void 0===t&&(t=!1);var i=this._buffer.getByTime(this._video.currentTime),a=this._findRef(this._video.currentTime);if(i&&a){var n=.1;if(a.toTime<i.end+n){var s=this._findRef(a.toTime);s&&s.toTime<i.end+n?(this._buffer.smartRemove(a.fromTime-n,s.toTime+n,(function(e,t){return r._stream.remove(e,t)})),this._loadRef(e,s.toTime)):(this._buffer.smartRemove(a.fromTime-n,a.toTime+n,(function(e,t){return r._stream.remove(e,t)})),this._loadRef(e,a.toTime))}}else this._video.currentTime&&t&&this._loadRef(e,this._video.currentTime)},t.prototype.setQuality=function(e){return this.setQualityByRepresentation(this._representations[e])},t.prototype.pauseCaching=function(){this._cachingPaused=!0},t.prototype.resumeCaching=function(){this._cachingPaused=!1},t.prototype.seek=function(e,t){void 0===t&&(t=!1),this._stream&&this._buffer.getByTime(e)&&!t?this._video.currentTime=e:this._loadRef(this._params.selectRepresentation(this._representations),e,!0)},t.prototype.updateRefsForCurrentTime=function(){var t=this._video.currentTime;this._stream&&!e.isNullable(this._buffer.getByTime(t))||this._loadRef(this._params.selectRepresentation(this._representations),t,!1)},t.prototype._findRef=function(e){var t,r=null===(t=this._currentRepresentation)||void 0===t?void 0:t.refs;if(r){if(!Array.isArray(r)||0!==r.length){for(var i=void 0,a=0;a<r.length;a++){var n=r[a];if(n.fromTime<=e&&n.toTime>e)return n;n.fromTime>e&&(!i||n.fromTime<i.fromTime)&&(i=n)}if(!i){var s=r[r.length-1];if(e>s.toTime)return s}return i}this._params.onError("emptyrefs","Empty refs")}},t.prototype._isLastRef=function(e){var t,r=null===(t=this._currentRepresentation)||void 0===t?void 0:t.refs;if(!r)return!1;var i=r[r.length-1];return e.fromTime===i.fromTime},t.prototype._findBufferRangeEnd=function(e){for(var t=this._video.buffered.length;t-- >0;){var r=this._video.buffered.start(t),i=this._video.buffered.end(t);if(e>r&&e<i)return Math.round(10*i)/10}return e},t.prototype.destroy=function(){this._stream&&this._stream.destroy(),clearTimeout(this._loopTimeout),this._loopTimeout=void 0},t}();!function(e){e.STOPPED="stopped",e.MANIFEST_LOADED="manifest-loaded",e.INITIAL_REPRESENTATION_SELECTED="initial-representation-selected",e.METADATA_LOADED="metadata-loaded",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(De||(De={}));var Le,Oe=[De.PAUSED,De.PLAYING],Ve=function(){function t(t){var r=this;this.videoState=new te(De.STOPPED),this.subscription=new e.Subscription,this.representations$=new e.ValueSubject([]),this.currentRepresentation$=new e.ValueSubject(void 0),this.textTracksManager=new D,this.elementSize$=new e.ValueSubject(void 0),this.dashLiteEvents={idxRequestPing$:new e.Subject,responseHeaders$:new e.Subject,manifestReady$:new e.Subject,representationPlay$:new e.Subject,error$:new e.Subject},this.handleManifestReady=function(e){var t,i,a,n,s=[];try{for(var o=h(e),u=o.next();!u.done;u=o.next()){var d=u.value,l=null!==(n=null!==(a=d.name)&&void 0!==a?a:d.id)&&void 0!==n?n:d.height.toString(10),c=q(d),p=d.bandwidth/1e3,f={width:d.width,height:d.height};if(c){var v={id:l,quality:c,bitrate:p,size:f};s.push({track:v,representation:d})}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}r.representations$.next(s),r.params.output.availableVideoTracks$.next(s.map((function(e){return e.track}))),r.videoState.setState(De.MANIFEST_LOADED)},this.handleRepresentationPlay=function(e){var t,i=null===(t=r.representations$.getValue().find((function(t){return t.representation===e})))||void 0===t?void 0:t.track;i&&(r.params.output.currentVideoTrack$.next(i),r.params.desiredState.videoTrack.getTransition()&&r.params.desiredState.videoTrack.setState(i.id))},this.selectRepresentation=function(){var t=r.currentRepresentation$.getValue();return e.assertNonNullable(t,"Can't select representation. something went wrong"),t},this.syncPlayback=function(){var t=r.videoState.getState(),i=r.videoState.getTransition(),a=r.params.desiredState.playbackState.getState(),n=r.params.desiredState.playbackState.getTransition(),s=r.params.desiredState.seekPosition.getTransition();if(r.log({message:"[syncPlayback] videoState: "+t+"; videoTransition: "+JSON.stringify(i)+"; desiredPlaybackState: "+a+"; seekPositionTransition: "+JSON.stringify(s)+";"}),a!==exports.PlaybackState.STOPPED){if(!i){var o=null==s?void 0:s.to;switch((null==n?void 0:n.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&Oe.includes(t)&&r.seek(o),t){case De.STOPPED:return r.videoState.startTransitionTo(De.MANIFEST_LOADED),void r.prepare();case De.MANIFEST_LOADED:return void r.videoState.startTransitionTo(De.INITIAL_REPRESENTATION_SELECTED);case De.INITIAL_REPRESENTATION_SELECTED:return r.videoState.startTransitionTo(De.METADATA_LOADED),void r.dash.startPlay(r.selectRepresentation());case De.METADATA_LOADED:return r.videoState.startTransitionTo(De.READY),void r.dash.seek(null!=o?o:0);case De.READY:return void(a===exports.PlaybackState.PAUSED?(r.videoState.setState(De.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):a===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(De.PLAYING),r.playIfAllowed()));case De.PLAYING:return void(a===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(De.PAUSED),r.video.pause()):(null==n?void 0:n.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case De.PAUSED:return void(a===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(De.PLAYING),r.playIfAllowed()):(null==n?void 0:n.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==De.STOPPED&&(r.videoState.startTransitionTo(De.STOPPED),r.dash.destroy(),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState(De.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.log=this.params.dependencies.logger.createComponentLog("DashProvider"),e.merge(this.videoState.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,type:"start"}}))),this.videoState.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,type:"end"}})))).subscribe((function(e){var t=e.transition,i=e.type;r.log({message:"[videoState change] "+i+": "+JSON.stringify(t)})})),this.video=_(t.container),this.params.output.element$.next(this.video),this.params.output.isLive$.next(!1),"url"===this.params.source.type&&this.params.output.hostname$.next(Z(this.params.source.url)),this.buffer=new I(this.video),this.dash=new Ce({video:this.video,buffer:this.buffer,selectRepresentation:this.selectRepresentation,onIdxRequestPing:function(e){return r.dashLiteEvents.idxRequestPing$.next(e)},onResponseHeaders:function(e){return r.dashLiteEvents.responseHeaders$.next(e)},onManifestReady:function(e){return r.dashLiteEvents.manifestReady$.next(e)},onRepresentationPlay:function(e){return r.dashLiteEvents.representationPlay$.next(e)},onBandwidthChange:function(e){return r.params.dependencies.throughputEstimator.addRawSpeed(e.size,e.duration)},onError:function(e,t,i){r.log({message:"[DashLite error], "+e}),r.dashLiteEvents.error$.next({id:e,message:t,thrown:i})},config:{SEEK_IN_SEGMENT_THRESHOLD:this.params.tuning.dashSeekInSegmentDurationThreshold,SEEK_IN_SEGMENT_DELTA:this.params.tuning.dashSeekInSegmentAlwaysSeekDelta,FRONT_CACHE_DURATION:this.params.config.cacheDuration/1e3}}),this.subscribe()}return t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"DashProvider",message:"DashProvider internal logic error",thrown:e})},s=function(){var e=t.params.desiredState.autoVideoTrackSwitching.getState(),r=t.params.desiredState.autoVideoTrackSwitching.getTransition();return r?r.to:e},o=O(this.video),u=function(e,r){return t.subscription.add(e.subscribe(r,n))};u(o.timeUpdate$,i.position$),u(o.durationChange$,i.duration$),u(o.ended$,i.endedEvent$),u(o.error$,i.error$),u(o.isBuffering$,i.isBuffering$),u(o.firstFrame$,i.firstFrameEvent$),this.subscription.add(o.seeking$.subscribe((function(){e.isNullable(t.params.desiredState.seekPosition.getTransition())&&(t.videoState.getState()===De.PLAYING||t.videoState.getState()===De.PAUSED)&&t.dash.updateRefsForCurrentTime()}))),this.subscription.add(o.seeked$.subscribe(i.seekedEvent$,n)),this.subscription.add(A(this.video,a.isLooped,n)),this.subscription.add($(this.video,a.volume,o.volumeState$,n)),this.subscription.add(o.volumeState$.subscribe(this.params.output.volume$)),this.textTracksManager.connect(this.video,a,i),u(ee(this.video),this.elementSize$),this.subscription.add(o.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===De.READY&&t.videoState.setState(De.READY)}),n)).add(o.pause$.subscribe((function(){t.videoState.setState(De.PAUSED),V(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED)}))).add(o.playing$.subscribe((function(){t.videoState.setState(De.PLAYING),V(t.params.desiredState.playbackState,exports.PlaybackState.PLAYING)}),n)).add(o.loadedMetadata$.subscribe((function(){t.videoState.setState(De.METADATA_LOADED)}),n)).add(o.currentBuffer$.subscribe((function(e){t.buffer.fill(),i.currentBuffer$.next(e)}),n)).add(this.dashLiteEvents.error$.pipe(e.map((function(e){return{id:"DashLite_"+e.id,message:e.message,thrown:e.thrown}}))).subscribe(this.params.output.error$)).add(e.merge(this.params.desiredState.videoTrack.transitionStarted$,this.params.desiredState.autoVideoTrackSwitching.transitionStarted$,this.representations$,this.params.dependencies.throughputEstimator.rttAdjustedThroughput$,this.params.output.element$,this.elementSize$,e.fromEvent(this.video,"progress")).pipe(e.map((function(){var r,i,a,n=t.currentRepresentation$.getValue(),o=t.representations$.getValue(),u=t.params.desiredState.autoVideoTrackSwitching.getTransition(),d=t.params.desiredState.videoTrack.getState(),l=t.params.dependencies.throughputEstimator.rttAdjustedThroughput$.getValue(),c=t.elementSize$.getValue(),p=s();if(u&&t.params.desiredState.autoVideoTrackSwitching.setState(u.to),!p&&e.isNonNullable(d))a=d;else{var h=X(t.video.buffered,1e3*t.video.currentTime),f=Math.min(h/t.params.tuning.dash.forwardBufferTarget,1);a=null===(r=K(o.map((function(e){return e.track})),{container:c,throughput:l,tuning:t.params.tuning.autoTrackSelection,forwardBufferHealth:f,currentRepresentation:n}))||void 0===r?void 0:r.id}return e.isNonNullable(a)?null===(i=o.find((function(e){return e.track.id===a})))||void 0===i?void 0:i.representation:void 0})),e.filterChanged()).subscribe(this.currentRepresentation$,n)).add(e.combine({needToSelectRepresentation:this.videoState.stateChangeStarted$.pipe(e.filter((function(e){return e.to===De.INITIAL_REPRESENTATION_SELECTED}))),currentRepresentationSelected:this.currentRepresentation$.pipe(e.filter(e.isNonNullable))}).pipe(e.once()).subscribe((function(){return t.videoState.setState(De.INITIAL_REPRESENTATION_SELECTED)}),n)).add(this.currentRepresentation$.pipe(e.filter(e.isNonNullable),e.filterChanged((function(e,r){return t.params.tuning.autoTrackSelection.lazyQualitySwitch&&s()?e.height<=r.height:e===r}))).subscribe((function(e){var r=X(t.video.buffered,1e3*t.video.currentTime),i=Math.min(r/t.params.tuning.dash.forwardBufferTarget,1);(!t.params.tuning.autoTrackSelection.lazyQualitySwitch||i<=.5||!s())&&(t.dash.setQualityByRepresentation(e,!0),t.params.output.hostname$.next(Z(e.baseURL)))}),n)).add(this.dashLiteEvents.responseHeaders$.subscribe((function(e){var r=re(e),i=r.type,a=r.reused;t.params.output.httpConnectionType$.next(i),t.params.output.httpConnectionReused$.next(a)}))).add(this.dashLiteEvents.idxRequestPing$.pipe(e.once()).subscribe(this.params.output.firstBytesEvent$)).add(this.dashLiteEvents.idxRequestPing$.subscribe((function(e){return t.params.dependencies.throughputEstimator.addRawRtt(e)}))).add(this.dashLiteEvents.manifestReady$.subscribe(this.handleManifestReady,n)).add(this.dashLiteEvents.representationPlay$.pipe(e.filter(e.isNonNullable)).subscribe(this.handleRepresentationPlay,n)).add(e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)).subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0),this.buffer.destroy(),this.dash.destroy()},t.prototype.prepare=function(){var t=this.params.source;switch(t.type){case"url":this.dash.attachSource(t.url);break;case"raw":this.dash.attachManifest(t.raw);break;default:return e.assertNever(t)}},t.prototype.seek=function(e){this.log({message:"[seek] position: "+e}),this.params.output.willSeekEvent$.next(),this.dash.seek(e)},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(De.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t}(),Me=function(e){return e.range?e.range.split("-").map((function(e){return parseInt(e,10)})):[NaN,NaN]},Be=function(){function e(e){this.params=e,this.dashJsRequestQueue=new Map,this.activeRequests=new Map}return e.prototype.setMetrics=function(e){this.dashMetrics=e},e.prototype.queueDashJSRequest=function(e){var t,r=e.request.url,i=null!==(t=this.dashJsRequestQueue.get(r))&&void 0!==t?t:[];i.push(e),this.dashJsRequestQueue.set(r,i)},e.prototype.executeNextRequests=function(){return c(this,void 0,void 0,(function(){var e,t,r,i,a,n,s,o,u,d,l,c,v;return p(this,(function(p){try{for(e=h(this.dashJsRequestQueue.entries()),t=e.next();!t.done;t=e.next()){if(r=f(t.value,2),i=r[0],a=r[1],n=this.activeRequests.get(i)){if(a.length&&this.onBigRequestProgress(n),!(s=a[0])||!s.request.range)continue;if(o=f(Me(s.request),2),u=o[0],d=o[1],u>=n.from&&d<=n.to)continue;this.activeRequests.delete(i)}a.length&&(l=this.sendBigRequest(i,a.map((function(e){return e.request}))),this.activeRequests.set(i,l))}}catch(e){c={error:e}}finally{try{t&&!t.done&&(v=e.return)&&v.call(e)}finally{if(c)throw c.error}}return[2]}))}))},e.prototype.abort=function(e){var t,r,i;if(e){var a=e.request,n=(null!==(i=this.dashJsRequestQueue.get(a.url))&&void 0!==i?i:[]).includes(e),s=this.activeRequests.get(a.url);n&&s&&s.abortController.abort()}else try{for(var o=h(this.activeRequests.values()),u=o.next();!u.done;u=o.next()){u.value.abortController.abort()}}catch(e){t={error:e}}finally{try{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}},e.prototype.destroy=function(){this.abort(),this.dashMetrics=void 0,this.dashJsRequestQueue.clear(),this.activeRequests.clear()},e.prototype.sendBigRequest=function(t,r){for(var i=this,a=r.map(Me),n=a[0][0],s=a[0][1],o=1;o<a.length&&s<this.params.minDataSize;o++){var u=a[o][1];u-n<=2*this.params.minDataSize&&(s=Math.max(s,u))}s=0===n?Math.max(s,n+this.params.minInitSize):Math.max(s,n+this.params.minDataSize);var d=new URL(t,location.href);d.searchParams.append("bytes",n+"-"+s);var l=d.toString(),h=new AbortController,v=h.signal,m={url:t,from:n,to:s,loaded:0,data:null,abortController:h};v.addEventListener("abort",(function(){return i.onBigRequestAbort(m)}));var S=function(e){var t,r;throw null===(r=(t=i.params).onError)||void 0===r||r.call(t,{id:"BigRequestParsing",message:"Error parsing response data",thrown:e}),e};return fetch(l,{signal:v}).then((function(t){var r,a,n;if(t.ok&&t.body){var s=f(t.body.tee(),2),o=s[0],u=s[1];null===(a=(r=i.params).onDownloadStream)||void 0===a||a.call(r,u);var d=o.getReader(),l=parseInt(null!==(n=t.headers.get("Content-Length"))&&void 0!==n?n:"",10);m.data=new ArrayBuffer(l);var h=new Uint8Array(m.data),v=function(t){var r=t.done,a=t.value;return c(i,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return r?(this.onBigRequestProgress(m),[3,3]):[3,1];case 1:return a?(h.set(a,m.loaded),m.loaded+=a.byteLength,this.onBigRequestProgress(m),[4,null==d?void 0:d.read().then(v,e.suppressStreamErrors).catch(S)]):[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))};null==d||d.read().then(v,e.suppressStreamErrors).catch(S)}else i.onBigRequestError(m)}),e.suppressAbort).catch((function(e){return i.onBigRequestError(m,e)})),m},e.prototype.onBigRequestProgress=function(e){var t,r,i,a,n,s,o,u,d,l=e.url,c=e.from,p=e.to,v=e.loaded,m=e.data;if(this.activeRequests.has(l)&&m){var S=null!==(i=this.dashJsRequestQueue.get(l))&&void 0!==i?i:[],b=function(e){var t=e.request,r=f(Me(t),2),i=r[0],h=r[1],S=i>=c&&h<=c+v,b=c>=i&&c+v<h,y=m.slice(i-c,Math.min(h-c+1,v));(S||b)&&(t.requestStartDate=null!==(a=t.requestStartDate)&&void 0!==a?a:new Date,t.firstByteDate=null!==(n=t.firstByteDate)&&void 0!==n?n:new Date,t.bytesLoaded=y.byteLength,t.bytesTotal=p-c),S?(t.requestEndDate=new Date,g.dashJsRequestQueue.set(l,(null!==(s=g.dashJsRequestQueue.get(l))&&void 0!==s?s:[]).filter((function(t){return t!==e}))),null===(o=e.success)||void 0===o||o.call(e,y,"",l),null===(u=g.dashMetrics)||void 0===u||u.addHttpRequest(t,l,200,{},[])):b&&(null===(d=e.progress)||void 0===d||d.call(e,{loaded:v,total:p-c,lengthComputable:!0,stream:!0}))},g=this;try{for(var y=h(S),T=y.next();!T.done;T=y.next()){b(T.value)}}catch(e){t={error:e}}finally{try{T&&!T.done&&(r=y.return)&&r.call(y)}finally{if(t)throw t.error}}}},e.prototype.onBigRequestError=function(e,t){var r,i,a,n,s,o,u=e.url,d=e.from,l=e.to;if(null===(n=(a=this.params).onError)||void 0===n||n.call(a,{id:"BigRequest",message:"Download error",thrown:t}),this.activeRequests.has(u)){var c=null!==(s=this.dashJsRequestQueue.get(u))&&void 0!==s?s:[];try{for(var p=h(c),v=p.next();!v.done;v=p.next()){var m=v.value,S=f(Me(m.request),2),b=S[0],g=S[1];(b>=d&&b<l||g>d&&g<=l)&&(null===(o=null==m?void 0:m.error)||void 0===o||o.call(m,m.request,String(t)))}}catch(e){r={error:e}}finally{try{v&&!v.done&&(i=p.return)&&i.call(p)}finally{if(r)throw r.error}}if(this.activeRequests.delete(u),t)throw t}},e.prototype.onBigRequestAbort=function(e){var t,r,i,a,n=e.url,s=e.from,o=e.to;if(this.activeRequests.has(n)){var u=null!==(i=this.dashJsRequestQueue.get(n))&&void 0!==i?i:[];try{for(var d=h(u),l=d.next();!l.done;l=d.next()){var c=l.value,p=f(Me(c.request),2),v=p[0],m=p[1];(v>=s&&v<o||m>s&&m<=o)&&(null===(a=null==c?void 0:c.abort)||void 0===a||a.call(c,c.request))}}catch(e){t={error:e}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(t)throw t.error}}this.activeRequests.delete(n)}},e.suppressAbort=function(e){if(!(e instanceof DOMException)||"AbortError"!==e.name&&20!==e.code)throw e},e.suppressStreamErrors=function(){},e}(),Ue=function(){function e(e,t,r){this.baseLoader=e,this.config=r,this.bigRequest=t,t.setMetrics(r.dashMetrics)}return e.shouldDelegateToBase=function(e){return"download"!==e.action||"text"===e.mediaType||!e.range||"arraybuffer"!==e.responseType},e.prototype.load=function(t){var r=t.request;if(e.shouldDelegateToBase(r))return this.baseLoader.load(t);this.bigRequest.queueDashJSRequest(t),this.bigRequest.executeNextRequests()},e.prototype.abort=function(t){if(!t)return this.baseLoader.abort(),void this.bigRequest.abort();var r=t.request;e.shouldDelegateToBase(r)?this.baseLoader.abort(t):this.bigRequest.abort(t)},e}(),Fe=function(e,t){var r=new Be(t);return e.extend("SchemeLoaderFactory",(function(){var e=this.parent.getLoader;return{getLoader:function(t){return function(e,t){return function(r){return{create:function(i){var a=e(r).create(i);return new Ue(a,t,i)}}}}(e(t),r)}}}),!0),function(){return r.destroy()}},He=function(t){var r=new e.ValueSubject(1/0),i=new e.Subject,a=NaN,n=!1,s=function(t){var i,a,n;if(t.getAllResponseHeaders().includes("x-playback-duration")){var s=parseInt(null!==(i=t.getResponseHeader("X-Playback-Duration"))&&void 0!==i?i:"",10),o=parseInt(null!==(a=t.getResponseHeader("X-Playback-Duration-Millis"))&&void 0!==a?a:"",10),u=null!==(n=null!=o?o:1e3*s)&&void 0!==n?n:NaN;e.isNonNullable(u)&&!isNaN(u)&&r.next(u)}},o=function(e){e.readyState>=2&&!n&&(n=!0,i.next(Date.now()-a))};return t.extend("XHRLoader",(function(){var e=this.parent,t=e.load.bind(e);return{load:function(e){if("MPD"===e.request.type){var r=e.onload,i=e.progress;e.onload=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return s(this),r.apply(void 0,v([],f(e),!1))},e.progress=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o(this),i.apply(void 0,v([],f(e),!1))},a=Date.now(),n=!1}return t(e)}}}),!0),{playbackDuration$:r,ping$:i}},qe=function(){function e(){this.pausedTime=0,this.streamOffset=0,this.pauseTimestamp=0}return e.prototype.getTotalPausedTime=function(){return this.pausedTime+this.getCurrentPausedTime()},e.prototype.getCurrentPausedTime=function(){return this.pauseTimestamp>0?Date.now()-this.pauseTimestamp:0},e.prototype.getStreamOffset=function(){return this.streamOffset},e.prototype.getTotalOffset=function(){return this.getTotalPausedTime()+this.streamOffset},e.prototype.pause=function(){0===this.pauseTimestamp&&(this.pauseTimestamp=Date.now())},e.prototype.resume=function(){this.pauseTimestamp>0&&(this.pausedTime+=this.getCurrentPausedTime(),this.pauseTimestamp=0)},e.prototype.resetTo=function(e){this.streamOffset=e,this.pauseTimestamp=0,this.pausedTime=0},e}(),Ge={};!function(e){e.DOWNLOADING_LIB="downloading_lib",e.STOPPED="stopped",e.STREAM_INITIALIZED="stream_initialized",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(Le||(Le={}));var je=function(t,r){return new e.Observable((function(e){var i=function(t){return e.next(t)};return t.on(r,i),function(){return t.off(r,i)}}))},Ye=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(Le.DOWNLOADING_LIB),this.textTracksManager=new D,this.videoTracks=[],this.isLive$=new e.ValueSubject(void 0),this.maxSeekBackTime$=new e.ValueSubject(1/0),this.availableFrom$=new e.ValueSubject(void 0),this.elementSize$=new e.ValueSubject(void 0),this.liveOffset=new qe,this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.seekPosition.getTransition(),s=r.isLive$.getValue();if(!r.videoState.getTransition()&&t!==Le.DOWNLOADING_LIB&&t!==Le.STREAM_INITIALIZED){var o=null==n?void 0:n.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&t!==Le.STOPPED&&i!==exports.PlaybackState.STOPPED&&(s?r.seek(o+ze(r.liveOffset.getTotalPausedTime())):r.seek(o)),i){case exports.PlaybackState.STOPPED:switch(t){case Le.STOPPED:break;case Le.PLAYING:case Le.PAUSED:case Le.READY:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case Le.PLAYING:break;case Le.PAUSED:s&&(r.liveOffset.getTotalPausedTime()<r.params.config.maxPausedTime&&r.liveOffset.getTotalOffset()<r.maxSeekBackTime$.getValue()?(r.liveOffset.resume(),r.params.output.position$.next(ze(r.liveOffset.getTotalOffset()))):r.seek(ze(r.liveOffset.getTotalOffset()))),r.play();break;case Le.READY:r.play();break;case Le.STOPPED:r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case Le.PLAYING:r.pause(),r.liveOffset.pause();break;case Le.PAUSED:break;case Le.READY:r.videoState.setState(Le.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case Le.STOPPED:r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=_(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(Z(this.params.source.url)),this.loadDashJs()}return t.prototype.loadDashJs=function(){var e=this,t=!1,i=function(r){var i,a;t||e.params.output.error$.next({id:"timeout"===r?"DashJSTimedOut":"DashJSLoadingError",message:"Dash.js failed to load: "+(null===(a=null===(i=r)||void 0===i?void 0:i.toString)||void 0===a?void 0:a.call(i)),thrown:r}),t=!0},a=window.setTimeout((function(){return i("timeout")}),5e3);Promise.resolve().then((function(){return r(require("dashjs/dist/dash.mediaplayer.min.js"))})).then((function(r){t||(Ge.MediaPlayer=r.MediaPlayer,Ge.Debug=r.Debug,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){var t=this;e.assertNonNullable(Ge.MediaPlayer,"dashjs not loaded"),e.assertNonNullable(Ge.Debug,"dashjs not loaded"),this.player=Ge.MediaPlayer().create(),this.player.updateSettings({debug:{logLevel:3},streaming:{buffer:{fastSwitchEnabled:!0},abr:{limitBitrateByPortal:this.params.tuning.autoTrackSelection.limitByContainer,usePixelRatioInLimitBitrateByPortal:this.params.tuning.autoTrackSelection.usePixelRatio,additionalAbrRules:{insufficientBufferRule:!1}},utcSynchronization:{useManifestDateHeaderTimeSource:!0}}}),(this.params.format===exports.VideoFormat.DASH_WEBM||this.params.format===exports.VideoFormat.DASH_LIVE_WEBM)&&this.params.tuning.useWebmBigRequest?this.destroyBigRequest=Fe(this.player,{minInitSize:this.params.tuning.bigRequestMinInitSize,minDataSize:this.params.tuning.bigRequestMinDataSize,onError:function(e){return t.params.output.error$.next(e)},onDownloadStream:function(e){return t.params.dependencies.throughputEstimator.trackStream(e)}}):this.params.tuning.stripRangeHeader&&this.player.extend("HTTPLoader",(function(){var e=this.parent.load;return{load:function(t){if(t.request&&t.request.range){var r=f(t.request.range.split("-").map((function(e){return parseInt(e,10)})),2),i=r[0],a=r[1],n=new URL(t.request.url,location.href);n.searchParams.append("bytes",i+"-"+a),t.request.url=n.toString(),t.request.range=void 0}e(t)}}}),!0),function(e){var t,r=!1,i=!1;e.on("playbackTimeUpdated",(function(e){var a=e.timeToEnd;i=a<=3,r&&i&&(null==t||t())})),e.extend("MediaSourceController",(function(){var e=this.parent.signalEndOfStream;return{signalEndOfStream:function(a){t=function(){return e(a)},(r=!0)&&i&&(null==t||t())}}}),!0)}(this.player),this.player.clearDefaultUTCTimingSources(),this.subscribe(),this.videoState.setState(Le.STOPPED)},t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"DashIFProvider",message:"DashIFProvider internal logic error",thrown:e})},s=function(e,r){return t.subscription.add(e.subscribe(r,n))};s(ee(this.video),this.elementSize$),s(je(this.player,"error").pipe(e.map((function(e){return{id:"DashJS#"+("object"==typeof e.error?e.error.code:e.error),message:"object"==typeof e.error?e.error.message:void 0}}))),i.error$),s(je(this.player,"playbackError").pipe(e.map((function(e){return{id:"DashJSPlayback",message:e.error}}))),i.error$);var o=je(this.player,"qualityChangeRendered").pipe(e.filter((function(e){return"video"===e.mediaType})),e.map((function(e){var r,i=e.newQuality;return null===(r=t.videoTracks.find((function(e){return e.bitrateInfo.qualityIndex===i})))||void 0===r?void 0:r.track})));o.pipe(e.filter(e.isNonNullable)).subscribe(i.currentVideoTrack$),this.subscription.add(this.videoState.transitionEnded$.pipe(e.filter((function(e){return e.to===Le.STREAM_INITIALIZED})),e.once()).subscribe((function(){t.subscription.add(x(a.videoTrack,(function(){var e,r,i=t.player.getQualityFor("video");return null===(r=null===(e=t.videoTracks.find((function(e){return e.bitrateInfo.qualityIndex===i})))||void 0===e?void 0:e.track)||void 0===r?void 0:r.id}),(function(r){var i;if(!e.isNullable(r)){var a=null===(i=t.videoTracks.find((function(e){return e.track.id===r})))||void 0===i?void 0:i.bitrateInfo;a&&t.player.setQualityFor("video",a.qualityIndex)}}),{changed$:o.pipe(e.map((function(e){return null==e?void 0:e.id}))),onError:n}))}),n)),this.subscription.add(x(a.autoVideoTrackSwitching,(function(){var e,r,i;return null===(i=null===(r=null===(e=t.player.getSettings().streaming)||void 0===e?void 0:e.abr)||void 0===r?void 0:r.autoSwitchBitrate)||void 0===i?void 0:i.video}),(function(e){return t.player.updateSettings({streaming:{abr:{autoSwitchBitrate:{video:e}}}})}),{onError:n})),s(je(this.player,"bufferStateChanged").pipe(e.filter((function(e){return"video"===e.mediaType})),e.map((function(e){return"bufferStalled"===e.state}))),i.isBuffering$),s(je(this.player,"fragmentLoadingStarted").pipe(e.map((function(e){return Z(e.request.url)}))),i.hostname$),s(je(this.player,"streamInitialized"),(function(e){var r,a,n=e.streamInfo,s=n.duration,o=n.manifestInfo,u=o.isDynamic,d=o.availableFrom;t.isLive$.next(u),t.availableFrom$.next(d.getTime()),u||i.duration$.next(s),t.videoTracks=[];var l,c=t.player.getQualityFor("video");try{for(var p=h(t.player.getBitrateInfoListFor("video")),f=p.next();!f.done;f=p.next()){var v=f.value,m=v.qualityIndex.toString(10),S=q(v),b=v.bitrate/1e3,g={width:v.width,height:v.height};if(S){var y={id:m,quality:S,bitrate:b,size:g};t.videoTracks.push({track:y,bitrateInfo:v}),v.qualityIndex===c&&(l=y)}}}catch(e){r={error:e}}finally{try{f&&!f.done&&(a=p.return)&&a.call(p)}finally{if(r)throw r.error}}i.availableVideoTracks$.next(t.videoTracks.map((function(e){return e.track}))),l&&i.currentVideoTrack$.next(l),t.videoState.setState(Le.STREAM_INITIALIZED),t.videoState.startTransitionTo(Le.READY)})),s(je(this.player,"fragmentLoadingCompleted"),(function(e){var r=e.request;if(r.requestEndDate&&r.firstByteDate&&r.bytesLoaded){var i=r.requestEndDate.getTime()-r.firstByteDate.getTime(),a=r.bytesLoaded;t.params.dependencies.throughputEstimator.addRawSpeed(a,i)}})),s(e.merge(this.params.dependencies.throughputEstimator.throughput$,this.elementSize$),(function(){if(t.params.desiredState.autoVideoTrackSwitching.getState()&&t.videoTracks.length){var e=t.params.dependencies.throughputEstimator.throughput$.getValue(),r=K(t.videoTracks.map((function(e){return e.track})),{container:t.elementSize$.getValue(),throughput:e,tuning:t.params.tuning.autoTrackSelection}),i=t.videoTracks.find((function(e){return e.track===r}));(null==i?void 0:i.bitrateInfo)&&t.player.setQualityFor("video",null==i?void 0:i.bitrateInfo.qualityIndex,!1)}})),s(e.combine({maxSeekBackTime:this.maxSeekBackTime$,isLive:this.isLive$.pipe(e.filter(e.isNonNullable))}).pipe(e.filter((function(e){return e.isLive})),e.map((function(e){var t=e.maxSeekBackTime;return ze(t)}))),this.params.output.duration$);var u=je(this.player,"playbackTimeUpdated").pipe(e.map((function(e){var t=e.time;return null!=t?t:0})));s(e.combine({availableFrom:this.availableFrom$.pipe(e.filter(e.isNonNullable)),currentTime:u}),(function(e){var r=e.availableFrom,i=e.currentTime;return t.params.output.liveTime$.next(r+1e3*i)})),s(u.pipe(e.filter((function(){return!1===t.isLive$.getValue()}))),i.position$),s(je(this.player,"playbackSeeked"),(function(){return i.seekedEvent$.next()})),s(je(this.player,"playbackEnded"),i.endedEvent$),s(je(this.player,"playbackProgress").pipe(e.map((function(){return C(t.video.buffered,t.video.currentTime)}))),i.currentBuffer$),s(je(this.player,"playbackPlaying"),(function(){t.videoState.setState(Le.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)})),s(je(this.player,"playbackNotAllowed"),(function(){t.player.isMuted()?(t.player.setMute(!1),t.videoState.setState(Le.PAUSED),V(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)):(t.player.setMute(!0),t.player.play())})),s(je(this.player,"playbackPaused"),(function(){t.videoState.setState(Le.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)})),s(je(this.player,"canPlay"),(function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===Le.READY&&t.videoState.setState(Le.READY)})),s(this.isLive$,i.isLive$),s(ee(this.video),(function(){t.player.isReady()&&t.player.updatePortalSize()})),s(e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)),this.syncPlayback);var d=He(this.player),l=d.playbackDuration$,c=d.ping$;s(l,this.maxSeekBackTime$),s(c.pipe(e.once()),i.firstBytesEvent$),this.params.tuning.flushShortLoopedBuffers&&s(e.combine({isLive:this.isLive$,isShort:i.duration$.pipe(e.map((function(e){return e<60})))}),(function(e){var r=e.isLive,i=e.isShort,a=!r&&i;t.player.updateSettings({streaming:{buffer:{flushBufferAtTrackSwitch:a}}})})),s(u.pipe(e.filter((function(e){return e>t.params.tuning.insufficientBufferRuleMargin})),e.once()),(function(){return t.player.updateSettings({streaming:{abr:{additionalAbrRules:{insufficientBufferRule:!0}}}})})),this.textTracksManager.connect(this.video,a,i),this.subscription.add(je(this.player,"manifestLoaded").pipe(e.once()).subscribe((function(){var r=Date.now();t.subscription.add(je(t.player,"playbackPlaying").pipe(e.once()).subscribe((function(){return i.firstFrameEvent$.next(Date.now()-r)}),n))}),n)),this.subscription.add(A(this.video,a.isLooped,n));var p=O(this.video).volumeState$;this.subscription.add($(this.video,a.volume,p,n)),this.subscription.add(p.subscribe(i.volume$,n))},t.prototype.stop=function(){this.params.output.position$.next(0),this.params.output.duration$.next(1/0),this.params.output.currentBuffer$.next(void 0),this.params.output.hostname$.next(void 0),this.player.attachSource(null),this.player.attachView(null),this.player.initialize(),this.player.clearDefaultUTCTimingSources(),this.videoState.setState(Le.STOPPED),V(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t.prototype.prepare=function(){this.videoState.startTransitionTo(Le.STREAM_INITIALIZED),this.player.initialize(),this.player.clearDefaultUTCTimingSources(),this.player.attachView(this.video),this.player.attachSource(this.params.source.url)},t.prototype.seek=function(e){if(this.params.output.willSeekEvent$.next(),this.isLive$.getValue()){var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(ze(r));var i=Ae(this.params.source.url,this.liveOffset.getTotalOffset()/1e3,Ee.PLAYBACK_SHIFT);this.player.attachSource(i)}else this.player.seek(e)},t.prototype.play=function(){this.videoState.startTransitionTo(Le.PLAYING),this.player.play()},t.prototype.pause=function(){this.videoState.startTransitionTo(Le.PAUSED),this.video.pause()},t.prototype.destroy=function(){var e,t;this.subscription.unsubscribe(),this.textTracksManager.destroy();try{null===(e=this.player)||void 0===e||e.destroy()}catch(e){}this.video.remove(),this.params.output.element$.next(void 0),null===(t=this.destroyBigRequest)||void 0===t||t.call(this)},t}(),ze=function(e){return-e/1e3};function Qe(){return e.now()}function We(e){return Qe()-e}function Je(e){var t=e.split("/"),r=t.slice(0,t.length-1).join("/"),i=/^([a-z]+:)?\/\//i;return{resolve:function(e,t,a){void 0===a&&(a=!1),function(e){return i.test(e)}(e)||(e.startsWith("/")||(e="/"+e),e=r+e);var n=e.indexOf("?")>-1?"&":"?";return a&&(e+=n+"lowLat=1",n="&"),t&&(e+=n+"_rnd="+Math.floor(999999999*Math.random())),e}}}function Ke(t,r,i,a){var n,s,o,u,d,l=window.XMLHttpRequest,c=!1,p=0,h=!1,f="arraybuffer",v=7e3,m=2e3,S=function(){if(!c){e.assertNonNullable(u);var t=We(u);t<m?setTimeout(S,m-t):((m*=2)>v&&(m=v),s&&s.abort(),s=new l,g())}},b=function(){if(!c){if(--p>=0)return S(),void(a&&a());c=!0,d&&d(),i&&i()}},g=function(){u=Qe(),(s=new l).open("get",t);var i,a=0,p=0,v=function(){return e.assertNonNullable(u),Math.max(u,Math.max(i||0,p||0))};if(n&&s.addEventListener("progress",(function(e){var t=Qe();n.updateChunk&&e.loaded>a&&(n.updateChunk(v(),e.loaded-a),a=e.loaded,i=t)})),o&&(s.timeout=o,s.addEventListener("timeout",(function(){return b()}))),s.addEventListener("load",(function(){if(!c){e.assertNonNullable(s);var t=s.status;if(t>=200&&t<300){if(s.response.byteLength&&n){var i=s.response.byteLength-a;i&&n.updateChunk&&n.updateChunk(v(),i)}d&&d(),s&&r(s.response)}else b()}})),s.addEventListener("error",(function(){b()})),h){var m=function(){e.assertNonNullable(s),s.readyState===XMLHttpRequest.HEADERS_RECEIVED&&(p=Qe(),s.removeEventListener("readystatechange",m))};s.addEventListener("readystatechange",m)}return s.responseType=f,s.send(),y},y={withBitrateReporting:function(e){return n=e,y},withParallel:function(e){return h=e,y},withJSONResponse:function(){return f="json",y},withRetryCount:function(e){return p=e,y},withRetryInterval:function(t,r){return e.isNonNullable(t)&&(m=t),e.isNonNullable(r)&&(v=r),y},withTimeout:function(e){return o=e,y},withFinally:function(e){return d=e,y},send:g,abort:function(){s&&(s.abort(),s=void 0),c=!0,d&&d()}};return y}var Xe,Ze=function(){function e(e){this.intervals=[],this.currentRate=0,this.logger=e}return e.prototype._updateRate=function(e){var t=.2;this.currentRate&&(e<.1*this.currentRate?t=.8:e<.5*this.currentRate?t=.5:e<.7*this.currentRate&&(t=.3)),e=Math.max(1,Math.min(e,104857600)),this.currentRate=this.currentRate?this.currentRate*(1-t)+e*t:e},e.prototype._createInterval=function(e,t,r){return{start:e,end:t,bytes:r}},e.prototype._doMergeIntervals=function(e,t){e.start=Math.min(t.start,e.start),e.end=Math.max(t.end,e.end),e.bytes+=t.bytes},e.prototype._mergeIntervals=function(e,t){return e.start<=t.end&&t.start<=e.end&&(this._doMergeIntervals(e,t),!0)},e.prototype._flushIntervals=function(){if(!this.intervals.length)return!1;var e=this.intervals[0].start,t=this.intervals[this.intervals.length-1].end-500;if(t-e>2e3){for(var r=0,i=0;this.intervals.length>0;){var a=this.intervals[0];if(a.end<=t)r+=a.end-a.start,i+=a.bytes,this.intervals.splice(0,1);else{if(a.start>=t)break;var n=t-a.start,s=a.end-a.start;r+=n;var o=a.bytes*n/s;i+=o,a.start=t,a.bytes-=o}}if(i>0&&r>0){var u=8*i/(r/1e3);return this._updateRate(u),this.logger("rate updated, new="+Math.round(u/1024)+"K; average="+Math.round(this.currentRate/1024)+"K bytes/ms="+Math.round(i)+"/"+Math.round(r)+" interval="+Math.round(t-e)),!0}}return!1},e.prototype._joinIntervals=function(){var e;do{e=!1;for(var t=0;t<this.intervals.length-1;++t)this._mergeIntervals(this.intervals[t],this.intervals[t+1])&&(this.intervals.splice(t+1,1),e=!0)}while(e)},e.prototype.addInterval=function(e,t,r){return this.intervals.push(this._createInterval(e,t,r)),this._joinIntervals(),this.intervals.length>100&&(this.logger("too many intervals ("+this.intervals.length+"); will merge",{type:"warn"}),this._doMergeIntervals(this.intervals[1],this.intervals[0]),this.intervals.splice(0,1)),this._flushIntervals()},e.prototype.getBitRate=function(){return this.currentRate},e}(),et=function(){function e(e,t,r,i,a){this.pendingQueue=[],this.activeRequests={},this.completeRequests={},this.averageSegmentDuration=2e3,this.lastPrefetchStart=0,this.throttleTimeout=null,this.RETRY_COUNT=e,this.TIMEOUT=t,this.BITRATE_ESTIMATOR=r,this.MAX_PARALLEL_REQUESTS=i,this.logger=a}return e.prototype.limitCompleteCount=function(){for(var e;(e=Object.keys(this.completeRequests)).length>this._getParallelRequestCount()+2;){var t=e[Math.floor(Math.random()*e.length)];this.logger("Dropping completed request for url "+t,{type:"warn"}),delete this.completeRequests[t]}},e.prototype._sendRequest=function(e,t){var r=this,i=Qe();e._request=Ke(t,(function(a){e._complete=1,e._responseData=a,e._downloadTime=Qe()-i,delete r.activeRequests[t],r._sendPending(),e._cb?e._cb(a,e._downloadTime):(r.limitCompleteCount(),r.completeRequests[t]=e)}),(function(){return i="error",delete r.activeRequests[t],r.limitCompleteCount(),r.completeRequests[t]=e,r._sendPending(),e._error=1,e._errorMsg=i,void(e._errorCB?e._errorCB(i):(r.limitCompleteCount(),r.completeRequests[t]=e));var i}),(function(){e._retry=1,e._retryCB&&e._retryCB()})),e._request.withRetryCount(this.RETRY_COUNT).withTimeout(this.TIMEOUT).withBitrateReporting(this.BITRATE_ESTIMATOR).withParallel(this._getParallelRequestCount()>1).withFinally((function(){e._finallyCB&&e._finallyCB()})),this.activeRequests[t]=e,e._request.send(),this.lastPrefetchStart=Qe()},e.prototype._getParallelRequestCount=function(){return Math.min(this.MAX_PARALLEL_REQUESTS,this.averageSegmentDuration<3e3?3:2)},e.prototype._getPrefetchDelay=function(){return Math.max(100,Math.min(5e3,this.averageSegmentDuration/3))},e.prototype._canSendPending=function(){var e=this,t=this._getParallelRequestCount(),r=Qe();if(Object.keys(this.activeRequests).length>=t)return!1;var i=this._getPrefetchDelay()-(r-this.lastPrefetchStart);return this.throttleTimeout&&clearTimeout(this.throttleTimeout),!(i>0)||(this.throttleTimeout=window.setTimeout((function(){return e._sendPending()}),i),!1)},e.prototype._sendPending=function(){for(;this._canSendPending();){var e=this.pendingQueue.pop();if(!e)return;this.activeRequests[e]||this.completeRequests[e]||(this.logger("Submitting pending request url="+e),this._sendRequest({},e))}},e.prototype._removeFromActive=function(e){delete this.completeRequests[e],delete this.activeRequests[e]},e.prototype.abortAll=function(){Object.values(this.activeRequests).forEach((function(e){e&&e._request&&e._request.abort()})),this.activeRequests={},this.pendingQueue=[],this.completeRequests={}},e.prototype.requestData=function(e,t,r,i){var a=this,n={send:function(){var s=a.activeRequests[e]||a.completeRequests[e];if(s)s._cb=t,s._errorCB=r,s._retryCB=i,s._finallyCB=n._finallyCB,s._error||s._complete?(a._removeFromActive(e),setTimeout((function(){s._complete?(a.logger("Requested url already prefetched, url="+e),t(s._responseData,s._downloadTime)):(a.logger("Requested url already prefetched with error, url="+e),r(s._errorMsg)),n._finallyCB&&n._finallyCB()}),0)):a.logger("Attached to active request, url="+e);else{var o=a.pendingQueue.indexOf(e);-1!==o&&a.pendingQueue.splice(o,1),a.logger("Request not prefetched, starting new request, url="+e+(-1===o?"":"; removed pending")),a._sendRequest(n,e)}}};return n._cb=t,n._errorCB=r,n._retryCB=i,n.abort=function(){n.request&&n.request.abort()},n.withFinally=function(e){return n._finallyCB=e,n},n},e.prototype.prefetch=function(e){this.activeRequests[e]||this.completeRequests[e]?this.logger("Request already active for url="+e):(this.logger("Added to pending queue; url="+e),this.pendingQueue.unshift(e),this._sendPending())},e.prototype.optimizeForSegDuration=function(e){this.averageSegmentDuration=e},e}(),tt=function(){function t(e){this.paused=!1,this.autoQuality=!0,this.buffering=!0,this.destroyed=!1,this.videoPlayStarted=!1,this.lowLatency=!1,this.bitrate=0,this.manifest=[],this.sourceBuffer=0,this.bufferStates=[],this.sourceJitter=-1,this.params=e,this.chunkRateEstimator=new Ze(this.params.logger),this._initVideo()}return t.prototype.attachSource=function(e){this.manifestUrl=e,this.urlResolver=Je(e),this.bitrateSwitcher=this._initBitrateSwitcher(),this._initManifest()},t.prototype.setAutoQualityEnabled=function(e){this.autoQuality=e},t.prototype.switchByName=function(e){for(var t,r=0;r<this.manifest.length;++r)if((t=this.manifest[r]).name===e)return void this._switchToQuality(t)},t.prototype.catchUp=function(){this.rep&&this.rep.stop(),this.currentManifestEntry&&(this.paused=!1,this._initPlayerWith(this.currentManifestEntry),this._notifyBuffering(!0))},t.prototype.stop=function(){this.params.videoElement.pause(),this.rep&&(this.rep.stop(),this.rep=null)},t.prototype.pause=function(){this.paused=!0,this.params.videoElement.pause(),this.videoPlayStarted=!1,this._notifyBuffering(!1)},t.prototype.play=function(e){this.paused=!1;var t=this.lowLatency&&this._getBufferSizeSec()>this.sourceJitter+5;this.rep&&!t?(this.bufferStates=[],this.videoPlayStarted=!1,this.shouldPlay()?this._playVideoElement(e):this._notifyBuffering(!0)):this.catchUp()},t.prototype.startPlay=function(e,t){this.autoQuality=t,this._initPlayerWith(e)},t.prototype.destroy=function(){this.destroyed=!0,this.rep&&(this.rep.stop(),this.rep=null),this.manifestRequest&&this.manifestRequest.abort(),this.manifestRefetchTimer&&(clearTimeout(this.manifestRefetchTimer),this.manifestRefetchTimer=void 0)},t.prototype.reinit=function(e){this.manifestUrl=e,this.urlResolver=Je(e),this.catchUp()},t.prototype._handleNetworkError=function(){this.params.logger("Fatal network error"),this.params.playerCallback({name:"error",type:"network"})},t.prototype._retryCallback=function(){this.params.playerCallback({name:"retry"})},t.prototype._getBufferSizeSec=function(){var e=this.params.videoElement,t=0,r=e.buffered.length;return 0!==r&&(t=e.buffered.end(r-1)-Math.max(e.currentTime,e.buffered.start(0))),t},t.prototype._notifyBuffering=function(e){this.destroyed||(this.params.logger("buffering: "+e),this.params.playerCallback({name:"buffering",isBuffering:e}),this.buffering=e)},t.prototype._initVideo=function(){var e=this,t=this.params,r=t.videoElement,i=t.logger;r.addEventListener("error",(function(t){var a;e.destroyed||(i("Video element error: "+(null===(a=r.error)||void 0===a?void 0:a.code)),e.params.playerCallback({name:"error",type:"media"}))})),r.addEventListener("timeupdate",(function(){var t=e._getBufferSizeSec();!e.paused&&t<.3?e.buffering||(e.buffering=!0,window.setTimeout((function(){!e.paused&&e.buffering&&e._notifyBuffering(!0),r.pause(),e.videoPlayStarted=!1}),1e3*(t+.1))):e.buffering&&e.videoPlayStarted&&e._notifyBuffering(!1)})),r.addEventListener("playing",(function(){i("playing")})),r.addEventListener("stalled",(function(){return e._fixupStall()})),r.addEventListener("waiting",(function(){return e._fixupStall()}))},t.prototype._fixupStall=function(){var e,t=this.params,r=t.logger,i=t.videoElement,a=i.buffered.length;0!==a&&(e=i.buffered.start(a-1),i.currentTime<e&&(r("Fixup stall"),i.currentTime=e))},t.prototype._selectQuality=function(e){for(var t,r,i,a=this.params.videoElement,n=a&&1.62*(window.devicePixelRatio||1)*a.offsetHeight||520,s=0;s<this.manifest.length;++s)(i=this.manifest[s]).bitrate<e&&n>Math.min(i.video.height,i.video.width)?(!r||i.bitrate>r.bitrate)&&(r=i):(!t||t.bitrate>i.bitrate)&&(t=i);return r||t},t.prototype.shouldPlay=function(){if(this.paused)return!1;var t=this._getBufferSizeSec()-Math.max(1,this.sourceJitter);return t>3||e.isNonNullable(this.downloadRate)&&(this.downloadRate>1.5&&t>2||this.downloadRate>2&&t>1)},t.prototype._setVideoSrc=function(t,r){var i=this,a=this.params,n=a.logger,s=a.videoElement,o=a.playerCallback;this.mediaSource=new window.MediaSource,n("setting video src"),s.src=URL.createObjectURL(this.mediaSource),this.mediaSource.addEventListener("sourceopen",(function(){e.assertNonNullable(i.mediaSource),i.sourceBuffer=i.mediaSource.addSourceBuffer(t.codecs),i.bufferStates=[],r()})),this.videoPlayStarted=!1,s.addEventListener("canplay",(function(){i.shouldPlay()&&(i.videoPlayStarted=!0,i._playVideoElement())}));var u=function(){var e,t,r,i;t="progress",r=function(){s.buffered.length?(s.currentTime=s.buffered.start(0),o({name:"playing"})):u()},i=function(){for(var a=[],n=0;n<arguments.length;n++)a[n]=arguments[n];r.apply(null,a),e.removeEventListener(t,i)},(e=s).addEventListener(t,i)};u()},t.prototype._initPlayerWith=function(e){var t=this;this.bitrate=0,this.rep=0,this.sourceBuffer=0,this.bufferStates=[],this.filesFetcher&&this.filesFetcher.abortAll(),this.filesFetcher=new et(3,1e4,this.bitrateSwitcher,this.params.config.MAX_PARALLEL_REQUESTS,this.params.logger),this._setVideoSrc(e,(function(){return t._switchToQuality(e)}))},t.prototype._representation=function(t){var r=this,i=this.params,a=i.logger,n=i.videoElement,s=i.playerCallback,o=!1,u=null,d=null,l=null,c=null,p=!1,h=function(){var e=o&&(!p||p===r.rep);return e||a("Not running!"),e},f=function(e){var t=n.playbackRate;n.playbackRate!==e&&(a("Playback rate switch: "+t+"=>"+e),n.playbackRate=e)},v=function(){if(r.lowLatency){var e=r._getBufferSizeSec();if(r.bufferStates.length<5)return void f(1);for(var t=Qe()-6e4,i=0,n=0;n<r.bufferStates.length;n++){var s=r.bufferStates[n];e=Math.min(e,s.buf),s.ts<t&&i++}r.bufferStates.splice(0,i),a("update playback rate; minBuffer="+e+" drop="+i+" jitter="+r.sourceJitter);var o=e-1;r.sourceJitter>=0?o-=r.sourceJitter/2:r.sourceJitter-=1,f(o>3?1.15:o>1?1.1:o>.3?1.01:1)}else f(1)},m=function(t){var i,n=function(){return i&&i.start?i.start.length:0},o=function(e){return i.start[e]/1e3},u=function(e){return i.dur[e]/1e3},d=function(e){return i.fragIndex+e},l=function(e,t){return{chunkIdx:d(e),startTS:o(e),dur:u(e),discontinuity:t}},p=function(){var e=0;if(i&&i.dur){var t=Math.max(r.sourceJitter,1);for(r.lowLatency||(t+=2),e=i.dur.length-1;e>=0&&!((t-=i.dur[e]/1e3)<=0);--e);}return l(e,!0)};return{seek:function(u,d){!function(e,t,i){c&&c.abort(),c=Ke(r.urlResolver.resolve(e,!0,r.lowLatency),t,i,(function(){return r._retryCallback()})).withTimeout(1e4).withRetryCount(3).withFinally((function(){c=null})).withJSONResponse().send()}(t,(function(t){if(h()){i=t;var c,f=Boolean(i.lowLatency);f!==r.lowLatency&&(c=f,r.lowLatency=c,a("lowLatency changed to "+c),v());for(var m=0,S=0;S<i.dur.length;++S)m+=i.dur[S];m>0&&(e.assertNonNullable(r.filesFetcher),r.filesFetcher.optimizeForSegDuration(m/i.dur.length)),s({name:"index",zeroTime:i.zeroTime,shiftDuration:i.shiftDuration}),r.sourceJitter=i.hasOwnProperty("jitter")?Math.min(10,Math.max(.01,i.jitter/1e3)):1,u(function(t){var r=n();if(!(r<=0)){if(e.isNonNullable(t))for(var i=0;i<r;i++)if(o(i)>t)return l(i);return p()}}(d))}}),(function(){return r._handleNetworkError()}))},nextChunk:function(e){var t=n(),r=e?e.chunkIdx+1:0,s=r-i.fragIndex;if(!(t<=0)){if(!e||s<0||s-t>10)return a("Resync: offset="+s+" bChunks="+t+" chunk="+JSON.stringify(e)),p();if(!(s>=t))return l(r-i.fragIndex,!1)}}}},S=function(){o=!1,d&&d.abort(),l&&l.abort(),c&&c.abort(),e.assertNonNullable(r.filesFetcher),r.filesFetcher.abortAll()};return p={start:function(i){var a,n,s,p,f,b,g,y,T,E,P=r.params,k=P.videoElement,w=P.logger,x=m(t.jidxUrl),A=0,$=function(){f&&(clearTimeout(f),f=void 0);var e=Math.max(500,1e3*(r._getBufferSizeSec()-r.sourceJitter-5)),t=A+e,i=Qe(),a=Math.min(1e4,t-i);A=i;var n=function(){c||h()&&x.seek((function(){h()&&(A=Qe(),N(),$())}))};a>0?f=window.setTimeout((function(){r.paused?$():n()}),a):n()},N=function(){for(var e;e=x.nextChunk(p);)p=e,C(e);var i=x.nextChunk(s);if(i){if(s&&i.discontinuity)return w("Detected discontinuity; restarting playback"),void(r.paused?$():(S(),r._initPlayerWith(t)));I(i)}else $()},D=function(e,t){if(h()&&r.sourceBuffer){var i,a,n=function(r){window.setTimeout((function(){h()&&D(e,t)}),r)};if(r.sourceBuffer.updating)w("Source buffer is updating; delaying appendBuffer"),n(100);else{var s=Qe(),o=k.currentTime;!r.paused&&k.buffered.length>1&&b===o&&s-g>500&&(w("Stall suspected; trying to fix"),r._fixupStall()),b!==o&&(b=o,g=s);var u=r._getBufferSizeSec();if(u>30)w("Buffered "+u+" seconds; delaying appendBuffer"),n(2e3);else try{r.sourceBuffer.appendBuffer(e),r.videoPlayStarted?(r.bufferStates.push({ts:s,buf:u}),v(),r.bufferStates.length>200&&r.bufferStates.shift()):r.shouldPlay()&&(r.videoPlayStarted=!0,r._playVideoElement()),t&&t()}catch(e){if("QuotaExceededError"!==e.name)throw e;w("QuotaExceededError; delaying appendBuffer"),0!==r.sourceBuffer.buffered.length&&(a=o)-(i=r.sourceBuffer.buffered.start(0))>4&&r.sourceBuffer.remove(i,a-3),n(1e3)}}}},_=function(){n&&a&&(w(["Appending chunk, sz="+n.byteLength+":",JSON.stringify(s)]),D(n,(function(){n=null,N()})))},R=function(e){return t.fragUrlTemplate.replace("%%id%%",e.chunkIdx)},I=function(t){var i,a,o;h()&&(i=R(t),a=function(e,i){if(h()){if(i/=1e3,n=e,s=t,u=t.startTS,i){var a=Math.min(10,t.dur/i);r.downloadRate=r.downloadRate?.7*r.downloadRate+.3*a:a}_()}},o=function(){return r._handleNetworkError()},e.assertNonNullable(r.filesFetcher),null==d||d.abort(),d=r.filesFetcher.requestData(r.urlResolver.resolve(i,!1),a,o,(function(){return r._retryCallback()})).withFinally((function(){d=null})).send())},C=function(t){h()&&(e.assertNonNullable(r.filesFetcher),r.filesFetcher.prefetch(r.urlResolver.resolve(R(t),!1)))},L=function(e){h()&&(t.cachedHeader=e,D(e,(function(){a=!0,_()})))};o=!0,x.seek((function(t){h()&&(A=Qe(),t?(p=t,!e.isNullable(i)||t.startTS>i?I(t):(s=t,N())):$())}),i),t.cachedHeader?L(t.cachedHeader):(y=t.headerUrl,T=L,E=function(){return r._handleNetworkError()},l&&l.abort(),l=Ke(r.urlResolver.resolve(y,!1),T,E,(function(){return r._retryCallback()})).withTimeout(1e4).withBitrateReporting(r.bitrateSwitcher).withRetryCount(3).withFinally((function(){l=null})).send())},stop:S,getTimestampSec:function(){return u}}},t.prototype._switchToQuality=function(t){var r,i=this.params,a=i.logger,n=i.playerCallback;t.bitrate!==this.bitrate&&(this.rep&&(r=this.rep.getTimestampSec(),e.isNonNullable(r)&&(r+=.1),this.rep.stop()),this.currentManifestEntry=t,this.rep=this._representation(t),a("switch to quality: codecs="+t.codecs+"; headerUrl="+t.headerUrl+"; bitrate="+t.bitrate),this.bitrate=t.bitrate,e.assertNonNullable(this.bitrateSwitcher),this.bitrateSwitcher.notifySwitch(this.bitrate),this.rep.start(r),n({name:"qualitySwitch",quality:t}))},t.prototype._qualityAvailable=function(t){return e.isNonNullable(this.manifest.find((function(e){return e.name===t})))},t.prototype._initBitrateSwitcher=function(){var e,t=this,r=this.params,i=r.logger,a=r.playerCallback,n={updateChunk:function(e,r){var i=Qe();if(t.chunkRateEstimator.addInterval(e,i,r)){var n=t.chunkRateEstimator.getBitRate();return a({name:"bandwidth",size:r,duration:i-e,speed:n}),!0}},get:function(){var e=t.chunkRateEstimator.getBitRate();return e?.85*e:0}},s=-1/0,o=!0,u=function(){var r=n.get();if(r&&e&&t.autoQuality){if(o&&r>e&&We(s)<3e4)return;!function(e){var r,a,n;t.autoQuality&&(t.currentManifestEntry&&t._qualityAvailable(t.currentManifestEntry.name)&&e<t.bitrate&&(a=t._getBufferSizeSec(),n=e/t.bitrate,a>10&&n>.8||a>15&&n>.5||a>20&&n>.3)?i("Not switching: buffer="+Math.floor(a)+"; bitrate="+t.bitrate+"; newRate="+Math.floor(e)):(r=t._selectQuality(e))?t._switchToQuality(r):i("Could not find quality by bitrate "+e))}(r)}o=t.autoQuality};return{updateChunk:function(e,t){var r=n.updateChunk(e,t);return r&&u(),r},notifySwitch:function(t){var r=Qe();t<e&&(s=r),e=t}}},t.prototype._fetchManifest=function(e,t,r){var i=this;this.manifestRequest=Ke(this.urlResolver.resolve(e,!0),t,r,(function(){return i._retryCallback()})).withJSONResponse().withTimeout(1e4).withRetryCount(3).withRetryInterval(300,2e3).send().withFinally((function(){i.manifestRequest=void 0}))},t.prototype._playVideoElement=function(e){var t=this.params.videoElement;w(t).then((function(t){t||null==e||e()}))},t.prototype._handleManifestUpdate=function(e){var t=this,r=this.params,i=r.logger,a=r.playerCallback,n=r.videoElement;this.manifest=function(e){var r=[];return(null==e?void 0:e.length)?(e.forEach((function(e,t){e.video&&n.canPlayType(e.codecs).replace(/no/,"")&&window.MediaSource.isTypeSupported(e.codecs)&&(e.index=t,r.push(e))})),r.sort((function(e,t){return e.video&&t.video?t.video.height-e.video.height:t.bitrate-e.bitrate})),r):(t.params.playerCallback({name:"error",type:"partial_metadata"}),[])}(e),i("Valid manifest entries: "+this.manifest.length+"/"+e.length),a({name:"manifest",manifest:this.manifest})},t.prototype._refetchManifest=function(e){var t=this;this.destroyed||(this.manifestRefetchTimer&&clearTimeout(this.manifestRefetchTimer),this.manifestRefetchTimer=window.setTimeout((function(){t._fetchManifest(e,(function(r){t.destroyed||(t._handleManifestUpdate(r),t._refetchManifest(e))}),(function(){return t._refetchManifest(e)}))}),6e4))},t.prototype._initManifest=function(){var e=this;this._fetchManifest(this.manifestUrl,(function(t){e.destroyed||(e._handleManifestUpdate(t),e._refetchManifest(e.manifestUrl))}),(function(){return e._handleNetworkError()}))},t}();!function(e){e.STOPPED="stopped",e.MANIFEST_READY="manifest_ready",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(Xe||(Xe={}));var rt,it=[Xe.PAUSED,Xe.PLAYING,Xe.READY],at=[Xe.PAUSED,Xe.PLAYING,Xe.READY],nt=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(Xe.STOPPED),this.representations$=new e.ValueSubject([]),this.textTracksManager=new D,this.maxSeekBackTime$=new e.ValueSubject(1/0),this.zeroTime$=new e.ValueSubject(void 0),this.liveOffset=new qe,this._dashCb=function(t){var i,a,n,s,o;switch(t.name){case"buffering":var u=t.isBuffering;r.params.output.isBuffering$.next(u);break;case"error":r.params.output.error$.next({id:"DashLiveProviderInternal:"+t.type,message:"LiveDashPlayer reported error"});break;case"manifest":var d=t.manifest,c=[];try{for(var p=h(d),f=p.next();!f.done;f=p.next()){var v=f.value,m=null!==(n=v.name)&&void 0!==n?n:v.index.toString(10),S=q(v.video),b=v.bitrate/1e3,g=l({},v.video);if(S){var y={id:m,quality:S,bitrate:b,size:g};c.push({track:y,representation:v})}}}catch(e){i={error:e}}finally{try{f&&!f.done&&(a=p.return)&&a.call(p)}finally{if(i)throw i.error}}r.representations$.next(c),r.params.output.availableVideoTracks$.next(c.map((function(e){return e.track}))),(null===(s=r.videoState.getTransition())||void 0===s?void 0:s.to)===Xe.MANIFEST_READY&&r.videoState.setState(Xe.MANIFEST_READY);break;case"qualitySwitch":var T=t.quality;y=null===(o=r.representations$.getValue().find((function(e){return e.representation===T})))||void 0===o?void 0:o.track;r.params.output.hostname$.next(new URL(T.headerUrl,r.params.source.url).hostname),e.isNonNullable(y)&&r.params.output.currentVideoTrack$.next(y);break;case"bandwidth":g=t.size;var E=t.duration;r.params.dependencies.throughputEstimator.addRawSpeed(g,E);break;case"index":r.maxSeekBackTime$.next(t.shiftDuration),r.zeroTime$.next(t.zeroTime)}},this.syncPlayback=function(){var t,i=r.videoState.getState(),a=r.videoState.getTransition(),n=r.params.desiredState.playbackState.getState(),s=r.params.desiredState.playbackState.getTransition(),o=r.params.desiredState.seekPosition.getTransition();if(r.log({message:"[syncPlayback] videoState: "+i+"; videoTransition: "+JSON.stringify(a)+"; desiredPlaybackState: "+n+"; seekPositionTransition: "+JSON.stringify(o)+";"}),n!==exports.PlaybackState.STOPPED){if(!a){if(at.includes(i)){var u=null===(t=r.params.desiredState.videoTrack.getTransition())||void 0===t?void 0:t.to;e.isNonNullable(u)&&r.setVideoTrack(u);var d=r.params.desiredState.autoVideoTrackSwitching.getTransition();d&&r.setAutoQuality(d.to)}var l=null==o?void 0:o.to;if((null==s?void 0:s.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(l)&&it.includes(i))r.seek(l+st(r.liveOffset.getTotalPausedTime()));else switch(i){case Xe.STOPPED:return r.videoState.startTransitionTo(Xe.MANIFEST_READY),void r.dash.attachSource(Ae(r.params.source.url));case Xe.MANIFEST_READY:r.videoState.startTransitionTo(Xe.READY),r.prepare();break;case Xe.READY:return void(n===exports.PlaybackState.PAUSED?r.videoState.setState(Xe.PAUSED):n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Xe.PLAYING),r.dash.play((function(){r.liveOffset.pause(),r.videoState.setState(Xe.PAUSED)}))));case Xe.PLAYING:return void(n===exports.PlaybackState.PAUSED&&(r.videoState.startTransitionTo(Xe.PAUSED),r.liveOffset.pause(),r.dash.pause()));case Xe.PAUSED:return void(n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Xe.PLAYING),r.liveOffset.getTotalPausedTime()<r.params.config.maxPausedTime&&r.liveOffset.getTotalOffset()<r.maxSeekBackTime$.getValue()?(r.liveOffset.resume(),r.dash.play((function(){r.liveOffset.pause(),r.videoState.setState(Xe.PAUSED)})),r.params.output.position$.next(st(r.liveOffset.getTotalOffset()))):r.seek(st(r.liveOffset.getTotalOffset()))));default:return e.assertNever(i)}}}else i!==Xe.STOPPED&&(r.videoState.startTransitionTo(Xe.STOPPED),r.dash.destroy(),r.video.setAttribute("src",""),r.video.load(),r.videoState.setState(Xe.STOPPED))},this.params=t,this.log=this.params.dependencies.logger.createComponentLog("DashLiveProvider");var i=function(e){t.output.error$.next({id:"DashLiveProvider",message:"DashLiveProvider internal logic error",thrown:e})};e.merge(this.videoState.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,type:"start"}}))),this.videoState.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,type:"end"}})))).subscribe((function(e){var t=e.transition,i=e.type;r.log({message:"[videoState change] "+i+": "+JSON.stringify(t)})})),this.video=_(t.container),this.params.output.element$.next(this.video),this.dash=this.createLiveDashPlayer(),this.params.output.duration$.next(1/0),this.params.output.position$.next(0),this.params.output.isLive$.next(!0),this.params.output.hostname$.next(Z(this.params.source.url)),this.textTracksManager.connect(this.video,this.params.desiredState,this.params.output);var a=O(this.video);this.subscription.add(a.canplay$.subscribe((function(){var e;(null===(e=r.videoState.getTransition())||void 0===e?void 0:e.to)===Xe.READY&&r.videoState.setState(Xe.READY)}),i)).add(a.pause$.subscribe((function(){r.videoState.setState(Xe.PAUSED)}),i)).add(a.playing$.subscribe((function(){r.videoState.setState(Xe.PLAYING)}),i)).add(a.error$.subscribe(this.params.output.error$)).add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(st)).subscribe(this.params.output.duration$)).add(e.combine({zeroTime:this.zeroTime$.pipe(e.filter(e.isNonNullable)),position:a.timeUpdate$}).subscribe((function(e){var t=e.zeroTime,i=e.position;return r.params.output.liveTime$.next(t+1e3*i)}),i)).add(A(this.video,this.params.desiredState.isLooped,i)).add($(this.video,this.params.desiredState.volume,a.volumeState$,i)).add(a.volumeState$.subscribe(this.params.output.volume$,i)).add(L(this.video).subscribe(this.params.output.firstBytesEvent$)).add(R(this.video).subscribe(this.params.output.firstFrameEvent$)).add(this.videoState.stateChangeEnded$.subscribe((function(t){switch(t.to){case Xe.STOPPED:r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.desiredState.playbackState.setState(exports.PlaybackState.STOPPED);break;case Xe.MANIFEST_READY:case Xe.READY:break;case Xe.PAUSED:r.params.desiredState.playbackState.setState(exports.PlaybackState.PAUSED);break;case Xe.PLAYING:r.params.desiredState.playbackState.setState(exports.PlaybackState.PLAYING);break;default:return e.assertNever(t.to)}}),i)).add(e.merge(t.desiredState.playbackState.stateChangeStarted$,t.desiredState.seekPosition.stateChangeStarted$,t.desiredState.videoTrack.stateChangeStarted$,t.desiredState.autoVideoTrackSwitching.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)).subscribe(this.syncPlayback,i))}return t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0),this.dash.destroy()},t.prototype.createLiveDashPlayer=function(){var e=this,t=new tt({videoElement:this.video,config:{CHUNK_DURATION:this.params.config.chunkDuration,BUFFER_OPTIMAL_DURATION:this.params.config.optimalBufferDuration,MAX_PARALLEL_REQUESTS:this.params.config.maxParallelRequests},playerCallback:this._dashCb,logger:function(t){e.params.dependencies.logger.log({message:String(t),component:"LiveDashPlayer"})}});return t.pause(),t},t.prototype.prepare=function(){var t,r,i,a,n,s,o=this.representations$.getValue(),u=null!==(r=null===(t=this.params.desiredState.videoTrack.getTransition())||void 0===t?void 0:t.to)&&void 0!==r?r:this.params.desiredState.videoTrack.getState(),d=null!==(a=null===(i=this.params.desiredState.autoVideoTrackSwitching.getTransition())||void 0===i?void 0:i.to)&&void 0!==a?a:this.params.desiredState.autoVideoTrackSwitching.getState(),l=!d&&e.isNonNullable(u)?u:null===(n=K(o.map((function(e){return e.track})),{container:{width:this.video.offsetWidth,height:this.video.offsetHeight},throughput:this.params.dependencies.throughputEstimator.throughput$.getValue(),tuning:this.params.tuning.autoTrackSelection}))||void 0===n?void 0:n.id,c=null===(s=o.find((function(e){return e.track.id===l})))||void 0===s?void 0:s.representation;e.assertNonNullable(c),this.dash.startPlay(c,d),this.params.desiredState.videoTrack.getTransition()&&this.params.desiredState.videoTrack.setState(l),this.params.desiredState.autoVideoTrackSwitching.getTransition()&&this.params.desiredState.autoVideoTrackSwitching.setState(d)},t.prototype.setVideoTrack=function(t){var r,i=null===(r=this.representations$.getValue().find((function(e){return e.track.id===t})))||void 0===r?void 0:r.representation;e.assertNonNullable(i),this.dash.switchByName(i.name),this.params.desiredState.videoTrack.setState(t)},t.prototype.setAutoQuality=function(e){this.dash.setAutoQualityEnabled(e),this.params.desiredState.autoVideoTrackSwitching.setState(e)},t.prototype.seek=function(e){this.log({message:"[seek] position: "+e}),this.params.output.willSeekEvent$.next();var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(st(r)),this.dash.reinit(Ae(this.params.source.url,r)),this.params.output.seekedEvent$.next()},t}(),st=function(e){return-e/1e3},ot=function(e){switch(e){case"mobile":return exports.VideoQuality.Q_144P;case"lowest":return exports.VideoQuality.Q_240P;case"low":return exports.VideoQuality.Q_360P;case"sd":case"medium":return exports.VideoQuality.Q_480P;case"hd":case"high":return exports.VideoQuality.Q_720P;case"fullhd":case"full":return exports.VideoQuality.Q_1080P;case"quadhd":case"quad":return exports.VideoQuality.Q_1440P;case"ultrahd":case"ultra":return exports.VideoQuality.Q_2160P}},ut=function(e){var t=null;if(e.QUALITY&&(t=ot(e.QUALITY)),!t&&e.RESOLUTION){var r=f(e.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),i=r[0],a=r[1];t=q({width:i,height:a})}return null!=t?t:null},dt=function(e,t){return void 0===t&&(t=e),c(void 0,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,l,c,h,v,m,S,b,g;return p(this,(function(p){switch(p.label){case 0:return[4,fetch(e)];case 1:return[4,p.sent().text()];case 2:for(r=p.sent(),i=r.split("\n"),a=[],n=0;n<i.length;n++)s=i[n],(o=s.match(/^#EXT-X-STREAM-INF:(.+)/))&&(u=Object.fromEntries(o[1].split(",").map((function(e){return e.split("=")}))),d=null!==(g=u.QUALITY)&&void 0!==g?g:"stream-"+u.BANDWIDTH,l=ut(u),c=void 0,u.BANDWIDTH&&(c=parseInt(u.BANDWIDTH,10)/1e3||void 0),!c&&u["AVERAGE-BANDWIDTH"]&&(c=parseInt(u["AVERAGE-BANDWIDTH"],10)/1e3||void 0),h=void 0,u.RESOLUTION&&(v=f(u.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),m=v[0],S=v[1],m&&S&&(h={width:m,height:S})),b=new URL(i[++n],t).toString(),l&&a.push({id:d,quality:l,url:b,bandwidth:c,size:h}));return[2,a]}}))}))};!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(rt||(rt={}));var lt,ct=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(rt.STOPPED),this.textTracksManager=new D,this.manifests$=new e.ValueSubject([]),this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.videoTrack.getTransition(),s=r.params.desiredState.autoVideoTrackSwitching.getTransition();if(i!==exports.PlaybackState.STOPPED){if(!r.videoState.getTransition()){var o=r.params.desiredState.seekPosition.getTransition();if(t===rt.STOPPED)return r.videoState.startTransitionTo(rt.READY),void r.prepare();if(n||s){var u=r.videoState.getState();r.videoState.setState(rt.CHANGING_MANIFEST),r.videoState.startTransitionTo(u);var d=r.video.currentTime;return r.prepare(),void(o&&!e.isNullable(o.to)||r.params.desiredState.seekPosition.startTransitionTo(d))}var l=null==o?void 0:o.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(l)&&r.seek(l),t){case rt.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(rt.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(rt.PLAYING),r.playIfAllowed()));case rt.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(rt.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case rt.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(rt.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));case rt.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==rt.STOPPED&&(r.videoState.startTransitionTo(rt.STOPPED),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState(rt.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=_(t.container),this.params.output.element$.next(this.video);var i={id:"master",quality:exports.VideoQuality.INVARIANT,url:this.params.source.url};this.manifests$.next([i]),this.params.output.isLive$.next(!1),this.params.output.hostname$.next(Z(this.params.source.url)),dt(this.params.source.url).then((function(e){r.manifests$.next(v([i],f(e),!1))}),(function(e){return r.params.output.error$.next({id:"ExtractHlsQualities",message:"Error fetching manifest and extracting qualities",thrown:e})})),this.subscribe()}return t.prototype.selectManifest=function(){var e,t,r=this.params.desiredState,i=r.autoVideoTrackSwitching,a=r.videoTrack,n=i.getState(),s=a.getTransition(),o=null!==(t=null!==(e=null==s?void 0:s.to)&&void 0!==e?e:a.getState())&&void 0!==t?t:"master",u=this.manifests$.getValue();if(u){var d=n?"master":o;return n&&!s&&a.startTransitionTo("master"),u.find((function(e){return e.id===d}))}},t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"HlsProvider",message:"HlsProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r))};o(s.timeUpdate$,i.position$),o(s.durationChange$,i.duration$),o(s.ended$,i.endedEvent$),o(s.error$,i.error$),o(s.isBuffering$,i.isBuffering$),o(s.currentBuffer$,i.currentBuffer$),o(s.firstBytes$,i.firstBytesEvent$),o(s.firstFrame$,i.firstFrameEvent$),o(s.seeked$,i.seekedEvent$),this.subscription.add(A(this.video,a.isLooped,n)),this.subscription.add($(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.textTracksManager.connect(this.video,a,i),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState(rt.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(rt.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===rt.READY&&t.videoState.setState(rt.READY),t.videoState.getState()===rt.PLAYING&&t.playIfAllowed()}),n).add(s.loadedMetadata$.subscribe((function(){var r=t.params.desiredState.seekPosition.getTransition(),i=t.videoState.getTransition(),a=t.params.desiredState.videoTrack.getTransition(),n=t.params.desiredState.autoVideoTrackSwitching.getTransition();if(a&&e.isNonNullable(a.to)){var s=a.to;t.params.desiredState.videoTrack.setState(s);var o=t.manifests$.getValue().find((function(e){return e.id===s}));o&&(t.params.output.currentVideoTrack$.next(o),t.params.output.hostname$.next(Z(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===rt.CHANGING_MANIFEST&&t.videoState.setState(i.to),r&&e.isNonNullable(r.to)&&t.seek(r.to)}),n))),this.subscription.add(this.manifests$.pipe(e.map((function(e){return e.map((function(e){return{id:e.id,quality:e.quality,size:e.size,bitrate:e.bandwidth}}))}))).subscribe(this.params.output.availableVideoTracks$,n));var u=e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,a.videoTrack.stateChangeStarted$,a.autoVideoTrackSwitching.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.prepare=function(){var t=this.selectManifest();e.isNullable(t)||(this.video.setAttribute("src",t.url),this.video.load())},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(rt.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.video.currentTime=e},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(lt||(lt={}));var pt,ht=function(){function t(t){var r,i=this;this.subscription=new e.Subscription,this.videoState=new te(lt.STOPPED),this.textTracksManager=new D,this.manifests$=new e.ValueSubject([]),this.liveOffset=new qe,this.manifestStartTime$=new e.ValueSubject(void 0),this.syncPlayback=function(){var t=i.videoState.getState(),r=i.params.desiredState.playbackState.getState(),a=i.params.desiredState.playbackState.getTransition(),n=i.params.desiredState.videoTrack.getTransition(),s=i.params.desiredState.autoVideoTrackSwitching.getTransition();if(r!==exports.PlaybackState.STOPPED){if(!i.videoState.getTransition()){var o=i.params.desiredState.seekPosition.getTransition();if(t===lt.STOPPED)return i.videoState.startTransitionTo(lt.READY),void i.prepare();if(n||s){var u=i.videoState.getState();i.videoState.setState(lt.CHANGING_MANIFEST),i.videoState.startTransitionTo(u);var d=ft(i.liveOffset.getTotalOffset());return i.prepare(),void(o&&!e.isNullable(o.to)||i.params.desiredState.seekPosition.startTransitionTo(d))}var l=null==o?void 0:o.to;if((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(l))return i.videoState.startTransitionTo(lt.READY),i.seek(l+ft(i.liveOffset.getTotalPausedTime())),void i.prepare();switch(t){case lt.READY:return void(r===exports.PlaybackState.PAUSED?(i.videoState.setState(lt.PAUSED),i.liveOffset.pause(),V(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):r===exports.PlaybackState.PLAYING&&(i.videoState.startTransitionTo(lt.PLAYING),i.playIfAllowed()));case lt.PLAYING:return void(r===exports.PlaybackState.PAUSED?(i.videoState.startTransitionTo(lt.PAUSED),i.liveOffset.pause(),i.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(i.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case lt.PAUSED:return void(r===exports.PlaybackState.PLAYING?(i.videoState.startTransitionTo(lt.PLAYING),i.liveOffset.getTotalPausedTime()<i.params.config.maxPausedTime&&i.liveOffset.getTotalOffset()<i.maxSeekBackTime$.getValue()?(i.liveOffset.resume(),i.playIfAllowed(),i.params.output.position$.next(ft(i.liveOffset.getTotalOffset()))):i.seek(ft(i.liveOffset.getTotalOffset()))):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&(V(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED),i.liveOffset.pause()));case lt.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==lt.STOPPED&&(i.videoState.startTransitionTo(lt.STOPPED),i.video.setAttribute("src",""),i.video.load(),i.params.output.position$.next(0),i.params.output.duration$.next(1/0),i.params.output.currentBuffer$.next(void 0),i.params.output.hostname$.next(void 0),i.videoState.setState(lt.STOPPED),V(i.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=_(t.container),this.params.output.element$.next(this.video);var a={id:"master",quality:exports.VideoQuality.INVARIANT,url:this.params.source.url};this.manifests$.next([a]),dt(Ae(this.params.source.url)).then((function(e){i.manifests$.next(v([a],f(e),!1))}),(function(e){return i.params.output.error$.next({id:"ExtractHlsQualities",message:"Error fetching manifest and extracting qualities",thrown:e})})),this.params.output.isLive$.next(!0),this.params.output.hostname$.next(Z(this.params.source.url)),this.maxSeekBackTime$=new e.ValueSubject(null!==(r=t.source.maxSeekBackTime)&&void 0!==r?r:1/0),this.subscribe()}return t.prototype.selectManifest=function(){var e,t,r=this.params.desiredState,i=r.autoVideoTrackSwitching,a=r.videoTrack,n=i.getState(),s=a.getTransition(),o=null!==(t=null!==(e=null==s?void 0:s.to)&&void 0!==e?e:a.getState())&&void 0!==t?t:"master",u=this.manifests$.getValue();if(u){var d=n?"master":o;return n&&!s&&a.startTransitionTo("master"),u.find((function(e){return e.id===d}))}},t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"HlsLiveProvider",message:"HlsLiveProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r,n))};o(s.ended$,i.endedEvent$),o(s.error$,i.error$),o(s.isBuffering$,i.isBuffering$),o(s.currentBuffer$,i.currentBuffer$),o(s.firstBytes$,i.firstBytesEvent$),o(s.firstFrame$,i.firstFrameEvent$),this.subscription.add(a.isLooped.stateChangeStarted$.subscribe((function(){return a.isLooped.setState(!1)}),n)),this.subscription.add($(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.textTracksManager.connect(this.video,a,i),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState(lt.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(lt.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===lt.READY&&t.videoState.setState(lt.READY),t.videoState.getState()===lt.PLAYING&&t.playIfAllowed()}),n)),this.subscription.add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(ft)).subscribe(this.params.output.duration$,n)),this.subscription.add(s.loadedMetadata$.subscribe((function(){var r=t.params.desiredState.seekPosition.getTransition(),i=t.videoState.getTransition(),a=t.params.desiredState.videoTrack.getTransition(),n=t.params.desiredState.autoVideoTrackSwitching.getTransition();if(a&&e.isNonNullable(a.to)){var s=a.to;t.params.desiredState.videoTrack.setState(s);var o=t.manifests$.getValue().find((function(e){return e.id===s}));o&&(t.params.output.currentVideoTrack$.next(o),t.params.output.hostname$.next(Z(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===lt.CHANGING_MANIFEST&&t.videoState.setState(i.to),r&&e.isNonNullable(r.to)&&t.seek(r.to)}),n)),this.subscription.add(s.loadedData$.subscribe((function(){var e,r,i=null===(r=null===(e=t.video)||void 0===e?void 0:e.getStartDate())||void 0===r?void 0:r.getTime();t.manifestStartTime$.next(i||void 0)}),n)),this.subscription.add(e.combine({startTime:this.manifestStartTime$.pipe(e.filter(e.isNonNullable)),currentTime:s.timeUpdate$}).subscribe((function(e){var r=e.startTime,i=e.currentTime;return t.params.output.liveTime$.next(r+1e3*i)}),n)),this.subscription.add(this.manifests$.pipe(e.map((function(e){return e.map((function(e){return{id:e.id,quality:e.quality,size:e.size,bitrate:e.bandwidth}}))}))).subscribe(this.params.output.availableVideoTracks$,n));var u=e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,a.videoTrack.stateChangeStarted$,a.autoVideoTrackSwitching.stateChangeStarted$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.prepare=function(){var t=this,r=this.selectManifest();if(!e.isNullable(r)){var i,a=Ae(r.url,this.liveOffset.getTotalOffset());this.video.setAttribute("src",a),this.video.load(),(i=a,c(void 0,void 0,void 0,(function(){var e;return p(this,(function(t){switch(t.label){case 0:return[4,fetch(i,{method:"HEAD"})];case 1:return[2,(e=t.sent()).headers.has("X-Playback-Duration")?parseInt(e.headers.get("X-Playback-Duration"),10):void 0]}}))}))).then((function(r){e.isNullable(r)||t.maxSeekBackTime$.next(r)}))}},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(lt.PAUSED),e.liveOffset.pause(),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next();var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(ft(r)),this.params.output.seekedEvent$.next()},t}(),ft=function(e){return-e/1e3},vt={};!function(e){e.INITIALIZING="initializing",e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(pt||(pt={}));var mt,St,bt,gt,yt,Tt,Et,Pt,kt,wt,xt,At,$t,Nt,Dt,_t,Rt,It,Ct,Lt,Ot=function(t,r){return new e.Observable((function(e){var i=function(t,r){return e.next(r)};return t.on(r,i),function(){return t.off(r,i)}}))},Vt=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(pt.INITIALIZING),this.textTracksManager=new D,this.trackLevels=new Map,this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.seekPosition.getTransition();if(t!==pt.INITIALIZING){var s=null==n?void 0:n.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(s)&&r.seek(s),i){case exports.PlaybackState.STOPPED:switch(t){case pt.STOPPED:break;case pt.READY:case pt.PLAYING:case pt.PAUSED:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case pt.PLAYING:break;case pt.STOPPED:r.prepare();break;case pt.READY:case pt.PAUSED:r.playIfAllowed();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case pt.PAUSED:break;case pt.STOPPED:r.prepare();break;case pt.READY:r.videoState.setState(pt.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case pt.PLAYING:r.pause();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=_(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.isLive$.next(!1),this.params.output.hostname$.next(Z(this.params.source.url)),this.loadHlsJs()}return t.prototype.destroy=function(){var e,t;this.subscription.unsubscribe(),this.trackLevels.clear(),this.textTracksManager.destroy(),null===(e=this.hls)||void 0===e||e.detachMedia(),null===(t=this.hls)||void 0===t||t.destroy(),this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.loadHlsJs=function(){var e=this,t=!1,i=function(r){t||e.params.output.error$.next({id:"timeout"===r?"HlsJsTimeout":"HlsJsLoadError",message:"Failed to load Hls.js",thrown:r}),t=!0},a=window.setTimeout((function(){return i("timeout")}),5e3);Promise.resolve().then((function(){return r(require("hls.js"))})).then((function(r){t||(vt.Hls=r.default,vt.Events=r.default.Events,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){e.assertNonNullable(vt.Hls,"hls.js not loaded"),this.hls=new vt.Hls({fragLoadingMaxRetry:5,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetryTimeout:16e3,manifestLoadingMaxRetryTimeout:2e3,levelLoadingMaxRetryTimeout:2e3}),this.subscribe(),this.videoState.setState(pt.STOPPED)},t.prototype.subscribe=function(){var t=this;e.assertNonNullable(vt.Events,"hls.js not loaded");var r=this.params,i=r.desiredState,a=r.output,n=function(e){a.error$.next({id:"HlsJsProvider",message:"HlsJsProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r,n))};o(s.timeUpdate$,a.position$),o(s.durationChange$,a.duration$),o(s.ended$,a.endedEvent$),o(s.error$,a.error$),o(s.isBuffering$,a.isBuffering$),o(s.currentBuffer$,a.currentBuffer$),o(s.firstBytes$,a.firstBytesEvent$),o(s.firstFrame$,a.firstFrameEvent$),o(s.seeked$,a.seekedEvent$),this.subscription.add(A(this.video,i.isLooped,n)),this.subscription.add($(this.video,i.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$)),this.subscription.add(Ot(this.hls,vt.Events.ERROR).subscribe((function(e){var t;e.fatal&&a.error$.next({id:["HlsJsFatal",e.type,e.details].join("_"),message:"HlsJs fatal "+e.type+" "+e.details+", "+(null===(t=e.err)||void 0===t?void 0:t.message)+" "+e.reason,thrown:e.error})}))),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState(pt.PLAYING),V(i.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(pt.PAUSED),V(i.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===pt.READY&&t.videoState.setState(pt.READY),t.videoState.getState()===pt.PLAYING&&t.playIfAllowed()}),n)),o(Ot(this.hls,vt.Events.MANIFEST_PARSED).pipe(e.map((function(e){return e.levels.reduce((function(e,r){var i,a,n=r.name||r.height.toString(10),s=r.width,o=r.height,u=null!==(a=ot(null!==(i=r.attrs.QUALITY)&&void 0!==i?i:""))&&void 0!==a?a:q({width:s,height:o});if(!u)return e;var d={id:n.toString(),quality:u,bitrate:r.bitrate/1e3,size:{width:s,height:o}};return t.trackLevels.set(n,{track:d,level:r}),e.push(d),e}),[])}))),a.availableVideoTracks$),o(Ot(this.hls,vt.Events.LEVEL_LOADING).pipe(e.map((function(e){var t=e.url;return Z(t)}))),a.hostname$),this.subscription.add(x(i.autoVideoTrackSwitching,(function(){return t.hls.autoLevelEnabled}),(function(e){t.hls.nextLevel=e?-1:t.hls.currentLevel,t.hls.loadLevel=e?-1:t.hls.loadLevel}),{onError:n}));var u=function(e){var r;return null===(r=Array.from(t.trackLevels.values()).find((function(t){return t.level===e})))||void 0===r?void 0:r.track},d=Ot(this.hls,vt.Events.LEVEL_SWITCHED).pipe(e.map((function(e){var r=e.level;return u(t.hls.levels[r])})));d.pipe(e.filter(e.isNonNullable)).subscribe(a.currentVideoTrack$,n),this.subscription.add(x(i.videoTrack,(function(){var e;return null===(e=u(t.hls.levels[t.hls.currentLevel]))||void 0===e?void 0:e.id}),(function(r){var i;if(!e.isNullable(r)){var a=null===(i=t.trackLevels.get(r))||void 0===i?void 0:i.level;if(a){var n=t.hls.levels.indexOf(a),s=t.hls.currentLevel,o=t.hls.levels[s];!o||a.bitrate>o.bitrate?t.hls.nextLevel=n:(t.hls.loadLevel=n,t.hls.loadLevel=n)}}}),{changed$:d.pipe(e.map((function(e){return null==e?void 0:e.id}))),onError:n})),o(s.progress$,(function(){t.params.dependencies.throughputEstimator.addRawThroughput(t.hls.bandwidthEstimate/1e3)})),this.textTracksManager.connect(this.video,i,a);var l=e.merge(i.playbackState.stateChangeStarted$,i.videoTrack.stateChangeStarted$,i.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(l.subscribe(this.syncPlayback,n))},t.prototype.prepare=function(){this.videoState.startTransitionTo(pt.READY),this.hls.attachMedia(this.video),this.hls.loadSource(this.params.source.url)},t.prototype.playIfAllowed=function(){return c(this,void 0,void 0,(function(){return p(this,(function(e){switch(e.label){case 0:return this.videoState.startTransitionTo(pt.PLAYING),[4,w(this.video)];case 1:return e.sent()||(this.videoState.setState(pt.PAUSED),V(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)),[2]}}))}))},t.prototype.pause=function(){this.videoState.startTransitionTo(pt.PAUSED),this.video.pause()},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.video.currentTime=e},t.prototype.stop=function(){this.params.output.position$.next(0),this.params.output.duration$.next(1/0),this.params.output.currentBuffer$.next(void 0),this.params.output.hostname$.next(void 0),this.hls.stopLoad(),this.hls.detachMedia(),this.video.setAttribute("src",""),this.video.load(),this.videoState.setState(pt.STOPPED),V(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t}(),Mt=function(){function e(e){this.iterator=e[Symbol.iterator](),this.next()}return e.prototype.next=function(){this.current=this.iterator.next()},e.prototype.getValue=function(){if(this.current.done)throw new Error("Iterable is completed");return this.current.value},e.prototype.isCompleted=function(){return Boolean(this.current.done)},e}(),Bt=(Ct=window.navigator.userAgent,!/chrome/i.test(Ct)&&/webkit|safari|khtml/i.test(Ct)),Ut=(null===(St=null===(mt=navigator)||void 0===mt?void 0:mt.userAgentData)||void 0===St?void 0:St.mobile)||/Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(navigator.appVersion),Ft=document.createElement("video"),Ht={mse:Boolean(window.MediaSource&&window.MediaStreamTrack&&(null===(gt=null===(bt=window.SourceBuffer)||void 0===bt?void 0:bt.prototype)||void 0===gt?void 0:gt.appendBuffer)),hls:Boolean((null===(yt=Ft.canPlayType)||void 0===yt?void 0:yt.call(Ft,"application/x-mpegurl"))||(null===(Tt=Ft.canPlayType)||void 0===Tt?void 0:Tt.call(Ft,"vnd.apple.mpegURL")))},qt={mp4:Boolean(null===(Et=Ft.canPlayType)||void 0===Et?void 0:Et.call(Ft,"video/mp4")),webm:Boolean(null===(Pt=Ft.canPlayType)||void 0===Pt?void 0:Pt.call(Ft,"video/webm"))},Gt={h264:Boolean(null===(wt=null===(kt=window.MediaSource)||void 0===kt?void 0:kt.isTypeSupported)||void 0===wt?void 0:wt.call(kt,'video/mp4; codecs="avc1.42000a,mp4a.40.2"')),h265:Boolean(null===(At=null===(xt=window.MediaSource)||void 0===xt?void 0:xt.isTypeSupported)||void 0===At?void 0:At.call(xt,'video/mp4; codecs="hev1.1.6.L93.B0"')),vp9:Boolean(null===(Nt=null===($t=window.MediaSource)||void 0===$t?void 0:$t.isTypeSupported)||void 0===Nt?void 0:Nt.call($t,'video/webm; codecs="vp9"')),aac:Boolean(null===(_t=null===(Dt=window.MediaSource)||void 0===Dt?void 0:Dt.isTypeSupported)||void 0===_t?void 0:_t.call(Dt,'audio/mp4; codecs="mp4a.40.2"')),opus:Boolean(null===(It=null===(Rt=window.MediaSource)||void 0===Rt?void 0:Rt.isTypeSupported)||void 0===It?void 0:It.call(Rt,'audio/webm; codecs="opus"'))},jt=(Gt.h264||Gt.h265)&&Gt.aac,Yt=!Bt,zt=Ut||Bt,Qt=!Ht.hls||!zt,Wt=3e4,Jt=18e4,Kt=3,Xt=100,Zt={cacheDuration:12e4},er={maxPausedTime:3e4,chunkDuration:5e3,optimalBufferDuration:1e4,maxParallelRequests:5},tr={maxPausedTime:3e4},rr={maxPausedTime:3e4},ir=function(){function t(t){this.current$=new e.ValueSubject({type:void 0}),this.providerError$=new e.Subject,this.noAvailableProvidersError$=new e.Subject,this.providerOutput={position$:new e.ValueSubject(0),duration$:new e.ValueSubject(1/0),volume$:new e.ValueSubject({muted:!1,volume:1}),currentVideoTrack$:new e.ValueSubject(void 0),availableVideoTracks$:new e.ValueSubject([]),currentBuffer$:new e.ValueSubject(void 0),isBuffering$:new e.ValueSubject(!0),error$:new e.Subject,willSeekEvent$:new e.Subject,seekedEvent$:new e.Subject,endedEvent$:new e.Subject,firstBytesEvent$:new e.Subject,firstFrameEvent$:new e.Subject,isLive$:new e.ValueSubject(void 0),liveTime$:new e.ValueSubject(void 0),availableTextTracks$:new e.ValueSubject([]),currentTextTrack$:new e.ValueSubject(void 0),hostname$:new e.ValueSubject(void 0),httpConnectionType$:new e.ValueSubject(void 0),httpConnectionReused$:new e.ValueSubject(void 0),element$:new e.ValueSubject(void 0)},this.subscription=new e.Subscription,this.params=t,this.log=this.params.dependencies.logger.createComponentLog("ProviderContainer");var r=this.params.tuning.formatsToAvoid,i=r.length?v(v([],f(t.screenFormatsPriority.filter((function(e){return!r.includes(e)}))),!1),f(t.screenFormatsPriority.filter((function(e){return r.includes(e)}))),!1):t.screenFormatsPriority;this.screenFormatsIterator=new Mt(i.filter((function(r){return e.isNonNullable(t.sources[r])})).filter((function(t){switch(t){case exports.VideoFormat.DASH:return Ht.mse&&qt.mp4&&jt&&Yt;case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_SEP_VK:return Ht.mse&&qt.mp4&&jt;case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.DASH_LIVE_WEBM:return Ht.mse&&qt.webm&&Gt.vp9&&Gt.opus;case exports.VideoFormat.DASH_LIVE:case exports.VideoFormat.DASH_ONDEMAND:return Ht.mse&&qt.mp4&&jt;case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_LIVE:case exports.VideoFormat.HLS_ONDEMAND:return Ht.hls&&qt.mp4&&zt;case exports.VideoFormat.HLS_JS:return Ht.mse&&qt.mp4&&jt&&Qt;case exports.VideoFormat.MPEG:return qt.mp4;default:return e.assertNever(t)}}))),this.chromecastFormatsIterator=new Mt(t.chromecastFormatsPriority.filter((function(r){return e.isNonNullable(t.sources[r])})))}return t.prototype.init=function(){var e=this;this.subscription.add(this.initProviderErrorHandling()),this.subscription.add(this.params.dependencies.chromecastInitializer.connection$.subscribe((function(){e.reinitProvider()})))},t.prototype.destroy=function(){this.destroyProvider(),this.current$.next({type:void 0}),this.subscription.unsubscribe()},t.prototype.initProvider=function(){var t=this.chooseDestination(),r=this.chooseFormat(t);if(e.isNullable(r))this.handleNoFormatsError(t);else{var i=this.createProvider(t,r);this.current$.next({type:r,provider:i,destination:t})}},t.prototype.reinitProvider=function(){this.destroyProvider(),this.initProvider()},t.prototype.switchToNextProvider=function(){this.destroyProvider();var t=this.current$.getValue().destination;e.assertNonNullable(t),this.skipFormat(t),this.initProvider()},t.prototype.destroyProvider=function(){var t=this.current$.getValue().provider;if(t){this.log({message:"destroyProvider"});var r=this.params.desiredState.seekPosition,i=r.getTransition();i?e.isNonNullable(i.from)&&r.startTransitionTo(i.from):r.startTransitionTo(this.providerOutput.position$.getValue()),t.destroy();var a=this.providerOutput.isBuffering$;a.getValue()||a.next(!0)}},t.prototype.createProvider=function(t,r){switch(this.log({message:"createProvider: "+t+":"+r}),t){case n.SCREEN:return this.createScreenProvider(r);case n.CHROMECAST:return this.createChromecastProvider(r);default:return e.assertNever(t)}},t.prototype.createScreenProvider=function(t){var r=this.params,i=r.sources,a=r.container,n=r.desiredState,s=this.providerOutput;switch(t){case exports.VideoFormat.DASH:var o=i[t];return e.assertNonNullable(o),new Ve({container:a,source:o,desiredState:n,output:s,config:Zt,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_SEP_VK:case exports.VideoFormat.DASH_WEBM_VK:o=i[t];return e.assertNonNullable(o),new we({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_ONDEMAND:case exports.VideoFormat.DASH_LIVE_WEBM:o=i[t];return e.assertNonNullable(o),new Ye({container:a,source:o,desiredState:n,output:s,format:t,config:rr,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_ONDEMAND:o=i[t];return e.assertNonNullable(o),new ct({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS_LIVE:o=i[t];return e.assertNonNullable(o),new ht({container:a,source:o,desiredState:n,output:s,config:tr,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS_JS:o=i[t];return e.assertNonNullable(o),new Vt({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.MPEG:o=i[t];return e.assertNonNullable(o),new _e({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_LIVE:o=i[t];return e.assertNonNullable(o),new nt({container:a,source:o,desiredState:n,output:s,config:er,dependencies:this.params.dependencies,tuning:this.params.tuning});default:return e.assertNever(t)}},t.prototype.createChromecastProvider=function(t){var r=this.params,i=r.sources,a=r.container,n=r.desiredState,s=r.meta,o=this.providerOutput,u=this.params.dependencies.chromecastInitializer.connection$.getValue();return e.assertNonNullable(u),new Ne({connection:u,meta:s,container:a,source:i,format:t,desiredState:n,output:o,dependencies:this.params.dependencies,tuning:this.params.tuning})},t.prototype.chooseDestination=function(){return this.params.dependencies.chromecastInitializer.connection$.getValue()?n.CHROMECAST:n.SCREEN},t.prototype.chooseFormat=function(t){switch(t){case n.SCREEN:return this.screenFormatsIterator.isCompleted()?void 0:this.screenFormatsIterator.getValue();case n.CHROMECAST:return this.chromecastFormatsIterator.isCompleted()?void 0:this.chromecastFormatsIterator.getValue();default:return e.assertNever(t)}},t.prototype.skipFormat=function(t){switch(t){case n.SCREEN:return this.screenFormatsIterator.next();case n.CHROMECAST:return this.chromecastFormatsIterator.next();default:return e.assertNever(t)}},t.prototype.handleNoFormatsError=function(t){switch(t){case n.SCREEN:return this.noAvailableProvidersError$.next(),void this.current$.next({type:void 0});case n.CHROMECAST:return void this.params.dependencies.chromecastInitializer.disconnect();default:return e.assertNever(t)}},t.prototype.initProviderErrorHandling=function(){var t,r=this,i=[],a=0,s=new e.Subscription;return s.add(e.merge(this.providerOutput.error$,(t={desiredPlaybackState$:this.params.desiredState.playbackState,maxTransitionInterval:Wt,position$:this.providerOutput.position$,providerChanged$:this.current$},new e.Observable((function(r){var i=new e.Subscription,a=e.timeout(t.maxTransitionInterval),n=new e.ValueSubject(void 0);e.merge(t.desiredPlaybackState$.stateChangeStarted$.pipe(e.mapTo(a)),t.desiredPlaybackState$.stateChangeEnded$.pipe(e.mapTo(void 0)),t.providerChanged$.pipe(e.map((function(){return n.getValue()})))).subscribe(n);var s=new e.Subscription;return i.add(s),i.add(n.subscribe((function(e){s.unsubscribe(),e&&s.add(e.subscribe(r))}))),i}))).pipe(e.mapTo({id:"ProviderHangup",message:"An operation failed to complete within reasonable time"}))).subscribe(this.providerError$)),s.add(this.providerError$.pipe(e.throttle(Xt,{leading:!1,trailing:!0})).subscribe((function(){var t=Date.now();r.current$.getValue().destination===n.CHROMECAST?(r.destroyProvider(),r.params.dependencies.chromecastInitializer.stopMedia().then((function(){r.switchToNextProvider()}),(function(){r.params.dependencies.chromecastInitializer.disconnect()}))):e.isNonNullable(i[a])&&t<i[a]+Jt?(i=[],r.switchToNextProvider()):(i[a]=t,r.reinitProvider()),a=(a+1)%Kt}))),s},t}(),ar=function(e,t,r){return r*t+(1-r)*e},nr=function(){function t(t){var r;this.prevReported=void 0,this.params=t,this.slow=this.fast=this.smoothed=this.prevReported=t.initial,this.smoothed$=new e.ValueSubject(t.initial),this.debounced$=new e.ValueSubject(t.initial);var i=null!==(r=t.label)&&void 0!==r?r:"value"+Math.random().toString(16).substring(2,6);this.rawSeries$=new W("raw_"+i),this.smoothedSeries$=new W("smoothed_"+i),this.reportedSeries$=new W("reported_"+i)}return t.prototype.next=function(t){this.slow=ar(this.slow,t,this.params.emaAlphaSlow),this.fast=ar(this.fast,t,this.params.emaAlphaFast);var r=this.params.fastDirection>0?Math.max:Math.min;this.smoothed=r(this.slow,this.fast),this.smoothed$.next(this.smoothed),(e.isNullable(this.prevReported)||Math.abs(this.smoothed-this.prevReported)/this.prevReported>=this.params.changeThreshold)&&(this.prevReported=this.smoothed,this.debounced$.next(this.smoothed),this.reportedSeries$.next(this.smoothed)),this.rawSeries$.next(t),this.smoothedSeries$.next(this.smoothed)},t}();!function(e){e[e.LOCAL_STORAGE=0]="LOCAL_STORAGE",e[e.SESSION_STORAGE=1]="SESSION_STORAGE",e[e.RUNTIME=2]="RUNTIME"}(Lt||(Lt={}));var sr=new Map,or=Lt.RUNTIME,ur="vk-videoplayer-dummy-key-"+Math.random();!function(){try{localStorage.setItem(ur,"test"),localStorage.removeItem(ur),or=Lt.LOCAL_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;try{sessionStorage.getItem(ur),or=Lt.SESSION_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;or=Lt.RUNTIME}}}();var dr,lr=function(t,r){switch(or){case Lt.LOCAL_STORAGE:return localStorage.setItem(t,r);case Lt.SESSION_STORAGE:return sessionStorage.setItem(t,r);case Lt.RUNTIME:return void sr.set(t,r);default:e.assertNever(or)}},cr=window.navigator.connection,pr=function(){var t=null==cr?void 0:cr.downlink;if(e.isNonNullable(t)&&10!==t)return 1e3*t},hr=function(){var t=null==cr?void 0:cr.rtt;if(e.isNonNullable(t)&&3e3!==t)return t},fr=function(e,t,r){var i=8*r;return i/(i/e+t)},vr=function(){function t(r){var i,a,n=this;this.subscription=new e.Subscription,this.tuningConfig=r;var s=t.load("one_video_throughput")||(r.useBrowserEstimation?pr():void 0)||5e3,o=null!==(a=null!==(i=t.load("one_video_rtt"))&&void 0!==i?i:r.useBrowserEstimation?hr():void 0)&&void 0!==a?a:0;if(this.throughput$=new e.ValueSubject(s),this.rtt$=new e.ValueSubject(o),this.rttAdjustedThroughput$=new e.ValueSubject(fr(s,o,r.rttPenaltyRequestSize)),this.throughput=new nr({initial:s,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:-1,label:"throughput"}),this.rtt=new nr({initial:o,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:1,label:"rtt"}),r.useBrowserEstimation){var u=function(){var t=pr();t&&n.throughput.next(t);var r=hr();e.isNonNullable(r)&&n.rtt.next(r)};cr&&"onchange"in cr&&this.subscription.add(e.fromEvent(cr,"change").subscribe(u)),u()}this.subscription.add(this.throughput.smoothed$.subscribe((function(e){lr("one_video_throughput",e.toFixed(0))}))),this.subscription.add(this.rtt.smoothed$.subscribe((function(e){lr("one_video_rtt",e.toFixed(0))}))),this.subscription.add(this.throughput.debounced$.subscribe(this.throughput$)),this.subscription.add(this.rtt.debounced$.subscribe(this.rtt$)),this.subscription.add(e.combine({throughput:this.throughput.smoothed$,rtt:this.rtt.smoothed$}).pipe(e.map((function(e){var t=e.throughput,i=e.rtt;return fr(t,i,r.rttPenaltyRequestSize)})),e.filter((function(e){var t=n.rttAdjustedThroughput$.getValue()||0;return Math.abs(e-t)/t>=r.changeThreshold}))).subscribe(this.rttAdjustedThroughput$))}return t.prototype.destroy=function(){this.subscription.unsubscribe()},t.prototype.trackXHR=function(t){var r=this,i=0,a=e.now(),n=new e.Subscription;switch(this.subscription.add(n),t.readyState){case 4:break;case 3:case 2:n.add(e.fromEvent(t,"progress").pipe(e.once()).subscribe((function(t){i=t.loaded,a=e.now()})));break;case 1:case 0:n.add(e.fromEvent(t,"loadstart").subscribe((function(){i=0,a=e.now()})))}n.add(e.fromEvent(t,"loadend").subscribe((function(s){if(200===t.status){var o=s.loaded,u=e.now(),d=o-i,l=u-a;r.addRawSpeed(d,l)}n.unsubscribe()})))},t.prototype.trackStream=function(t){var r=this,i=t.getReader();if(i){var a=0,n=e.now(),s=0,o=e.now(),u=function(e){i.releaseLock(),t.cancel("Throughput Estimator error: "+e).catch((function(){}))},d=function(t){var l=t.done,h=t.value;return c(r,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return l?(this.addRawSpeed(a,e.now()-n),[3,3]):[3,1];case 1:return h?(a+=h.byteLength,(s+=h.byteLength)>=this.tuningConfig.streamMinSampleSize&&e.now()-o>=this.tuningConfig.streamMinSampleTime&&(this.addRawSpeed(s,e.now()-o),s=0,o=e.now()),[4,null==i?void 0:i.read().then(d,u)]):[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))};null==i||i.read().then(d,u)}else t.cancel("Could not get reader")},t.prototype.addRawSpeed=function(e,r){if(t.sanityCheck(e,r)){var i=8*e/r;this.throughput.next(i)}},t.prototype.addRawThroughput=function(e){this.throughput.next(e)},t.prototype.addRawRtt=function(e){this.rtt.next(e)},t.sanityCheck=function(e,t){var r=8*e/t;return!(!r||!isFinite(r))&&(!(r>1e6)&&(!(r<30)&&(!(e<10240)&&!(t<=20))))},t.load=function(t){var r,i=function(t){var r,i;switch(or){case Lt.LOCAL_STORAGE:return null!==(r=localStorage.getItem(t))&&void 0!==r?r:void 0;case Lt.SESSION_STORAGE:return null!==(i=sessionStorage.getItem(t))&&void 0!==i?i:void 0;case Lt.RUNTIME:return sr.get(t);default:e.assertNever(or)}}(t);if(e.isNonNullable(i))return null!==(r=parseInt(i,10))&&void 0!==r?r:void 0},t}(),mr=function(t){return void 0===t&&(t=function(e){return e}),function(r){var i=r.playbackState,a=r.seekPosition,n=r.playbackAbort$,s=r.position$;return new e.Observable((function(r){var o,u=i.transitionEnded$.pipe(e.filter((function(e){return(e.from===exports.PlaybackState.PAUSED||e.from===exports.PlaybackState.STOPPED)&&e.to===exports.PlaybackState.PLAYING}))),d=i.stateChangeEnded$.pipe(e.filter((function(e){return e.from===exports.PlaybackState.PLAYING&&e.to===exports.PlaybackState.PAUSED}))),l=a.stateChangeEnded$.pipe(e.filter((function(t){var r,a;return e.isNonNullable(t.to)&&(null!==(a=null===(r=i.getTransition())||void 0===r?void 0:r.from)&&void 0!==a?a:i.getState())===exports.PlaybackState.PLAYING}))),c=a.stateChangeEnded$.pipe(e.filter((function(t){var r,a;return e.isNullable(t.to)&&(null!==(a=null===(r=i.getTransition())||void 0===r?void 0:r.from)&&void 0!==a?a:i.getState())===exports.PlaybackState.PLAYING}))),p=e.merge(u,c).pipe(e.map((function(){return t(s.getValue())}))),h=e.merge(d,l,n).pipe(e.map((function(){return t(s.getValue())})));return(new e.Subscription).add(p.subscribe((function(e){o=t(e)}))).add(h.subscribe((function(i){if(!e.isNullable(o)){var a={start:o,end:t(i)};o=void 0,r.next(a)}})))}))}},Sr=mr((function(e){return e})),br=mr((function(e){return Math.round(1e3*e)+Date.now()})),gr=((dr={})[n.SCREEN]={vod:[exports.VideoFormat.HLS,exports.VideoFormat.HLS_ONDEMAND,exports.VideoFormat.DASH_WEBM_VK,exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH,exports.VideoFormat.DASH_SEP_VK,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_ONDEMAND,exports.VideoFormat.HLS_JS,exports.VideoFormat.MPEG],live:[exports.VideoFormat.HLS_LIVE,exports.VideoFormat.DASH_LIVE,exports.VideoFormat.DASH_LIVE_WEBM]},dr[n.CHROMECAST]={vod:[exports.VideoFormat.DASH_WEBM_VK,exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH_SEP_VK,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_ONDEMAND,exports.VideoFormat.HLS,exports.VideoFormat.HLS_ONDEMAND,exports.VideoFormat.MPEG],live:[exports.VideoFormat.HLS_LIVE]},dr),yr=function(){function t(t){var r=this;if(void 0===t&&(t={}),this.subscription=new e.Subscription,this.logger=new e.Logger,this.isPlaybackStarted=!1,this.desiredState={playbackState:new te(exports.PlaybackState.STOPPED),seekPosition:new te(void 0),volume:new te({volume:1,muted:!1}),videoTrack:new te(void 0),autoVideoTrackSwitching:new te(!0),isLooped:new te(!1),externalTextTracks:new te([]),currentTextTrack:new te(void 0),textTrackCuesSettings:new te({})},this.info={playbackState$:new e.ValueSubject(exports.PlaybackState.STOPPED),position$:new e.ValueSubject(0),duration$:new e.ValueSubject(1/0),muted$:new e.ValueSubject(!1),volume$:new e.ValueSubject(1),availableQualities$:new e.ValueSubject([]),currentQuality$:new e.ValueSubject(void 0),isAutoQualityEnabled$:new e.ValueSubject(!0),currentBuffer$:new e.ValueSubject(void 0),isBuffering$:new e.ValueSubject(!0),isStalled$:new e.ValueSubject(!1),isEnded$:new e.ValueSubject(!1),isLooped$:new e.ValueSubject(!1),isLive$:new e.ValueSubject(void 0),liveTime$:new e.ValueSubject(void 0),currentFormat$:new e.ValueSubject(void 0),availableTextTracks$:new e.ValueSubject([]),currentTextTrack$:new e.ValueSubject(void 0),throughputEstimation$:new e.ValueSubject(void 0),rttEstimation$:new e.ValueSubject(void 0),videoBitrate$:new e.ValueSubject(void 0),hostname$:new e.ValueSubject(void 0),httpConnectionType$:new e.ValueSubject(void 0),httpConnectionReused$:new e.ValueSubject(void 0),chromecastState$:new e.ValueSubject(exports.ChromecastState.NOT_AVAILABLE),chromecastDeviceName$:new e.ValueSubject(void 0)},this.events={started$:new e.Subject,startAttempt$:new e.Subject,willPause$:new e.Subject,willResume$:new e.Subject,willDestruct$:new e.Subject,watchCoverageRecord$:new e.Subject,watchCoverageLive$:new e.Subject,managedError$:new e.Subject,fatalError$:new e.Subject,ended$:new e.Subject,seeked$:new e.Subject,willSeek$:new e.Subject,firstBytes$:new e.Subject,firstFrame$:new e.Subject,log$:new e.Subject},this.experimental={element$:new e.ValueSubject(void 0),enableDebugTelemetry$:new e.ValueSubject(!1),dumpTelemetry:z},this.initLogs(),this.tuning=function(e){var t,r,i={};try{for(var a=h(Object.keys(y)),n=a.next();!n.done;n=a.next()){var s=n.value,o=y[s],u=e[s];Array.isArray(o)&&Array.isArray(u)?i[s]=u:i[s]="object"==typeof o&&"object"==typeof u?l(l({},o),u):null!=u?u:o}}catch(e){t={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return i}(t),this.chromecastInitializer=new T({receiverApplicationId:t.chromecastReceiverId,isDisabled:t.disableChromecast,dependencies:{logger:this.logger}}),this.throughputEstimator=new vr(this.tuning.throughputEstimator),this.initChromecastSubscription(),this.initDesiredStateSubscriptions(),Proxy&&Reflect)return new Proxy(this,{get:function(e,t,i){var a=Reflect.get(e,t,i);return"function"!=typeof a?a:function(){for(var i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];try{return a.apply(e,i)}catch(e){var s=i.map((function(e){return JSON.stringify(e,(function(e,t){var r=typeof t;return["number","string","boolean"].includes(r)?t:null===t?null:"<"+r+">"}))})),o="Player."+String(t),u="Exception calling "+o+" ("+s.join(", ")+")";throw r.events.fatalError$.next({id:o,message:u,thrown:e}),e}}}})}return t.prototype.initVideo=function(t){var r,i;return this.config=t,this.domContainer=function(t){var r="string"==typeof t.container?document.getElementById(t.container):t.container;return e.assertNonNullable(r,"Wrong container or containerId {"+t.container+"}"),r}(t),this.chromecastInitializer.contentId=null===(r=t.meta)||void 0===r?void 0:r.videoId,this.providerContainer=new ir({screenFormatsPriority:v(v([],f(gr[n.SCREEN].live),!1),f(gr[n.SCREEN].vod),!1),chromecastFormatsPriority:v(v([],f(gr[n.CHROMECAST].live),!1),f(gr[n.CHROMECAST].vod),!1),sources:t.sources,meta:null!==(i=t.meta)&&void 0!==i?i:{},container:this.domContainer,desiredState:this.desiredState,dependencies:{throughputEstimator:this.throughputEstimator,chromecastInitializer:this.chromecastInitializer,logger:this.logger},tuning:this.tuning}),this.initProviderContainerSubscription(this.providerContainer),this.initStartingVideoTrack(this.providerContainer),this.providerContainer.init(),this.initDebugTelemetry(),this},t.prototype.destroy=function(){var e;this.events.willDestruct$.next(),null===(e=this.providerContainer)||void 0===e||e.destroy(),this.throughputEstimator.destroy(),this.chromecastInitializer.destroy(),this.subscription.unsubscribe()},t.prototype.play=function(){var e=this.desiredState.playbackState;return e.getState()!==exports.PlaybackState.PLAYING&&e.startTransitionTo(exports.PlaybackState.PLAYING),this},t.prototype.pause=function(){var e=this.desiredState.playbackState;return e.getState()!==exports.PlaybackState.PAUSED&&e.startTransitionTo(exports.PlaybackState.PAUSED),this},t.prototype.stop=function(){var e=this.desiredState.playbackState;return e.getState()!==exports.PlaybackState.STOPPED&&e.startTransitionTo(exports.PlaybackState.STOPPED),this},t.prototype.seekTime=function(e){return this.events.willSeek$.next({from:this.getExactTime(),to:e}),this.desiredState.seekPosition.startTransitionTo(e),this},t.prototype.seekPercent=function(e){var t=this.info.duration$.getValue();return isFinite(t)&&this.seekTime(Math.abs(t)*e),this},t.prototype.setVolume=function(e){return this.chromecastInitializer.castState$.getValue()===exports.ChromecastState.CONNECTED?this.chromecastInitializer.setVolume(e):this.desiredState.volume.startTransitionTo({volume:e,muted:this.desiredState.volume.getState().muted}),this},t.prototype.setMuted=function(e){return this.chromecastInitializer.castState$.getValue()===exports.ChromecastState.CONNECTED?this.chromecastInitializer.setMuted(e):this.desiredState.volume.startTransitionTo({volume:this.desiredState.volume.getState().volume,muted:e}),this},t.prototype.setQuality=function(t){e.assertNonNullable(this.providerContainer);var r=this.providerContainer.providerOutput.availableVideoTracks$.getValue();r.length||(this.explicitInitialQuality=t);var i=r.find((function(e){return e.quality===t}));return i&&this.desiredState.videoTrack.startTransitionTo(i.id),this},t.prototype.setAutoQuality=function(e){return this.desiredState.autoVideoTrackSwitching.startTransitionTo(e),this},t.prototype.setExternalTextTracks=function(e){return this.desiredState.externalTextTracks.startTransitionTo(e.map((function(e){return l({type:"external"},e)}))),this},t.prototype.selectTextTrack=function(e){var t;return(void 0===e||(null===(t=this.providerContainer)||void 0===t?void 0:t.providerOutput.availableTextTracks$.getValue().find((function(t){return t.id===e}))))&&this.desiredState.currentTextTrack.startTransitionTo(e),this},t.prototype.setTextTrackCueSettings=function(e){return this.desiredState.textTrackCuesSettings.startTransitionTo(e),this},t.prototype.setLooped=function(e){return this.desiredState.isLooped.startTransitionTo(e),this},t.prototype.toggleChromecast=function(){this.chromecastInitializer.toggleConnection()},t.prototype.getExactTime=function(){var t;e.assertNonNullable(this.providerContainer);var r=this.providerContainer.providerOutput.element$.getValue();if(e.isNullable(r))return this.info.position$.getValue();var i=this.desiredState.seekPosition.getTransition(),a=null!==(t=null==i?void 0:i.to)&&void 0!==t?t:null==i?void 0:i.from;return e.isNonNullable(a)?a:r.currentTime},t.prototype.getAllLogs=function(){return this.logger.getAllLogs()},t.prototype.initDesiredStateSubscriptions=function(){var t=this;this.subscription.add(e.merge(this.desiredState.playbackState.stateChangeStarted$,this.desiredState.playbackState.forceChanged$).pipe(e.map((function(e){return e.to}))).subscribe(this.info.playbackState$)).add(this.desiredState.isLooped.stateChangeEnded$.pipe(e.map((function(e){return e.to}))).subscribe(this.info.isLooped$)).add(this.desiredState.autoVideoTrackSwitching.stateChangeEnded$.pipe(e.map((function(e){return e.to}))).subscribe(this.info.isAutoQualityEnabled$));var r=new e.Subscription;this.subscription.add(r),this.subscription.add(this.desiredState.playbackState.stateChangeStarted$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING}))).subscribe((function(){r.unsubscribe(),r.add(t.desiredState.playbackState.stateChangeEnded$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING||e.to===exports.PlaybackState.PAUSED})),e.once()).subscribe((function(e){var r=e.to===exports.PlaybackState.PLAYING,i=t.info.muted$.getValue(),a=r?i?exports.StartStatus.SuccessWithoutSound:exports.StartStatus.SuccessWithSound:exports.StartStatus.Failed;t.events.startAttempt$.next(a)})))}))),this.subscription.add(this.desiredState.playbackState.stateChangeEnded$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING}))).subscribe((function(){t.isPlaybackStarted||(t.isPlaybackStarted=!0,t.events.started$.next())}))).add(this.desiredState.playbackState.stateChangeStarted$.subscribe((function(e){switch(e.to){case exports.PlaybackState.PAUSED:t.events.willPause$.next();break;case exports.PlaybackState.PLAYING:t.isPlaybackStarted&&t.events.willResume$.next()}})))},t.prototype.initProviderContainerSubscription=function(t){var r=this;this.subscription.add(t.providerOutput.willSeekEvent$.subscribe((function(){var t=r.desiredState.seekPosition.getTransition(),i=null==t?void 0:t.to;e.isNonNullable(i)&&(r.desiredState.seekPosition.setState(i),r.desiredState.seekPosition.startTransitionTo(void 0))}))).add(t.providerOutput.seekedEvent$.subscribe((function(){var t=r.desiredState.seekPosition.getTransition();e.isNonNullable(null==t?void 0:t.to)||r.desiredState.seekPosition.setState(void 0),r.events.seeked$.next()}))).add(t.current$.pipe(e.map((function(e){return e.type}))).subscribe(this.info.currentFormat$)).add(t.current$.pipe(e.map((function(e){return e.destination})),e.filterChanged()).subscribe((function(){r.isPlaybackStarted=!1}))).add(t.providerOutput.availableVideoTracks$.pipe(e.map((function(e){return e.map((function(e){return e.quality})).sort((function(e,t){return G(e)?1:G(t)?-1:U(t,e)?1:-1}))}))).subscribe(this.info.availableQualities$)).add(t.providerOutput.currentVideoTrack$.subscribe((function(e){r.info.currentQuality$.next(null==e?void 0:e.quality),r.info.videoBitrate$.next(null==e?void 0:e.bitrate)}))).add(t.providerOutput.hostname$.pipe(e.filterChanged()).subscribe(this.info.hostname$)).add(t.providerOutput.httpConnectionType$.pipe(e.filterChanged()).subscribe(this.info.httpConnectionType$)).add(t.providerOutput.httpConnectionReused$.pipe(e.filterChanged()).subscribe(this.info.httpConnectionReused$)).add(t.providerOutput.currentTextTrack$.subscribe(this.info.currentTextTrack$)).add(t.providerOutput.availableTextTracks$.subscribe(this.info.availableTextTracks$)).add(t.providerOutput.currentBuffer$.subscribe(this.info.currentBuffer$)).add(t.providerOutput.duration$.subscribe(this.info.duration$)).add(t.providerOutput.isBuffering$.subscribe(this.info.isBuffering$)).add(t.providerOutput.isLive$.subscribe(this.info.isLive$)).add(t.providerOutput.liveTime$.subscribe(this.info.liveTime$)).add(t.providerOutput.volume$.pipe(e.map((function(e){return e.muted})),e.filterChanged()).subscribe(this.info.muted$)).add(t.providerOutput.volume$.pipe(e.map((function(e){return e.volume})),e.filterChanged()).subscribe(this.info.volume$)).add(function(t){var r=t.seekPosition,i=t.position$;return e.merge(r.stateChangeStarted$.pipe(e.map((function(e){return e.to})),e.filter(e.isNonNullable)),i.pipe(e.filter((function(){return e.isNullable(r.getState())&&e.isNullable(r.getTransition())}))))}({seekPosition:this.desiredState.seekPosition,position$:t.providerOutput.position$}).subscribe(this.info.position$)).add(e.merge(t.providerOutput.endedEvent$.pipe(e.mapTo(!0)),t.providerOutput.seekedEvent$.pipe(e.mapTo(!1))).pipe(e.filterChanged()).subscribe(this.info.isEnded$)).add(t.providerOutput.endedEvent$.subscribe(this.events.ended$)).add(t.providerError$.subscribe(this.events.managedError$)).add(t.noAvailableProvidersError$.pipe(e.map((function(e){return{id:"NoProviders",message:"No suitable providers or all providers failed"}}))).subscribe(this.events.fatalError$)).add(t.providerOutput.element$.subscribe(this.experimental.element$)).add(t.providerOutput.firstBytesEvent$.subscribe(this.events.firstBytes$)).add(t.providerOutput.firstFrameEvent$.subscribe(this.events.firstFrame$)).add(this.throughputEstimator.throughput$.subscribe(this.info.throughputEstimation$)).add(this.throughputEstimator.rtt$.subscribe(this.info.rttEstimation$));var i=new e.ValueSubject(!1);this.subscription.add(t.providerOutput.seekedEvent$.subscribe((function(){return i.next(!1)}))).add(t.providerOutput.willSeekEvent$.subscribe((function(){return i.next(!0)})));var a=new e.ValueSubject(!0);this.subscription.add(t.current$.subscribe((function(){return a.next(!0)}))).add(this.desiredState.playbackState.stateChangeEnded$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING})),e.once()).subscribe((function(){return a.next(!1)})));var n=0,s=e.merge(t.providerOutput.isBuffering$,i,a).pipe(e.map((function(){var e=t.providerOutput.isBuffering$.getValue(),r=i.getValue()||a.getValue();return e&&!r})),e.filterChanged());this.subscription.add(s.subscribe((function(e){e?n=window.setTimeout((function(){return r.info.isStalled$.next(!0)}),r.tuning.stallIgnoreThreshold):(window.clearTimeout(n),r.info.isStalled$.next(!1))})));var o=new e.Subscription;this.subscription.add(o);var u=e.merge(this.events.willDestruct$,t.current$.pipe(e.filter((function(e){return Boolean(null==e?void 0:e.provider)}))));t.providerOutput.isLive$.pipe(e.filterChanged()).subscribe((function(t){switch(e.assertNonNullable(r.providerContainer),o.unsubscribe(),t){case!0:o.add(br({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:u,position$:r.providerContainer.providerOutput.position$}).subscribe(r.events.watchCoverageLive$));break;case!1:o.add(Sr({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:u,position$:r.providerContainer.providerOutput.position$}).subscribe(r.events.watchCoverageRecord$))}}))},t.prototype.initChromecastSubscription=function(){this.subscription.add(this.chromecastInitializer.castState$.subscribe(this.info.chromecastState$)),this.subscription.add(this.chromecastInitializer.connection$.pipe(e.map((function(e){return null==e?void 0:e.castDevice.friendlyName}))).subscribe(this.info.chromecastDeviceName$)),this.subscription.add(this.chromecastInitializer.errorEvent$.subscribe(this.events.managedError$))},t.prototype.initStartingVideoTrack=function(t){var r=this,i=new e.Subscription;this.subscription.add(i),this.subscription.add(t.current$.pipe(e.filterChanged((function(e,t){return e.provider===t.provider}))).subscribe((function(){i.unsubscribe(),i.add(t.providerOutput.availableVideoTracks$.pipe(e.filter((function(e){return e.length>0})),e.once()).subscribe((function(e){r.setStartingVideoTrack(e)})))})))},t.prototype.setStartingVideoTrack=function(e){var t,r=this;this.explicitInitialQuality&&(t=e.find((function(e){return e.quality===r.explicitInitialQuality})),this.explicitInitialQuality=void 0),t||(t=K(e,{container:this.domContainer.getBoundingClientRect(),throughput:this.throughputEstimator.throughput$.getValue(),tuning:this.tuning.autoTrackSelection,forwardBufferHealth:0})),this.desiredState.videoTrack.startTransitionTo(t.id),this.info.currentQuality$.next(t.quality),this.info.videoBitrate$.next(t.bitrate)},t.prototype.initLogs=function(){this.subscription.add(e.merge(this.desiredState.videoTrack.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"quality",type:"start"}}))),this.desiredState.videoTrack.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"quality",type:"end"}}))),this.desiredState.autoVideoTrackSwitching.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"autoQualityEnabled",type:"start"}}))),this.desiredState.autoVideoTrackSwitching.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"autoQualityEnabled",type:"end"}}))),this.desiredState.seekPosition.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"seekPosition",type:"start"}}))),this.desiredState.seekPosition.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"seekPosition",type:"end"}}))),this.desiredState.playbackState.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"playbackState",type:"start"}}))),this.desiredState.playbackState.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"playbackState",type:"end"}})))).pipe(e.map((function(e){return{component:"desiredState",message:"["+e.entity+" change] "+e.type+": "+JSON.stringify(e.transition)}}))).subscribe(this.logger.log)),this.subscription.add(this.logger.log$.subscribe(this.events.log$))},t.prototype.initDebugTelemetry=function(){var t,r=this,i=null===(t=this.providerContainer)||void 0===t?void 0:t.providerOutput;e.assertNonNullable(this.providerContainer),e.assertNonNullable(i),Y={},this.experimental.enableDebugTelemetry$.next(this.tuning.enableTelemetryAtStart),[this.experimental.enableDebugTelemetry$.subscribe((function(e){j=e})),this.providerContainer.current$.subscribe((function(e){var t=e.type;return Q("provider",t)})),i.duration$.subscribe((function(e){return Q("duration",e)})),i.availableVideoTracks$.pipe(e.filter((function(e){return!!e.length})),e.once()).subscribe((function(e){return Q("tracks",e)})),this.events.fatalError$.subscribe(new W("fatalError")),this.events.managedError$.subscribe(new W("managedError")),i.position$.subscribe(new W("position")),i.currentVideoTrack$.pipe(e.map((function(e){return null==e?void 0:e.quality}))).subscribe(new W("quality")),i.currentBuffer$.subscribe(new W("buffer")),i.isBuffering$.subscribe(new W("isBuffering"))].forEach((function(e){return r.subscription.add(e)})),Q("codecs",Object.keys(Gt).filter((function(e){return Gt[e]})))},t}();Object.defineProperty(exports,"Observable",{enumerable:!0,get:function(){return e.Observable}}),Object.defineProperty(exports,"Subject",{enumerable:!0,get:function(){return e.Subject}}),Object.defineProperty(exports,"Subscription",{enumerable:!0,get:function(){return e.Subscription}}),Object.defineProperty(exports,"ValueSubject",{enumerable:!0,get:function(){return e.ValueSubject}}),exports.Player=yr,exports.SDK_VERSION="@vkontakte/videoplayer-core@2.0.38";
|
|
6
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@vkontakte/videoplayer-shared");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i,a,n,s,o,u,d=t(require("lodash/debounce"));exports.PlaybackState=void 0,(i=exports.PlaybackState||(exports.PlaybackState={})).STOPPED="stopped",i.PLAYING="playing",i.PAUSED="paused",exports.VideoFormat=void 0,(a=exports.VideoFormat||(exports.VideoFormat={})).MPEG="MPEG",a.DASH="DASH",a.DASH_SEP="DASH_SEP",a.DASH_SEP_VK="DASH_SEP_VK",a.DASH_WEBM="DASH_WEBM",a.DASH_WEBM_VK="DASH_WEBM_VK",a.DASH_ONDEMAND="DASH_ONDEMAND",a.DASH_LIVE="DASH_LIVE",a.DASH_LIVE_WEBM="DASH_LIVE_WEBM",a.HLS="HLS",a.HLS_ONDEMAND="HLS_ONDEMAND",a.HLS_JS="HLS_JS",a.HLS_LIVE="HLS_LIVE",function(e){e.SCREEN="SCREEN",e.CHROMECAST="CHROMECAST"}(n||(n={})),exports.ChromecastState=void 0,(s=exports.ChromecastState||(exports.ChromecastState={})).NOT_AVAILABLE="NOT_AVAILABLE",s.AVAILABLE="AVAILABLE",s.CONNECTING="CONNECTING",s.CONNECTED="CONNECTED",exports.StartStatus=void 0,(o=exports.StartStatus||(exports.StartStatus={})).SuccessWithSound="success_with_sound",o.SuccessWithoutSound="success_without_sound",o.Failed="failed",exports.HttpConnectionType=void 0,(u=exports.HttpConnectionType||(exports.HttpConnectionType={})).HTTP1="http1",u.HTTP2="http2",u.QUIC="quic";var l=function(){return(l=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function c(e,t,r,i){return new(r||(r=Promise))((function(a,n){function s(e){try{u(i.next(e))}catch(e){n(e)}}function o(e){try{u(i.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,o)}u((i=i.apply(e,t||[])).next())}))}function p(e,t){var r,i,a,n,s={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return n={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function o(n){return function(o){return function(n){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(a=2&n[0]?i.return:n[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,n[1])).done)return a;switch(i=0,a&&(n=[2&n[0],a.value]),n[0]){case 0:case 1:a=n;break;case 4:return s.label++,{value:n[1],done:!1};case 5:s.label++,i=n[1],n=[0];continue;case 7:n=s.ops.pop(),s.trys.pop();continue;default:if(!(a=s.trys,(a=a.length>0&&a[a.length-1])||6!==n[0]&&2!==n[0])){s=0;continue}if(3===n[0]&&(!a||n[1]>a[0]&&n[1]<a[3])){s.label=n[1];break}if(6===n[0]&&s.label<a[1]){s.label=a[1],a=n;break}if(a&&s.label<a[2]){s.label=a[2],s.ops.push(n);break}a[2]&&s.ops.pop(),s.trys.pop();continue}n=t.call(e,s)}catch(e){n=[6,e],i=0}finally{r=a=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,o])}}}function h(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function f(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,a,n=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(e){a={error:e}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return s}function v(e,t,r){if(r||2===arguments.length)for(var i,a=0,n=t.length;a<n;a++)!i&&a in t||(i||(i=Array.prototype.slice.call(t,0,a)),i[a]=t[a]);return e.concat(i||Array.prototype.slice.call(t))}var m,S,b,g,y={throughputEstimator:{emaAlphaSlow:.2,emaAlphaFast:.7,changeThreshold:.2,useBrowserEstimation:!0,rttPenaltyRequestSize:1048576,streamMinSampleSize:10240,streamMinSampleTime:300},autoTrackSelection:{bitrateFactorAtEmptyBuffer:1.8,bitrateFactorAtFullBuffer:1.2,usePixelRatio:!0,limitByContainer:!0,containerSizeFactor:2,lazyQualitySwitch:!1},dash:{extraInitSize:1e3,forwardBufferTarget:3e4,segmentRequestSize:1048576,representationSwitchForwardBufferGap:3e3},enableTelemetryAtStart:!1,formatsToAvoid:[exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_SEP_VK],disableChromecast:!1,chromecastReceiverId:void 0,useWebmBigRequest:!0,bigRequestMinInitSize:51200,bigRequestMinDataSize:1048576,stripRangeHeader:!0,flushShortLoopedBuffers:!0,insufficientBufferRuleMargin:1e4,dashSeekInSegmentDurationThreshold:18e4,dashSeekInSegmentAlwaysSeekDelta:1e4,endGapTolerance:300,stallIgnoreThreshold:33},T=function(){function t(t){var r,i=this;this.connection$=new e.ValueSubject(void 0),this.castState$=new e.ValueSubject(exports.ChromecastState.NOT_AVAILABLE),this.errorEvent$=new e.Subject,this.realCastState$=new e.ValueSubject(exports.ChromecastState.NOT_AVAILABLE),this.subscription=new e.Subscription,this.params=t,this.log=this.params.dependencies.logger.createComponentLog("ChromecastInitializer");var a,n="chrome"in window;(this.log({message:"[constructor] receiverApplicationId: "+this.params.receiverApplicationId+", isDisabled: "+this.params.isDisabled+", isSupported: "+n}),!t.isDisabled&&n)&&(e.isNonNullable(null===(r=window.chrome)||void 0===r?void 0:r.cast)?this.initializeCastApi():(window.__onGCastApiAvailable=function(e){e&&i.initializeCastApi()},(a="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",new Promise((function(e,t){var r=document.createElement("script");r.setAttribute("src",a),r.onload=function(){return e},r.onerror=function(){return t},document.body.appendChild(r)}))).catch((function(){return i.errorEvent$.next({id:"ChromecastLoading",message:"Script loading failed!"})}))))}return t.prototype.connect=function(){var e;null===(e=cast.framework.CastContext.getInstance())||void 0===e||e.requestSession()},t.prototype.disconnect=function(){var e,t;null===(t=null===(e=cast.framework.CastContext.getInstance())||void 0===e?void 0:e.getCurrentSession())||void 0===t||t.endSession(!0)},t.prototype.stopMedia=function(){return new Promise((function(e,t){var r,i,a;null===(a=null===(i=null===(r=cast.framework.CastContext.getInstance())||void 0===r?void 0:r.getCurrentSession())||void 0===i?void 0:i.getMediaSession())||void 0===a||a.stop(new chrome.cast.media.StopRequest,e,t)}))},t.prototype.toggleConnection=function(){e.isNonNullable(this.connection$.getValue())?this.disconnect():this.connect()},t.prototype.setVolume=function(t){var r=this.connection$.getValue();e.isNullable(r)||(r.remotePlayer.volumeLevel=t,r.remotePlayerController.setVolumeLevel())},t.prototype.setMuted=function(t){var r=this.connection$.getValue();e.isNullable(r)||t!==r.remotePlayer.isMuted&&r.remotePlayerController.muteOrUnmute()},t.prototype.destroy=function(){this.subscription.unsubscribe()},t.prototype.initListeners=function(){var t=this,r=new cast.framework.RemotePlayer,i=new cast.framework.RemotePlayerController(r),a=cast.framework.CastContext.getInstance();this.subscription.add(e.fromEvent(a,cast.framework.CastContextEventType.SESSION_STATE_CHANGED).subscribe((function(r){var i,n;switch(r.sessionState){case cast.framework.SessionState.SESSION_STARTED:case cast.framework.SessionState.SESSION_STARTING:case cast.framework.SessionState.SESSION_RESUMED:t.contentId=null===(n=null===(i=a.getCurrentSession())||void 0===i?void 0:i.getMediaSession())||void 0===n?void 0:n.media.contentId;break;case cast.framework.SessionState.NO_SESSION:case cast.framework.SessionState.SESSION_ENDING:case cast.framework.SessionState.SESSION_ENDED:case cast.framework.SessionState.SESSION_START_FAILED:t.contentId=void 0;break;default:return e.assertNever(r.sessionState)}}))).add(e.merge(e.fromEvent(a,cast.framework.CastContextEventType.CAST_STATE_CHANGED).pipe(e.tap((function(e){t.log({message:"[cast.framework.RemotePlayerEventType.CAST_STATE_CHANGED]: "+JSON.stringify(e)})})),e.map((function(e){return e.castState}))),e.observableFrom([a.getCastState()])).pipe(e.filterChanged(),e.map(E),e.tap((function(e){t.log({message:"realCastState$: "+e})}))).subscribe(this.realCastState$)).add(this.realCastState$.subscribe((function(n){var s,o=n===exports.ChromecastState.CONNECTED,u=e.isNonNullable(t.connection$.getValue());if(o&&!u){var d=a.getCurrentSession();e.assertNonNullable(d);var l=d.getCastDevice(),c=null===(s=d.getMediaSession())||void 0===s?void 0:s.media.contentId;(e.isNullable(c)||c===t.contentId)&&(t.log({message:"connection created"}),t.connection$.next({remotePlayer:r,remotePlayerController:i,session:d,castDevice:l}))}else!o&&u&&(t.log({message:"connection destroyed"}),t.connection$.next(void 0));t.castState$.next(n===exports.ChromecastState.CONNECTED?e.isNonNullable(t.connection$.getValue())?exports.ChromecastState.CONNECTED:exports.ChromecastState.AVAILABLE:n)})))},t.prototype.initializeCastApi=function(){var e,t,r,i;try{t=cast.framework.CastContext.getInstance(),r=chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,i=chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}catch(e){return}try{t.setOptions({receiverApplicationId:null!==(e=this.params.receiverApplicationId)&&void 0!==e?e:r,autoJoinPolicy:i}),this.initListeners()}catch(e){this.errorEvent$.next({id:"ChromecastInitializer",message:"[initializeCastApi] failed",thrown:e})}},t}(),E=function(t){switch(t){case cast.framework.CastState.NO_DEVICES_AVAILABLE:return exports.ChromecastState.NOT_AVAILABLE;case cast.framework.CastState.NOT_CONNECTED:return exports.ChromecastState.AVAILABLE;case cast.framework.CastState.CONNECTING:return exports.ChromecastState.CONNECTING;case cast.framework.CastState.CONNECTED:return exports.ChromecastState.CONNECTED;default:return e.assertNever(t)}};!function(e){e.VIDEO="video",e.AUDIO="audio",e.TEXT="text"}(m||(m={})),function(e){e.WEBM_AS_IN_SPEC="urn:mpeg:dash:profile:webm-on-demand:2012",e.WEBM_AS_IN_FFMPEG="urn:webm:dash:profile:webm-on-demand:2012"}(S||(S={})),function(e){e.NONE="none",e.DOWNLOADING="downloading",e.DOWNLOADED="downloaded",e.FED="fed"}(b||(b={})),function(e){e.MP4="mp4",e.WEBM="webm"}(g||(g={}));var P,k,w=function(e){return c(void 0,void 0,void 0,(function(){var t,r,i;return p(this,(function(a){switch(a.label){case 0:t=e.muted,a.label=1;case 1:return a.trys.push([1,3,,8]),[4,e.play()];case 2:return a.sent(),[3,8];case 3:if((r=a.sent())instanceof DOMException&&(20===r.code||"AbortError"===r.name))return[2,!1];if(t)return console.warn(r),[2,!1];e.muted=!0,a.label=4;case 4:return a.trys.push([4,6,,7]),[4,e.play()];case 5:return a.sent(),[3,7];case 6:return i=a.sent(),e.muted=!1,console.warn(i),[2,!1];case 7:return[3,8];case 8:return[2,!0]}}))}))},x=function(t,r,i,a){var n=void 0===a?{}:a,s=n.equal,o=void 0===s?function(e,t){return e===t}:s,u=n.changed$,d=n.onError,l=t.getState(),c=r(),p=e.isNullable(u),h=new e.Subscription;return u&&h.add(u.subscribe((function(e){var r=t.getState();o(e,r)&&t.setState(e)}),d)),o(c,l)||(i(l),p&&t.setState(l)),h.add(t.stateChangeStarted$.subscribe((function(e){i(e.to),p&&t.setState(e.to)}),d)),h},A=function(t,r,i){return x(r,(function(){return t.loop}),(function(r){e.isNonNullable(r)&&(t.loop=r)}),{onError:i})},$=function(t,r,i,a){return x(r,(function(){return{muted:t.muted,volume:t.volume}}),(function(r){e.isNonNullable(r)&&(t.muted=r.muted,t.volume=r.volume)}),{equal:function(e,t){return e===t||(null==e?void 0:e.muted)===(null==t?void 0:t.muted)&&(null==e?void 0:e.volume)===(null==t?void 0:t.volume)},changed$:i,onError:a})},N=function(e,t){if(e.id===t)return!0;var r=f(t.split("|"),3);r[0];var i=r[1],a=r[2];return e.language===i&&e.label===a},D=function(){function t(){this.available$=new e.Subject,this.current$=new e.ValueSubject(void 0),this.error$=new e.Subject,this.subscription=new e.Subscription,this.externalTracks=new Map}return t.prototype.connect=function(t,r,i){var a=this;this.video=t,this.cueSettings=r.textTrackCuesSettings,this.subscribe();var n=function(e){a.error$.next({id:"TextTracksManager",message:"Generic HtmlVideoTextTrackManager error",thrown:e})};this.subscription.add(this.available$.subscribe(i.availableTextTracks$)),this.subscription.add(this.current$.subscribe(i.currentTextTrack$)),this.subscription.add(this.error$.subscribe(i.error$)),this.subscription.add(x(r.externalTextTracks,(function(){return Object.values(a.externalTracks)}),(function(t){e.isNonNullable(t)&&a.setExternal(t)}),{equal:function(t,r){return e.isNonNullable(t)&&e.isNonNullable(r)&&t.length===r.length&&t.every((function(e,t){return e.id===r[t].id}))},changed$:this.available$.pipe(e.map((function(e){return e.filter((function(e){return"external"===e.type}))}))),onError:n})),this.subscription.add(x(r.currentTextTrack,(function(){if(!a.video){var e=a.htmlTextTracksAsArray().find((function(e){return"showing"===e.mode}));return e&&a.htmlTextTrackToITextTrack(e).id}}),(function(e){return a.select(e)}),{changed$:this.current$,onError:n})),this.subscription.add(x(r.textTrackCuesSettings,(function(){return{}}),(function(){var e,t;if(a.video)try{for(var r=h(a.htmlTextTracksAsArray()),i=r.next();!i.done;i=r.next()){var n=i.value;a.applyCueSettings(n.cues),a.applyCueSettings(n.activeCues)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}})))},t.prototype.subscribe=function(){var t=this;e.assertNonNullable(this.video);var r=this.video.textTracks;this.subscription.add(e.fromEvent(r,"addtrack").subscribe((function(){var e=t.current$.getValue();t.select(e)}))),this.subscription.add(e.merge(e.fromEvent(r,"addtrack"),e.fromEvent(r,"removetrack"),e.observableFrom(["init"])).pipe(e.map((function(){return t.htmlTextTracksAsArray().map((function(e){return t.htmlTextTrackToITextTrack(e)}))})),e.filterChanged((function(e,t){return e.length===t.length&&e.every((function(e,r){return e.id===t[r].id}))}))).subscribe(this.available$)),this.subscription.add(e.merge(e.fromEvent(r,"change"),e.observableFrom(["init"])).pipe(e.map((function(){return t.htmlTextTracksAsArray().find((function(e){return"showing"===e.mode}))})),e.map((function(e){return e&&t.htmlTextTrackToITextTrack(e).id})),e.filterChanged()).subscribe(this.current$));var i=function(e){var r,i;return t.applyCueSettings(null!==(i=null===(r=e.target)||void 0===r?void 0:r.activeCues)&&void 0!==i?i:null)};this.subscription.add(e.fromEvent(r,"addtrack").subscribe((function(e){var r,a;null===(r=e.track)||void 0===r||r.addEventListener("cuechange",i);var n=function(e){var r,i,a,s,o,u=null!==(i=null===(r=e.target)||void 0===r?void 0:r.cues)&&void 0!==i?i:null;u&&u.length&&(t.applyCueSettings(null!==(s=null===(a=e.target)||void 0===a?void 0:a.cues)&&void 0!==s?s:null),null===(o=e.target)||void 0===o||o.removeEventListener("cuechange",n))};null===(a=e.track)||void 0===a||a.addEventListener("cuechange",n)}))),this.subscription.add(e.fromEvent(r,"removetrack").subscribe((function(e){var t;null===(t=e.track)||void 0===t||t.removeEventListener("cuechange",i)})))},t.prototype.applyCueSettings=function(t){var r,i;if(t&&t.length){var a=this.cueSettings.getState();try{for(var n=h(Array.from(t)),s=n.next();!s.done;s=n.next()){var o=s.value;e.isNonNullable(a.align)&&(o.align=a.align),e.isNonNullable(a.position)&&(o.position=a.position),e.isNonNullable(a.size)&&(o.size=a.size),e.isNonNullable(a.line)&&(o.line=a.line)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(i=n.return)&&i.call(n)}finally{if(r)throw r.error}}}},t.prototype.htmlTextTracksAsArray=function(r){void 0===r&&(r=!1),e.assertNonNullable(this.video);var i=v([],f(this.video.textTracks),!1);return r?i:i.filter(t.isHealthyTrack)},t.prototype.htmlTextTrackToITextTrack=function(e){var t=e.language,r=e.label,i=""!==e.id?e.id:function(e){return["__",e.language,e.label].join("|")}(e);return this.externalTracks.has(i)?{id:i,type:"external",language:t,label:r,url:this.externalTracks.get(i).url}:{id:i,type:"internal",language:t,label:r}},t.isHealthyTrack=function(e){return"metadata"!==e.kind&&(""!==e.id||""!==e.label||""!==e.language)},t.prototype.setExternal=function(e){var t=this;e.filter((function(e){var r=e.id;return!t.externalTracks.has(r)})).forEach((function(e){return t.attach(e)})),Array.from(this.externalTracks.keys()).filter((function(t){return!e.find((function(e){return e.id===t}))})).forEach((function(e){return t.detach(e)}))},t.prototype.select=function(t){var r,i;e.assertNonNullable(this.video);try{for(var a=h(this.htmlTextTracksAsArray(!0)),n=a.next();!n.done;n=a.next()){var s=n.value;e.isNonNullable(t)&&N(s,t)?s.mode="showing":s.mode="disabled"}}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}},t.prototype.destroy=function(){var e,t;if(this.subscription.unsubscribe(),this.video)try{for(var r=h(Array.from(this.video.getElementsByTagName("track"))),i=r.next();!i.done;i=r.next()){var a=i.value,n=a.getAttribute("id");n&&this.externalTracks.has(n)&&this.video.removeChild(a)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}this.externalTracks.clear()},t.prototype.attach=function(t){e.assertNonNullable(this.video);var r=document.createElement("track");r.setAttribute("src",t.url),r.setAttribute("id",t.id),t.label&&r.setAttribute("label",t.label),t.language&&r.setAttribute("srclang",t.language),this.externalTracks.set(t.id,t),this.video.appendChild(r)},t.prototype.detach=function(t){e.assertNonNullable(this.video);var r=Array.prototype.find.call(this.video.getElementsByTagName("track"),(function(e){return e.getAttribute("id")===t}));r&&this.video.removeChild(r),this.externalTracks.delete(t)},t}(),_=function(e){var t=document.createElement("video");return t.setAttribute("crossorigin","anonymous"),t.setAttribute("playsinline","playsinline"),e.appendChild(t),t},R=function(t){return new e.Observable((function(r){var i=0;return(new e.Subscription).add(e.fromEvent(t,"loadstart").subscribe((function(){i=Date.now()}))).add(e.fromEvent(t,"loadeddata").subscribe((function(){r.next(Date.now()-i)})))})).pipe(e.once())},I=function(){function e(e){this._buffer=[],this._source=e}return e.prototype.fill=function(){this._buffer=[];for(var e=this._source.currentTime,t=0,r=this._source.buffered.length;t<r;t++){var i=this._source.buffered.start(t),a=this._source.buffered.end(t);i>e&&i-e<3&&(i=e),this._buffer.push({start:i,end:a,i:t})}return this._buffer.sort((function(e,t){return e.start-t.start})),this._buffer},e.prototype.getByTime=function(e){return this._buffer.find((function(t){return e>=t.start&&e<t.end}))},e.prototype.getNextWithGap=function(e,t){var r=this.getNext(e);if(r&&r.start-e.end<(t||3))return r},e.prototype.getNext=function(e){var t=this._buffer.indexOf(e);if(~t&&this._buffer.length-1>t)return this._buffer[++t]},e.prototype.smartRemove=function(e,t,r){this._buffer.forEach((function(i){var a=i.start,n=i.end,s=a>=e&&a<t,o=n>=e&&n<t;s&&o||(s?r(t,n):o?r(a,e):a<e&&n>t?(r(t,n),r(a,e)):r(a,n))}))},e.prototype.destroy=function(){this._buffer=[]},e}(),C=function(e,t,r){void 0===r&&(r=3);for(var i=0,a=0,n=0;n<e.length;n++){var s=e.start(n),o=e.end(n);if(s<=t&&t<=o){if(i=s,a=o,!r)return{start:i,end:a};for(var u=n-1;u>=0;u--)e.end(u)+r>=i&&(i=e.start(u));for(var d=n+1;d<e.length;d++)e.start(d)-r<=a&&(a=e.end(d))}}return{start:i,end:a}},L=function(t){return new e.Observable((function(r){var i=0;return(new e.Subscription).add(e.fromEvent(t,"loadstart").subscribe((function(){i=Date.now()}))).add(e.fromEvent(t,"loadedmetadata").subscribe((function(){r.next(Date.now()-i)})))})).pipe(e.once())},O=function(t){var r=function(r,i){return void 0===i&&(i=function(){}),e.fromEvent(t,r).pipe(e.map(i))},i=e.merge.apply(void 0,v([],f(["waiting","pause","canplay","play","canplaythrough","playing","seeking","seeked","ended"].map((function(r){return e.fromEvent(t,r)}))),!1)).pipe(e.map((function(){return t.readyState<3})),e.filterChanged()),a=e.merge(e.fromEvent(t,"progress"),e.fromEvent(t,"timeupdate")).pipe(e.map((function(){return C(t.buffered,t.currentTime)}))),n=e.fromEvent(t,"volumechange").pipe(e.debounce(0),e.map((function(){return{muted:t.muted,volume:t.volume}}))),s=e.fromEvent(t,"error").pipe(e.map((function(){var e=t.error;return{id:e?"MediaError#"+e.code:"HtmlVideoError",message:e?e.message:"Error event from HTML video element"}})));return{playing$:r("playing"),pause$:r("pause"),canplay$:r("canplay"),ended$:r("ended"),error$:s,seeked$:r("seeked"),seeking$:r("seeking"),progress$:r("progress"),loadedMetadata$:r("loadedmetadata"),loadedData$:r("loadeddata"),timeUpdate$:r("timeupdate",(function(){return t.currentTime})),durationChange$:r("durationchange",(function(){return t.duration})),isBuffering$:i,currentBuffer$:a,volumeState$:n,firstBytes$:L(t),firstFrame$:R(t)}},V=function(e,t,r){void 0===r&&(r=!1);var i=e.getTransition();!r&&i&&i.to!==t||e.setState(t)};exports.VideoQuality=void 0,(P=exports.VideoQuality||(exports.VideoQuality={})).INVARIANT="Invariant quality",P.Q_144P="144p",P.Q_240P="240p",P.Q_360P="360p",P.Q_480P="480p",P.Q_720P="720p",P.Q_1080P="1080p",P.Q_1440P="1440p",P.Q_2160P="2160p",P.Q_4320P="4320p";var M,B=((k={})[exports.VideoQuality.Q_144P]=144,k[exports.VideoQuality.Q_240P]=240,k[exports.VideoQuality.Q_360P]=360,k[exports.VideoQuality.Q_480P]=480,k[exports.VideoQuality.Q_720P]=720,k[exports.VideoQuality.Q_1080P]=1080,k[exports.VideoQuality.Q_1440P]=1440,k[exports.VideoQuality.Q_2160P]=2160,k[exports.VideoQuality.Q_4320P]=4320,k),U=function(e,t){return B[e]>B[t]},F=function(e,t){return B[e]<B[t]},H=Object.keys(B).sort((function(e,t){return F(e,t)?-1:1})),q=function(e,t){var r=e.width,i=e.height;return function(e,t){return void 0===t&&(t=.02),v([],f(H),!1).find((function(r){return B[r]*(1+t)>=e}))}(Math.min(r,i),t)},G=function(e){return e===exports.VideoQuality.INVARIANT},j=!1,Y={},z=function(e){e(Y)},Q=function(e,t){var r;j&&(Y.meta=null!==(r=Y.meta)&&void 0!==r?r:{},Y.meta[e]=t)},W=function(){function e(e){this.name=e}return e.prototype.next=function(e){var t,r;if(j){Y.series=null!==(t=Y.series)&&void 0!==t?t:{};var i=null!==(r=Y.series[this.name])&&void 0!==r?r:[];i.push([Date.now(),e]),Y.series[this.name]=i}},e}(),J=new W("best_bitrate"),K=function(t,r){var i,a,n=r.container,s=r.throughput,o=r.tuning,u=r.forwardBufferHealth,d=r.currentRepresentation,l=o.usePixelRatio&&null!==(i=window.devicePixelRatio)&&void 0!==i?i:1,c=o.limitByContainer&&n&&n.width>0&&n.height>0&&{width:n.width*l*o.containerSizeFactor,height:n.height*l*o.containerSizeFactor},p=c&&q(c,0),h=t.filter((function(e){return!G(e.quality)})).sort((function(e,t){return U(e.quality,t.quality)?-1:1})),f=h.filter((function(t){var r,i,a,n,l=!p||F(t.quality,p),c=!(e.isNonNullable(s)&&isFinite(s)&&e.isNonNullable(t.bitrate))||s>=t.bitrate*(i=null!=u?u:.5,a=o.bitrateFactorAtEmptyBuffer,n=o.bitrateFactorAtFullBuffer,(a-n)*Math.pow(2,-10*i)+n),h=!o.lazyQualitySwitch||!d||(null!=u?u:.5)>=.5||((null===(r=t.size)||void 0===r?void 0:r.height)||0)<=((null==d?void 0:d.height)||0);return l&&c&&h}))[0];return f&&f.bitrate&&J.next(f.bitrate),null!==(a=null!=f?f:h[h.length-1])&&void 0!==a?a:t[0]},X=function(e,t){for(var r=0,i=0;i<e.length;i++){var a=1e3*e.start(i),n=1e3*e.end(i);a<=t&&t<=n&&(r=n)}return Math.max(r-t,0)},Z=function(e){return new URL(e).hostname},ee=function(t,r){return void 0===r&&(r=300),new e.Observable((function(i){var a=t.getBoundingClientRect(),n=a.width,s=a.height;if(i.next({width:n,height:s}),window.ResizeObserver){var o=new ResizeObserver(d.default((function(t){var r,a,n=t[0];n&&(n.contentBoxSize&&n.contentBoxSize[0]?(a=n.contentBoxSize[0].blockSize,r=n.contentBoxSize[0].inlineSize):n.contentRect&&(r=n.contentRect.width,a=n.contentRect.height),e.isNonNullable(r)&&e.isNonNullable(a)&&i.next({width:r,height:a}))}),r));return o.observe(t),function(){return o.disconnect()}}}))},te=function(){function t(t){this.transitionStarted$=new e.Subject,this.transitionEnded$=new e.Subject,this.transitionUpdated$=new e.Subject,this.forceChanged$=new e.Subject,this.stateChangeStarted$=e.merge(this.transitionStarted$,this.transitionUpdated$),this.stateChangeEnded$=e.merge(this.transitionEnded$,this.forceChanged$),this.state=t}return t.prototype.setState=function(e){var t=this.transition,r=this.state;this.transition=void 0,this.state=e,t?t.to===e?this.transitionEnded$.next(t):this.forceChanged$.next({from:t.from,to:e,canceledTransition:t}):this.forceChanged$.next({from:r,to:e,canceledTransition:t})},t.prototype.startTransitionTo=function(t){var r=this.transition,i=this.state;i===t||e.isNonNullable(r)&&r.to===t||(this.state=t,r?(this.transition={from:r.from,to:t,canceledTransition:r},this.transitionUpdated$.next(this.transition)):(this.transition={from:i,to:t},this.transitionStarted$.next(this.transition)))},t.prototype.getTransition=function(){return this.transition},t.prototype.getState=function(){return this.state},t}(),re=function(e){var t,r,i=e.get("X-Delivery-Type"),a=e.get("X-Reused");return{type:null===i?exports.HttpConnectionType.HTTP1:null!==(t=i)&&void 0!==t?t:void 0,reused:null===a?void 0:null!==(r={1:!0,0:!1}[a])&&void 0!==r?r:void 0}};!function(e){e[e.HEADER=0]="HEADER",e[e.PARAM=1]="PARAM"}(M||(M={}));var ie,ae,ne,se=function(){function t(t){var r=this,i=(void 0===t?{}:t).throughputEstimator;this.lastConnectionType$=new e.ValueSubject(void 0),this.lastConnectionReused$=new e.ValueSubject(void 0),this.lastRequestFirstBytes$=new e.ValueSubject(void 0),this.abortAllController=new AbortController,this.subscription=new e.Subscription,this.fetchRepresentation=function(e,t,i){return void 0===i&&(i=0),c(r,void 0,void 0,(function(){var r,a,n,s,o,u,d,l,c,h,f,v,m,S,b;return p(this,(function(p){switch(p.label){case 0:return r=e.initRange,a=r.from,n=r.to,s=a,o=n,u=!1,e.indexRange&&(d=e.indexRange.from,l=e.indexRange.to,(u=n+1===d)&&(s=Math.min(d,a),o=Math.max(l,n))),s=Math.min(s,0),o+=i,[4,this.fetchRange(e.url,s,o,{method:M.PARAM})];case 1:if(!(c=p.sent()))return[2,null];if(h=new DataView(c,a-s,n-s),!t.validateData(h))throw new Error("Invalid media file");return f=t.parseInit(h),u&&void 0!==d&&void 0!==l?(v=new DataView(c,d-s,l-d),[3,4]):[3,2];case 2:return(m=t.getIndexRange(f))?[4,this.fetchRange(e.url,m.from,m.to,{method:M.PARAM})]:[3,4];case 3:if(!(S=p.sent()))return[2,null];v=new DataView(S),p.label=4;case 4:if(!v)throw new ReferenceError("No way to load representation index");return b=t.parseSegments(v,f),[2,{dataView:new DataView(c),segments:b}]}}))}))},this.throughputEstimator=i}return t.prototype.onHeadersReceived=function(e){var t=re(e),r=t.type,i=t.reused;this.lastConnectionType$.next(r),this.lastConnectionReused$.next(i)},t.prototype.fetchManifest=function(e){return c(this,void 0,void 0,(function(){var t;return p(this,(function(r){switch(r.label){case 0:return[4,fetch(e,{signal:this.abortAllController.signal}).catch(oe)];case 1:return(t=r.sent())?(this.onHeadersReceived(t.headers),[2,t.text()]):[2,null]}}))}))},t.prototype.fetchRange=function(t,r,i,a){var n,s,o,u=void 0===a?{}:a,d=u.method,l=void 0===d?M.HEADER:d,h=u.onProgress,v=u.signal;return c(this,void 0,void 0,(function(){var a,u,d,m,S,b,g,y,T,E,P,k,w,x,A,$,N,D,_,R=this;return p(this,(function(I){switch(I.label){case 0:switch(a=t,u=new Headers,l){case M.HEADER:u.append("Range",r+"-"+i);break;case M.PARAM:(d=new URL(a,location.href)).searchParams.append("bytes",r+"-"+i),a=d.toString();break;default:e.assertNever(l)}return m=this.abortAllController.signal,v&&(S=new AbortController,this.subscription.add(e.merge(e.fromEvent(this.abortAllController.signal,"abort"),e.fromEvent(v,"abort")).subscribe((function(){S.abort()}))),(this.abortAllController.signal.aborted||v.aborted)&&S.abort(),m=S.signal),b=e.now(),[4,fetch(a,{headers:u,signal:m}).catch(oe)];case 1:return g=I.sent(),null===(n=this.throughputEstimator)||void 0===n||n.addRawRtt(e.now()-b),g?g.ok&&g.body?(this.onHeadersReceived(g.headers),y=f(g.body.tee(),2),T=y[0],E=y[1],P=T.getReader(),null===(s=this.throughputEstimator)||void 0===s||s.trackStream(E),k=parseInt(null!==(o=g.headers.get("Content-Length"))&&void 0!==o?o:"",10),w=0,x=new ArrayBuffer(k),A=new Uint8Array(x),$=new DataView(x),N=!1,D=function(e){N=!0,oe(e)},_=function(t){var r=t.done,i=t.value;return c(R,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return 0===w&&this.lastRequestFirstBytes$.next(e.now()-b),r?(null==h||h($,w),[3,3]):[3,1];case 1:return i?(A.set(i,w),w+=i.byteLength,null==h||h($,w),[4,null==P?void 0:P.read().then(_,D)]):[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))},[4,null==P?void 0:P.read().then(_,D)]):[2,Promise.reject(new Error("Fetch error "+g.status+": "+g.statusText))]:[2,null];case 2:return I.sent(),[2,N?null:x]}}))}))},t.prototype.destroy=function(){this.abortAllController.abort(),this.subscription.unsubscribe()},t}(),oe=function(e){if(!(e instanceof DOMException)||"AbortError"!==e.name&&20!==e.code)throw e};!function(e){e[e.EBML=440786851]="EBML",e[e.EBMLVersion=17030]="EBMLVersion",e[e.EBMLReadVersion=17143]="EBMLReadVersion",e[e.EBMLMaxIDLength=17138]="EBMLMaxIDLength",e[e.EBMLMaxSizeLength=17139]="EBMLMaxSizeLength",e[e.DocType=17026]="DocType",e[e.DocTypeVersion=17031]="DocTypeVersion",e[e.DocTypeReadVersion=17029]="DocTypeReadVersion",e[e.Void=236]="Void",e[e.Segment=408125543]="Segment",e[e.SeekHead=290298740]="SeekHead",e[e.Seek=19899]="Seek",e[e.SeekID=21419]="SeekID",e[e.SeekPosition=21420]="SeekPosition",e[e.Info=357149030]="Info",e[e.TimestampScale=2807729]="TimestampScale",e[e.Duration=17545]="Duration",e[e.Tracks=374648427]="Tracks",e[e.Chapters=272869232]="Chapters",e[e.Cluster=524531317]="Cluster",e[e.Attachments=423732329]="Attachments",e[e.Tags=307544935]="Tags",e[e.Cues=475249515]="Cues",e[e.CuePoint=187]="CuePoint",e[e.CueTime=179]="CueTime",e[e.CueTrackPositions=183]="CueTrackPositions",e[e.CueTrack=247]="CueTrack",e[e.CueClusterPosition=241]="CueClusterPosition",e[e.CueRelativePosition=240]="CueRelativePosition",e[e.CueDuration=178]="CueDuration",e[e.CueBlockNumber=21368]="CueBlockNumber",e[e.CueCodecState=234]="CueCodecState",e[e.CueReference=219]="CueReference",e[e.CueRefTime=150]="CueRefTime"}(ae||(ae={})),function(e){e.SignedInteger="int",e.UnsignedInteger="uint",e.Float="float",e.String="string",e.UTF8="utf8",e.Date="date",e.Master="master",e.Binary="binary"}(ne||(ne={}));var ue,de=((ie={})[ae.EBML]={type:ne.Master},ie[ae.EBMLVersion]={type:ne.UnsignedInteger},ie[ae.EBMLReadVersion]={type:ne.UnsignedInteger},ie[ae.EBMLMaxIDLength]={type:ne.UnsignedInteger},ie[ae.EBMLMaxSizeLength]={type:ne.UnsignedInteger},ie[ae.DocType]={type:ne.String},ie[ae.DocTypeVersion]={type:ne.UnsignedInteger},ie[ae.DocTypeReadVersion]={type:ne.UnsignedInteger},ie[ae.Void]={type:ne.Binary},ie[ae.Segment]={type:ne.Master},ie[ae.SeekHead]={type:ne.Master},ie[ae.Seek]={type:ne.Master},ie[ae.SeekID]={type:ne.Binary},ie[ae.SeekPosition]={type:ne.UnsignedInteger},ie[ae.Info]={type:ne.Master},ie[ae.TimestampScale]={type:ne.UnsignedInteger},ie[ae.Duration]={type:ne.Float},ie[ae.Tracks]={type:ne.Master},ie[ae.Chapters]={type:ne.Master},ie[ae.Cluster]={type:ne.Master},ie[ae.Attachments]={type:ne.Master},ie[ae.Tags]={type:ne.Master},ie[ae.Cues]={type:ne.Master},ie[ae.CuePoint]={type:ne.Master},ie[ae.CueTime]={type:ne.UnsignedInteger},ie[ae.CueTrackPositions]={type:ne.Master},ie[ae.CueTrack]={type:ne.UnsignedInteger},ie[ae.CueClusterPosition]={type:ne.UnsignedInteger},ie[ae.CueRelativePosition]={type:ne.UnsignedInteger},ie[ae.CueDuration]={type:ne.UnsignedInteger},ie[ae.CueBlockNumber]={type:ne.UnsignedInteger},ie[ae.CueCodecState]={type:ne.UnsignedInteger},ie[ae.CueReference]={type:ne.Master},ie[ae.CueRefTime]={type:ne.UnsignedInteger},ie),le=function(e){var t=e.getUint8(0),r=0;128&t?r=1:64&t?r=2:32&t?r=3:16&t&&(r=4);var i=ce(e,r),a=i in de,n=a?de[i].type:ne.Binary,s=e.getUint8(r),o=0;128&s?o=1:64&s?o=2:32&s?o=3:16&s?o=4:8&s?o=5:4&s?o=6:2&s?o=7:1&s&&(o=8);var u,d=new DataView(e.buffer,e.byteOffset+r+1,o-1),l=((s&255>>o)<<8*(o-1))+ce(d),c=r+o;return u=c+l>e.byteLength?new DataView(e.buffer,e.byteOffset+c):new DataView(e.buffer,e.byteOffset+c,l),{tag:a?i:"0x"+i.toString(16).toUpperCase(),type:n,value:u,valueSize:l}},ce=function(e,t){switch(void 0===t&&(t=e.byteLength),t){case 1:return e.getUint8(0);case 2:return e.getUint16(0);case 3:return e.getUint16(0)<<8|e.getUint8(2);case 4:return e.getUint32(0);case 5:return e.getUint32(0)<<8|e.getUint8(4);case 6:return e.getUint32(0)<<16|e.getUint16(4);case 7:return e.getUint32(0)<<32|e.getUint16(4)<<8|e.getUint8(6);case 8:return e.getUint32(0)<<32|e.getUint32(4)}return 0},pe=function(t,r){switch(r){case ne.SignedInteger:return t.getInt8(0);case ne.UnsignedInteger:return ce(t);case ne.Float:return 4===t.byteLength?t.getFloat32(0):t.getFloat64(0);case ne.String:return new TextDecoder("ascii").decode(t);case ne.UTF8:return new TextDecoder("utf-8").decode(t);case ne.Date:return new Date(Date.UTC(2001,0)+t.getInt8(0)).getTime();case ne.Master:case ne.Binary:return t;default:e.assertNever(r)}},he=function(e,t){for(var r=0;r<e.byteLength;){var i=new DataView(e.buffer,e.byteOffset+r),a=le(i);if(!t(a))return;a.type===ne.Master&&he(a.value,t),r=a.value.byteOffset-e.byteOffset+a.valueSize}},fe=[ae.Info,ae.SeekHead,ae.Tracks,ae.Chapters,ae.Cluster,ae.Cues,ae.Attachments,ae.Tags],ve={validateData:function(e){if(e.getUint32(0)!==ae.EBML)return!1;var t=void 0,r=void 0,i=void 0,a=le(e);return he(a.value,(function(e){var a=e.tag,n=e.type,s=e.value;return a===ae.EBMLReadVersion?t=pe(s,n):a===ae.DocType?r=pe(s,n):a===ae.DocTypeReadVersion&&(i=pe(s,n)),!0})),(void 0===t||t<=1)&&void 0!==r&&"webm"===r&&(void 0===i||i<=2)},parseInit:function(t){var r=void 0,i=void 0,a=void 0,n=void 0,s=!1,o=!1,u=!1,d=void 0,l=void 0;return he(t,(function(e){var t=e.tag,c=e.type,p=e.value,h=e.valueSize;if(t===ae.SeekID){var f=pe(p,c);l=ce(f)}else t!==ae.SeekPosition&&(l=void 0);return t===ae.Segment?(r=p.byteOffset,i=p.byteOffset+h):t===ae.Info?s=!0:t===ae.SeekHead?o=!0:t===ae.TimestampScale?a=pe(p,c):t===ae.Duration?n=pe(p,c):t===ae.SeekPosition&&l===ae.Cues?d=pe(p,c):s&&o&&fe.includes(t)&&(u=!0),!u})),e.assertNonNullable(r,"Failed to parse webm Segment start"),e.assertNonNullable(i,"Failed to parse webm Segment end"),e.assertNonNullable(n,"Failed to parse webm Segment duration"),a=null!=a?a:1e6,{segmentStart:Math.round(r/1e9*a*1e3),segmentEnd:Math.round(i/1e9*a*1e3),timeScale:a,segmentDuration:Math.round(n/1e9*a*1e3),cuesSeekPosition:d}},getIndexRange:function(t){if(!e.isNullable(t.cuesSeekPosition)){var r=t.segmentStart+t.cuesSeekPosition;return{from:r,to:r+1048576}}},parseSegments:function(t,r){var i,a=!1,n=!1,s=function(t){return e.isNonNullable(t.time)&&e.isNonNullable(t.position)},o=[];return he(t,(function(e){var t=e.tag,r=e.type,u=e.value;switch(t){case ae.Cues:a=!0;break;case ae.CuePoint:i&&s(i)&&o.push(i),i={};break;case ae.CueTime:i&&(i.time=pe(u,r));break;case ae.CueTrackPositions:break;case ae.CueClusterPosition:i&&(i.position=pe(u,r));break;default:a&&fe.includes(t)&&(n=!0)}return!(a&&n)})),i&&s(i)&&o.push(i),o.map((function(e,t){var i=e.time,a=e.position,n=o[t+1];return{status:b.NONE,time:{from:i,to:n?n.time:r.segmentDuration},byte:{from:r.segmentStart+a,to:n?r.segmentStart+n.position-1:r.segmentEnd-1}}}))}},me=new TextDecoder("ascii"),Se={validateData:function(e){return"ftyp"===me.decode(new DataView(e.buffer,e.byteOffset+4,4))},parseInit:function(){return null},getIndexRange:function(){},parseSegments:function(e){var t=function(e){var t=0,r=e.getUint32(t);t+=4;var i=new DataView(e.buffer,e.byteOffset+t,4),a=me.decode(i);t+=4,0===r?r=1/0:1===r&&(t+=8,r=1/0);var n=Math.min(r,e.byteLength)-t+1;return{id:a,size:r,contents:new DataView(e.buffer,e.byteOffset+t,n)}}(e),r=[],i=0,a=function(){var e=t.contents.getUint32(i);return i+=4,e};if(0!==(4278190080&a()))throw new SyntaxError("Unsupported sidx version");a();for(var n=a(),s=a(),o=a(),u=255&a(),d=s/n*1e3,l=e.byteOffset+e.byteLength+o+1,c=0;c<u;c++){var p=a(),h=p>>>31,f=p<<1>>>1,v=a();if(a(),0!==h)throw new Error("Unsupported multilevel sidx");var m=v/n*1e3;r.push({status:b.NONE,time:{from:d,to:d+m},byte:{from:l,to:l+f-1}}),d+=m,l+=f}return r}},be=function(){function t(t,r,i,a,n){var s=n.fetcher,o=n.tuning;switch(this.ended$=new e.ValueSubject(!1),this.playingRepresentation$=new e.ValueSubject(void 0),this.error$=new e.Subject,this.subscription=new e.Subscription,this.abortController=new AbortController,this.allInitsLoaded=!1,this.fetcher=s,this.tuning=o,this.container=i,i){case g.MP4:this.containerParser=Se;break;case g.WEBM:this.containerParser=ve;break;default:e.assertNever(i)}this.initData=new Map,this.segments=new Map,this.representations=new Map(a.map((function(e){return[e.id,e]}))),this.kind=t,this.mediaSource=r,this.sourceBuffer=null,this.segmentDownloadPromise=Promise.resolve()}return t.prototype.startWith=function(t){return c(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,c,h=this;return p(this,(function(p){switch(p.label){case 0:return r=this.representations.get(t),e.assertNonNullable(r,"Cannot find representation "+t),i=Math.ceil(1e3*r.bitrate/8*(this.tuning.extraInitSize/1e3)*1.1),this.playingRepresentationId=t,this.downloadingRepresentationId=t,this.sourceBuffer=this.mediaSource.addSourceBuffer(r.mime+'; codecs="'+r.codecs+'"'),this.subscription.add(e.fromEvent(this.sourceBuffer,"updateEnd").subscribe((function(){return h.checkEjectedSegments()}),(function(e){return h.error$.next({id:"SegmentEjection",message:"Error when trying to clear segments ejecte by browser",thrown:e})}))),this.subscription.add(e.fromEvent(this.sourceBuffer,"error").subscribe((function(e){return h.error$.next({id:"SourceBuffer",message:"SourceBuffer Error event fired",thrown:e})}))),[4,this.fetcher.fetchRepresentation(r,this.containerParser,i).catch((function(e){return h.error$.next({id:"LoadInit",message:"Failed to init Representation",thrown:e})}))];case 1:return(a=p.sent())?(n=a.dataView,s=a.segments,o=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength-i),this.initData.set(t,o),u=s.filter((function(e){return e.byte.from>=n.byteOffset&&e.byte.to<n.byteOffset+n.byteLength})),d=u.at(-1),c=new DataView(n.buffer,n.byteOffset,u.length&&d?Math.min(d.byte.to-n.byteOffset+1,n.byteLength):n.byteLength-i),[4,this.appendDataToBuffer(c)]):[2,!1];case 2:return p.sent(),this.segments.set(t,s.map((function(e){return l(l({},e),{status:e.byte.from>=n.byteOffset&&e.byte.to<n.byteOffset+n.byteLength?b.FED:b.NONE})}))),this.maintain(0),[2,!0]}}))}))},t.prototype.switchTo=function(t){var r;return c(this,void 0,void 0,(function(){var i,a,n,s,o,u,d=this;return p(this,(function(l){switch(l.label){case 0:return t===this.downloadingRepresentationId||t===this.switchingToRepresentationId?[2]:(this.switchingToRepresentationId=t,this.initData.has(t)?[3,4]:this.loadAllInitsPromise?[4,this.loadAllInitsPromise]:[3,2]);case 1:return l.sent(),[3,4];case 2:return i=this.representations.get(t),e.assertNonNullable(i),[4,this.fetcher.fetchRepresentation(i,this.containerParser,0).catch((function(e){return d.error$.next({id:"LoadInit",message:"Failed to init Representation",thrown:e})}))];case 3:if(!(a=l.sent()))return[2];n=a.dataView,s=a.segments,o=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),this.initData.set(t,o),this.segments.set(t,s),l.label=4;case 4:u=this.initData.get(t),e.assertNonNullable(u,"No init buffer for "+t),e.assertNonNullable(this.sourceBuffer),this.switchingToRepresentationId=void 0,this.downloadingRepresentationId=t,this.abortController.abort(),this.abortController=new AbortController;try{this.sourceBuffer.abort()}catch(e){this.error$.next({id:"SourceBufferAbort",message:"SourceBuffer.abort() threw",thrown:e})}return[4,this.appendDataToBuffer(u,this.abortController.signal)];case 5:return l.sent(),e.isNonNullable(this.playingRepresentationId)&&(null===(r=this.segments.get(this.playingRepresentationId))||void 0===r||r.forEach((function(e){e.status===b.FED&&(e.status=b.NONE)}))),[2]}}))}))},t.prototype.maintain=function(t){return c(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d=this;return p(this,(function(l){switch(l.label){case 0:return e.isNullable(this.downloadingRepresentationId)||e.isNullable(this.playingRepresentationId)||e.isNullable(this.sourceBuffer)||this.ended$.getValue()?[2]:(r=this.representations.get(this.downloadingRepresentationId),i=this.segments.get(this.downloadingRepresentationId),e.assertNonNullable(r),e.assertNonNullable(i),a=i.find((function(e){return t>=e.time.from&&t<e.time.to})),n=t,this.playingRepresentationId!==this.downloadingRepresentationId&&(s=X(this.sourceBuffer.buffered,t),n=t+Math.min(s,this.tuning.representationSwitchForwardBufferGap)),(o=this.selectForwardBufferSegments(i,n)).length?[4,this.loadSegments(o,r)]:[3,2]);case 1:l.sent(),l.label=2;case 2:return!this.allInitsLoaded&&!this.loadAllInitsPromise&&a&&a.status===b.FED&&!o.length&&X(this.sourceBuffer.buffered,t)>3e3&&this.loadAllInits().catch((function(e){return d.error$.next({id:"InitDownload",message:"Error when trying to load all inits",thrown:e})})),(u=i.at(-1))&&a===u&&u.status===b.FED&&this.ended$.next(!0),[2]}}))}))},t.prototype.destroy=function(){this.initData.clear(),this.segments.clear(),this.representations.clear(),this.subscription.unsubscribe(),this.sourceBuffer&&"open"===this.mediaSource.readyState&&(this.sourceBuffer.abort(),this.mediaSource.removeSourceBuffer(this.sourceBuffer)),this.abortController.abort()},t.prototype.selectForwardBufferSegments=function(e,t){var r=this,i=e.findIndex((function(e){var i=e.status,a=e.time,n=a.from,s=a.to;return i===b.NONE&&(n>t||n<=t&&s>=t)&&s<=t+r.tuning.forwardBufferTarget}));if(-1===i)return[];for(var a=0,n=[],s=i;s<e.length&&a<=this.tuning.segmentRequestSize;s++){var o=e[s];if(a+=o.byte.to+1-o.byte.from,o.status===b.NONE)n.push(o);else if([b.DOWNLOADING,b.DOWNLOADED,b.FED].includes(o.status))break}return n},t.prototype.loadSegments=function(e,t){return c(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,l,f=this;return p(this,(function(v){if(!e.length)return[2];r=e.at(0).byte.from,i=e.at(-1).byte.to;try{for(a=h(e),n=a.next();!n.done;n=a.next())n.value.status=b.DOWNLOADING}catch(e){d={error:e}}finally{try{n&&!n.done&&(l=a.return)&&l.call(a)}finally{if(d)throw d.error}}return s=this.abortController.signal,o=function(e,r){e.status=b.DOWNLOADED,f.appendDataToBuffer(r,s).then((function(r){!r||s.aborted?e.status=b.NONE:(f.playingRepresentationId=t.id,f.playingRepresentation$.next(f.playingRepresentationId),e.status=b.FED)}))},u=function(t,i){var a,n;try{for(var s=h(e),u=s.next();!u.done;u=s.next()){var d=u.value;d.status===b.DOWNLOADING&&d.byte.from-r>=0&&d.byte.to+1-r<=i&&o(d,new DataView(t.buffer,t.byteOffset+d.byte.from-r,d.byte.to+1-d.byte.from))}}catch(e){a={error:e}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(a)throw a.error}}},this.segmentDownloadPromise=this.segmentDownloadPromise.then((function(){return c(f,void 0,void 0,(function(){var a,n,d,l,c,f,v,m,S,g,y,T,E;return p(this,(function(p){switch(p.label){case 0:if(s.aborted){try{for(a=h(e),n=a.next();!n.done;n=a.next())(m=n.value).status===b.DOWNLOADING&&(m.status=b.NONE)}catch(e){S={error:e}}finally{try{n&&!n.done&&(g=a.return)&&g.call(a)}finally{if(S)throw S.error}}return[2]}return[4,this.fetcher.fetchRange(t.url,r,i,{method:M.PARAM,onProgress:u,signal:s})];case 1:if(d=p.sent(),l=e.at(-1),c=null===(E=this.segments.get(t.id))||void 0===E?void 0:E.at(-1),!d)try{for(f=h(e),v=f.next();!v.done;v=f.next())(m=v.value).status===b.DOWNLOADING&&(m.status=b.NONE)}catch(e){y={error:e}}finally{try{v&&!v.done&&(T=f.return)&&T.call(f)}finally{if(y)throw y.error}}return d&&!s.aborted&&l&&c&&l.status===b.DOWNLOADING&&l===c&&o(l,new DataView(d,l.byte.from-r)),[2]}}))}))})).catch((function(e){return f.error$.next({id:"SegmentDownload",message:"Error when fetching segments",thrown:e})})),[2,this.segmentDownloadPromise]}))}))},t.prototype.loadAllInits=function(){return c(this,void 0,void 0,(function(){var e=this;return p(this,(function(t){return this.loadAllInitsPromise||(this.loadAllInitsPromise=Promise.all(Array.from(this.representations.entries()).map((function(t){var r=f(t,2),i=r[0],a=r[1];return e.initData.has(i)?Promise.resolve():e.fetcher.fetchRepresentation(a,e.containerParser).then((function(t){if(t){var r=t.dataView,a=t.segments,n=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);e.initData.set(i,n),e.segments.set(i,a)}}))}))).then((function(){e.allInitsLoaded=!0})).finally((function(){e.loadAllInitsPromise=null}))),[2,this.loadAllInitsPromise]}))}))},t.prototype.appendDataToBuffer=function(r,i){return c(this,void 0,void 0,(function(){return p(this,(function(a){switch(a.label){case 0:if(e.assertNonNullable(this.sourceBuffer),i&&i.aborted)return[2,!1];if(this.sourceBuffer.updating)return[3,2];try{this.sourceBuffer.appendBuffer(r)}catch(e){return this.error$.next({id:"AppendBuffer",message:"Error appending data to buffer",thrown:e}),[2,!1]}return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 1:return a.sent(),[3,4];case 2:return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 3:return a.sent(),[2,this.appendDataToBuffer(r,i)];case 4:return[2,!0]}}))}))},t.prototype.checkEjectedSegments=function(){var t,r;if(!e.isNullable(this.sourceBuffer)&&!e.isNullable(this.playingRepresentationId)){var i=this.segments.get(this.playingRepresentationId);e.assertNonNullable(i);for(var a=[],n=0;n<this.sourceBuffer.buffered.length;n++){var s=1e3*this.sourceBuffer.buffered.start(n),o=this.sourceBuffer.buffered.end(n),u=1e3*(o%1>.9?Math.round(o):o);a.push({from:s,to:u})}var d=function(e){var t=a.some((function(t){return t.from<=e.time.from&&t.to>=e.time.to}));e.status!==b.FED||t||(e.status=b.NONE)};try{for(var l=h(i),c=l.next();!c.done;c=l.next()){d(c.value)}}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}}},t.waitForBufferUpdate=function(e){return c(this,void 0,void 0,(function(){return p(this,(function(t){return[2,new Promise((function(t){return e?e.addEventListener("update",(function(){return t()})):t()}))]}))}))},t}(),ge=["timeupdate","progress","play","seeked","stalled"];!function(e){e.NONE="none",e.MANIFEST_LOADED="manifest_loaded",e.REPRESENTATION_SELECTED="representation_selected"}(ue||(ue={}));var ye,Te=function(){function t(t){var r=this;this.element=null,this.source=null,this.manifest=null,this.subscription=new e.Subscription,this.state$=new te(ue.NONE),this.currentVideoRepresentation$=new e.ValueSubject(void 0),this.error$=new e.Subject,this.lastConnectionType$=new e.ValueSubject(void 0),this.lastConnectionReused$=new e.ValueSubject(void 0),this.lastRequestFirstBytes$=new e.ValueSubject(void 0),this.forceEnded$=new e.Subject,this.tick=function(){var e,t;if(r.element){var i=1e3*r.element.currentTime;null===(e=r.videoBufferManager)||void 0===e||e.maintain(i),null===(t=r.audioBufferManager)||void 0===t||t.maintain(i)}},this.throughputEstimator=t.throughputEstimator,this.tuning=t.tuning,this.fetcher=new se({throughputEstimator:this.throughputEstimator})}return t.prototype.initManifest=function(t,r){return c(this,void 0,void 0,(function(){var i,a,n,s=this;return p(this,(function(o){switch(o.label){case 0:return this.element=t,this.subscription.add(e.fromEvent(t,"waiting").subscribe((function(){t.duration-t.currentTime<s.tuning.endGapTolerance/1e3&&s.forceEnded$.next()}),(function(e){return s.error$.next({id:"ForceEnd",message:"Error when forcing stream end",thrown:e})}))),this.state$.startTransitionTo(ue.MANIFEST_LOADED),[4,this.fetcher.fetchManifest(r)];case 1:i=o.sent();try{a=function(e,t){var r,i,a,n,s,o,u,d,l,c,p,b,y,T,E,P,k,w,x,A,$,N,D,_,R,I,C={video:[],audio:[],text:[]},L=(new DOMParser).parseFromString(e,"application/xml").children[0],O=L.getElementsByTagName("Period")[0].children,V=0,M=null!==(o=null===(s=L.getAttribute("profiles"))||void 0===s?void 0:s.split(","))&&void 0!==o?o:[],B=M.includes(S.WEBM_AS_IN_FFMPEG)||M.includes(S.WEBM_AS_IN_SPEC)?g.WEBM:g.MP4;try{for(var U=h(O),F=U.next();!F.done;F=U.next()){var H=F.value,q=H.getAttribute("mimeType"),G=H.getAttribute("codecs"),j=null!==(u=H.getAttribute("contentType"))&&void 0!==u?u:null==q?void 0:q.split("/")[0],Y=null!==(l=null===(d=H.getAttribute("profiles"))||void 0===d?void 0:d.split(","))&&void 0!==l?l:[],z=H.querySelectorAll("Representation");try{for(var Q=(a=void 0,h(z)),W=Q.next();!W.done;W=Q.next()){var J=W.value,K=null!==(c=J.getAttribute("mimeType"))&&void 0!==c?c:q,X=null!==(b=null!==(p=J.getAttribute("codecs"))&&void 0!==p?p:G)&&void 0!==b?b:"",Z=null!==(T=null!==(y=J.getAttribute("contentType"))&&void 0!==y?y:null==K?void 0:K.split("/")[0])&&void 0!==T?T:j,ee=null!==(P=null===(E=H.getAttribute("profiles"))||void 0===E?void 0:E.split(","))&&void 0!==P?P:[],te=parseInt(null!==(k=J.getAttribute("width"))&&void 0!==k?k:"",10),re=parseInt(null!==(w=J.getAttribute("height"))&&void 0!==w?w:"",10),ie=parseInt(null!==(x=J.getAttribute("bandwidth"))&&void 0!==x?x:"",10)/1e3,ae=(null!==(A=J.getAttribute("id"))&&void 0!==A?A:(V++).toString(10))+"@"+("video"===Z?re+"p":"audio"===Z?ie+"Kbps":X),ne=null!==(D=null===(N=null===($=J.querySelector("BaseURL"))||void 0===$?void 0:$.textContent)||void 0===N?void 0:N.trim())&&void 0!==D?D:"",se=new URL(ne,t).toString(),oe=v(v(v([],f(M),!1),f(Y),!1),f(ee),!1),ue=f((null!==(R=null===(_=J.querySelector("SegmentBase Initialization"))||void 0===_?void 0:_.getAttribute("range"))&&void 0!==R?R:"").split("-").map((function(e){return parseInt(e,10)})),2),de={from:ue[0],to:ue[1]},le=null===(I=J.querySelector("SegmentBase"))||void 0===I?void 0:I.getAttribute("indexRange"),ce=f(le?le.split("-").map((function(e){return parseInt(e,10)})):[],2),pe=ce[0],he=ce[1],fe=le?{from:pe,to:he}:void 0;if(Z&&K){var ve={video:m.VIDEO,audio:m.AUDIO,text:m.TEXT}[Z];ve&&C[ve].push({id:ae,kind:ve,profiles:oe,initRange:de,indexRange:fe,bitrate:ie,mime:K,codecs:X,width:te,height:re,url:se})}}}catch(e){a={error:e}}finally{try{W&&!W.done&&(n=Q.return)&&n.call(Q)}finally{if(a)throw a.error}}}}catch(e){r={error:e}}finally{try{F&&!F.done&&(i=U.return)&&i.call(U)}finally{if(r)throw r.error}}return{container:B,representations:C}}(null!=i?i:"",r)}catch(e){this.error$.next({id:"ManifestParsing",message:"Failed to parse MPD manifest",thrown:e})}return e.assertNonNullable(a),n=function(e){var r,i,a,n=e.mime,s=e.codecs;return Boolean((null===(r=t.canPlayType)||void 0===r?void 0:r.call(t,n))&&(null===(a=null===(i=window.MediaSource)||void 0===i?void 0:i.isTypeSupported)||void 0===a?void 0:a.call(i,n+'; codecs="'+s+'"')))},this.manifest=l(l({},a),{representations:Object.fromEntries(Object.entries(a.representations).map((function(e){var t=f(e,2);return[t[0],t[1].filter(n)]})))}),this.manifest.representations.video.length?this.state$.setState(ue.MANIFEST_LOADED):this.error$.next({id:"NoRepresentations",message:"No playable video representations"}),[2,this.manifest]}}))}))},t.prototype.initRepresentations=function(t,r){return c(this,void 0,void 0,(function(){var i,a=this;return p(this,(function(n){switch(n.label){case 0:return e.assertNonNullable(this.manifest),e.assertNonNullable(this.element),this.state$.startTransitionTo(ue.REPRESENTATION_SELECTED),this.source=new MediaSource,this.element.src=URL.createObjectURL(this.source),i={fetcher:this.fetcher,tuning:this.tuning.dash},this.videoBufferManager=new be(m.VIDEO,this.source,this.manifest.container,this.manifest.representations.video,i),this.audioBufferManager=new be(m.AUDIO,this.source,this.manifest.container,this.manifest.representations.audio,i),this.subscription.add(this.fetcher.lastConnectionType$.subscribe(this.lastConnectionType$)),this.subscription.add(this.fetcher.lastConnectionReused$.subscribe(this.lastConnectionReused$)),this.subscription.add(this.fetcher.lastRequestFirstBytes$.subscribe(this.lastRequestFirstBytes$)),this.subscription.add(e.merge(this.forceEnded$,e.combine({video:this.videoBufferManager.ended$,audio:this.audioBufferManager.ended$}).pipe(e.filter((function(e){return Object.values(e).every((function(e){return!0===e}))})))).subscribe((function(){var e,t;if("open"===(null===(e=a.source)||void 0===e?void 0:e.readyState))try{null===(t=a.source)||void 0===t||t.endOfStream()}catch(e){a.error$.next({id:"EndOfStream",message:"Failed to end MediaSource stream",thrown:e})}}))),this.subscription.add(e.merge(this.videoBufferManager.error$,this.audioBufferManager.error$).subscribe(this.error$)),this.subscription.add(this.videoBufferManager.playingRepresentation$.subscribe(this.currentVideoRepresentation$)),"open"===this.source.readyState?[3,2]:[4,new Promise((function(e){var t;return null===(t=a.source)||void 0===t?void 0:t.addEventListener("sourceopen",e)}))];case 1:n.sent(),n.label=2;case 2:return[4,Promise.all([this.videoBufferManager.startWith(t),this.audioBufferManager.startWith(r)])];case 3:return n.sent().some((function(e){return!e}))||(this.state$.setState(ue.REPRESENTATION_SELECTED),e.assertNonNullable(this.element),this.subscription.add(e.merge.apply(void 0,v(v([],f(ge.map((function(t){return e.fromEvent(a.element,t)}))),!1),[e.fromEvent(window,"online")],!1)).subscribe(this.tick,(function(e){a.error$.next({id:"DashVKPlayer",message:"Internal logic error",thrown:e})}))),this.subscription.add(e.fromEvent(this.element,"progress").subscribe((function(){a.element&&2===a.element.readyState&&!a.element.seeking&&(a.element.currentTime=a.element.currentTime)}))),this.tick()),[2]}}))}))},t.prototype.switchRepresentation=function(t,r){return c(this,void 0,void 0,(function(){var i,a;return p(this,(function(n){return i=(a={},a[m.VIDEO]=this.videoBufferManager,a[m.AUDIO]=this.audioBufferManager,a[m.TEXT]=null,a)[t],e.assertNonNullable(i),[2,i.switchTo(r)]}))}))},t.prototype.seek=function(t){e.assertNonNullable(this.element),e.assertNonNullable(this.videoBufferManager),e.assertNonNullable(this.audioBufferManager),this.videoBufferManager.maintain(t),this.audioBufferManager.maintain(t),this.element.currentTime=t/1e3},t.prototype.stop=function(){var e,t;this.element=null,this.source=null,this.manifest=null,this.currentVideoRepresentation$.next(void 0),null===(e=this.videoBufferManager)||void 0===e||e.destroy(),this.videoBufferManager=null,null===(t=this.audioBufferManager)||void 0===t||t.destroy(),this.audioBufferManager=null,this.state$.setState(ue.NONE)},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.fetcher.destroy(),this.stop(),this.source=null},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(ye||(ye={}));var Ee,Pe=function(e){var t=e.id,r=e.width,i=e.height,a=e.bitrate,n=q({width:r,height:i});return n&&{id:t,quality:n,bitrate:a,size:{width:r,height:i}}},ke=function(e,t,r){var i,a=Array.from(t).sort((function(e,t){return t.bitrate-e.bitrate})).indexOf(r);return null!==(i=e.at(Math.round(e.length*a/t.length)))&&void 0!==i?i:e.at(-1)},we=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(ye.STOPPED),this.elementSize$=new e.ValueSubject(void 0),this.textTracksManager=new D,this.videoTracks=[],this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.seekPosition.getTransition();if(!r.videoState.getTransition()){var s=null==n?void 0:n.to;if((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(s)&&t!==ye.STOPPED&&i!==exports.PlaybackState.STOPPED&&r.seek(s),i!==exports.PlaybackState.STOPPED){if(t===ye.STOPPED)return r.videoState.startTransitionTo(ye.READY),void r.prepare();switch(t){case ye.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(ye.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(ye.PLAYING),r.playIfAllowed()));case ye.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(ye.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case ye.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(ye.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}else t!==ye.STOPPED&&(r.videoState.startTransitionTo(ye.STOPPED),r.player.stop(),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState(ye.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))}},this.params=t,this.video=_(this.params.container),this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(Z(this.params.source.url)),this.params.output.isLive$.next(!1),this.player=new Te({throughputEstimator:this.params.dependencies.throughputEstimator,tuning:this.params.tuning}),this.subscribe()}return t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=O(this.video),s=function(e){i.error$.next({id:"DashVKProvider",message:"DashVKProvider internal logic error",thrown:e})},o=function(e,r){return t.subscription.add(e.subscribe(r,s))};o(n.timeUpdate$,i.position$),o(n.durationChange$,i.duration$),o(n.ended$,i.endedEvent$),o(n.error$,i.error$),o(n.isBuffering$,i.isBuffering$),o(n.currentBuffer$,i.currentBuffer$),o(n.firstFrame$,i.firstFrameEvent$),o(this.player.error$,i.error$),o(this.player.lastConnectionType$,i.httpConnectionType$),o(this.player.lastConnectionReused$,i.httpConnectionReused$),o(this.player.lastRequestFirstBytes$.pipe(e.filter(e.isNonNullable),e.once()),i.firstBytesEvent$),this.subscription.add(n.seeked$.subscribe(i.seekedEvent$,s)),this.subscription.add(A(this.video,a.isLooped,s)),this.subscription.add($(this.video,a.volume,n.volumeState$,s)),this.subscription.add(n.volumeState$.subscribe(this.params.output.volume$,s)),o(ee(this.video),this.elementSize$),this.subscription.add(n.playing$.subscribe((function(){t.videoState.setState(ye.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),s)).add(n.pause$.subscribe((function(){t.videoState.setState(ye.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),s)).add(n.canplay$.subscribe((function(){t.videoState.getState()===ye.PLAYING&&t.playIfAllowed()}),s)),this.subscription.add(this.player.state$.stateChangeEnded$.pipe(e.filter((function(e){return e.to===ue.REPRESENTATION_SELECTED}))).subscribe((function(){t.videoState.setState(ye.READY)}))),this.subscription.add(e.merge(this.player.state$.stateChangeEnded$,a.videoTrack.stateChangeStarted$,a.autoVideoTrackSwitching.transitionStarted$,this.params.dependencies.throughputEstimator.rttAdjustedThroughput$,this.elementSize$,e.fromEvent(this.video,"progress")).subscribe((function(){var r,i,n,s=t.player.state$.getState(),o=t.player.state$.getTransition();if(s!==ue.NONE&&t.videoTracks.length){var u=s===ue.MANIFEST_LOADED&&!o,d=a.autoVideoTrackSwitching.getState(),l=a.videoTrack.getState(),c=null===(r=t.videoTracks.find((function(e){return e.track.id===l})))||void 0===r?void 0:r.track;a.autoVideoTrackSwitching.getTransition()&&a.autoVideoTrackSwitching.setState(d);var p=X(t.video.buffered,1e3*t.video.currentTime),h=Math.min(p/Math.min(t.params.tuning.dash.forwardBufferTarget,(t.video.duration||1/0)-t.video.currentTime),1),f=K(t.videoTracks.map((function(e){return e.track})),{container:t.elementSize$.getValue(),throughput:t.params.dependencies.throughputEstimator.rttAdjustedThroughput$.getValue(),tuning:t.params.tuning.autoTrackSelection,forwardBufferHealth:h}),v=d?null!=f?f:c:null!=c?c:f;if(u){var S=v&&(null===(i=t.videoTracks.find((function(e){return e.track===v})))||void 0===i?void 0:i.representation);e.assertNonNullable(S);var b=ke(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);e.assertNonNullable(b),t.player.initRepresentations(S.id,b.id)}else{if(S=v&&(null===(n=t.videoTracks.find((function(e){return e.track===v})))||void 0===n?void 0:n.representation)){b=ke(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);t.player.switchRepresentation(m.VIDEO,S.id),b&&t.player.switchRepresentation(m.AUDIO,b.id)}}}}))),this.subscription.add(this.player.currentVideoRepresentation$.pipe(e.filterChanged(),e.map((function(e){var r;return e&&(null===(r=t.videoTracks.find((function(t){return t.representation.id===e})))||void 0===r?void 0:r.track)}))).subscribe(i.currentVideoTrack$)),this.textTracksManager.connect(this.video,a,i);var u=e.merge(a.playbackState.stateChangeStarted$,a.videoTrack.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,s))},t.prototype.prepare=function(){return c(this,void 0,void 0,(function(){var e,t,r,i,a,n,s;return p(this,(function(o){switch(o.label){case 0:return[4,this.player.initManifest(this.video,this.params.source.url)];case 1:e=o.sent(),this.videoTracks=[];try{for(t=h(e.representations.video),r=t.next();!r.done;r=t.next())i=r.value,(a=Pe(i))&&this.videoTracks.push({track:a,representation:i})}catch(e){n={error:e}}finally{try{r&&!r.done&&(s=t.return)&&s.call(t)}finally{if(n)throw n.error}}return this.audioRepresentations=Array.from(e.representations.audio).sort((function(e,t){return t.bitrate-e.bitrate})),this.params.output.availableVideoTracks$.next(this.videoTracks.map((function(e){return e.track}))),[2]}}))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.player.seek(1e3*e)},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0),this.player.destroy()},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(ye.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t}();!function(e){e[e.OFFSET_P=0]="OFFSET_P",e[e.PLAYBACK_SHIFT=1]="PLAYBACK_SHIFT"}(Ee||(Ee={}));var xe,Ae=function(t,r,i){switch(void 0===r&&(r=0),void 0===i&&(i=Ee.OFFSET_P),i){case Ee.OFFSET_P:return t.replace("_offset_p",0===r?"":"_"+r.toFixed(0));case Ee.PLAYBACK_SHIFT:if(0===r)return t;var a=new URL(t);return a.searchParams.append("playback_shift",r.toFixed(0)),a.toString();default:e.assertNever(i)}return t};!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(xe||(xe={}));var $e,Ne=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.loadMediaTimeoutSubscription=new e.Subscription,this.videoState=new te(xe.STOPPED),this.syncPlayback=function(){var t=r.videoState.getState(),i=r.videoState.getTransition(),a=r.params.desiredState.playbackState.getState(),n=r.params.desiredState.playbackState.getTransition(),s=r.params.desiredState.seekPosition.getTransition();if(r.log({message:"[syncPlayback] videoState: "+t+"; videoTransition: "+JSON.stringify(i)+"; desiredPlaybackState: "+a+"; desiredPlaybackStateTransition: "+r.params.desiredState.playbackState.getTransition()+"; seekPositionTransition: "+JSON.stringify(s)+";"}),a!==exports.PlaybackState.STOPPED){if(!i){var o=null==s?void 0:s.to;if((null==n?void 0:n.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&t!==xe.STOPPED)r.seek(o);else switch(a){case exports.PlaybackState.PLAYING:switch(t){case xe.PLAYING:break;case xe.PAUSED:case xe.READY:r.videoState.startTransitionTo(xe.PLAYING),r.params.connection.remotePlayerController.playOrPause();break;case xe.STOPPED:r.videoState.startTransitionTo(xe.READY),r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case xe.PLAYING:r.videoState.startTransitionTo(xe.PAUSED),r.params.connection.remotePlayerController.playOrPause();break;case xe.PAUSED:break;case xe.READY:r.videoState.startTransitionTo(xe.PAUSED),r.videoState.setState(xe.PAUSED);break;case xe.STOPPED:r.videoState.startTransitionTo(xe.READY),r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(a)}}}else t!==xe.STOPPED&&(r.videoState.startTransitionTo(xe.STOPPED),r.stop())},this.params=t,this.log=this.params.dependencies.logger.createComponentLog("ChromecastProvider"),this.log({message:"constructor, format: "+t.format}),this.params.output.isLive$.next(function(t){switch(t){case exports.VideoFormat.MPEG:case exports.VideoFormat.DASH:case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_SEP_VK:case exports.VideoFormat.DASH_ONDEMAND:case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_JS:case exports.VideoFormat.HLS_ONDEMAND:return!1;case exports.VideoFormat.HLS_LIVE:case exports.VideoFormat.DASH_LIVE:case exports.VideoFormat.DASH_LIVE_WEBM:return!0;default:return e.assertNever(t)}}(t.format)),this.handleRemoteVolumeChange({volume:this.params.connection.remotePlayer.volumeLevel,muted:this.params.connection.remotePlayer.isMuted});var i=this.params.connection.session.getMediaSession();i&&this.restoreSession(i),this.subscribe()}return t.prototype.destroy=function(){this.log({message:"[destroy]"}),this.subscription.unsubscribe()},t.prototype.subscribe=function(){var t=this;this.subscription.add(this.loadMediaTimeoutSubscription);var r=new e.Subscription;this.subscription.add(r),this.subscription.add(e.merge(this.videoState.stateChangeStarted$.pipe(e.map((function(e){return"stateChangeStarted$ "+JSON.stringify(e)}))),this.videoState.stateChangeEnded$.pipe(e.map((function(e){return"stateChangeEnded$ "+JSON.stringify(e)})))).subscribe((function(e){return t.log({message:"[videoState] "+e})})));var i=function(e,r){return t.subscription.add(e.subscribe(r))};if(this.params.output.isLive$.getValue())this.params.output.position$.next(0),this.params.output.duration$.next(0);else{var a=new e.Subject;r.add(a.pipe(e.debounce(500)).subscribe((function(){t.params.output.seekedEvent$.next()})));var n=NaN;r.add(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.CURRENT_TIME_CHANGED).subscribe((function(r){t.logRemoteEvent(r);var i=r.value;t.params.output.position$.next(i);var s=t.params.desiredState.seekPosition.getTransition();(e.isNonNullable(s)&&e.isNullable(s.to)||Math.abs(i-n)>5)&&a.next(i),n=i}))),r.add(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.DURATION_CHANGED).subscribe((function(e){t.logRemoteEvent(e),t.params.output.duration$.next(e.value)})))}i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MEDIA_LOADED_CHANGED),(function(e){t.logRemoteEvent(e),e.value?t.handleRemoteReady():(t.handleRemoteStop(),r.unsubscribe())})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_PAUSED_CHANGED),(function(e){t.logRemoteEvent(e),e.value?t.handleRemotePause():t.handleRemotePlay()})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.PLAYER_STATE_CHANGED),(function(r){t.logRemoteEvent(r);var i=t.params.connection.remotePlayer,a=r.value,n=t.params.output.isBuffering$.getValue(),s=a===chrome.cast.media.PlayerState.BUFFERING;switch(n!==s&&t.params.output.isBuffering$.next(s),a){case chrome.cast.media.PlayerState.IDLE:!t.params.output.isLive$.getValue()&&i.duration-i.currentTime<5&&t.params.output.endedEvent$.next(),t.handleRemoteStop(),V(t.params.desiredState.playbackState,exports.PlaybackState.STOPPED);break;case chrome.cast.media.PlayerState.PAUSED:t.handleRemotePause();break;case chrome.cast.media.PlayerState.PLAYING:t.handleRemotePlay();break;case chrome.cast.media.PlayerState.BUFFERING:break;default:e.assertNever(a)}})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.VOLUME_LEVEL_CHANGED),(function(e){t.logRemoteEvent(e),t.handleRemoteVolumeChange({volume:e.value})})),i(e.fromEvent(this.params.connection.remotePlayerController,cast.framework.RemotePlayerEventType.IS_MUTED_CHANGED),(function(e){t.logRemoteEvent(e),t.handleRemoteVolumeChange({muted:e.value})})),i(e.merge(this.params.desiredState.playbackState.stateChangeStarted$,this.params.desiredState.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)),this.syncPlayback)},t.prototype.restoreSession=function(e){this.log({message:"restoreSession"});var t=this.params.connection.remotePlayer;if(e.playerState!==chrome.cast.media.PlayerState.IDLE){t.isPaused?(this.videoState.setState(xe.PAUSED),V(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):(this.videoState.setState(xe.PLAYING),V(this.params.desiredState.playbackState,exports.PlaybackState.PLAYING));var r=this.params.output.isLive$.getValue();this.params.output.duration$.next(r?0:t.duration),this.params.output.position$.next(r?0:t.currentTime),this.params.desiredState.seekPosition.setState(void 0)}},t.prototype.prepare=function(){var e=this.params.format;this.log({message:"[prepare] format: "+e});var t=this.createMediaInfo(e),r=this.createLoadRequest(t);this.loadMedia(r)},t.prototype.handleRemotePause=function(){var e=this.videoState.getState(),t=this.videoState.getTransition();(null==t?void 0:t.to)!==xe.PAUSED&&e!==xe.PLAYING||(this.videoState.setState(xe.PAUSED),V(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED))},t.prototype.handleRemotePlay=function(){var e=this.videoState.getState(),t=this.videoState.getTransition();(null==t?void 0:t.to)!==xe.PLAYING&&e!==xe.PAUSED||(this.videoState.setState(xe.PLAYING),V(this.params.desiredState.playbackState,exports.PlaybackState.PLAYING))},t.prototype.handleRemoteReady=function(){var e=this.videoState.getTransition();(null==e?void 0:e.to)===xe.READY&&this.videoState.setState(xe.READY)},t.prototype.handleRemoteStop=function(){this.videoState.getState()!==xe.STOPPED&&this.videoState.setState(xe.STOPPED)},t.prototype.handleRemoteVolumeChange=function(e){var t,r,i=this.params.output.volume$.getValue(),a={volume:null!==(t=e.volume)&&void 0!==t?t:i.volume,muted:null!==(r=e.muted)&&void 0!==r?r:i.muted};a.volume===i.volume&&a.muted==a.muted||this.params.output.volume$.next(a)},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next();var t=this.params.connection,r=t.remotePlayer,i=t.remotePlayerController;r.currentTime=e,i.seek()},t.prototype.stop=function(){this.params.connection.remotePlayerController.stop()},t.prototype.createMediaInfo=function(t){var r,i,a,n,s=this.params.source;switch(t){case exports.VideoFormat.MPEG:var o=s[t];e.assertNonNullable(o);var u=Object.keys(o).sort((function(e,t){return e===t?0:e===exports.VideoQuality.INVARIANT?1:t===exports.VideoQuality.INVARIANT?-1:F(e,t)?1:-1}))[0];e.assertNonNullable(u);var d=o[u];e.assertNonNullable(d),i=d,a="video/mp4",n=chrome.cast.media.StreamType.BUFFERED;break;case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_ONDEMAND:var l=s[t];e.assertNonNullable(l),i=l.url,a="application/x-mpegurl",n=chrome.cast.media.StreamType.BUFFERED;break;case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_SEP_VK:case exports.VideoFormat.DASH_ONDEMAND:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.DASH_WEBM:var c=s[t];e.assertNonNullable(c),i=c.url,a="application/dash+xml",n=chrome.cast.media.StreamType.BUFFERED;break;case exports.VideoFormat.HLS_LIVE:l=s[t];e.assertNonNullable(l),i=Ae(l.url),a="application/x-mpegurl",n=chrome.cast.media.StreamType.LIVE;break;case exports.VideoFormat.DASH_LIVE_WEBM:c=s[t];e.assertNonNullable(c),i=c.url,a="application/dash+xml",n=chrome.cast.media.StreamType.LIVE;break;case exports.VideoFormat.HLS_JS:case exports.VideoFormat.DASH:case exports.VideoFormat.DASH_LIVE:var p="Unsupported format for Chromecast",h=new Error(p);throw this.params.output.error$.next({id:"ChromecastProvider.createMediaInfo()",message:p,thrown:h}),h;default:return e.assertNever(t)}var f=new chrome.cast.media.MediaInfo(null!==(r=this.params.meta.videoId)&&void 0!==r?r:i,a);f.contentUrl=i,f.streamType=n,f.metadata=new chrome.cast.media.GenericMediaMetadata;var v=this.params.meta,m=v.title,S=v.subtitle;return e.isNonNullable(m)&&(f.metadata.title=m),e.isNonNullable(S)&&(f.metadata.subtitle=S),f},t.prototype.createLoadRequest=function(e){var t,r=new chrome.cast.media.LoadRequest(e);r.autoplay=!1;var i=this.params.desiredState.seekPosition.getTransition();return r.currentTime=i?this.params.output.isLive$.getValue()?0:null!==(t=i.to)&&void 0!==t?t:0:0,r},t.prototype.loadMedia=function(t){var r=this,i=this.params.connection.session.loadMedia(t),a=new Promise((function(t,i){r.loadMediaTimeoutSubscription.add(e.timeout(7e3).subscribe((function(){return i("timeout(7000)")})))}));Promise.race([i,a]).then((function(){r.log({message:"[loadMedia] completed, format: "+r.params.format});var e=r.params.desiredState.seekPosition;e.getTransition()&&e.setState(void 0),r.handleRemoteReady()}),(function(e){var t="[prepare] loadMedia failed, format: "+r.params.format+", reason: "+e;r.log({message:t}),r.params.output.error$.next({id:"ChromecastProvider.loadMedia",message:t,thrown:e})})).finally((function(){r.loadMediaTimeoutSubscription.unsubscribe()}))},t.prototype.logRemoteEvent=function(e){this.log({message:"[remoteEvent] "+JSON.stringify(e)})},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}($e||($e={}));var De,_e=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te($e.STOPPED),this.trackUrls={},this.textTracksManager=new D,this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition();if(i!==exports.PlaybackState.STOPPED){if(!r.videoState.getTransition()){var n=r.params.desiredState.videoTrack.getTransition(),s=r.params.desiredState.seekPosition.getTransition();if(t===$e.STOPPED)return r.videoState.startTransitionTo($e.READY),void r.prepare();if(n){var o=r.video.currentTime;return r.prepare(),void(s||r.params.desiredState.seekPosition.startTransitionTo(o))}var u=null==s?void 0:s.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(u)&&r.seek(u),t){case $e.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState($e.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo($e.PLAYING),r.playIfAllowed()));case $e.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo($e.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case $e.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo($e.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==$e.STOPPED&&(r.videoState.startTransitionTo($e.STOPPED),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState($e.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=_(t.container),this.params.output.element$.next(this.video),Object.entries(this.params.source).forEach((function(e,t){var i=f(e,2),a=i[0],n=i[1],s=t.toString(10);r.trackUrls[s]={track:{quality:a,id:s},url:n}})),this.params.output.availableVideoTracks$.next(Object.values(this.trackUrls).map((function(e){return e.track}))),this.params.output.isLive$.next(!1),this.subscribe()}return t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"MpegProvider",message:"MpegProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r,n))};o(s.timeUpdate$,i.position$),o(s.durationChange$,i.duration$),o(s.ended$,i.endedEvent$),o(s.error$,i.error$),o(s.isBuffering$,i.isBuffering$),o(s.currentBuffer$,i.currentBuffer$),o(s.firstBytes$,i.firstBytesEvent$),o(s.firstFrame$,i.firstFrameEvent$),o(s.seeked$,i.seekedEvent$),this.subscription.add(A(this.video,a.isLooped,n)),this.subscription.add($(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState($e.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState($e.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var r;(null===(r=t.videoState.getTransition())||void 0===r?void 0:r.to)===$e.READY&&t.videoState.setState($e.READY);var i=t.params.desiredState.videoTrack.getTransition();i&&e.isNonNullable(i.to)&&(t.params.desiredState.videoTrack.setState(i.to),t.params.output.currentVideoTrack$.next(t.trackUrls[i.to].track)),t.videoState.getState()===$e.PLAYING&&t.playIfAllowed()}),n)),this.subscription.add(a.autoVideoTrackSwitching.stateChangeStarted$.subscribe((function(){return a.autoVideoTrackSwitching.setState(!1)}),n)),this.textTracksManager.connect(this.video,a,i);var u=e.merge(a.playbackState.stateChangeStarted$,a.videoTrack.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.trackUrls={},this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.prepare=function(){var t,r,i=null!==(r=null===(t=this.params.desiredState.videoTrack.getTransition())||void 0===t?void 0:t.to)&&void 0!==r?r:this.params.desiredState.videoTrack.getState();e.assertNonNullable(i,"MpegProvider: track is not selected");var a=this.trackUrls[i].url;e.assertNonNullable(a,"MpegProvider: No url for "+i),this.video.setAttribute("src",a),this.video.load(),this.params.output.hostname$.next(Z(a))},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState($e.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.video.currentTime=e},t}(),Re=function(){function t(e,t,r,i,a,n){void 0===t&&(t=[]),this._failoverIndex=0,this._failoverCount=0,this._xhr=null,this._retryTimeout=0,this._url=e,this._failoverHosts=t,this._completeCb=r,this._progressCb=i,this._headersCb=a,this._errorCb=n,this._request()}return t.prototype._request=function(){var t=this;this._xhr=new XMLHttpRequest,this._xhr.open("GET",this._url,!0),this._xhr.overrideMimeType("text/plain; charset=x-user-defined");var r=!1;this._xhr.onreadystatechange=function(){var i,a,n,s,o,u,d,l;if(e.assertNonNullable(t._xhr),(null===(i=t._xhr)||void 0===i?void 0:i.status)>=400)return null===(a=t._errorCb)||void 0===a||a.call(t,"Http"+(null===(n=t._xhr)||void 0===n?void 0:n.status),"XHR response code "+(null===(s=t._xhr)||void 0===s?void 0:s.status)),void t.abort();if(4!==t._xhr.readyState||0!==t._xhr.status)try{if(t._xhr.readyState>=2&&!r){r=!0;var c=Object.fromEntries(t._xhr.getAllResponseHeaders().trim().split(/[\n\r]+/).map((function(e){return e.split(":").map((function(e){return e.trim()}))})));null===(o=t._headersCb)||void 0===o||o.call(t,new Headers(c))}else 4===t._xhr.readyState?null===(u=t._completeCb)||void 0===u||u.call(t,t._xhr.response):3===t._xhr.readyState&&(null===(d=t._progressCb)||void 0===d||d.call(t,t._xhr.response))}catch(e){throw null===(l=t._errorCb)||void 0===l||l.call(t,"XHR2CallbackError","xhr2 callback threw "+String(e),e),e}},this._xhr.onerror=function(){var e;null===(e=t._xhr)||void 0===e||e.abort(),t._retryTimeout=window.setTimeout((function(){var e;if(t._xhr)if(++t._failoverCount>=30)t._xhr=null,null===(e=t._errorCb)||void 0===e||e.call(t,"XHR2Failover","XHR failed, retrying failover host");else{var r=void 0;t._failoverIndex>=t._failoverHosts.length?(r=t._url,t._failoverIndex=0):(r=t._url.replace(function(e){var t=document.createElement("a");return t.href=e,t.host}(t._url),t._failoverHosts[t._failoverIndex]),t._failoverIndex++),t._xhr.open("GET",r,!0),t._xhr.send(null)}}),500)},this._xhr.send(null)},t.prototype.abort=function(){window.clearTimeout(this._retryTimeout),this._completeCb=this._progressCb=this._errorCb=void 0,this._xhr&&(this._xhr.abort(),this._xhr=null)},t}(),Ie=function(){function e(e){this._maxBufferDuration=Number.POSITIVE_INFINITY,this._isFull=!1,this._params=e,this._mediaSource=e.mediaSource,this._sourceBuffer=e.sourceBuffer,this._onDashCallback=e.onDashCallback}return e.prototype._appendBuffer=function(e,t){try{this._isFull=!1,(this._sourceBuffer.appendBuffer||this._sourceBuffer.append).bind(this._sourceBuffer)(e),null==t||t()}catch(e){if("QuotaExceededError"!==e.name)throw this._params.onError("AppendBuffer","Unknown Buffer error",e),e;this._isFull=!0;for(var r=this._sourceBuffer.buffered,i=0,a=0,n=r.length;a<n;a++)i+=r.end(a)-r.start(a);i&&(this._maxBufferDuration=Math.round(i))}},e.prototype.getMaxBufferDuration=function(){return this._maxBufferDuration},e.prototype.isFull=function(){return this._isFull},e.prototype.load=function(t,r,i,a,n,s,o){var u=this;this.abort((function(){var d=0,l=Date.now(),c=0,p=0,h=0,f=function(t){a(e._str2ua(t.substr(d))),d=t.length};u._lastXhr=new Re(t.baseURL+"&bytes="+r+"-"+i,t.failoverHosts,(function(e){u._lastXhr=void 0,f(e);var t=Date.now()-l;u._params.onBandwidthChange({size:e.length,duration:t,speed:8*e.length/(t/1e3)}),u._onDashCallback("loading",{size:e.length,done:!0}),null==n||n()}),(function(e){if(e.length-d>o&&f(e),0!==p){h=e.length-c;var t=Date.now()-p;h>=102400&&t>=1e3&&(u._params.onBandwidthChange({size:h,duration:t,speed:8*h/(t/1e3)}),h=0,c=e.length,p=Date.now()),u._onDashCallback("loading",{size:e.length,done:!1})}else p=Date.now()}),s,(function(e,t,r){return u._params.onError(e,t,r)}))}))},e.prototype.abort=function(e){var t,r=this;null===(t=this._lastXhr)||void 0===t||t.abort(),this._lastXhr=void 0,this._sbUpdatingStop(this._lastStreamUpdatingCallback),this._lastStreamUpdatingCallback=this._sbUpdatingWatch((function(){r._appendPromiseUint8Array&&(r._appendBuffer(r._appendPromiseUint8Array),r._appendPromiseUint8Array=void 0),r._lastStreamUpdatingCallback=r._sbUpdatingWatch((function(){"open"===r._mediaSource.readyState&&r._sourceBuffer.abort(),null==e||e()}))}))},e.prototype._sbUpdatingWatch=function(e){var t=this;if(this._sourceBuffer.updating){var r=function(){try{t._sbUpdatingStop(r),t._sbUpdatingWatch(e)}catch(e){throw t._params.onError("SourceBuffer","Source Buffer update error",e),e}};return this._sourceBuffer.addEventListener("updateend",r,!1),r}e()},e.prototype._sbUpdatingStop=function(e){e&&this._sourceBuffer.removeEventListener("updateend",e,!1)},e.prototype.append=function(t,r){var i=this;this._appendPromiseUint8Array?this._appendPromiseUint8Array=e._concatUint8(this._appendPromiseUint8Array,t):(this._appendPromiseUint8Array=t,this._lastStreamUpdatingCallback=this._sbUpdatingWatch((function(){i._appendPromiseUint8Array&&i._appendBuffer(i._appendPromiseUint8Array,(function(){i._appendPromiseUint8Array=void 0,r&&i._sbUpdatingWatch(r)}))})))},e.prototype.endOfStream=function(){var e=this;"open"===this._mediaSource.readyState&&this._sbUpdatingWatch((function(){return e._mediaSource.endOfStream()}))},e._concatUint8=function(e,t){var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(e,0),r.set(t,e.byteLength),r},e._str2ua=function(e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t},e.prototype.remove=function(e,t){var r=this;this._sbUpdatingWatch((function(){!r._sourceBuffer.updating&&r._sourceBuffer.remove&&r._sourceBuffer.remove(e,t),r._maxBufferDuration=Number.POSITIVE_INFINITY}))},e.prototype.destroy=function(){var e;null===(e=this._lastXhr)||void 0===e||e.abort(),this._sbUpdatingStop(this._lastStreamUpdatingCallback),"open"===this._mediaSource.readyState&&this._sourceBuffer.abort()},e}(),Ce=function(){function t(e){var t;this._representations=[],this._appendVector={},this._cachingPaused=!1,this._duration=0,this.STREAM_END_THRESHOLD=1,this._params=e,this._video=e.video,this._buffer=e.buffer,this._onDashCallback=null!==(t=e.onDashCallback)&&void 0!==t?t:function(){},this._config=e.config}return t.prototype._parseDurationFromISO8601=function(e){var t=function(e,t){var r=e?parseFloat(e.replace(",",".")):NaN;return(isNaN(r)?0:r)*t},r=/^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/.exec(e),i="-"===(null==r?void 0:r[1])?-1:1;t(null==r?void 0:r[2],i),t(null==r?void 0:r[3],i),t(null==r?void 0:r[4],i),t(null==r?void 0:r[5],i);return 3600*t(null==r?void 0:r[6],i)+60*t(null==r?void 0:r[7],i)+t(null==r?void 0:r[8],i)},t.prototype.getRepresentations=function(){return this._representations},t.prototype.attachSource=function(e,t){var r=this;new Re(e,t,(function(i){r.attachManifest(i,t,function(e){var t=document.createElement("a");return t.href=e,t.origin}(e))}),void 0,(function(e){r._params.onResponseHeaders(e)}),(function(e,t,i){return r._params.onError(e,t,i)}))},t.prototype.attachManifest=function(e,t,r){var i=this,a=(new DOMParser).parseFromString(e,"text/xml").documentElement,n=function(e,t){var r=e.attributes.getNamedItem(t);return r?r.value:null};this._duration=this._parseDurationFromISO8601(String(n(a,"mediaPresentationDuration")));var s=[],o=[];Array.prototype.forEach.call(a.getElementsByTagName("Representation"),(function(e){var i,a,u,d,l,c,p,h,f,v,m,S,b,g,y,T,E,P=e.getElementsByTagName("SegmentBase")[0],k=P&&n(P,"indexRange").split("-"),w=P&&P.getElementsByTagName("Initialization")[0],x=w&&n(w,"range").split("-");if(x&&k){var A=Number(null===(p=e.attributes.getNamedItem("bandwidth"))||void 0===p?void 0:p.value),$=(r?r+"/":"")+e.getElementsByTagName("BaseURL")[0].childNodes[0].data;s.push({width:Number(null===(h=e.attributes.getNamedItem("width"))||void 0===h?void 0:h.value),height:Number(null===(f=e.attributes.getNamedItem("height"))||void 0===f?void 0:f.value),bandwidth:A,baseURL:$,failoverHosts:t,indexFrom:Number(k[0]),indexTo:Number(k[1]),initFrom:Number(x[0]),initTo:Number(x[1]),codecs:null!==(m=null===(v=e.attributes.getNamedItem("codecs"))||void 0===v?void 0:v.value)&&void 0!==m?m:void 0,mimeType:null!==(b=null===(S=e.attributes.getNamedItem("mimeType"))||void 0===S?void 0:S.value)&&void 0!==b?b:void 0,bufferSize:.1*A/8,bufferLength:.1,name:null!==(y=null===(g=e.attributes.getNamedItem("okQuality"))||void 0===g?void 0:g.value)&&void 0!==y?y:void 0,id:null!==(E=null===(T=e.attributes.getNamedItem("id"))||void 0===T?void 0:T.value)&&void 0!==E?E:void 0})}else{var N=e.parentElement;if("text"===(null==N?void 0:N.getAttribute("contentType"))){var D=null!==(i=e.getAttribute("id"))&&void 0!==i?i:void 0,_=(r?r+"/":"")+(null===(l=null===(d=null===(u=null===(a=e.getElementsByTagName("BaseURL"))||void 0===a?void 0:a[0])||void 0===u?void 0:u.childNodes)||void 0===d?void 0:d[0])||void 0===l?void 0:l.data),R=null!==(c=N.getAttribute("lang"))&&void 0!==c?c:void 0;_&&o.push({id:D,url:_,language:R})}}})),s.length?(this._representations=s,o.forEach((function(e){var t=e.id,r=e.language,a=e.url,n=document.createElement("track");n.setAttribute("src",a),t&&n.setAttribute("id",t),r&&n.setAttribute("srclang",r),i._video.appendChild(n)})),this._representations.sort((function(e,t){return t.bandwidth-e.bandwidth})),this._params.onManifestReady(this._representations)):this._onDashCallback("error")},t.prototype._loadInitAndSidx=function(e,t){var r=this;if(e!==this._currentRepresentation)if(e.refs)this._stream.abort((function(){r._stream.append(e.initMessage,t)}));else{var i=Date.now();this._stream.load(e,e.initFrom,e.indexTo,(function(i){var a=e.initTo-e.initFrom+1;if(i.byteLength){e.initMessage=new Uint8Array(i.buffer,0,a);var n=new DataView(i.buffer);a+=12;var s=n.getUint32(a+4,!1);a+=8;var o=n.getUint32(a,!1),u=n.getUint32(a+4,!1)+(e.indexTo+1);a+=8;var d=n.getUint16(a+2,!1);a+=4,e.refs=[];for(var l=0;l<d;l+=1){var c=u+(2147483647&n.getUint32(a,!1)),p=o+n.getUint32(a+4,!1);a+=12,e.refs.push({fromTime:o/s,toTime:p/s,fromOffset:u,toOffset:c-1}),u=c,o=p}var h=e.refs[e.refs.length-1];h.toTime-h.fromTime<.3&&e.refs.pop(),r._stream.append(e.initMessage,t)}else r._params.onError("EmptyResponse","Empty response")}),void 0,(function(e){r._params.onResponseHeaders(e),r._params.onIdxRequestPing(Date.now()-i)}),e.indexTo-e.initFrom+1)}else t&&t()},t.prototype.startPlay=function(e){var t=this,r=window.MediaSource||window.WebKitMediaSource;if(r){var i=new r,a=void 0,n=void 0,s=function(){t._loopTimeout=window.setTimeout((function(){try{!function(){var r=t._findRef(t._video.currentTime);if(r&&!t._video.paused){if(!t._cachingPaused&&void 0!==t._lastLoadOffset&&t._lastLoadOffset-t._video.currentTime<t._config.FRONT_CACHE_DURATION&&t._lastLoadOffset-t._video.currentTime<t._stream.getMaxBufferDuration()){var i=t._stream.isFull()?t._findBufferRangeEnd(t._video.currentTime):t._lastLoadOffset;t._loadRef(t._params.selectRepresentation(t._representations),i)}var s,o=t._appendVector[String(r.fromTime)];if(o!==a&&(a=o,t._params.onRepresentationPlay(o)),t._findRef(r.toTime)){var u=t._buffer.getByTime(t._video.currentTime);if(!u)return void t._onDashCallback("buffering");(s=u.end-t._video.currentTime)<e.bufferLength&&(t._onDashCallback("buffering"),n!==u.end&&(n=u.end,window.setTimeout((function(){try{var e=t._buffer.getNextWithGap(u);e&&(t._video.currentTime=e.start)}catch(e){throw t._params.onError("GapSyncError","Seek Error "+String(e),e),e}}),1e3*s)))}}}()}catch(e){throw t._params.onError("LoopError","Dash Loop exception "+String(e),e),e}s()}),250)},o=function(){if(!t._stream)try{var r=i.addSourceBuffer(e.mimeType+'; codecs="'+e.codecs+'"');t._stream=new Ie({mediaSource:i,sourceBuffer:r,onBandwidthChange:t._params.onBandwidthChange,onError:t._params.onError,onDashCallback:t._onDashCallback})}catch(e){throw t._params.onError("DashSourceOpen","Source open exception "+String(e),e),e}t._loadInitAndSidx(e),i.duration||(i.duration=t._duration),t._loopTimeout||s(),i.removeEventListener("sourceopen",o),i.removeEventListener("webkitsourceopen",o)};i.addEventListener("sourceopen",o,!1),i.addEventListener("webkitsourceopen",o,!1),this._video&&(this._video.src=window.URL.createObjectURL(i),this._video.addEventListener("waiting",(function(){var e=t._video&&t._video.played.length;e&&!t._video.currentTime&&t._video.loop?t._video.duration-t._video.played.end(e-1)<t.STREAM_END_THRESHOLD&&t.seek(0):t._video.duration-t._video.currentTime<t.STREAM_END_THRESHOLD&&t._stream.endOfStream()})))}else this._params.onError("MediaSourceNotSupported","MediaSource is not supported")},t.prototype._loadRef=function(e,t,r){var i=this;void 0===r&&(r=!1),this._lastLoadOffset=void 0,this._loadInitAndSidx(e,(function(){i._currentRepresentation=e;var a=i._findRef(t);if(a){if(r){i._isLastRef(a)&&t>=a.toTime&&(t=a.fromTime);var n=i._findRef(i._video.currentTime),s=Math.abs(i._video.currentTime-t),o=i._video.duration<i._config.SEEK_IN_SEGMENT_THRESHOLD/1e3||a===n||s<=i._config.SEEK_IN_SEGMENT_DELTA/1e3;i._video.currentTime=o?t:a.fromTime}i._appendVector[String(a.fromTime)]=e,i._stream.load(e,a.fromOffset,a.toOffset,(function(e,t){return i._stream.append(e,t)}),(function(){i._lastLoadOffset=a.toTime,i._video.duration-i._lastLoadOffset<i.STREAM_END_THRESHOLD&&i._stream.endOfStream()}),(function(e){return i._params.onResponseHeaders(e)}),e.bufferSize)}}))},t.prototype.setQualityByRepresentation=function(e,t){var r=this;void 0===t&&(t=!1);var i=this._buffer.getByTime(this._video.currentTime),a=this._findRef(this._video.currentTime);if(i&&a){var n=.1;if(a.toTime<i.end+n){var s=this._findRef(a.toTime);s&&s.toTime<i.end+n?(this._buffer.smartRemove(a.fromTime-n,s.toTime+n,(function(e,t){return r._stream.remove(e,t)})),this._loadRef(e,s.toTime)):(this._buffer.smartRemove(a.fromTime-n,a.toTime+n,(function(e,t){return r._stream.remove(e,t)})),this._loadRef(e,a.toTime))}}else this._video.currentTime&&t&&this._loadRef(e,this._video.currentTime)},t.prototype.setQuality=function(e){return this.setQualityByRepresentation(this._representations[e])},t.prototype.pauseCaching=function(){this._cachingPaused=!0},t.prototype.resumeCaching=function(){this._cachingPaused=!1},t.prototype.seek=function(e,t){void 0===t&&(t=!1),this._stream&&this._buffer.getByTime(e)&&!t?this._video.currentTime=e:this._loadRef(this._params.selectRepresentation(this._representations),e,!0)},t.prototype.updateRefsForCurrentTime=function(){var t=this._video.currentTime;this._stream&&!e.isNullable(this._buffer.getByTime(t))||this._loadRef(this._params.selectRepresentation(this._representations),t,!1)},t.prototype._findRef=function(e){var t,r=null===(t=this._currentRepresentation)||void 0===t?void 0:t.refs;if(r){if(!Array.isArray(r)||0!==r.length){for(var i=void 0,a=0;a<r.length;a++){var n=r[a];if(n.fromTime<=e&&n.toTime>e)return n;n.fromTime>e&&(!i||n.fromTime<i.fromTime)&&(i=n)}if(!i){var s=r[r.length-1];if(e>s.toTime)return s}return i}this._params.onError("emptyrefs","Empty refs")}},t.prototype._isLastRef=function(e){var t,r=null===(t=this._currentRepresentation)||void 0===t?void 0:t.refs;if(!r)return!1;var i=r[r.length-1];return e.fromTime===i.fromTime},t.prototype._findBufferRangeEnd=function(e){for(var t=this._video.buffered.length;t-- >0;){var r=this._video.buffered.start(t),i=this._video.buffered.end(t);if(e>r&&e<i)return Math.round(10*i)/10}return e},t.prototype.destroy=function(){this._stream&&this._stream.destroy(),clearTimeout(this._loopTimeout),this._loopTimeout=void 0},t}();!function(e){e.STOPPED="stopped",e.MANIFEST_LOADED="manifest-loaded",e.INITIAL_REPRESENTATION_SELECTED="initial-representation-selected",e.METADATA_LOADED="metadata-loaded",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(De||(De={}));var Le,Oe=[De.PAUSED,De.PLAYING],Ve=function(){function t(t){var r=this;this.videoState=new te(De.STOPPED),this.subscription=new e.Subscription,this.representations$=new e.ValueSubject([]),this.currentRepresentation$=new e.ValueSubject(void 0),this.textTracksManager=new D,this.elementSize$=new e.ValueSubject(void 0),this.dashLiteEvents={idxRequestPing$:new e.Subject,responseHeaders$:new e.Subject,manifestReady$:new e.Subject,representationPlay$:new e.Subject,error$:new e.Subject},this.handleManifestReady=function(e){var t,i,a,n,s=[];try{for(var o=h(e),u=o.next();!u.done;u=o.next()){var d=u.value,l=null!==(n=null!==(a=d.name)&&void 0!==a?a:d.id)&&void 0!==n?n:d.height.toString(10),c=q(d),p=d.bandwidth/1e3,f={width:d.width,height:d.height};if(c){var v={id:l,quality:c,bitrate:p,size:f};s.push({track:v,representation:d})}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}r.representations$.next(s),r.params.output.availableVideoTracks$.next(s.map((function(e){return e.track}))),r.videoState.setState(De.MANIFEST_LOADED)},this.handleRepresentationPlay=function(e){var t,i=null===(t=r.representations$.getValue().find((function(t){return t.representation===e})))||void 0===t?void 0:t.track;i&&(r.params.output.currentVideoTrack$.next(i),r.params.desiredState.videoTrack.getTransition()&&r.params.desiredState.videoTrack.setState(i.id))},this.selectRepresentation=function(){var t=r.currentRepresentation$.getValue();return e.assertNonNullable(t,"Can't select representation. something went wrong"),t},this.syncPlayback=function(){var t=r.videoState.getState(),i=r.videoState.getTransition(),a=r.params.desiredState.playbackState.getState(),n=r.params.desiredState.playbackState.getTransition(),s=r.params.desiredState.seekPosition.getTransition();if(r.log({message:"[syncPlayback] videoState: "+t+"; videoTransition: "+JSON.stringify(i)+"; desiredPlaybackState: "+a+"; seekPositionTransition: "+JSON.stringify(s)+";"}),a!==exports.PlaybackState.STOPPED){if(!i){var o=null==s?void 0:s.to;switch((null==n?void 0:n.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&Oe.includes(t)&&r.seek(o),t){case De.STOPPED:return r.videoState.startTransitionTo(De.MANIFEST_LOADED),void r.prepare();case De.MANIFEST_LOADED:return void r.videoState.startTransitionTo(De.INITIAL_REPRESENTATION_SELECTED);case De.INITIAL_REPRESENTATION_SELECTED:return r.videoState.startTransitionTo(De.METADATA_LOADED),void r.dash.startPlay(r.selectRepresentation());case De.METADATA_LOADED:return r.videoState.startTransitionTo(De.READY),void r.dash.seek(null!=o?o:0);case De.READY:return void(a===exports.PlaybackState.PAUSED?(r.videoState.setState(De.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):a===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(De.PLAYING),r.playIfAllowed()));case De.PLAYING:return void(a===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(De.PAUSED),r.video.pause()):(null==n?void 0:n.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case De.PAUSED:return void(a===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(De.PLAYING),r.playIfAllowed()):(null==n?void 0:n.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==De.STOPPED&&(r.videoState.startTransitionTo(De.STOPPED),r.dash.destroy(),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState(De.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.log=this.params.dependencies.logger.createComponentLog("DashProvider"),e.merge(this.videoState.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,type:"start"}}))),this.videoState.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,type:"end"}})))).subscribe((function(e){var t=e.transition,i=e.type;r.log({message:"[videoState change] "+i+": "+JSON.stringify(t)})})),this.video=_(t.container),this.params.output.element$.next(this.video),this.params.output.isLive$.next(!1),"url"===this.params.source.type&&this.params.output.hostname$.next(Z(this.params.source.url)),this.buffer=new I(this.video),this.dash=new Ce({video:this.video,buffer:this.buffer,selectRepresentation:this.selectRepresentation,onIdxRequestPing:function(e){return r.dashLiteEvents.idxRequestPing$.next(e)},onResponseHeaders:function(e){return r.dashLiteEvents.responseHeaders$.next(e)},onManifestReady:function(e){return r.dashLiteEvents.manifestReady$.next(e)},onRepresentationPlay:function(e){return r.dashLiteEvents.representationPlay$.next(e)},onBandwidthChange:function(e){return r.params.dependencies.throughputEstimator.addRawSpeed(e.size,e.duration)},onError:function(e,t,i){r.log({message:"[DashLite error], "+e}),r.dashLiteEvents.error$.next({id:e,message:t,thrown:i})},config:{SEEK_IN_SEGMENT_THRESHOLD:this.params.tuning.dashSeekInSegmentDurationThreshold,SEEK_IN_SEGMENT_DELTA:this.params.tuning.dashSeekInSegmentAlwaysSeekDelta,FRONT_CACHE_DURATION:this.params.config.cacheDuration/1e3}}),this.subscribe()}return t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"DashProvider",message:"DashProvider internal logic error",thrown:e})},s=function(){var e=t.params.desiredState.autoVideoTrackSwitching.getState(),r=t.params.desiredState.autoVideoTrackSwitching.getTransition();return r?r.to:e},o=O(this.video),u=function(e,r){return t.subscription.add(e.subscribe(r,n))};u(o.timeUpdate$,i.position$),u(o.durationChange$,i.duration$),u(o.ended$,i.endedEvent$),u(o.error$,i.error$),u(o.isBuffering$,i.isBuffering$),u(o.firstFrame$,i.firstFrameEvent$),this.subscription.add(o.seeking$.subscribe((function(){e.isNullable(t.params.desiredState.seekPosition.getTransition())&&(t.videoState.getState()===De.PLAYING||t.videoState.getState()===De.PAUSED)&&t.dash.updateRefsForCurrentTime()}))),this.subscription.add(o.seeked$.subscribe(i.seekedEvent$,n)),this.subscription.add(A(this.video,a.isLooped,n)),this.subscription.add($(this.video,a.volume,o.volumeState$,n)),this.subscription.add(o.volumeState$.subscribe(this.params.output.volume$)),this.textTracksManager.connect(this.video,a,i),u(ee(this.video),this.elementSize$),this.subscription.add(o.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===De.READY&&t.videoState.setState(De.READY)}),n)).add(o.pause$.subscribe((function(){t.videoState.setState(De.PAUSED),V(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED)}))).add(o.playing$.subscribe((function(){t.videoState.setState(De.PLAYING),V(t.params.desiredState.playbackState,exports.PlaybackState.PLAYING)}),n)).add(o.loadedMetadata$.subscribe((function(){t.videoState.setState(De.METADATA_LOADED)}),n)).add(o.currentBuffer$.subscribe((function(e){t.buffer.fill(),i.currentBuffer$.next(e)}),n)).add(this.dashLiteEvents.error$.pipe(e.map((function(e){return{id:"DashLite_"+e.id,message:e.message,thrown:e.thrown}}))).subscribe(this.params.output.error$)).add(e.merge(this.params.desiredState.videoTrack.transitionStarted$,this.params.desiredState.autoVideoTrackSwitching.transitionStarted$,this.representations$,this.params.dependencies.throughputEstimator.rttAdjustedThroughput$,this.params.output.element$,this.elementSize$,e.fromEvent(this.video,"progress")).pipe(e.map((function(){var r,i,a,n=t.currentRepresentation$.getValue(),o=t.representations$.getValue(),u=t.params.desiredState.autoVideoTrackSwitching.getTransition(),d=t.params.desiredState.videoTrack.getState(),l=t.params.dependencies.throughputEstimator.rttAdjustedThroughput$.getValue(),c=t.elementSize$.getValue(),p=s();if(u&&t.params.desiredState.autoVideoTrackSwitching.setState(u.to),!p&&e.isNonNullable(d))a=d;else{var h=X(t.video.buffered,1e3*t.video.currentTime),f=Math.min(h/t.params.tuning.dash.forwardBufferTarget,1);a=null===(r=K(o.map((function(e){return e.track})),{container:c,throughput:l,tuning:t.params.tuning.autoTrackSelection,forwardBufferHealth:f,currentRepresentation:n}))||void 0===r?void 0:r.id}return e.isNonNullable(a)?null===(i=o.find((function(e){return e.track.id===a})))||void 0===i?void 0:i.representation:void 0})),e.filterChanged()).subscribe(this.currentRepresentation$,n)).add(e.combine({needToSelectRepresentation:this.videoState.stateChangeStarted$.pipe(e.filter((function(e){return e.to===De.INITIAL_REPRESENTATION_SELECTED}))),currentRepresentationSelected:this.currentRepresentation$.pipe(e.filter(e.isNonNullable))}).pipe(e.once()).subscribe((function(){return t.videoState.setState(De.INITIAL_REPRESENTATION_SELECTED)}),n)).add(this.currentRepresentation$.pipe(e.filter(e.isNonNullable),e.filterChanged((function(e,r){return t.params.tuning.autoTrackSelection.lazyQualitySwitch&&s()?e.height<=r.height:e===r}))).subscribe((function(e){var r=X(t.video.buffered,1e3*t.video.currentTime),i=Math.min(r/t.params.tuning.dash.forwardBufferTarget,1);(!t.params.tuning.autoTrackSelection.lazyQualitySwitch||i<=.5||!s())&&(t.dash.setQualityByRepresentation(e,!0),t.params.output.hostname$.next(Z(e.baseURL)))}),n)).add(this.dashLiteEvents.responseHeaders$.subscribe((function(e){var r=re(e),i=r.type,a=r.reused;t.params.output.httpConnectionType$.next(i),t.params.output.httpConnectionReused$.next(a)}))).add(this.dashLiteEvents.idxRequestPing$.pipe(e.once()).subscribe(this.params.output.firstBytesEvent$)).add(this.dashLiteEvents.idxRequestPing$.subscribe((function(e){return t.params.dependencies.throughputEstimator.addRawRtt(e)}))).add(this.dashLiteEvents.manifestReady$.subscribe(this.handleManifestReady,n)).add(this.dashLiteEvents.representationPlay$.pipe(e.filter(e.isNonNullable)).subscribe(this.handleRepresentationPlay,n)).add(e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)).subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0),this.buffer.destroy(),this.dash.destroy()},t.prototype.prepare=function(){var t=this.params.source;switch(t.type){case"url":this.dash.attachSource(t.url);break;case"raw":this.dash.attachManifest(t.raw);break;default:return e.assertNever(t)}},t.prototype.seek=function(e){this.log({message:"[seek] position: "+e}),this.params.output.willSeekEvent$.next(),this.dash.seek(e)},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(De.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t}(),Me=function(e){return e.range?e.range.split("-").map((function(e){return parseInt(e,10)})):[NaN,NaN]},Be=function(){function e(e){this.params=e,this.dashJsRequestQueue=new Map,this.activeRequests=new Map}return e.prototype.setMetrics=function(e){this.dashMetrics=e},e.prototype.queueDashJSRequest=function(e){var t,r=e.request.url,i=null!==(t=this.dashJsRequestQueue.get(r))&&void 0!==t?t:[];i.push(e),this.dashJsRequestQueue.set(r,i)},e.prototype.executeNextRequests=function(){return c(this,void 0,void 0,(function(){var e,t,r,i,a,n,s,o,u,d,l,c,v;return p(this,(function(p){try{for(e=h(this.dashJsRequestQueue.entries()),t=e.next();!t.done;t=e.next()){if(r=f(t.value,2),i=r[0],a=r[1],n=this.activeRequests.get(i)){if(a.length&&this.onBigRequestProgress(n),!(s=a[0])||!s.request.range)continue;if(o=f(Me(s.request),2),u=o[0],d=o[1],u>=n.from&&d<=n.to)continue;this.activeRequests.delete(i)}a.length&&(l=this.sendBigRequest(i,a.map((function(e){return e.request}))),this.activeRequests.set(i,l))}}catch(e){c={error:e}}finally{try{t&&!t.done&&(v=e.return)&&v.call(e)}finally{if(c)throw c.error}}return[2]}))}))},e.prototype.abort=function(e){var t,r,i;if(e){var a=e.request,n=(null!==(i=this.dashJsRequestQueue.get(a.url))&&void 0!==i?i:[]).includes(e),s=this.activeRequests.get(a.url);n&&s&&s.abortController.abort()}else try{for(var o=h(this.activeRequests.values()),u=o.next();!u.done;u=o.next()){u.value.abortController.abort()}}catch(e){t={error:e}}finally{try{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}},e.prototype.destroy=function(){this.abort(),this.dashMetrics=void 0,this.dashJsRequestQueue.clear(),this.activeRequests.clear()},e.prototype.sendBigRequest=function(t,r){for(var i=this,a=r.map(Me),n=a[0][0],s=a[0][1],o=1;o<a.length&&s<this.params.minDataSize;o++){var u=a[o][1];u-n<=2*this.params.minDataSize&&(s=Math.max(s,u))}s=0===n?Math.max(s,n+this.params.minInitSize):Math.max(s,n+this.params.minDataSize);var d=new URL(t,location.href);d.searchParams.append("bytes",n+"-"+s);var l=d.toString(),h=new AbortController,v=h.signal,m={url:t,from:n,to:s,loaded:0,data:null,abortController:h};v.addEventListener("abort",(function(){return i.onBigRequestAbort(m)}));var S=function(e){var t,r;throw null===(r=(t=i.params).onError)||void 0===r||r.call(t,{id:"BigRequestParsing",message:"Error parsing response data",thrown:e}),e};return fetch(l,{signal:v}).then((function(t){var r,a,n;if(t.ok&&t.body){var s=f(t.body.tee(),2),o=s[0],u=s[1];null===(a=(r=i.params).onDownloadStream)||void 0===a||a.call(r,u);var d=o.getReader(),l=parseInt(null!==(n=t.headers.get("Content-Length"))&&void 0!==n?n:"",10);m.data=new ArrayBuffer(l);var h=new Uint8Array(m.data),v=function(t){var r=t.done,a=t.value;return c(i,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return r?(this.onBigRequestProgress(m),[3,3]):[3,1];case 1:return a?(h.set(a,m.loaded),m.loaded+=a.byteLength,this.onBigRequestProgress(m),[4,null==d?void 0:d.read().then(v,e.suppressStreamErrors).catch(S)]):[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))};null==d||d.read().then(v,e.suppressStreamErrors).catch(S)}else i.onBigRequestError(m)}),e.suppressAbort).catch((function(e){return i.onBigRequestError(m,e)})),m},e.prototype.onBigRequestProgress=function(e){var t,r,i,a,n,s,o,u,d,l=e.url,c=e.from,p=e.to,v=e.loaded,m=e.data;if(this.activeRequests.has(l)&&m){var S=null!==(i=this.dashJsRequestQueue.get(l))&&void 0!==i?i:[],b=function(e){var t=e.request,r=f(Me(t),2),i=r[0],h=r[1],S=i>=c&&h<=c+v,b=c>=i&&c+v<h,y=m.slice(i-c,Math.min(h-c+1,v));(S||b)&&(t.requestStartDate=null!==(a=t.requestStartDate)&&void 0!==a?a:new Date,t.firstByteDate=null!==(n=t.firstByteDate)&&void 0!==n?n:new Date,t.bytesLoaded=y.byteLength,t.bytesTotal=p-c),S?(t.requestEndDate=new Date,g.dashJsRequestQueue.set(l,(null!==(s=g.dashJsRequestQueue.get(l))&&void 0!==s?s:[]).filter((function(t){return t!==e}))),null===(o=e.success)||void 0===o||o.call(e,y,"",l),null===(u=g.dashMetrics)||void 0===u||u.addHttpRequest(t,l,200,{},[])):b&&(null===(d=e.progress)||void 0===d||d.call(e,{loaded:v,total:p-c,lengthComputable:!0,stream:!0}))},g=this;try{for(var y=h(S),T=y.next();!T.done;T=y.next()){b(T.value)}}catch(e){t={error:e}}finally{try{T&&!T.done&&(r=y.return)&&r.call(y)}finally{if(t)throw t.error}}}},e.prototype.onBigRequestError=function(e,t){var r,i,a,n,s,o,u=e.url,d=e.from,l=e.to;if(null===(n=(a=this.params).onError)||void 0===n||n.call(a,{id:"BigRequest",message:"Download error",thrown:t}),this.activeRequests.has(u)){var c=null!==(s=this.dashJsRequestQueue.get(u))&&void 0!==s?s:[];try{for(var p=h(c),v=p.next();!v.done;v=p.next()){var m=v.value,S=f(Me(m.request),2),b=S[0],g=S[1];(b>=d&&b<l||g>d&&g<=l)&&(null===(o=null==m?void 0:m.error)||void 0===o||o.call(m,m.request,String(t)))}}catch(e){r={error:e}}finally{try{v&&!v.done&&(i=p.return)&&i.call(p)}finally{if(r)throw r.error}}if(this.activeRequests.delete(u),t)throw t}},e.prototype.onBigRequestAbort=function(e){var t,r,i,a,n=e.url,s=e.from,o=e.to;if(this.activeRequests.has(n)){var u=null!==(i=this.dashJsRequestQueue.get(n))&&void 0!==i?i:[];try{for(var d=h(u),l=d.next();!l.done;l=d.next()){var c=l.value,p=f(Me(c.request),2),v=p[0],m=p[1];(v>=s&&v<o||m>s&&m<=o)&&(null===(a=null==c?void 0:c.abort)||void 0===a||a.call(c,c.request))}}catch(e){t={error:e}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(t)throw t.error}}this.activeRequests.delete(n)}},e.suppressAbort=function(e){if(!(e instanceof DOMException)||"AbortError"!==e.name&&20!==e.code)throw e},e.suppressStreamErrors=function(){},e}(),Ue=function(){function e(e,t,r){this.baseLoader=e,this.config=r,this.bigRequest=t,t.setMetrics(r.dashMetrics)}return e.shouldDelegateToBase=function(e){return"download"!==e.action||"text"===e.mediaType||!e.range||"arraybuffer"!==e.responseType},e.prototype.load=function(t){var r=t.request;if(e.shouldDelegateToBase(r))return this.baseLoader.load(t);this.bigRequest.queueDashJSRequest(t),this.bigRequest.executeNextRequests()},e.prototype.abort=function(t){if(!t)return this.baseLoader.abort(),void this.bigRequest.abort();var r=t.request;e.shouldDelegateToBase(r)?this.baseLoader.abort(t):this.bigRequest.abort(t)},e}(),Fe=function(e,t){var r=new Be(t);return e.extend("SchemeLoaderFactory",(function(){var e=this.parent.getLoader;return{getLoader:function(t){return function(e,t){return function(r){return{create:function(i){var a=e(r).create(i);return new Ue(a,t,i)}}}}(e(t),r)}}}),!0),function(){return r.destroy()}},He=function(t){var r=new e.ValueSubject(1/0),i=new e.Subject,a=NaN,n=!1,s=function(t){var i,a,n;if(t.getAllResponseHeaders().includes("x-playback-duration")){var s=parseInt(null!==(i=t.getResponseHeader("X-Playback-Duration"))&&void 0!==i?i:"",10),o=parseInt(null!==(a=t.getResponseHeader("X-Playback-Duration-Millis"))&&void 0!==a?a:"",10),u=null!==(n=null!=o?o:1e3*s)&&void 0!==n?n:NaN;e.isNonNullable(u)&&!isNaN(u)&&r.next(u)}},o=function(e){e.readyState>=2&&!n&&(n=!0,i.next(Date.now()-a))};return t.extend("XHRLoader",(function(){var e=this.parent,t=e.load.bind(e);return{load:function(e){if("MPD"===e.request.type){var r=e.onload,i=e.progress;e.onload=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return s(this),r.apply(void 0,v([],f(e),!1))},e.progress=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o(this),i.apply(void 0,v([],f(e),!1))},a=Date.now(),n=!1}return t(e)}}}),!0),{playbackDuration$:r,ping$:i}},qe=function(){function e(){this.pausedTime=0,this.streamOffset=0,this.pauseTimestamp=0}return e.prototype.getTotalPausedTime=function(){return this.pausedTime+this.getCurrentPausedTime()},e.prototype.getCurrentPausedTime=function(){return this.pauseTimestamp>0?Date.now()-this.pauseTimestamp:0},e.prototype.getStreamOffset=function(){return this.streamOffset},e.prototype.getTotalOffset=function(){return this.getTotalPausedTime()+this.streamOffset},e.prototype.pause=function(){0===this.pauseTimestamp&&(this.pauseTimestamp=Date.now())},e.prototype.resume=function(){this.pauseTimestamp>0&&(this.pausedTime+=this.getCurrentPausedTime(),this.pauseTimestamp=0)},e.prototype.resetTo=function(e){this.streamOffset=e,this.pauseTimestamp=0,this.pausedTime=0},e}(),Ge={};!function(e){e.DOWNLOADING_LIB="downloading_lib",e.STOPPED="stopped",e.STREAM_INITIALIZED="stream_initialized",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(Le||(Le={}));var je=function(t,r){return new e.Observable((function(e){var i=function(t){return e.next(t)};return t.on(r,i),function(){return t.off(r,i)}}))},Ye=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(Le.DOWNLOADING_LIB),this.textTracksManager=new D,this.videoTracks=[],this.isLive$=new e.ValueSubject(void 0),this.maxSeekBackTime$=new e.ValueSubject(1/0),this.availableFrom$=new e.ValueSubject(void 0),this.elementSize$=new e.ValueSubject(void 0),this.liveOffset=new qe,this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.seekPosition.getTransition(),s=r.isLive$.getValue();if(!r.videoState.getTransition()&&t!==Le.DOWNLOADING_LIB&&t!==Le.STREAM_INITIALIZED){var o=null==n?void 0:n.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&t!==Le.STOPPED&&i!==exports.PlaybackState.STOPPED&&(s?r.seek(o+ze(r.liveOffset.getTotalPausedTime())):r.seek(o)),i){case exports.PlaybackState.STOPPED:switch(t){case Le.STOPPED:break;case Le.PLAYING:case Le.PAUSED:case Le.READY:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case Le.PLAYING:break;case Le.PAUSED:s&&(r.liveOffset.getTotalPausedTime()<r.params.config.maxPausedTime&&r.liveOffset.getTotalOffset()<r.maxSeekBackTime$.getValue()?(r.liveOffset.resume(),r.params.output.position$.next(ze(r.liveOffset.getTotalOffset()))):r.seek(ze(r.liveOffset.getTotalOffset()))),r.play();break;case Le.READY:r.play();break;case Le.STOPPED:r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case Le.PLAYING:r.pause(),r.liveOffset.pause();break;case Le.PAUSED:break;case Le.READY:r.videoState.setState(Le.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case Le.STOPPED:r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=_(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(Z(this.params.source.url)),this.loadDashJs()}return t.prototype.loadDashJs=function(){var e=this,t=!1,i=function(r){var i,a;t||e.params.output.error$.next({id:"timeout"===r?"DashJSTimedOut":"DashJSLoadingError",message:"Dash.js failed to load: "+(null===(a=null===(i=r)||void 0===i?void 0:i.toString)||void 0===a?void 0:a.call(i)),thrown:r}),t=!0},a=window.setTimeout((function(){return i("timeout")}),5e3);Promise.resolve().then((function(){return r(require("dashjs/dist/dash.mediaplayer.min.js"))})).then((function(r){t||(Ge.MediaPlayer=r.MediaPlayer,Ge.Debug=r.Debug,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){var t=this;e.assertNonNullable(Ge.MediaPlayer,"dashjs not loaded"),e.assertNonNullable(Ge.Debug,"dashjs not loaded"),this.player=Ge.MediaPlayer().create(),this.player.updateSettings({debug:{logLevel:3},streaming:{buffer:{fastSwitchEnabled:!0},abr:{limitBitrateByPortal:this.params.tuning.autoTrackSelection.limitByContainer,usePixelRatioInLimitBitrateByPortal:this.params.tuning.autoTrackSelection.usePixelRatio,additionalAbrRules:{insufficientBufferRule:!1}},utcSynchronization:{useManifestDateHeaderTimeSource:!0}}}),(this.params.format===exports.VideoFormat.DASH_WEBM||this.params.format===exports.VideoFormat.DASH_LIVE_WEBM)&&this.params.tuning.useWebmBigRequest?this.destroyBigRequest=Fe(this.player,{minInitSize:this.params.tuning.bigRequestMinInitSize,minDataSize:this.params.tuning.bigRequestMinDataSize,onError:function(e){return t.params.output.error$.next(e)},onDownloadStream:function(e){return t.params.dependencies.throughputEstimator.trackStream(e)}}):this.params.tuning.stripRangeHeader&&this.player.extend("HTTPLoader",(function(){var e=this.parent.load;return{load:function(t){if(t.request&&t.request.range){var r=f(t.request.range.split("-").map((function(e){return parseInt(e,10)})),2),i=r[0],a=r[1],n=new URL(t.request.url,location.href);n.searchParams.append("bytes",i+"-"+a),t.request.url=n.toString(),t.request.range=void 0}e(t)}}}),!0),function(e){var t,r=!1,i=!1;e.on("playbackTimeUpdated",(function(e){var a=e.timeToEnd;i=a<=3,r&&i&&(null==t||t())})),e.extend("MediaSourceController",(function(){var e=this.parent.signalEndOfStream;return{signalEndOfStream:function(a){t=function(){return e(a)},(r=!0)&&i&&(null==t||t())}}}),!0)}(this.player),this.player.clearDefaultUTCTimingSources(),this.subscribe(),this.videoState.setState(Le.STOPPED)},t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"DashIFProvider",message:"DashIFProvider internal logic error",thrown:e})},s=function(e,r){return t.subscription.add(e.subscribe(r,n))};s(ee(this.video),this.elementSize$),s(je(this.player,"error").pipe(e.map((function(e){return{id:"DashJS#"+("object"==typeof e.error?e.error.code:e.error),message:"object"==typeof e.error?e.error.message:void 0}}))),i.error$),s(je(this.player,"playbackError").pipe(e.map((function(e){return{id:"DashJSPlayback",message:e.error}}))),i.error$);var o=je(this.player,"qualityChangeRendered").pipe(e.filter((function(e){return"video"===e.mediaType})),e.map((function(e){var r,i=e.newQuality;return null===(r=t.videoTracks.find((function(e){return e.bitrateInfo.qualityIndex===i})))||void 0===r?void 0:r.track})));o.pipe(e.filter(e.isNonNullable)).subscribe(i.currentVideoTrack$),this.subscription.add(this.videoState.transitionEnded$.pipe(e.filter((function(e){return e.to===Le.STREAM_INITIALIZED})),e.once()).subscribe((function(){t.subscription.add(x(a.videoTrack,(function(){var e,r,i=t.player.getQualityFor("video");return null===(r=null===(e=t.videoTracks.find((function(e){return e.bitrateInfo.qualityIndex===i})))||void 0===e?void 0:e.track)||void 0===r?void 0:r.id}),(function(r){var i;if(!e.isNullable(r)){var a=null===(i=t.videoTracks.find((function(e){return e.track.id===r})))||void 0===i?void 0:i.bitrateInfo;a&&t.player.setQualityFor("video",a.qualityIndex)}}),{changed$:o.pipe(e.map((function(e){return null==e?void 0:e.id}))),onError:n}))}),n)),this.subscription.add(x(a.autoVideoTrackSwitching,(function(){var e,r,i;return null===(i=null===(r=null===(e=t.player.getSettings().streaming)||void 0===e?void 0:e.abr)||void 0===r?void 0:r.autoSwitchBitrate)||void 0===i?void 0:i.video}),(function(e){return t.player.updateSettings({streaming:{abr:{autoSwitchBitrate:{video:e}}}})}),{onError:n})),s(je(this.player,"bufferStateChanged").pipe(e.filter((function(e){return"video"===e.mediaType})),e.map((function(e){return"bufferStalled"===e.state}))),i.isBuffering$),s(je(this.player,"fragmentLoadingStarted").pipe(e.map((function(e){return Z(e.request.url)}))),i.hostname$),s(je(this.player,"streamInitialized"),(function(e){var r,a,n=e.streamInfo,s=n.duration,o=n.manifestInfo,u=o.isDynamic,d=o.availableFrom;t.isLive$.next(u),t.availableFrom$.next(d.getTime()),u||i.duration$.next(s),t.videoTracks=[];var l,c=t.player.getQualityFor("video");try{for(var p=h(t.player.getBitrateInfoListFor("video")),f=p.next();!f.done;f=p.next()){var v=f.value,m=v.qualityIndex.toString(10),S=q(v),b=v.bitrate/1e3,g={width:v.width,height:v.height};if(S){var y={id:m,quality:S,bitrate:b,size:g};t.videoTracks.push({track:y,bitrateInfo:v}),v.qualityIndex===c&&(l=y)}}}catch(e){r={error:e}}finally{try{f&&!f.done&&(a=p.return)&&a.call(p)}finally{if(r)throw r.error}}i.availableVideoTracks$.next(t.videoTracks.map((function(e){return e.track}))),l&&i.currentVideoTrack$.next(l),t.videoState.setState(Le.STREAM_INITIALIZED),t.videoState.startTransitionTo(Le.READY)})),s(je(this.player,"fragmentLoadingCompleted"),(function(e){var r=e.request;if(r.requestEndDate&&r.firstByteDate&&r.bytesLoaded){var i=r.requestEndDate.getTime()-r.firstByteDate.getTime(),a=r.bytesLoaded;t.params.dependencies.throughputEstimator.addRawSpeed(a,i)}})),s(e.merge(this.params.dependencies.throughputEstimator.throughput$,this.elementSize$),(function(){if(t.params.desiredState.autoVideoTrackSwitching.getState()&&t.videoTracks.length){var e=t.params.dependencies.throughputEstimator.throughput$.getValue(),r=K(t.videoTracks.map((function(e){return e.track})),{container:t.elementSize$.getValue(),throughput:e,tuning:t.params.tuning.autoTrackSelection}),i=t.videoTracks.find((function(e){return e.track===r}));(null==i?void 0:i.bitrateInfo)&&t.player.setQualityFor("video",null==i?void 0:i.bitrateInfo.qualityIndex,!1)}})),s(e.combine({maxSeekBackTime:this.maxSeekBackTime$,isLive:this.isLive$.pipe(e.filter(e.isNonNullable))}).pipe(e.filter((function(e){return e.isLive})),e.map((function(e){var t=e.maxSeekBackTime;return ze(t)}))),this.params.output.duration$);var u=je(this.player,"playbackTimeUpdated").pipe(e.map((function(e){var t=e.time;return null!=t?t:0})));s(e.combine({availableFrom:this.availableFrom$.pipe(e.filter(e.isNonNullable)),currentTime:u}),(function(e){var r=e.availableFrom,i=e.currentTime;return t.params.output.liveTime$.next(r+1e3*i)})),s(u.pipe(e.filter((function(){return!1===t.isLive$.getValue()}))),i.position$),s(je(this.player,"playbackSeeked"),(function(){return i.seekedEvent$.next()})),s(je(this.player,"playbackEnded"),i.endedEvent$),s(je(this.player,"playbackProgress").pipe(e.map((function(){return C(t.video.buffered,t.video.currentTime)}))),i.currentBuffer$),s(je(this.player,"playbackPlaying"),(function(){t.videoState.setState(Le.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)})),s(je(this.player,"playbackNotAllowed"),(function(){t.player.isMuted()?(t.player.setMute(!1),t.videoState.setState(Le.PAUSED),V(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)):(t.player.setMute(!0),t.player.play())})),s(je(this.player,"playbackPaused"),(function(){t.videoState.setState(Le.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)})),s(je(this.player,"canPlay"),(function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===Le.READY&&t.videoState.setState(Le.READY)})),s(this.isLive$,i.isLive$),s(ee(this.video),(function(){t.player.isReady()&&t.player.updatePortalSize()})),s(e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)),this.syncPlayback);var d=He(this.player),l=d.playbackDuration$,c=d.ping$;s(l,this.maxSeekBackTime$),s(c.pipe(e.once()),i.firstBytesEvent$),this.params.tuning.flushShortLoopedBuffers&&s(e.combine({isLive:this.isLive$,isShort:i.duration$.pipe(e.map((function(e){return e<60})))}),(function(e){var r=e.isLive,i=e.isShort,a=!r&&i;t.player.updateSettings({streaming:{buffer:{flushBufferAtTrackSwitch:a}}})})),s(u.pipe(e.filter((function(e){return e>t.params.tuning.insufficientBufferRuleMargin})),e.once()),(function(){return t.player.updateSettings({streaming:{abr:{additionalAbrRules:{insufficientBufferRule:!0}}}})})),this.textTracksManager.connect(this.video,a,i),this.subscription.add(je(this.player,"manifestLoaded").pipe(e.once()).subscribe((function(){var r=Date.now();t.subscription.add(je(t.player,"playbackPlaying").pipe(e.once()).subscribe((function(){return i.firstFrameEvent$.next(Date.now()-r)}),n))}),n)),this.subscription.add(A(this.video,a.isLooped,n));var p=O(this.video).volumeState$;this.subscription.add($(this.video,a.volume,p,n)),this.subscription.add(p.subscribe(i.volume$,n))},t.prototype.stop=function(){this.params.output.position$.next(0),this.params.output.duration$.next(1/0),this.params.output.currentBuffer$.next(void 0),this.params.output.hostname$.next(void 0),this.player.attachSource(null),this.player.attachView(null),this.player.initialize(),this.player.clearDefaultUTCTimingSources(),this.videoState.setState(Le.STOPPED),V(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t.prototype.prepare=function(){this.videoState.startTransitionTo(Le.STREAM_INITIALIZED),this.player.initialize(),this.player.clearDefaultUTCTimingSources(),this.player.attachView(this.video),this.player.attachSource(this.params.source.url)},t.prototype.seek=function(e){if(this.params.output.willSeekEvent$.next(),this.isLive$.getValue()){var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(ze(r));var i=Ae(this.params.source.url,this.liveOffset.getTotalOffset()/1e3,Ee.PLAYBACK_SHIFT);this.player.attachSource(i)}else this.player.seek(e)},t.prototype.play=function(){this.videoState.startTransitionTo(Le.PLAYING),this.player.play()},t.prototype.pause=function(){this.videoState.startTransitionTo(Le.PAUSED),this.video.pause()},t.prototype.destroy=function(){var e,t;this.subscription.unsubscribe(),this.textTracksManager.destroy();try{null===(e=this.player)||void 0===e||e.destroy()}catch(e){}this.video.remove(),this.params.output.element$.next(void 0),null===(t=this.destroyBigRequest)||void 0===t||t.call(this)},t}(),ze=function(e){return-e/1e3};function Qe(){return e.now()}function We(e){return Qe()-e}function Je(e){var t=e.split("/"),r=t.slice(0,t.length-1).join("/"),i=/^([a-z]+:)?\/\//i;return{resolve:function(e,t,a){void 0===a&&(a=!1),function(e){return i.test(e)}(e)||(e.startsWith("/")||(e="/"+e),e=r+e);var n=e.indexOf("?")>-1?"&":"?";return a&&(e+=n+"lowLat=1",n="&"),t&&(e+=n+"_rnd="+Math.floor(999999999*Math.random())),e}}}function Ke(t,r,i,a){var n,s,o,u,d,l=window.XMLHttpRequest,c=!1,p=0,h=!1,f="arraybuffer",v=7e3,m=2e3,S=function(){if(!c){e.assertNonNullable(u);var t=We(u);t<m?setTimeout(S,m-t):((m*=2)>v&&(m=v),s&&s.abort(),s=new l,g())}},b=function(){if(!c){if(--p>=0)return S(),void(a&&a());c=!0,d&&d(),i&&i()}},g=function(){u=Qe(),(s=new l).open("get",t);var i,a=0,p=0,v=function(){return e.assertNonNullable(u),Math.max(u,Math.max(i||0,p||0))};if(n&&s.addEventListener("progress",(function(e){var t=Qe();n.updateChunk&&e.loaded>a&&(n.updateChunk(v(),e.loaded-a),a=e.loaded,i=t)})),o&&(s.timeout=o,s.addEventListener("timeout",(function(){return b()}))),s.addEventListener("load",(function(){if(!c){e.assertNonNullable(s);var t=s.status;if(t>=200&&t<300){if(s.response.byteLength&&n){var i=s.response.byteLength-a;i&&n.updateChunk&&n.updateChunk(v(),i)}d&&d(),s&&r(s.response)}else b()}})),s.addEventListener("error",(function(){b()})),h){var m=function(){e.assertNonNullable(s),s.readyState===XMLHttpRequest.HEADERS_RECEIVED&&(p=Qe(),s.removeEventListener("readystatechange",m))};s.addEventListener("readystatechange",m)}return s.responseType=f,s.send(),y},y={withBitrateReporting:function(e){return n=e,y},withParallel:function(e){return h=e,y},withJSONResponse:function(){return f="json",y},withRetryCount:function(e){return p=e,y},withRetryInterval:function(t,r){return e.isNonNullable(t)&&(m=t),e.isNonNullable(r)&&(v=r),y},withTimeout:function(e){return o=e,y},withFinally:function(e){return d=e,y},send:g,abort:function(){s&&(s.abort(),s=void 0),c=!0,d&&d()}};return y}var Xe,Ze=function(){function e(e){this.intervals=[],this.currentRate=0,this.logger=e}return e.prototype._updateRate=function(e){var t=.2;this.currentRate&&(e<.1*this.currentRate?t=.8:e<.5*this.currentRate?t=.5:e<.7*this.currentRate&&(t=.3)),e=Math.max(1,Math.min(e,104857600)),this.currentRate=this.currentRate?this.currentRate*(1-t)+e*t:e},e.prototype._createInterval=function(e,t,r){return{start:e,end:t,bytes:r}},e.prototype._doMergeIntervals=function(e,t){e.start=Math.min(t.start,e.start),e.end=Math.max(t.end,e.end),e.bytes+=t.bytes},e.prototype._mergeIntervals=function(e,t){return e.start<=t.end&&t.start<=e.end&&(this._doMergeIntervals(e,t),!0)},e.prototype._flushIntervals=function(){if(!this.intervals.length)return!1;var e=this.intervals[0].start,t=this.intervals[this.intervals.length-1].end-500;if(t-e>2e3){for(var r=0,i=0;this.intervals.length>0;){var a=this.intervals[0];if(a.end<=t)r+=a.end-a.start,i+=a.bytes,this.intervals.splice(0,1);else{if(a.start>=t)break;var n=t-a.start,s=a.end-a.start;r+=n;var o=a.bytes*n/s;i+=o,a.start=t,a.bytes-=o}}if(i>0&&r>0){var u=8*i/(r/1e3);return this._updateRate(u),this.logger("rate updated, new="+Math.round(u/1024)+"K; average="+Math.round(this.currentRate/1024)+"K bytes/ms="+Math.round(i)+"/"+Math.round(r)+" interval="+Math.round(t-e)),!0}}return!1},e.prototype._joinIntervals=function(){var e;do{e=!1;for(var t=0;t<this.intervals.length-1;++t)this._mergeIntervals(this.intervals[t],this.intervals[t+1])&&(this.intervals.splice(t+1,1),e=!0)}while(e)},e.prototype.addInterval=function(e,t,r){return this.intervals.push(this._createInterval(e,t,r)),this._joinIntervals(),this.intervals.length>100&&(this.logger("too many intervals ("+this.intervals.length+"); will merge",{type:"warn"}),this._doMergeIntervals(this.intervals[1],this.intervals[0]),this.intervals.splice(0,1)),this._flushIntervals()},e.prototype.getBitRate=function(){return this.currentRate},e}(),et=function(){function e(e,t,r,i,a){this.pendingQueue=[],this.activeRequests={},this.completeRequests={},this.averageSegmentDuration=2e3,this.lastPrefetchStart=0,this.throttleTimeout=null,this.RETRY_COUNT=e,this.TIMEOUT=t,this.BITRATE_ESTIMATOR=r,this.MAX_PARALLEL_REQUESTS=i,this.logger=a}return e.prototype.limitCompleteCount=function(){for(var e;(e=Object.keys(this.completeRequests)).length>this._getParallelRequestCount()+2;){var t=e[Math.floor(Math.random()*e.length)];this.logger("Dropping completed request for url "+t,{type:"warn"}),delete this.completeRequests[t]}},e.prototype._sendRequest=function(e,t){var r=this,i=Qe();e._request=Ke(t,(function(a){e._complete=1,e._responseData=a,e._downloadTime=Qe()-i,delete r.activeRequests[t],r._sendPending(),e._cb?e._cb(a,e._downloadTime):(r.limitCompleteCount(),r.completeRequests[t]=e)}),(function(){return i="error",delete r.activeRequests[t],r.limitCompleteCount(),r.completeRequests[t]=e,r._sendPending(),e._error=1,e._errorMsg=i,void(e._errorCB?e._errorCB(i):(r.limitCompleteCount(),r.completeRequests[t]=e));var i}),(function(){e._retry=1,e._retryCB&&e._retryCB()})),e._request.withRetryCount(this.RETRY_COUNT).withTimeout(this.TIMEOUT).withBitrateReporting(this.BITRATE_ESTIMATOR).withParallel(this._getParallelRequestCount()>1).withFinally((function(){e._finallyCB&&e._finallyCB()})),this.activeRequests[t]=e,e._request.send(),this.lastPrefetchStart=Qe()},e.prototype._getParallelRequestCount=function(){return Math.min(this.MAX_PARALLEL_REQUESTS,this.averageSegmentDuration<3e3?3:2)},e.prototype._getPrefetchDelay=function(){return Math.max(100,Math.min(5e3,this.averageSegmentDuration/3))},e.prototype._canSendPending=function(){var e=this,t=this._getParallelRequestCount(),r=Qe();if(Object.keys(this.activeRequests).length>=t)return!1;var i=this._getPrefetchDelay()-(r-this.lastPrefetchStart);return this.throttleTimeout&&clearTimeout(this.throttleTimeout),!(i>0)||(this.throttleTimeout=window.setTimeout((function(){return e._sendPending()}),i),!1)},e.prototype._sendPending=function(){for(;this._canSendPending();){var e=this.pendingQueue.pop();if(!e)return;this.activeRequests[e]||this.completeRequests[e]||(this.logger("Submitting pending request url="+e),this._sendRequest({},e))}},e.prototype._removeFromActive=function(e){delete this.completeRequests[e],delete this.activeRequests[e]},e.prototype.abortAll=function(){Object.values(this.activeRequests).forEach((function(e){e&&e._request&&e._request.abort()})),this.activeRequests={},this.pendingQueue=[],this.completeRequests={}},e.prototype.requestData=function(e,t,r,i){var a=this,n={send:function(){var s=a.activeRequests[e]||a.completeRequests[e];if(s)s._cb=t,s._errorCB=r,s._retryCB=i,s._finallyCB=n._finallyCB,s._error||s._complete?(a._removeFromActive(e),setTimeout((function(){s._complete?(a.logger("Requested url already prefetched, url="+e),t(s._responseData,s._downloadTime)):(a.logger("Requested url already prefetched with error, url="+e),r(s._errorMsg)),n._finallyCB&&n._finallyCB()}),0)):a.logger("Attached to active request, url="+e);else{var o=a.pendingQueue.indexOf(e);-1!==o&&a.pendingQueue.splice(o,1),a.logger("Request not prefetched, starting new request, url="+e+(-1===o?"":"; removed pending")),a._sendRequest(n,e)}}};return n._cb=t,n._errorCB=r,n._retryCB=i,n.abort=function(){n.request&&n.request.abort()},n.withFinally=function(e){return n._finallyCB=e,n},n},e.prototype.prefetch=function(e){this.activeRequests[e]||this.completeRequests[e]?this.logger("Request already active for url="+e):(this.logger("Added to pending queue; url="+e),this.pendingQueue.unshift(e),this._sendPending())},e.prototype.optimizeForSegDuration=function(e){this.averageSegmentDuration=e},e}(),tt=function(){function t(e){this.paused=!1,this.autoQuality=!0,this.buffering=!0,this.destroyed=!1,this.videoPlayStarted=!1,this.lowLatency=!1,this.bitrate=0,this.manifest=[],this.sourceBuffer=0,this.bufferStates=[],this.sourceJitter=-1,this.params=e,this.chunkRateEstimator=new Ze(this.params.logger),this._initVideo()}return t.prototype.attachSource=function(e){this.manifestUrl=e,this.urlResolver=Je(e),this.bitrateSwitcher=this._initBitrateSwitcher(),this._initManifest()},t.prototype.setAutoQualityEnabled=function(e){this.autoQuality=e},t.prototype.switchByName=function(e){for(var t,r=0;r<this.manifest.length;++r)if((t=this.manifest[r]).name===e)return void this._switchToQuality(t)},t.prototype.catchUp=function(){this.rep&&this.rep.stop(),this.currentManifestEntry&&(this.paused=!1,this._initPlayerWith(this.currentManifestEntry),this._notifyBuffering(!0))},t.prototype.stop=function(){this.params.videoElement.pause(),this.rep&&(this.rep.stop(),this.rep=null)},t.prototype.pause=function(){this.paused=!0,this.params.videoElement.pause(),this.videoPlayStarted=!1,this._notifyBuffering(!1)},t.prototype.play=function(e){this.paused=!1;var t=this.lowLatency&&this._getBufferSizeSec()>this.sourceJitter+5;this.rep&&!t?(this.bufferStates=[],this.videoPlayStarted=!1,this.shouldPlay()?this._playVideoElement(e):this._notifyBuffering(!0)):this.catchUp()},t.prototype.startPlay=function(e,t){this.autoQuality=t,this._initPlayerWith(e)},t.prototype.destroy=function(){this.destroyed=!0,this.rep&&(this.rep.stop(),this.rep=null),this.manifestRequest&&this.manifestRequest.abort(),this.manifestRefetchTimer&&(clearTimeout(this.manifestRefetchTimer),this.manifestRefetchTimer=void 0)},t.prototype.reinit=function(e){this.manifestUrl=e,this.urlResolver=Je(e),this.catchUp()},t.prototype._handleNetworkError=function(){this.params.logger("Fatal network error"),this.params.playerCallback({name:"error",type:"network"})},t.prototype._retryCallback=function(){this.params.playerCallback({name:"retry"})},t.prototype._getBufferSizeSec=function(){var e=this.params.videoElement,t=0,r=e.buffered.length;return 0!==r&&(t=e.buffered.end(r-1)-Math.max(e.currentTime,e.buffered.start(0))),t},t.prototype._notifyBuffering=function(e){this.destroyed||(this.params.logger("buffering: "+e),this.params.playerCallback({name:"buffering",isBuffering:e}),this.buffering=e)},t.prototype._initVideo=function(){var e=this,t=this.params,r=t.videoElement,i=t.logger;r.addEventListener("error",(function(t){var a;e.destroyed||(i("Video element error: "+(null===(a=r.error)||void 0===a?void 0:a.code)),e.params.playerCallback({name:"error",type:"media"}))})),r.addEventListener("timeupdate",(function(){var t=e._getBufferSizeSec();!e.paused&&t<.3?e.buffering||(e.buffering=!0,window.setTimeout((function(){!e.paused&&e.buffering&&e._notifyBuffering(!0),r.pause(),e.videoPlayStarted=!1}),1e3*(t+.1))):e.buffering&&e.videoPlayStarted&&e._notifyBuffering(!1)})),r.addEventListener("playing",(function(){i("playing")})),r.addEventListener("stalled",(function(){return e._fixupStall()})),r.addEventListener("waiting",(function(){return e._fixupStall()}))},t.prototype._fixupStall=function(){var e,t=this.params,r=t.logger,i=t.videoElement,a=i.buffered.length;0!==a&&(e=i.buffered.start(a-1),i.currentTime<e&&(r("Fixup stall"),i.currentTime=e))},t.prototype._selectQuality=function(e){for(var t,r,i,a=this.params.videoElement,n=a&&1.62*(window.devicePixelRatio||1)*a.offsetHeight||520,s=0;s<this.manifest.length;++s)(i=this.manifest[s]).bitrate<e&&n>Math.min(i.video.height,i.video.width)?(!r||i.bitrate>r.bitrate)&&(r=i):(!t||t.bitrate>i.bitrate)&&(t=i);return r||t},t.prototype.shouldPlay=function(){if(this.paused)return!1;var t=this._getBufferSizeSec()-Math.max(1,this.sourceJitter);return t>3||e.isNonNullable(this.downloadRate)&&(this.downloadRate>1.5&&t>2||this.downloadRate>2&&t>1)},t.prototype._setVideoSrc=function(t,r){var i=this,a=this.params,n=a.logger,s=a.videoElement,o=a.playerCallback;this.mediaSource=new window.MediaSource,n("setting video src"),s.src=URL.createObjectURL(this.mediaSource),this.mediaSource.addEventListener("sourceopen",(function(){e.assertNonNullable(i.mediaSource),i.sourceBuffer=i.mediaSource.addSourceBuffer(t.codecs),i.bufferStates=[],r()})),this.videoPlayStarted=!1,s.addEventListener("canplay",(function(){i.shouldPlay()&&(i.videoPlayStarted=!0,i._playVideoElement())}));var u=function(){var e,t,r,i;t="progress",r=function(){s.buffered.length?(s.currentTime=s.buffered.start(0),o({name:"playing"})):u()},i=function(){for(var a=[],n=0;n<arguments.length;n++)a[n]=arguments[n];r.apply(null,a),e.removeEventListener(t,i)},(e=s).addEventListener(t,i)};u()},t.prototype._initPlayerWith=function(e){var t=this;this.bitrate=0,this.rep=0,this.sourceBuffer=0,this.bufferStates=[],this.filesFetcher&&this.filesFetcher.abortAll(),this.filesFetcher=new et(3,1e4,this.bitrateSwitcher,this.params.config.MAX_PARALLEL_REQUESTS,this.params.logger),this._setVideoSrc(e,(function(){return t._switchToQuality(e)}))},t.prototype._representation=function(t){var r=this,i=this.params,a=i.logger,n=i.videoElement,s=i.playerCallback,o=!1,u=null,d=null,l=null,c=null,p=!1,h=function(){var e=o&&(!p||p===r.rep);return e||a("Not running!"),e},f=function(e){var t=n.playbackRate;n.playbackRate!==e&&(a("Playback rate switch: "+t+"=>"+e),n.playbackRate=e)},v=function(){if(r.lowLatency){var e=r._getBufferSizeSec();if(r.bufferStates.length<5)return void f(1);for(var t=Qe()-6e4,i=0,n=0;n<r.bufferStates.length;n++){var s=r.bufferStates[n];e=Math.min(e,s.buf),s.ts<t&&i++}r.bufferStates.splice(0,i),a("update playback rate; minBuffer="+e+" drop="+i+" jitter="+r.sourceJitter);var o=e-1;r.sourceJitter>=0?o-=r.sourceJitter/2:r.sourceJitter-=1,f(o>3?1.15:o>1?1.1:o>.3?1.01:1)}else f(1)},m=function(t){var i,n=function(){return i&&i.start?i.start.length:0},o=function(e){return i.start[e]/1e3},u=function(e){return i.dur[e]/1e3},d=function(e){return i.fragIndex+e},l=function(e,t){return{chunkIdx:d(e),startTS:o(e),dur:u(e),discontinuity:t}},p=function(){var e=0;if(i&&i.dur){var t=Math.max(r.sourceJitter,1);for(r.lowLatency||(t+=2),e=i.dur.length-1;e>=0&&!((t-=i.dur[e]/1e3)<=0);--e);}return l(e,!0)};return{seek:function(u,d){!function(e,t,i){c&&c.abort(),c=Ke(r.urlResolver.resolve(e,!0,r.lowLatency),t,i,(function(){return r._retryCallback()})).withTimeout(1e4).withRetryCount(3).withFinally((function(){c=null})).withJSONResponse().send()}(t,(function(t){if(h()){i=t;var c,f=Boolean(i.lowLatency);f!==r.lowLatency&&(c=f,r.lowLatency=c,a("lowLatency changed to "+c),v());for(var m=0,S=0;S<i.dur.length;++S)m+=i.dur[S];m>0&&(e.assertNonNullable(r.filesFetcher),r.filesFetcher.optimizeForSegDuration(m/i.dur.length)),s({name:"index",zeroTime:i.zeroTime,shiftDuration:i.shiftDuration}),r.sourceJitter=i.hasOwnProperty("jitter")?Math.min(10,Math.max(.01,i.jitter/1e3)):1,u(function(t){var r=n();if(!(r<=0)){if(e.isNonNullable(t))for(var i=0;i<r;i++)if(o(i)>t)return l(i);return p()}}(d))}}),(function(){return r._handleNetworkError()}))},nextChunk:function(e){var t=n(),r=e?e.chunkIdx+1:0,s=r-i.fragIndex;if(!(t<=0)){if(!e||s<0||s-t>10)return a("Resync: offset="+s+" bChunks="+t+" chunk="+JSON.stringify(e)),p();if(!(s>=t))return l(r-i.fragIndex,!1)}}}},S=function(){o=!1,d&&d.abort(),l&&l.abort(),c&&c.abort(),e.assertNonNullable(r.filesFetcher),r.filesFetcher.abortAll()};return p={start:function(i){var a,n,s,p,f,b,g,y,T,E,P=r.params,k=P.videoElement,w=P.logger,x=m(t.jidxUrl),A=0,$=function(){f&&(clearTimeout(f),f=void 0);var e=Math.max(500,1e3*(r._getBufferSizeSec()-r.sourceJitter-5)),t=A+e,i=Qe(),a=Math.min(1e4,t-i);A=i;var n=function(){c||h()&&x.seek((function(){h()&&(A=Qe(),N(),$())}))};a>0?f=window.setTimeout((function(){r.paused?$():n()}),a):n()},N=function(){for(var e;e=x.nextChunk(p);)p=e,C(e);var i=x.nextChunk(s);if(i){if(s&&i.discontinuity)return w("Detected discontinuity; restarting playback"),void(r.paused?$():(S(),r._initPlayerWith(t)));I(i)}else $()},D=function(e,t){if(h()&&r.sourceBuffer){var i,a,n=function(r){window.setTimeout((function(){h()&&D(e,t)}),r)};if(r.sourceBuffer.updating)w("Source buffer is updating; delaying appendBuffer"),n(100);else{var s=Qe(),o=k.currentTime;!r.paused&&k.buffered.length>1&&b===o&&s-g>500&&(w("Stall suspected; trying to fix"),r._fixupStall()),b!==o&&(b=o,g=s);var u=r._getBufferSizeSec();if(u>30)w("Buffered "+u+" seconds; delaying appendBuffer"),n(2e3);else try{r.sourceBuffer.appendBuffer(e),r.videoPlayStarted?(r.bufferStates.push({ts:s,buf:u}),v(),r.bufferStates.length>200&&r.bufferStates.shift()):r.shouldPlay()&&(r.videoPlayStarted=!0,r._playVideoElement()),t&&t()}catch(e){if("QuotaExceededError"!==e.name)throw e;w("QuotaExceededError; delaying appendBuffer"),0!==r.sourceBuffer.buffered.length&&(a=o)-(i=r.sourceBuffer.buffered.start(0))>4&&r.sourceBuffer.remove(i,a-3),n(1e3)}}}},_=function(){n&&a&&(w(["Appending chunk, sz="+n.byteLength+":",JSON.stringify(s)]),D(n,(function(){n=null,N()})))},R=function(e){return t.fragUrlTemplate.replace("%%id%%",e.chunkIdx)},I=function(t){var i,a,o;h()&&(i=R(t),a=function(e,i){if(h()){if(i/=1e3,n=e,s=t,u=t.startTS,i){var a=Math.min(10,t.dur/i);r.downloadRate=r.downloadRate?.7*r.downloadRate+.3*a:a}_()}},o=function(){return r._handleNetworkError()},e.assertNonNullable(r.filesFetcher),null==d||d.abort(),d=r.filesFetcher.requestData(r.urlResolver.resolve(i,!1),a,o,(function(){return r._retryCallback()})).withFinally((function(){d=null})).send())},C=function(t){h()&&(e.assertNonNullable(r.filesFetcher),r.filesFetcher.prefetch(r.urlResolver.resolve(R(t),!1)))},L=function(e){h()&&(t.cachedHeader=e,D(e,(function(){a=!0,_()})))};o=!0,x.seek((function(t){h()&&(A=Qe(),t?(p=t,!e.isNullable(i)||t.startTS>i?I(t):(s=t,N())):$())}),i),t.cachedHeader?L(t.cachedHeader):(y=t.headerUrl,T=L,E=function(){return r._handleNetworkError()},l&&l.abort(),l=Ke(r.urlResolver.resolve(y,!1),T,E,(function(){return r._retryCallback()})).withTimeout(1e4).withBitrateReporting(r.bitrateSwitcher).withRetryCount(3).withFinally((function(){l=null})).send())},stop:S,getTimestampSec:function(){return u}}},t.prototype._switchToQuality=function(t){var r,i=this.params,a=i.logger,n=i.playerCallback;t.bitrate!==this.bitrate&&(this.rep&&(r=this.rep.getTimestampSec(),e.isNonNullable(r)&&(r+=.1),this.rep.stop()),this.currentManifestEntry=t,this.rep=this._representation(t),a("switch to quality: codecs="+t.codecs+"; headerUrl="+t.headerUrl+"; bitrate="+t.bitrate),this.bitrate=t.bitrate,e.assertNonNullable(this.bitrateSwitcher),this.bitrateSwitcher.notifySwitch(this.bitrate),this.rep.start(r),n({name:"qualitySwitch",quality:t}))},t.prototype._qualityAvailable=function(t){return e.isNonNullable(this.manifest.find((function(e){return e.name===t})))},t.prototype._initBitrateSwitcher=function(){var e,t=this,r=this.params,i=r.logger,a=r.playerCallback,n={updateChunk:function(e,r){var i=Qe();if(t.chunkRateEstimator.addInterval(e,i,r)){var n=t.chunkRateEstimator.getBitRate();return a({name:"bandwidth",size:r,duration:i-e,speed:n}),!0}},get:function(){var e=t.chunkRateEstimator.getBitRate();return e?.85*e:0}},s=-1/0,o=!0,u=function(){var r=n.get();if(r&&e&&t.autoQuality){if(o&&r>e&&We(s)<3e4)return;!function(e){var r,a,n;t.autoQuality&&(t.currentManifestEntry&&t._qualityAvailable(t.currentManifestEntry.name)&&e<t.bitrate&&(a=t._getBufferSizeSec(),n=e/t.bitrate,a>10&&n>.8||a>15&&n>.5||a>20&&n>.3)?i("Not switching: buffer="+Math.floor(a)+"; bitrate="+t.bitrate+"; newRate="+Math.floor(e)):(r=t._selectQuality(e))?t._switchToQuality(r):i("Could not find quality by bitrate "+e))}(r)}o=t.autoQuality};return{updateChunk:function(e,t){var r=n.updateChunk(e,t);return r&&u(),r},notifySwitch:function(t){var r=Qe();t<e&&(s=r),e=t}}},t.prototype._fetchManifest=function(e,t,r){var i=this;this.manifestRequest=Ke(this.urlResolver.resolve(e,!0),t,r,(function(){return i._retryCallback()})).withJSONResponse().withTimeout(1e4).withRetryCount(3).withRetryInterval(300,2e3).send().withFinally((function(){i.manifestRequest=void 0}))},t.prototype._playVideoElement=function(e){var t=this.params.videoElement;w(t).then((function(t){t||null==e||e()}))},t.prototype._handleManifestUpdate=function(e){var t=this,r=this.params,i=r.logger,a=r.playerCallback,n=r.videoElement;this.manifest=function(e){var r=[];return(null==e?void 0:e.length)?(e.forEach((function(e,t){e.video&&n.canPlayType(e.codecs).replace(/no/,"")&&window.MediaSource.isTypeSupported(e.codecs)&&(e.index=t,r.push(e))})),r.sort((function(e,t){return e.video&&t.video?t.video.height-e.video.height:t.bitrate-e.bitrate})),r):(t.params.playerCallback({name:"error",type:"partial_metadata"}),[])}(e),i("Valid manifest entries: "+this.manifest.length+"/"+e.length),a({name:"manifest",manifest:this.manifest})},t.prototype._refetchManifest=function(e){var t=this;this.destroyed||(this.manifestRefetchTimer&&clearTimeout(this.manifestRefetchTimer),this.manifestRefetchTimer=window.setTimeout((function(){t._fetchManifest(e,(function(r){t.destroyed||(t._handleManifestUpdate(r),t._refetchManifest(e))}),(function(){return t._refetchManifest(e)}))}),6e4))},t.prototype._initManifest=function(){var e=this;this._fetchManifest(this.manifestUrl,(function(t){e.destroyed||(e._handleManifestUpdate(t),e._refetchManifest(e.manifestUrl))}),(function(){return e._handleNetworkError()}))},t}();!function(e){e.STOPPED="stopped",e.MANIFEST_READY="manifest_ready",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(Xe||(Xe={}));var rt,it=[Xe.PAUSED,Xe.PLAYING,Xe.READY],at=[Xe.PAUSED,Xe.PLAYING,Xe.READY],nt=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(Xe.STOPPED),this.representations$=new e.ValueSubject([]),this.textTracksManager=new D,this.maxSeekBackTime$=new e.ValueSubject(1/0),this.zeroTime$=new e.ValueSubject(void 0),this.liveOffset=new qe,this._dashCb=function(t){var i,a,n,s,o;switch(t.name){case"buffering":var u=t.isBuffering;r.params.output.isBuffering$.next(u);break;case"error":r.params.output.error$.next({id:"DashLiveProviderInternal:"+t.type,message:"LiveDashPlayer reported error"});break;case"manifest":var d=t.manifest,c=[];try{for(var p=h(d),f=p.next();!f.done;f=p.next()){var v=f.value,m=null!==(n=v.name)&&void 0!==n?n:v.index.toString(10),S=q(v.video),b=v.bitrate/1e3,g=l({},v.video);if(S){var y={id:m,quality:S,bitrate:b,size:g};c.push({track:y,representation:v})}}}catch(e){i={error:e}}finally{try{f&&!f.done&&(a=p.return)&&a.call(p)}finally{if(i)throw i.error}}r.representations$.next(c),r.params.output.availableVideoTracks$.next(c.map((function(e){return e.track}))),(null===(s=r.videoState.getTransition())||void 0===s?void 0:s.to)===Xe.MANIFEST_READY&&r.videoState.setState(Xe.MANIFEST_READY);break;case"qualitySwitch":var T=t.quality;y=null===(o=r.representations$.getValue().find((function(e){return e.representation===T})))||void 0===o?void 0:o.track;r.params.output.hostname$.next(new URL(T.headerUrl,r.params.source.url).hostname),e.isNonNullable(y)&&r.params.output.currentVideoTrack$.next(y);break;case"bandwidth":g=t.size;var E=t.duration;r.params.dependencies.throughputEstimator.addRawSpeed(g,E);break;case"index":r.maxSeekBackTime$.next(t.shiftDuration),r.zeroTime$.next(t.zeroTime)}},this.syncPlayback=function(){var t,i=r.videoState.getState(),a=r.videoState.getTransition(),n=r.params.desiredState.playbackState.getState(),s=r.params.desiredState.playbackState.getTransition(),o=r.params.desiredState.seekPosition.getTransition();if(r.log({message:"[syncPlayback] videoState: "+i+"; videoTransition: "+JSON.stringify(a)+"; desiredPlaybackState: "+n+"; seekPositionTransition: "+JSON.stringify(o)+";"}),n!==exports.PlaybackState.STOPPED){if(!a){if(at.includes(i)){var u=null===(t=r.params.desiredState.videoTrack.getTransition())||void 0===t?void 0:t.to;e.isNonNullable(u)&&r.setVideoTrack(u);var d=r.params.desiredState.autoVideoTrackSwitching.getTransition();d&&r.setAutoQuality(d.to)}var l=null==o?void 0:o.to;if((null==s?void 0:s.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(l)&&it.includes(i))r.seek(l+st(r.liveOffset.getTotalPausedTime()));else switch(i){case Xe.STOPPED:return r.videoState.startTransitionTo(Xe.MANIFEST_READY),void r.dash.attachSource(Ae(r.params.source.url));case Xe.MANIFEST_READY:r.videoState.startTransitionTo(Xe.READY),r.prepare();break;case Xe.READY:return void(n===exports.PlaybackState.PAUSED?r.videoState.setState(Xe.PAUSED):n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Xe.PLAYING),r.dash.play((function(){r.liveOffset.pause(),r.videoState.setState(Xe.PAUSED)}))));case Xe.PLAYING:return void(n===exports.PlaybackState.PAUSED&&(r.videoState.startTransitionTo(Xe.PAUSED),r.liveOffset.pause(),r.dash.pause()));case Xe.PAUSED:return void(n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Xe.PLAYING),r.liveOffset.getTotalPausedTime()<r.params.config.maxPausedTime&&r.liveOffset.getTotalOffset()<r.maxSeekBackTime$.getValue()?(r.liveOffset.resume(),r.dash.play((function(){r.liveOffset.pause(),r.videoState.setState(Xe.PAUSED)})),r.params.output.position$.next(st(r.liveOffset.getTotalOffset()))):r.seek(st(r.liveOffset.getTotalOffset()))));default:return e.assertNever(i)}}}else i!==Xe.STOPPED&&(r.videoState.startTransitionTo(Xe.STOPPED),r.dash.destroy(),r.video.setAttribute("src",""),r.video.load(),r.videoState.setState(Xe.STOPPED))},this.params=t,this.log=this.params.dependencies.logger.createComponentLog("DashLiveProvider");var i=function(e){t.output.error$.next({id:"DashLiveProvider",message:"DashLiveProvider internal logic error",thrown:e})};e.merge(this.videoState.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,type:"start"}}))),this.videoState.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,type:"end"}})))).subscribe((function(e){var t=e.transition,i=e.type;r.log({message:"[videoState change] "+i+": "+JSON.stringify(t)})})),this.video=_(t.container),this.params.output.element$.next(this.video),this.dash=this.createLiveDashPlayer(),this.params.output.duration$.next(1/0),this.params.output.position$.next(0),this.params.output.isLive$.next(!0),this.params.output.hostname$.next(Z(this.params.source.url)),this.textTracksManager.connect(this.video,this.params.desiredState,this.params.output);var a=O(this.video);this.subscription.add(a.canplay$.subscribe((function(){var e;(null===(e=r.videoState.getTransition())||void 0===e?void 0:e.to)===Xe.READY&&r.videoState.setState(Xe.READY)}),i)).add(a.pause$.subscribe((function(){r.videoState.setState(Xe.PAUSED)}),i)).add(a.playing$.subscribe((function(){r.videoState.setState(Xe.PLAYING)}),i)).add(a.error$.subscribe(this.params.output.error$)).add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(st)).subscribe(this.params.output.duration$)).add(e.combine({zeroTime:this.zeroTime$.pipe(e.filter(e.isNonNullable)),position:a.timeUpdate$}).subscribe((function(e){var t=e.zeroTime,i=e.position;return r.params.output.liveTime$.next(t+1e3*i)}),i)).add(A(this.video,this.params.desiredState.isLooped,i)).add($(this.video,this.params.desiredState.volume,a.volumeState$,i)).add(a.volumeState$.subscribe(this.params.output.volume$,i)).add(L(this.video).subscribe(this.params.output.firstBytesEvent$)).add(R(this.video).subscribe(this.params.output.firstFrameEvent$)).add(this.videoState.stateChangeEnded$.subscribe((function(t){switch(t.to){case Xe.STOPPED:r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.desiredState.playbackState.setState(exports.PlaybackState.STOPPED);break;case Xe.MANIFEST_READY:case Xe.READY:break;case Xe.PAUSED:r.params.desiredState.playbackState.setState(exports.PlaybackState.PAUSED);break;case Xe.PLAYING:r.params.desiredState.playbackState.setState(exports.PlaybackState.PLAYING);break;default:return e.assertNever(t.to)}}),i)).add(e.merge(t.desiredState.playbackState.stateChangeStarted$,t.desiredState.seekPosition.stateChangeStarted$,t.desiredState.videoTrack.stateChangeStarted$,t.desiredState.autoVideoTrackSwitching.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0)).subscribe(this.syncPlayback,i))}return t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0),this.dash.destroy()},t.prototype.createLiveDashPlayer=function(){var e=this,t=new tt({videoElement:this.video,config:{CHUNK_DURATION:this.params.config.chunkDuration,BUFFER_OPTIMAL_DURATION:this.params.config.optimalBufferDuration,MAX_PARALLEL_REQUESTS:this.params.config.maxParallelRequests},playerCallback:this._dashCb,logger:function(t){e.params.dependencies.logger.log({message:String(t),component:"LiveDashPlayer"})}});return t.pause(),t},t.prototype.prepare=function(){var t,r,i,a,n,s,o=this.representations$.getValue(),u=null!==(r=null===(t=this.params.desiredState.videoTrack.getTransition())||void 0===t?void 0:t.to)&&void 0!==r?r:this.params.desiredState.videoTrack.getState(),d=null!==(a=null===(i=this.params.desiredState.autoVideoTrackSwitching.getTransition())||void 0===i?void 0:i.to)&&void 0!==a?a:this.params.desiredState.autoVideoTrackSwitching.getState(),l=!d&&e.isNonNullable(u)?u:null===(n=K(o.map((function(e){return e.track})),{container:{width:this.video.offsetWidth,height:this.video.offsetHeight},throughput:this.params.dependencies.throughputEstimator.throughput$.getValue(),tuning:this.params.tuning.autoTrackSelection}))||void 0===n?void 0:n.id,c=null===(s=o.find((function(e){return e.track.id===l})))||void 0===s?void 0:s.representation;e.assertNonNullable(c),this.dash.startPlay(c,d),this.params.desiredState.videoTrack.getTransition()&&this.params.desiredState.videoTrack.setState(l),this.params.desiredState.autoVideoTrackSwitching.getTransition()&&this.params.desiredState.autoVideoTrackSwitching.setState(d)},t.prototype.setVideoTrack=function(t){var r,i=null===(r=this.representations$.getValue().find((function(e){return e.track.id===t})))||void 0===r?void 0:r.representation;e.assertNonNullable(i),this.dash.switchByName(i.name),this.params.desiredState.videoTrack.setState(t)},t.prototype.setAutoQuality=function(e){this.dash.setAutoQualityEnabled(e),this.params.desiredState.autoVideoTrackSwitching.setState(e)},t.prototype.seek=function(e){this.log({message:"[seek] position: "+e}),this.params.output.willSeekEvent$.next();var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(st(r)),this.dash.reinit(Ae(this.params.source.url,r)),this.params.output.seekedEvent$.next()},t}(),st=function(e){return-e/1e3},ot=function(e){switch(e){case"mobile":return exports.VideoQuality.Q_144P;case"lowest":return exports.VideoQuality.Q_240P;case"low":return exports.VideoQuality.Q_360P;case"sd":case"medium":return exports.VideoQuality.Q_480P;case"hd":case"high":return exports.VideoQuality.Q_720P;case"fullhd":case"full":return exports.VideoQuality.Q_1080P;case"quadhd":case"quad":return exports.VideoQuality.Q_1440P;case"ultrahd":case"ultra":return exports.VideoQuality.Q_2160P}},ut=function(e){var t=null;if(e.QUALITY&&(t=ot(e.QUALITY)),!t&&e.RESOLUTION){var r=f(e.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),i=r[0],a=r[1];t=q({width:i,height:a})}return null!=t?t:null},dt=function(e,t){return void 0===t&&(t=e),c(void 0,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,l,c,h,v,m,S,b,g;return p(this,(function(p){switch(p.label){case 0:return[4,fetch(e)];case 1:return[4,p.sent().text()];case 2:for(r=p.sent(),i=r.split("\n"),a=[],n=0;n<i.length;n++)s=i[n],(o=s.match(/^#EXT-X-STREAM-INF:(.+)/))&&(u=Object.fromEntries(o[1].split(",").map((function(e){return e.split("=")}))),d=null!==(g=u.QUALITY)&&void 0!==g?g:"stream-"+u.BANDWIDTH,l=ut(u),c=void 0,u.BANDWIDTH&&(c=parseInt(u.BANDWIDTH,10)/1e3||void 0),!c&&u["AVERAGE-BANDWIDTH"]&&(c=parseInt(u["AVERAGE-BANDWIDTH"],10)/1e3||void 0),h=void 0,u.RESOLUTION&&(v=f(u.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),m=v[0],S=v[1],m&&S&&(h={width:m,height:S})),b=new URL(i[++n],t).toString(),l&&a.push({id:d,quality:l,url:b,bandwidth:c,size:h}));return[2,a]}}))}))};!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(rt||(rt={}));var lt,ct=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(rt.STOPPED),this.textTracksManager=new D,this.manifests$=new e.ValueSubject([]),this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.videoTrack.getTransition(),s=r.params.desiredState.autoVideoTrackSwitching.getTransition();if(i!==exports.PlaybackState.STOPPED){if(!r.videoState.getTransition()){var o=r.params.desiredState.seekPosition.getTransition();if(t===rt.STOPPED)return r.videoState.startTransitionTo(rt.READY),void r.prepare();if(n||s){var u=r.videoState.getState();r.videoState.setState(rt.CHANGING_MANIFEST),r.videoState.startTransitionTo(u);var d=r.video.currentTime;return r.prepare(),void(o&&!e.isNullable(o.to)||r.params.desiredState.seekPosition.startTransitionTo(d))}var l=null==o?void 0:o.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(l)&&r.seek(l),t){case rt.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(rt.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(rt.PLAYING),r.playIfAllowed()));case rt.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(rt.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case rt.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(rt.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));case rt.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==rt.STOPPED&&(r.videoState.startTransitionTo(rt.STOPPED),r.video.setAttribute("src",""),r.video.load(),r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.output.currentBuffer$.next(void 0),r.params.output.hostname$.next(void 0),r.videoState.setState(rt.STOPPED),V(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=_(t.container),this.params.output.element$.next(this.video);var i={id:"master",quality:exports.VideoQuality.INVARIANT,url:this.params.source.url};this.manifests$.next([i]),this.params.output.isLive$.next(!1),this.params.output.hostname$.next(Z(this.params.source.url)),dt(this.params.source.url).then((function(e){r.manifests$.next(v([i],f(e),!1))}),(function(e){return r.params.output.error$.next({id:"ExtractHlsQualities",message:"Error fetching manifest and extracting qualities",thrown:e})})),this.subscribe()}return t.prototype.selectManifest=function(){var e,t,r=this.params.desiredState,i=r.autoVideoTrackSwitching,a=r.videoTrack,n=i.getState(),s=a.getTransition(),o=null!==(t=null!==(e=null==s?void 0:s.to)&&void 0!==e?e:a.getState())&&void 0!==t?t:"master",u=this.manifests$.getValue();if(u){var d=n?"master":o;return n&&!s&&a.startTransitionTo("master"),u.find((function(e){return e.id===d}))}},t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"HlsProvider",message:"HlsProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r))};o(s.timeUpdate$,i.position$),o(s.durationChange$,i.duration$),o(s.ended$,i.endedEvent$),o(s.error$,i.error$),o(s.isBuffering$,i.isBuffering$),o(s.currentBuffer$,i.currentBuffer$),o(s.firstBytes$,i.firstBytesEvent$),o(s.firstFrame$,i.firstFrameEvent$),o(s.seeked$,i.seekedEvent$),this.subscription.add(A(this.video,a.isLooped,n)),this.subscription.add($(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.textTracksManager.connect(this.video,a,i),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState(rt.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(rt.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===rt.READY&&t.videoState.setState(rt.READY),t.videoState.getState()===rt.PLAYING&&t.playIfAllowed()}),n).add(s.loadedMetadata$.subscribe((function(){var r=t.params.desiredState.seekPosition.getTransition(),i=t.videoState.getTransition(),a=t.params.desiredState.videoTrack.getTransition(),n=t.params.desiredState.autoVideoTrackSwitching.getTransition();if(a&&e.isNonNullable(a.to)){var s=a.to;t.params.desiredState.videoTrack.setState(s);var o=t.manifests$.getValue().find((function(e){return e.id===s}));o&&(t.params.output.currentVideoTrack$.next(o),t.params.output.hostname$.next(Z(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===rt.CHANGING_MANIFEST&&t.videoState.setState(i.to),r&&e.isNonNullable(r.to)&&t.seek(r.to)}),n))),this.subscription.add(this.manifests$.pipe(e.map((function(e){return e.map((function(e){return{id:e.id,quality:e.quality,size:e.size,bitrate:e.bandwidth}}))}))).subscribe(this.params.output.availableVideoTracks$,n));var u=e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,a.videoTrack.stateChangeStarted$,a.autoVideoTrackSwitching.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.prepare=function(){var t=this.selectManifest();e.isNullable(t)||(this.video.setAttribute("src",t.url),this.video.load())},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(rt.PAUSED),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.video.currentTime=e},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(lt||(lt={}));var pt,ht=function(){function t(t){var r,i=this;this.subscription=new e.Subscription,this.videoState=new te(lt.STOPPED),this.textTracksManager=new D,this.manifests$=new e.ValueSubject([]),this.liveOffset=new qe,this.manifestStartTime$=new e.ValueSubject(void 0),this.syncPlayback=function(){var t=i.videoState.getState(),r=i.params.desiredState.playbackState.getState(),a=i.params.desiredState.playbackState.getTransition(),n=i.params.desiredState.videoTrack.getTransition(),s=i.params.desiredState.autoVideoTrackSwitching.getTransition();if(r!==exports.PlaybackState.STOPPED){if(!i.videoState.getTransition()){var o=i.params.desiredState.seekPosition.getTransition();if(t===lt.STOPPED)return i.videoState.startTransitionTo(lt.READY),void i.prepare();if(n||s){var u=i.videoState.getState();i.videoState.setState(lt.CHANGING_MANIFEST),i.videoState.startTransitionTo(u);var d=ft(i.liveOffset.getTotalOffset());return i.prepare(),void(o&&!e.isNullable(o.to)||i.params.desiredState.seekPosition.startTransitionTo(d))}var l=null==o?void 0:o.to;if((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(l))return i.videoState.startTransitionTo(lt.READY),i.seek(l+ft(i.liveOffset.getTotalPausedTime())),void i.prepare();switch(t){case lt.READY:return void(r===exports.PlaybackState.PAUSED?(i.videoState.setState(lt.PAUSED),i.liveOffset.pause(),V(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):r===exports.PlaybackState.PLAYING&&(i.videoState.startTransitionTo(lt.PLAYING),i.playIfAllowed()));case lt.PLAYING:return void(r===exports.PlaybackState.PAUSED?(i.videoState.startTransitionTo(lt.PAUSED),i.liveOffset.pause(),i.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&V(i.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case lt.PAUSED:return void(r===exports.PlaybackState.PLAYING?(i.videoState.startTransitionTo(lt.PLAYING),i.liveOffset.getTotalPausedTime()<i.params.config.maxPausedTime&&i.liveOffset.getTotalOffset()<i.maxSeekBackTime$.getValue()?(i.liveOffset.resume(),i.playIfAllowed(),i.params.output.position$.next(ft(i.liveOffset.getTotalOffset()))):i.seek(ft(i.liveOffset.getTotalOffset()))):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&(V(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED),i.liveOffset.pause()));case lt.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==lt.STOPPED&&(i.videoState.startTransitionTo(lt.STOPPED),i.video.setAttribute("src",""),i.video.load(),i.params.output.position$.next(0),i.params.output.duration$.next(1/0),i.params.output.currentBuffer$.next(void 0),i.params.output.hostname$.next(void 0),i.videoState.setState(lt.STOPPED),V(i.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=_(t.container),this.params.output.element$.next(this.video);var a={id:"master",quality:exports.VideoQuality.INVARIANT,url:this.params.source.url};this.manifests$.next([a]),dt(Ae(this.params.source.url)).then((function(e){i.manifests$.next(v([a],f(e),!1))}),(function(e){return i.params.output.error$.next({id:"ExtractHlsQualities",message:"Error fetching manifest and extracting qualities",thrown:e})})),this.params.output.isLive$.next(!0),this.params.output.hostname$.next(Z(this.params.source.url)),this.maxSeekBackTime$=new e.ValueSubject(null!==(r=t.source.maxSeekBackTime)&&void 0!==r?r:1/0),this.subscribe()}return t.prototype.selectManifest=function(){var e,t,r=this.params.desiredState,i=r.autoVideoTrackSwitching,a=r.videoTrack,n=i.getState(),s=a.getTransition(),o=null!==(t=null!==(e=null==s?void 0:s.to)&&void 0!==e?e:a.getState())&&void 0!==t?t:"master",u=this.manifests$.getValue();if(u){var d=n?"master":o;return n&&!s&&a.startTransitionTo("master"),u.find((function(e){return e.id===d}))}},t.prototype.subscribe=function(){var t=this,r=this.params,i=r.output,a=r.desiredState,n=function(e){i.error$.next({id:"HlsLiveProvider",message:"HlsLiveProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r,n))};o(s.ended$,i.endedEvent$),o(s.error$,i.error$),o(s.isBuffering$,i.isBuffering$),o(s.currentBuffer$,i.currentBuffer$),o(s.firstBytes$,i.firstBytesEvent$),o(s.firstFrame$,i.firstFrameEvent$),this.subscription.add(a.isLooped.stateChangeStarted$.subscribe((function(){return a.isLooped.setState(!1)}),n)),this.subscription.add($(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.textTracksManager.connect(this.video,a,i),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState(lt.PLAYING),V(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(lt.PAUSED),V(a.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===lt.READY&&t.videoState.setState(lt.READY),t.videoState.getState()===lt.PLAYING&&t.playIfAllowed()}),n)),this.subscription.add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(ft)).subscribe(this.params.output.duration$,n)),this.subscription.add(s.loadedMetadata$.subscribe((function(){var r=t.params.desiredState.seekPosition.getTransition(),i=t.videoState.getTransition(),a=t.params.desiredState.videoTrack.getTransition(),n=t.params.desiredState.autoVideoTrackSwitching.getTransition();if(a&&e.isNonNullable(a.to)){var s=a.to;t.params.desiredState.videoTrack.setState(s);var o=t.manifests$.getValue().find((function(e){return e.id===s}));o&&(t.params.output.currentVideoTrack$.next(o),t.params.output.hostname$.next(Z(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===lt.CHANGING_MANIFEST&&t.videoState.setState(i.to),r&&e.isNonNullable(r.to)&&t.seek(r.to)}),n)),this.subscription.add(s.loadedData$.subscribe((function(){var e,r,i=null===(r=null===(e=t.video)||void 0===e?void 0:e.getStartDate())||void 0===r?void 0:r.getTime();t.manifestStartTime$.next(i||void 0)}),n)),this.subscription.add(e.combine({startTime:this.manifestStartTime$.pipe(e.filter(e.isNonNullable)),currentTime:s.timeUpdate$}).subscribe((function(e){var r=e.startTime,i=e.currentTime;return t.params.output.liveTime$.next(r+1e3*i)}),n)),this.subscription.add(this.manifests$.pipe(e.map((function(e){return e.map((function(e){return{id:e.id,quality:e.quality,size:e.size,bitrate:e.bandwidth}}))}))).subscribe(this.params.output.availableVideoTracks$,n));var u=e.merge(a.playbackState.stateChangeStarted$,a.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,a.videoTrack.stateChangeStarted$,a.autoVideoTrackSwitching.stateChangeStarted$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(u.subscribe(this.syncPlayback,n))},t.prototype.destroy=function(){this.subscription.unsubscribe(),this.textTracksManager.destroy(),this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.prepare=function(){var t=this,r=this.selectManifest();if(!e.isNullable(r)){var i,a=Ae(r.url,this.liveOffset.getTotalOffset());this.video.setAttribute("src",a),this.video.load(),(i=a,c(void 0,void 0,void 0,(function(){var e;return p(this,(function(t){switch(t.label){case 0:return[4,fetch(i,{method:"HEAD"})];case 1:return[2,(e=t.sent()).headers.has("X-Playback-Duration")?parseInt(e.headers.get("X-Playback-Duration"),10):void 0]}}))}))).then((function(r){e.isNullable(r)||t.maxSeekBackTime$.next(r)}))}},t.prototype.playIfAllowed=function(){var e=this;w(this.video).then((function(t){t||(e.videoState.setState(lt.PAUSED),e.liveOffset.pause(),V(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next();var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(ft(r)),this.params.output.seekedEvent$.next()},t}(),ft=function(e){return-e/1e3},vt={};!function(e){e.INITIALIZING="initializing",e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(pt||(pt={}));var mt,St,bt,gt,yt,Tt,Et,Pt,kt,wt,xt,At,$t,Nt,Dt,_t,Rt,It,Ct,Lt,Ot=function(t,r){return new e.Observable((function(e){var i=function(t,r){return e.next(r)};return t.on(r,i),function(){return t.off(r,i)}}))},Vt=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new te(pt.INITIALIZING),this.textTracksManager=new D,this.trackLevels=new Map,this.syncPlayback=function(){var t=r.videoState.getState(),i=r.params.desiredState.playbackState.getState(),a=r.params.desiredState.playbackState.getTransition(),n=r.params.desiredState.seekPosition.getTransition();if(t!==pt.INITIALIZING){var s=null==n?void 0:n.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(s)&&r.seek(s),i){case exports.PlaybackState.STOPPED:switch(t){case pt.STOPPED:break;case pt.READY:case pt.PLAYING:case pt.PAUSED:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case pt.PLAYING:break;case pt.STOPPED:r.prepare();break;case pt.READY:case pt.PAUSED:r.playIfAllowed();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case pt.PAUSED:break;case pt.STOPPED:r.prepare();break;case pt.READY:r.videoState.setState(pt.PAUSED),V(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case pt.PLAYING:r.pause();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=_(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.isLive$.next(!1),this.params.output.hostname$.next(Z(this.params.source.url)),this.loadHlsJs()}return t.prototype.destroy=function(){var e,t;this.subscription.unsubscribe(),this.trackLevels.clear(),this.textTracksManager.destroy(),null===(e=this.hls)||void 0===e||e.detachMedia(),null===(t=this.hls)||void 0===t||t.destroy(),this.video.remove(),this.params.output.element$.next(void 0)},t.prototype.loadHlsJs=function(){var e=this,t=!1,i=function(r){t||e.params.output.error$.next({id:"timeout"===r?"HlsJsTimeout":"HlsJsLoadError",message:"Failed to load Hls.js",thrown:r}),t=!0},a=window.setTimeout((function(){return i("timeout")}),5e3);Promise.resolve().then((function(){return r(require("hls.js"))})).then((function(r){t||(vt.Hls=r.default,vt.Events=r.default.Events,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){e.assertNonNullable(vt.Hls,"hls.js not loaded"),this.hls=new vt.Hls({fragLoadingMaxRetry:5,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetryTimeout:16e3,manifestLoadingMaxRetryTimeout:2e3,levelLoadingMaxRetryTimeout:2e3}),this.subscribe(),this.videoState.setState(pt.STOPPED)},t.prototype.subscribe=function(){var t=this;e.assertNonNullable(vt.Events,"hls.js not loaded");var r=this.params,i=r.desiredState,a=r.output,n=function(e){a.error$.next({id:"HlsJsProvider",message:"HlsJsProvider internal logic error",thrown:e})},s=O(this.video),o=function(e,r){return t.subscription.add(e.subscribe(r,n))};o(s.timeUpdate$,a.position$),o(s.durationChange$,a.duration$),o(s.ended$,a.endedEvent$),o(s.error$,a.error$),o(s.isBuffering$,a.isBuffering$),o(s.currentBuffer$,a.currentBuffer$),o(s.firstBytes$,a.firstBytesEvent$),o(s.firstFrame$,a.firstFrameEvent$),o(s.seeked$,a.seekedEvent$),this.subscription.add(A(this.video,i.isLooped,n)),this.subscription.add($(this.video,i.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$)),this.subscription.add(Ot(this.hls,vt.Events.ERROR).subscribe((function(e){var t;e.fatal&&a.error$.next({id:["HlsJsFatal",e.type,e.details].join("_"),message:"HlsJs fatal "+e.type+" "+e.details+", "+(null===(t=e.err)||void 0===t?void 0:t.message)+" "+e.reason,thrown:e.error})}))),this.subscription.add(s.playing$.subscribe((function(){t.videoState.setState(pt.PLAYING),V(i.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(pt.PAUSED),V(i.playbackState,exports.PlaybackState.PAUSED)}),n)).add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===pt.READY&&t.videoState.setState(pt.READY),t.videoState.getState()===pt.PLAYING&&t.playIfAllowed()}),n)),o(Ot(this.hls,vt.Events.MANIFEST_PARSED).pipe(e.map((function(e){return e.levels.reduce((function(e,r){var i,a,n=r.name||r.height.toString(10),s=r.width,o=r.height,u=null!==(a=ot(null!==(i=r.attrs.QUALITY)&&void 0!==i?i:""))&&void 0!==a?a:q({width:s,height:o});if(!u)return e;var d={id:n.toString(),quality:u,bitrate:r.bitrate/1e3,size:{width:s,height:o}};return t.trackLevels.set(n,{track:d,level:r}),e.push(d),e}),[])}))),a.availableVideoTracks$),o(Ot(this.hls,vt.Events.LEVEL_LOADING).pipe(e.map((function(e){var t=e.url;return Z(t)}))),a.hostname$),this.subscription.add(x(i.autoVideoTrackSwitching,(function(){return t.hls.autoLevelEnabled}),(function(e){t.hls.nextLevel=e?-1:t.hls.currentLevel,t.hls.loadLevel=e?-1:t.hls.loadLevel}),{onError:n}));var u=function(e){var r;return null===(r=Array.from(t.trackLevels.values()).find((function(t){return t.level===e})))||void 0===r?void 0:r.track},d=Ot(this.hls,vt.Events.LEVEL_SWITCHED).pipe(e.map((function(e){var r=e.level;return u(t.hls.levels[r])})));d.pipe(e.filter(e.isNonNullable)).subscribe(a.currentVideoTrack$,n),this.subscription.add(x(i.videoTrack,(function(){var e;return null===(e=u(t.hls.levels[t.hls.currentLevel]))||void 0===e?void 0:e.id}),(function(r){var i;if(!e.isNullable(r)){var a=null===(i=t.trackLevels.get(r))||void 0===i?void 0:i.level;if(a){var n=t.hls.levels.indexOf(a),s=t.hls.currentLevel,o=t.hls.levels[s];!o||a.bitrate>o.bitrate?t.hls.nextLevel=n:(t.hls.loadLevel=n,t.hls.loadLevel=n)}}}),{changed$:d.pipe(e.map((function(e){return null==e?void 0:e.id}))),onError:n})),o(s.progress$,(function(){t.params.dependencies.throughputEstimator.addRawThroughput(t.hls.bandwidthEstimate/1e3)})),this.textTracksManager.connect(this.video,i,a);var l=e.merge(i.playbackState.stateChangeStarted$,i.videoTrack.stateChangeStarted$,i.seekPosition.stateChangeStarted$,this.videoState.stateChangeEnded$,e.observableFrom(["init"])).pipe(e.debounce(0));this.subscription.add(l.subscribe(this.syncPlayback,n))},t.prototype.prepare=function(){this.videoState.startTransitionTo(pt.READY),this.hls.attachMedia(this.video),this.hls.loadSource(this.params.source.url)},t.prototype.playIfAllowed=function(){return c(this,void 0,void 0,(function(){return p(this,(function(e){switch(e.label){case 0:return this.videoState.startTransitionTo(pt.PLAYING),[4,w(this.video)];case 1:return e.sent()||(this.videoState.setState(pt.PAUSED),V(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)),[2]}}))}))},t.prototype.pause=function(){this.videoState.startTransitionTo(pt.PAUSED),this.video.pause()},t.prototype.seek=function(e){this.params.output.willSeekEvent$.next(),this.video.currentTime=e},t.prototype.stop=function(){this.params.output.position$.next(0),this.params.output.duration$.next(1/0),this.params.output.currentBuffer$.next(void 0),this.params.output.hostname$.next(void 0),this.hls.stopLoad(),this.hls.detachMedia(),this.video.setAttribute("src",""),this.video.load(),this.videoState.setState(pt.STOPPED),V(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t}(),Mt=function(){function e(e){this.iterator=e[Symbol.iterator](),this.next()}return e.prototype.next=function(){this.current=this.iterator.next()},e.prototype.getValue=function(){if(this.current.done)throw new Error("Iterable is completed");return this.current.value},e.prototype.isCompleted=function(){return Boolean(this.current.done)},e}(),Bt=(Ct=window.navigator.userAgent,!/chrome/i.test(Ct)&&/webkit|safari|khtml/i.test(Ct)),Ut=(null===(St=null===(mt=navigator)||void 0===mt?void 0:mt.userAgentData)||void 0===St?void 0:St.mobile)||/Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(navigator.appVersion),Ft=document.createElement("video"),Ht={mse:Boolean(window.MediaSource&&window.MediaStreamTrack&&(null===(gt=null===(bt=window.SourceBuffer)||void 0===bt?void 0:bt.prototype)||void 0===gt?void 0:gt.appendBuffer)),hls:Boolean((null===(yt=Ft.canPlayType)||void 0===yt?void 0:yt.call(Ft,"application/x-mpegurl"))||(null===(Tt=Ft.canPlayType)||void 0===Tt?void 0:Tt.call(Ft,"vnd.apple.mpegURL")))},qt={mp4:Boolean(null===(Et=Ft.canPlayType)||void 0===Et?void 0:Et.call(Ft,"video/mp4")),webm:Boolean(null===(Pt=Ft.canPlayType)||void 0===Pt?void 0:Pt.call(Ft,"video/webm"))},Gt={h264:Boolean(null===(wt=null===(kt=window.MediaSource)||void 0===kt?void 0:kt.isTypeSupported)||void 0===wt?void 0:wt.call(kt,'video/mp4; codecs="avc1.42000a,mp4a.40.2"')),h265:Boolean(null===(At=null===(xt=window.MediaSource)||void 0===xt?void 0:xt.isTypeSupported)||void 0===At?void 0:At.call(xt,'video/mp4; codecs="hev1.1.6.L93.B0"')),vp9:Boolean(null===(Nt=null===($t=window.MediaSource)||void 0===$t?void 0:$t.isTypeSupported)||void 0===Nt?void 0:Nt.call($t,'video/webm; codecs="vp9"')),aac:Boolean(null===(_t=null===(Dt=window.MediaSource)||void 0===Dt?void 0:Dt.isTypeSupported)||void 0===_t?void 0:_t.call(Dt,'audio/mp4; codecs="mp4a.40.2"')),opus:Boolean(null===(It=null===(Rt=window.MediaSource)||void 0===Rt?void 0:Rt.isTypeSupported)||void 0===It?void 0:It.call(Rt,'audio/webm; codecs="opus"'))},jt=(Gt.h264||Gt.h265)&&Gt.aac,Yt=!Bt,zt=Ut||Bt,Qt=!Ht.hls||!zt,Wt=3e4,Jt=18e4,Kt=3,Xt=100,Zt={cacheDuration:12e4},er={maxPausedTime:3e4,chunkDuration:5e3,optimalBufferDuration:1e4,maxParallelRequests:5},tr={maxPausedTime:3e4},rr={maxPausedTime:3e4},ir=function(){function t(t){this.current$=new e.ValueSubject({type:void 0}),this.providerError$=new e.Subject,this.noAvailableProvidersError$=new e.Subject,this.providerOutput={position$:new e.ValueSubject(0),duration$:new e.ValueSubject(1/0),volume$:new e.ValueSubject({muted:!1,volume:1}),currentVideoTrack$:new e.ValueSubject(void 0),availableVideoTracks$:new e.ValueSubject([]),currentBuffer$:new e.ValueSubject(void 0),isBuffering$:new e.ValueSubject(!0),error$:new e.Subject,willSeekEvent$:new e.Subject,seekedEvent$:new e.Subject,endedEvent$:new e.Subject,firstBytesEvent$:new e.Subject,firstFrameEvent$:new e.Subject,isLive$:new e.ValueSubject(void 0),liveTime$:new e.ValueSubject(void 0),availableTextTracks$:new e.ValueSubject([]),currentTextTrack$:new e.ValueSubject(void 0),hostname$:new e.ValueSubject(void 0),httpConnectionType$:new e.ValueSubject(void 0),httpConnectionReused$:new e.ValueSubject(void 0),element$:new e.ValueSubject(void 0)},this.subscription=new e.Subscription,this.params=t,this.log=this.params.dependencies.logger.createComponentLog("ProviderContainer");var r=this.params.tuning.formatsToAvoid,i=r.length?v(v([],f(t.screenFormatsPriority.filter((function(e){return!r.includes(e)}))),!1),f(t.screenFormatsPriority.filter((function(e){return r.includes(e)}))),!1):t.screenFormatsPriority;this.screenFormatsIterator=new Mt(i.filter((function(r){return e.isNonNullable(t.sources[r])})).filter((function(t){switch(t){case exports.VideoFormat.DASH:return Ht.mse&&qt.mp4&&jt&&Yt;case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_SEP_VK:return Ht.mse&&qt.mp4&&jt;case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.DASH_LIVE_WEBM:return Ht.mse&&qt.webm&&Gt.vp9&&Gt.opus;case exports.VideoFormat.DASH_LIVE:case exports.VideoFormat.DASH_ONDEMAND:return Ht.mse&&qt.mp4&&jt;case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_LIVE:case exports.VideoFormat.HLS_ONDEMAND:return Ht.hls&&qt.mp4&&zt;case exports.VideoFormat.HLS_JS:return Ht.mse&&qt.mp4&&jt&&Qt;case exports.VideoFormat.MPEG:return qt.mp4;default:return e.assertNever(t)}}))),this.chromecastFormatsIterator=new Mt(t.chromecastFormatsPriority.filter((function(r){return e.isNonNullable(t.sources[r])})))}return t.prototype.init=function(){var e=this;this.subscription.add(this.initProviderErrorHandling()),this.subscription.add(this.params.dependencies.chromecastInitializer.connection$.subscribe((function(){e.reinitProvider()})))},t.prototype.destroy=function(){this.destroyProvider(),this.current$.next({type:void 0}),this.subscription.unsubscribe()},t.prototype.initProvider=function(){var t=this.chooseDestination(),r=this.chooseFormat(t);if(e.isNullable(r))this.handleNoFormatsError(t);else{var i=this.createProvider(t,r);this.current$.next({type:r,provider:i,destination:t})}},t.prototype.reinitProvider=function(){this.destroyProvider(),this.initProvider()},t.prototype.switchToNextProvider=function(){this.destroyProvider();var t=this.current$.getValue().destination;e.assertNonNullable(t),this.skipFormat(t),this.initProvider()},t.prototype.destroyProvider=function(){var t=this.current$.getValue().provider;if(t){this.log({message:"destroyProvider"});var r=this.params.desiredState.seekPosition,i=r.getTransition();i?e.isNonNullable(i.from)&&r.startTransitionTo(i.from):r.startTransitionTo(this.providerOutput.position$.getValue()),t.destroy();var a=this.providerOutput.isBuffering$;a.getValue()||a.next(!0)}},t.prototype.createProvider=function(t,r){switch(this.log({message:"createProvider: "+t+":"+r}),t){case n.SCREEN:return this.createScreenProvider(r);case n.CHROMECAST:return this.createChromecastProvider(r);default:return e.assertNever(t)}},t.prototype.createScreenProvider=function(t){var r=this.params,i=r.sources,a=r.container,n=r.desiredState,s=this.providerOutput;switch(t){case exports.VideoFormat.DASH:var o=i[t];return e.assertNonNullable(o),new Ve({container:a,source:o,desiredState:n,output:s,config:Zt,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_SEP_VK:case exports.VideoFormat.DASH_WEBM_VK:o=i[t];return e.assertNonNullable(o),new we({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_SEP:case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_ONDEMAND:case exports.VideoFormat.DASH_LIVE_WEBM:o=i[t];return e.assertNonNullable(o),new Ye({container:a,source:o,desiredState:n,output:s,format:t,config:rr,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_ONDEMAND:o=i[t];return e.assertNonNullable(o),new ct({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS_LIVE:o=i[t];return e.assertNonNullable(o),new ht({container:a,source:o,desiredState:n,output:s,config:tr,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS_JS:o=i[t];return e.assertNonNullable(o),new Vt({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.MPEG:o=i[t];return e.assertNonNullable(o),new _e({container:a,source:o,desiredState:n,output:s,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_LIVE:o=i[t];return e.assertNonNullable(o),new nt({container:a,source:o,desiredState:n,output:s,config:er,dependencies:this.params.dependencies,tuning:this.params.tuning});default:return e.assertNever(t)}},t.prototype.createChromecastProvider=function(t){var r=this.params,i=r.sources,a=r.container,n=r.desiredState,s=r.meta,o=this.providerOutput,u=this.params.dependencies.chromecastInitializer.connection$.getValue();return e.assertNonNullable(u),new Ne({connection:u,meta:s,container:a,source:i,format:t,desiredState:n,output:o,dependencies:this.params.dependencies,tuning:this.params.tuning})},t.prototype.chooseDestination=function(){return this.params.dependencies.chromecastInitializer.connection$.getValue()?n.CHROMECAST:n.SCREEN},t.prototype.chooseFormat=function(t){switch(t){case n.SCREEN:return this.screenFormatsIterator.isCompleted()?void 0:this.screenFormatsIterator.getValue();case n.CHROMECAST:return this.chromecastFormatsIterator.isCompleted()?void 0:this.chromecastFormatsIterator.getValue();default:return e.assertNever(t)}},t.prototype.skipFormat=function(t){switch(t){case n.SCREEN:return this.screenFormatsIterator.next();case n.CHROMECAST:return this.chromecastFormatsIterator.next();default:return e.assertNever(t)}},t.prototype.handleNoFormatsError=function(t){switch(t){case n.SCREEN:return this.noAvailableProvidersError$.next(),void this.current$.next({type:void 0});case n.CHROMECAST:return void this.params.dependencies.chromecastInitializer.disconnect();default:return e.assertNever(t)}},t.prototype.initProviderErrorHandling=function(){var t,r=this,i=[],a=0,s=new e.Subscription;return s.add(e.merge(this.providerOutput.error$,(t={desiredPlaybackState$:this.params.desiredState.playbackState,maxTransitionInterval:Wt,position$:this.providerOutput.position$,providerChanged$:this.current$},new e.Observable((function(r){var i=new e.Subscription,a=e.timeout(t.maxTransitionInterval),n=new e.ValueSubject(void 0);e.merge(t.desiredPlaybackState$.stateChangeStarted$.pipe(e.mapTo(a)),t.desiredPlaybackState$.stateChangeEnded$.pipe(e.mapTo(void 0)),t.providerChanged$.pipe(e.map((function(){return n.getValue()})))).subscribe(n);var s=new e.Subscription;return i.add(s),i.add(n.subscribe((function(e){s.unsubscribe(),e&&s.add(e.subscribe(r))}))),i}))).pipe(e.mapTo({id:"ProviderHangup",message:"An operation failed to complete within reasonable time"}))).subscribe(this.providerError$)),s.add(this.providerError$.pipe(e.throttle(Xt,{leading:!1,trailing:!0})).subscribe((function(){var t=Date.now();r.current$.getValue().destination===n.CHROMECAST?(r.destroyProvider(),r.params.dependencies.chromecastInitializer.stopMedia().then((function(){r.switchToNextProvider()}),(function(){r.params.dependencies.chromecastInitializer.disconnect()}))):e.isNonNullable(i[a])&&t<i[a]+Jt?(i=[],r.switchToNextProvider()):(i[a]=t,r.reinitProvider()),a=(a+1)%Kt}))),s},t}(),ar=function(e,t,r){return r*t+(1-r)*e},nr=function(){function t(t){var r;this.prevReported=void 0,this.params=t,this.slow=this.fast=this.smoothed=this.prevReported=t.initial,this.smoothed$=new e.ValueSubject(t.initial),this.debounced$=new e.ValueSubject(t.initial);var i=null!==(r=t.label)&&void 0!==r?r:"value"+Math.random().toString(16).substring(2,6);this.rawSeries$=new W("raw_"+i),this.smoothedSeries$=new W("smoothed_"+i),this.reportedSeries$=new W("reported_"+i)}return t.prototype.next=function(t){this.slow=ar(this.slow,t,this.params.emaAlphaSlow),this.fast=ar(this.fast,t,this.params.emaAlphaFast);var r=this.params.fastDirection>0?Math.max:Math.min;this.smoothed=r(this.slow,this.fast),this.smoothed$.next(this.smoothed),(e.isNullable(this.prevReported)||Math.abs(this.smoothed-this.prevReported)/this.prevReported>=this.params.changeThreshold)&&(this.prevReported=this.smoothed,this.debounced$.next(this.smoothed),this.reportedSeries$.next(this.smoothed)),this.rawSeries$.next(t),this.smoothedSeries$.next(this.smoothed)},t}();!function(e){e[e.LOCAL_STORAGE=0]="LOCAL_STORAGE",e[e.SESSION_STORAGE=1]="SESSION_STORAGE",e[e.RUNTIME=2]="RUNTIME"}(Lt||(Lt={}));var sr=new Map,or=Lt.RUNTIME,ur="vk-videoplayer-dummy-key-"+Math.random();!function(){try{localStorage.setItem(ur,"test"),localStorage.removeItem(ur),or=Lt.LOCAL_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;try{sessionStorage.getItem(ur),or=Lt.SESSION_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;or=Lt.RUNTIME}}}();var dr,lr=function(t,r){switch(or){case Lt.LOCAL_STORAGE:try{localStorage.setItem(t,r)}catch(e){if(!(e instanceof DOMException))throw e;console.error(e)}break;case Lt.SESSION_STORAGE:try{sessionStorage.setItem(t,r)}catch(e){if(!(e instanceof DOMException))throw e;console.error(e)}break;case Lt.RUNTIME:return void sr.set(t,r);default:e.assertNever(or)}},cr=window.navigator.connection,pr=function(){var t=null==cr?void 0:cr.downlink;if(e.isNonNullable(t)&&10!==t)return 1e3*t},hr=function(){var t=null==cr?void 0:cr.rtt;if(e.isNonNullable(t)&&3e3!==t)return t},fr=function(e,t,r){var i=8*r;return i/(i/e+t)},vr=function(){function t(r){var i,a,n=this;this.subscription=new e.Subscription,this.tuningConfig=r;var s=t.load("one_video_throughput")||(r.useBrowserEstimation?pr():void 0)||5e3,o=null!==(a=null!==(i=t.load("one_video_rtt"))&&void 0!==i?i:r.useBrowserEstimation?hr():void 0)&&void 0!==a?a:0;if(this.throughput$=new e.ValueSubject(s),this.rtt$=new e.ValueSubject(o),this.rttAdjustedThroughput$=new e.ValueSubject(fr(s,o,r.rttPenaltyRequestSize)),this.throughput=new nr({initial:s,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:-1,label:"throughput"}),this.rtt=new nr({initial:o,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:1,label:"rtt"}),r.useBrowserEstimation){var u=function(){var t=pr();t&&n.throughput.next(t);var r=hr();e.isNonNullable(r)&&n.rtt.next(r)};cr&&"onchange"in cr&&this.subscription.add(e.fromEvent(cr,"change").subscribe(u)),u()}this.subscription.add(this.throughput.smoothed$.subscribe((function(e){lr("one_video_throughput",e.toFixed(0))}))),this.subscription.add(this.rtt.smoothed$.subscribe((function(e){lr("one_video_rtt",e.toFixed(0))}))),this.subscription.add(this.throughput.debounced$.subscribe(this.throughput$)),this.subscription.add(this.rtt.debounced$.subscribe(this.rtt$)),this.subscription.add(e.combine({throughput:this.throughput.smoothed$,rtt:this.rtt.smoothed$}).pipe(e.map((function(e){var t=e.throughput,i=e.rtt;return fr(t,i,r.rttPenaltyRequestSize)})),e.filter((function(e){var t=n.rttAdjustedThroughput$.getValue()||0;return Math.abs(e-t)/t>=r.changeThreshold}))).subscribe(this.rttAdjustedThroughput$))}return t.prototype.destroy=function(){this.subscription.unsubscribe()},t.prototype.trackXHR=function(t){var r=this,i=0,a=e.now(),n=new e.Subscription;switch(this.subscription.add(n),t.readyState){case 4:break;case 3:case 2:n.add(e.fromEvent(t,"progress").pipe(e.once()).subscribe((function(t){i=t.loaded,a=e.now()})));break;case 1:case 0:n.add(e.fromEvent(t,"loadstart").subscribe((function(){i=0,a=e.now()})))}n.add(e.fromEvent(t,"loadend").subscribe((function(s){if(200===t.status){var o=s.loaded,u=e.now(),d=o-i,l=u-a;r.addRawSpeed(d,l)}n.unsubscribe()})))},t.prototype.trackStream=function(t){var r=this,i=t.getReader();if(i){var a=0,n=e.now(),s=0,o=e.now(),u=function(e){i.releaseLock(),t.cancel("Throughput Estimator error: "+e).catch((function(){}))},d=function(t){var l=t.done,h=t.value;return c(r,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return l?(this.addRawSpeed(a,e.now()-n),[3,3]):[3,1];case 1:return h?(a+=h.byteLength,(s+=h.byteLength)>=this.tuningConfig.streamMinSampleSize&&e.now()-o>=this.tuningConfig.streamMinSampleTime&&(this.addRawSpeed(s,e.now()-o),s=0,o=e.now()),[4,null==i?void 0:i.read().then(d,u)]):[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))};null==i||i.read().then(d,u)}else t.cancel("Could not get reader")},t.prototype.addRawSpeed=function(e,r){if(t.sanityCheck(e,r)){var i=8*e/r;this.throughput.next(i)}},t.prototype.addRawThroughput=function(e){this.throughput.next(e)},t.prototype.addRawRtt=function(e){this.rtt.next(e)},t.sanityCheck=function(e,t){var r=8*e/t;return!(!r||!isFinite(r))&&(!(r>1e6)&&(!(r<30)&&(!(e<10240)&&!(t<=20))))},t.load=function(t){var r,i=function(t){var r,i;switch(or){case Lt.LOCAL_STORAGE:return null!==(r=localStorage.getItem(t))&&void 0!==r?r:void 0;case Lt.SESSION_STORAGE:return null!==(i=sessionStorage.getItem(t))&&void 0!==i?i:void 0;case Lt.RUNTIME:return sr.get(t);default:e.assertNever(or)}}(t);if(e.isNonNullable(i))return null!==(r=parseInt(i,10))&&void 0!==r?r:void 0},t}(),mr=function(t){return void 0===t&&(t=function(e){return e}),function(r){var i=r.playbackState,a=r.seekPosition,n=r.playbackAbort$,s=r.position$;return new e.Observable((function(r){var o,u=i.transitionEnded$.pipe(e.filter((function(e){return(e.from===exports.PlaybackState.PAUSED||e.from===exports.PlaybackState.STOPPED)&&e.to===exports.PlaybackState.PLAYING}))),d=i.stateChangeEnded$.pipe(e.filter((function(e){return e.from===exports.PlaybackState.PLAYING&&e.to===exports.PlaybackState.PAUSED}))),l=a.stateChangeEnded$.pipe(e.filter((function(t){var r,a;return e.isNonNullable(t.to)&&(null!==(a=null===(r=i.getTransition())||void 0===r?void 0:r.from)&&void 0!==a?a:i.getState())===exports.PlaybackState.PLAYING}))),c=a.stateChangeEnded$.pipe(e.filter((function(t){var r,a;return e.isNullable(t.to)&&(null!==(a=null===(r=i.getTransition())||void 0===r?void 0:r.from)&&void 0!==a?a:i.getState())===exports.PlaybackState.PLAYING}))),p=e.merge(u,c).pipe(e.map((function(){return t(s.getValue())}))),h=e.merge(d,l,n).pipe(e.map((function(){return t(s.getValue())})));return(new e.Subscription).add(p.subscribe((function(e){o=t(e)}))).add(h.subscribe((function(i){if(!e.isNullable(o)){var a={start:o,end:t(i)};o=void 0,r.next(a)}})))}))}},Sr=mr((function(e){return e})),br=mr((function(e){return Math.round(1e3*e)+Date.now()})),gr=((dr={})[n.SCREEN]={vod:[exports.VideoFormat.HLS,exports.VideoFormat.HLS_ONDEMAND,exports.VideoFormat.DASH_WEBM_VK,exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH,exports.VideoFormat.DASH_SEP_VK,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_ONDEMAND,exports.VideoFormat.HLS_JS,exports.VideoFormat.MPEG],live:[exports.VideoFormat.HLS_LIVE,exports.VideoFormat.DASH_LIVE,exports.VideoFormat.DASH_LIVE_WEBM]},dr[n.CHROMECAST]={vod:[exports.VideoFormat.DASH_WEBM_VK,exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH_SEP_VK,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_ONDEMAND,exports.VideoFormat.HLS,exports.VideoFormat.HLS_ONDEMAND,exports.VideoFormat.MPEG],live:[exports.VideoFormat.HLS_LIVE]},dr),yr=function(){function t(t){var r=this;if(void 0===t&&(t={}),this.subscription=new e.Subscription,this.logger=new e.Logger,this.isPlaybackStarted=!1,this.desiredState={playbackState:new te(exports.PlaybackState.STOPPED),seekPosition:new te(void 0),volume:new te({volume:1,muted:!1}),videoTrack:new te(void 0),autoVideoTrackSwitching:new te(!0),isLooped:new te(!1),externalTextTracks:new te([]),currentTextTrack:new te(void 0),textTrackCuesSettings:new te({})},this.info={playbackState$:new e.ValueSubject(exports.PlaybackState.STOPPED),position$:new e.ValueSubject(0),duration$:new e.ValueSubject(1/0),muted$:new e.ValueSubject(!1),volume$:new e.ValueSubject(1),availableQualities$:new e.ValueSubject([]),currentQuality$:new e.ValueSubject(void 0),isAutoQualityEnabled$:new e.ValueSubject(!0),currentBuffer$:new e.ValueSubject(void 0),isBuffering$:new e.ValueSubject(!0),isStalled$:new e.ValueSubject(!1),isEnded$:new e.ValueSubject(!1),isLooped$:new e.ValueSubject(!1),isLive$:new e.ValueSubject(void 0),liveTime$:new e.ValueSubject(void 0),currentFormat$:new e.ValueSubject(void 0),availableTextTracks$:new e.ValueSubject([]),currentTextTrack$:new e.ValueSubject(void 0),throughputEstimation$:new e.ValueSubject(void 0),rttEstimation$:new e.ValueSubject(void 0),videoBitrate$:new e.ValueSubject(void 0),hostname$:new e.ValueSubject(void 0),httpConnectionType$:new e.ValueSubject(void 0),httpConnectionReused$:new e.ValueSubject(void 0),chromecastState$:new e.ValueSubject(exports.ChromecastState.NOT_AVAILABLE),chromecastDeviceName$:new e.ValueSubject(void 0)},this.events={started$:new e.Subject,startAttempt$:new e.Subject,willPause$:new e.Subject,willResume$:new e.Subject,willDestruct$:new e.Subject,watchCoverageRecord$:new e.Subject,watchCoverageLive$:new e.Subject,managedError$:new e.Subject,fatalError$:new e.Subject,ended$:new e.Subject,seeked$:new e.Subject,willSeek$:new e.Subject,firstBytes$:new e.Subject,firstFrame$:new e.Subject,log$:new e.Subject},this.experimental={element$:new e.ValueSubject(void 0),enableDebugTelemetry$:new e.ValueSubject(!1),dumpTelemetry:z},this.initLogs(),this.tuning=function(e){var t,r,i={};try{for(var a=h(Object.keys(y)),n=a.next();!n.done;n=a.next()){var s=n.value,o=y[s],u=e[s];Array.isArray(o)&&Array.isArray(u)?i[s]=u:i[s]="object"==typeof o&&"object"==typeof u?l(l({},o),u):null!=u?u:o}}catch(e){t={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return i}(t),this.chromecastInitializer=new T({receiverApplicationId:t.chromecastReceiverId,isDisabled:t.disableChromecast,dependencies:{logger:this.logger}}),this.throughputEstimator=new vr(this.tuning.throughputEstimator),this.initChromecastSubscription(),this.initDesiredStateSubscriptions(),Proxy&&Reflect)return new Proxy(this,{get:function(e,t,i){var a=Reflect.get(e,t,i);return"function"!=typeof a?a:function(){for(var i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];try{return a.apply(e,i)}catch(e){var s=i.map((function(e){return JSON.stringify(e,(function(e,t){var r=typeof t;return["number","string","boolean"].includes(r)?t:null===t?null:"<"+r+">"}))})),o="Player."+String(t),u="Exception calling "+o+" ("+s.join(", ")+")";throw r.events.fatalError$.next({id:o,message:u,thrown:e}),e}}}})}return t.prototype.initVideo=function(t){var r,i;return this.config=t,this.domContainer=function(t){var r="string"==typeof t.container?document.getElementById(t.container):t.container;return e.assertNonNullable(r,"Wrong container or containerId {"+t.container+"}"),r}(t),this.chromecastInitializer.contentId=null===(r=t.meta)||void 0===r?void 0:r.videoId,this.providerContainer=new ir({screenFormatsPriority:v(v([],f(gr[n.SCREEN].live),!1),f(gr[n.SCREEN].vod),!1),chromecastFormatsPriority:v(v([],f(gr[n.CHROMECAST].live),!1),f(gr[n.CHROMECAST].vod),!1),sources:t.sources,meta:null!==(i=t.meta)&&void 0!==i?i:{},container:this.domContainer,desiredState:this.desiredState,dependencies:{throughputEstimator:this.throughputEstimator,chromecastInitializer:this.chromecastInitializer,logger:this.logger},tuning:this.tuning}),this.initProviderContainerSubscription(this.providerContainer),this.initStartingVideoTrack(this.providerContainer),this.providerContainer.init(),this.initDebugTelemetry(),this},t.prototype.destroy=function(){var e;this.events.willDestruct$.next(),null===(e=this.providerContainer)||void 0===e||e.destroy(),this.throughputEstimator.destroy(),this.chromecastInitializer.destroy(),this.subscription.unsubscribe()},t.prototype.play=function(){var e=this.desiredState.playbackState;return e.getState()!==exports.PlaybackState.PLAYING&&e.startTransitionTo(exports.PlaybackState.PLAYING),this},t.prototype.pause=function(){var e=this.desiredState.playbackState;return e.getState()!==exports.PlaybackState.PAUSED&&e.startTransitionTo(exports.PlaybackState.PAUSED),this},t.prototype.stop=function(){var e=this.desiredState.playbackState;return e.getState()!==exports.PlaybackState.STOPPED&&e.startTransitionTo(exports.PlaybackState.STOPPED),this},t.prototype.seekTime=function(e){return this.events.willSeek$.next({from:this.getExactTime(),to:e}),this.desiredState.seekPosition.startTransitionTo(e),this},t.prototype.seekPercent=function(e){var t=this.info.duration$.getValue();return isFinite(t)&&this.seekTime(Math.abs(t)*e),this},t.prototype.setVolume=function(e){return this.chromecastInitializer.castState$.getValue()===exports.ChromecastState.CONNECTED?this.chromecastInitializer.setVolume(e):this.desiredState.volume.startTransitionTo({volume:e,muted:this.desiredState.volume.getState().muted}),this},t.prototype.setMuted=function(e){return this.chromecastInitializer.castState$.getValue()===exports.ChromecastState.CONNECTED?this.chromecastInitializer.setMuted(e):this.desiredState.volume.startTransitionTo({volume:this.desiredState.volume.getState().volume,muted:e}),this},t.prototype.setQuality=function(t){e.assertNonNullable(this.providerContainer);var r=this.providerContainer.providerOutput.availableVideoTracks$.getValue();r.length||(this.explicitInitialQuality=t);var i=r.find((function(e){return e.quality===t}));return i&&this.desiredState.videoTrack.startTransitionTo(i.id),this},t.prototype.setAutoQuality=function(e){return this.desiredState.autoVideoTrackSwitching.startTransitionTo(e),this},t.prototype.setExternalTextTracks=function(e){return this.desiredState.externalTextTracks.startTransitionTo(e.map((function(e){return l({type:"external"},e)}))),this},t.prototype.selectTextTrack=function(e){var t;return(void 0===e||(null===(t=this.providerContainer)||void 0===t?void 0:t.providerOutput.availableTextTracks$.getValue().find((function(t){return t.id===e}))))&&this.desiredState.currentTextTrack.startTransitionTo(e),this},t.prototype.setTextTrackCueSettings=function(e){return this.desiredState.textTrackCuesSettings.startTransitionTo(e),this},t.prototype.setLooped=function(e){return this.desiredState.isLooped.startTransitionTo(e),this},t.prototype.toggleChromecast=function(){this.chromecastInitializer.toggleConnection()},t.prototype.getExactTime=function(){var t;e.assertNonNullable(this.providerContainer);var r=this.providerContainer.providerOutput.element$.getValue();if(e.isNullable(r))return this.info.position$.getValue();var i=this.desiredState.seekPosition.getTransition(),a=null!==(t=null==i?void 0:i.to)&&void 0!==t?t:null==i?void 0:i.from;return e.isNonNullable(a)?a:r.currentTime},t.prototype.getAllLogs=function(){return this.logger.getAllLogs()},t.prototype.initDesiredStateSubscriptions=function(){var t=this;this.subscription.add(e.merge(this.desiredState.playbackState.stateChangeStarted$,this.desiredState.playbackState.forceChanged$).pipe(e.map((function(e){return e.to}))).subscribe(this.info.playbackState$)).add(this.desiredState.isLooped.stateChangeEnded$.pipe(e.map((function(e){return e.to}))).subscribe(this.info.isLooped$)).add(this.desiredState.autoVideoTrackSwitching.stateChangeEnded$.pipe(e.map((function(e){return e.to}))).subscribe(this.info.isAutoQualityEnabled$));var r=new e.Subscription;this.subscription.add(r),this.subscription.add(this.desiredState.playbackState.stateChangeStarted$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING}))).subscribe((function(){r.unsubscribe(),r.add(t.desiredState.playbackState.stateChangeEnded$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING||e.to===exports.PlaybackState.PAUSED})),e.debounce(0),e.once()).subscribe((function(e){var r=e.to===exports.PlaybackState.PLAYING,i=t.info.muted$.getValue(),a=r?i?exports.StartStatus.SuccessWithoutSound:exports.StartStatus.SuccessWithSound:exports.StartStatus.Failed;t.events.startAttempt$.next(a)})))}))),this.subscription.add(this.desiredState.playbackState.stateChangeEnded$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING})),e.debounce(0)).subscribe((function(){if(!t.isPlaybackStarted){var e=t.info.muted$.getValue();t.isPlaybackStarted=!0,t.events.started$.next(e)}}))).add(this.desiredState.playbackState.stateChangeStarted$.subscribe((function(e){switch(e.to){case exports.PlaybackState.PAUSED:t.events.willPause$.next();break;case exports.PlaybackState.PLAYING:t.isPlaybackStarted&&t.events.willResume$.next()}})))},t.prototype.initProviderContainerSubscription=function(t){var r=this;this.subscription.add(t.providerOutput.willSeekEvent$.subscribe((function(){var t=r.desiredState.seekPosition.getTransition(),i=null==t?void 0:t.to;e.isNonNullable(i)&&(r.desiredState.seekPosition.setState(i),r.desiredState.seekPosition.startTransitionTo(void 0))}))).add(t.providerOutput.seekedEvent$.subscribe((function(){var t=r.desiredState.seekPosition.getTransition();e.isNonNullable(null==t?void 0:t.to)||r.desiredState.seekPosition.setState(void 0),r.events.seeked$.next()}))).add(t.current$.pipe(e.map((function(e){return e.type}))).subscribe(this.info.currentFormat$)).add(t.current$.pipe(e.map((function(e){return e.destination})),e.filterChanged()).subscribe((function(){r.isPlaybackStarted=!1}))).add(t.providerOutput.availableVideoTracks$.pipe(e.map((function(e){return e.map((function(e){return e.quality})).sort((function(e,t){return G(e)?1:G(t)?-1:U(t,e)?1:-1}))}))).subscribe(this.info.availableQualities$)).add(t.providerOutput.currentVideoTrack$.subscribe((function(e){r.info.currentQuality$.next(null==e?void 0:e.quality),r.info.videoBitrate$.next(null==e?void 0:e.bitrate)}))).add(t.providerOutput.hostname$.pipe(e.filterChanged()).subscribe(this.info.hostname$)).add(t.providerOutput.httpConnectionType$.pipe(e.filterChanged()).subscribe(this.info.httpConnectionType$)).add(t.providerOutput.httpConnectionReused$.pipe(e.filterChanged()).subscribe(this.info.httpConnectionReused$)).add(t.providerOutput.currentTextTrack$.subscribe(this.info.currentTextTrack$)).add(t.providerOutput.availableTextTracks$.subscribe(this.info.availableTextTracks$)).add(t.providerOutput.currentBuffer$.subscribe(this.info.currentBuffer$)).add(t.providerOutput.duration$.subscribe(this.info.duration$)).add(t.providerOutput.isBuffering$.subscribe(this.info.isBuffering$)).add(t.providerOutput.isLive$.subscribe(this.info.isLive$)).add(t.providerOutput.liveTime$.subscribe(this.info.liveTime$)).add(t.providerOutput.volume$.pipe(e.map((function(e){return e.muted})),e.filterChanged()).subscribe(this.info.muted$)).add(t.providerOutput.volume$.pipe(e.map((function(e){return e.volume})),e.filterChanged()).subscribe(this.info.volume$)).add(function(t){var r=t.seekPosition,i=t.position$;return e.merge(r.stateChangeStarted$.pipe(e.map((function(e){return e.to})),e.filter(e.isNonNullable)),i.pipe(e.filter((function(){return e.isNullable(r.getState())&&e.isNullable(r.getTransition())}))))}({seekPosition:this.desiredState.seekPosition,position$:t.providerOutput.position$}).subscribe(this.info.position$)).add(e.merge(t.providerOutput.endedEvent$.pipe(e.mapTo(!0)),t.providerOutput.seekedEvent$.pipe(e.mapTo(!1))).pipe(e.filterChanged()).subscribe(this.info.isEnded$)).add(t.providerOutput.endedEvent$.subscribe(this.events.ended$)).add(t.providerError$.subscribe(this.events.managedError$)).add(t.noAvailableProvidersError$.pipe(e.map((function(e){return{id:"NoProviders",message:"No suitable providers or all providers failed"}}))).subscribe(this.events.fatalError$)).add(t.providerOutput.element$.subscribe(this.experimental.element$)).add(t.providerOutput.firstBytesEvent$.subscribe(this.events.firstBytes$)).add(t.providerOutput.firstFrameEvent$.subscribe(this.events.firstFrame$)).add(this.throughputEstimator.throughput$.subscribe(this.info.throughputEstimation$)).add(this.throughputEstimator.rtt$.subscribe(this.info.rttEstimation$));var i=new e.ValueSubject(!1);this.subscription.add(t.providerOutput.seekedEvent$.subscribe((function(){return i.next(!1)}))).add(t.providerOutput.willSeekEvent$.subscribe((function(){return i.next(!0)})));var a=new e.ValueSubject(!0);this.subscription.add(t.current$.subscribe((function(){return a.next(!0)}))).add(this.desiredState.playbackState.stateChangeEnded$.pipe(e.filter((function(e){return e.to===exports.PlaybackState.PLAYING})),e.once()).subscribe((function(){return a.next(!1)})));var n=0,s=e.merge(t.providerOutput.isBuffering$,i,a).pipe(e.map((function(){var e=t.providerOutput.isBuffering$.getValue(),r=i.getValue()||a.getValue();return e&&!r})),e.filterChanged());this.subscription.add(s.subscribe((function(e){e?n=window.setTimeout((function(){return r.info.isStalled$.next(!0)}),r.tuning.stallIgnoreThreshold):(window.clearTimeout(n),r.info.isStalled$.next(!1))})));var o=new e.Subscription;this.subscription.add(o);var u=e.merge(this.events.willDestruct$,t.current$.pipe(e.filter((function(e){return Boolean(null==e?void 0:e.provider)}))));t.providerOutput.isLive$.pipe(e.filterChanged()).subscribe((function(t){switch(e.assertNonNullable(r.providerContainer),o.unsubscribe(),t){case!0:o.add(br({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:u,position$:r.providerContainer.providerOutput.position$}).subscribe(r.events.watchCoverageLive$));break;case!1:o.add(Sr({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:u,position$:r.providerContainer.providerOutput.position$}).subscribe(r.events.watchCoverageRecord$))}}))},t.prototype.initChromecastSubscription=function(){this.subscription.add(this.chromecastInitializer.castState$.subscribe(this.info.chromecastState$)),this.subscription.add(this.chromecastInitializer.connection$.pipe(e.map((function(e){return null==e?void 0:e.castDevice.friendlyName}))).subscribe(this.info.chromecastDeviceName$)),this.subscription.add(this.chromecastInitializer.errorEvent$.subscribe(this.events.managedError$))},t.prototype.initStartingVideoTrack=function(t){var r=this,i=new e.Subscription;this.subscription.add(i),this.subscription.add(t.current$.pipe(e.filterChanged((function(e,t){return e.provider===t.provider}))).subscribe((function(){i.unsubscribe(),i.add(t.providerOutput.availableVideoTracks$.pipe(e.filter((function(e){return e.length>0})),e.once()).subscribe((function(e){r.setStartingVideoTrack(e)})))})))},t.prototype.setStartingVideoTrack=function(e){var t,r=this;this.explicitInitialQuality&&(t=e.find((function(e){return e.quality===r.explicitInitialQuality})),this.explicitInitialQuality=void 0),t||(t=K(e,{container:this.domContainer.getBoundingClientRect(),throughput:this.throughputEstimator.throughput$.getValue(),tuning:this.tuning.autoTrackSelection,forwardBufferHealth:0})),this.desiredState.videoTrack.startTransitionTo(t.id),this.info.currentQuality$.next(t.quality),this.info.videoBitrate$.next(t.bitrate)},t.prototype.initLogs=function(){this.subscription.add(e.merge(this.desiredState.videoTrack.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"quality",type:"start"}}))),this.desiredState.videoTrack.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"quality",type:"end"}}))),this.desiredState.autoVideoTrackSwitching.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"autoQualityEnabled",type:"start"}}))),this.desiredState.autoVideoTrackSwitching.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"autoQualityEnabled",type:"end"}}))),this.desiredState.seekPosition.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"seekPosition",type:"start"}}))),this.desiredState.seekPosition.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"seekPosition",type:"end"}}))),this.desiredState.playbackState.stateChangeStarted$.pipe(e.map((function(e){return{transition:e,entity:"playbackState",type:"start"}}))),this.desiredState.playbackState.stateChangeEnded$.pipe(e.map((function(e){return{transition:e,entity:"playbackState",type:"end"}})))).pipe(e.map((function(e){return{component:"desiredState",message:"["+e.entity+" change] "+e.type+": "+JSON.stringify(e.transition)}}))).subscribe(this.logger.log)),this.subscription.add(this.logger.log$.subscribe(this.events.log$))},t.prototype.initDebugTelemetry=function(){var t,r=this,i=null===(t=this.providerContainer)||void 0===t?void 0:t.providerOutput;e.assertNonNullable(this.providerContainer),e.assertNonNullable(i),Y={},this.experimental.enableDebugTelemetry$.next(this.tuning.enableTelemetryAtStart),[this.experimental.enableDebugTelemetry$.subscribe((function(e){j=e})),this.providerContainer.current$.subscribe((function(e){var t=e.type;return Q("provider",t)})),i.duration$.subscribe((function(e){return Q("duration",e)})),i.availableVideoTracks$.pipe(e.filter((function(e){return!!e.length})),e.once()).subscribe((function(e){return Q("tracks",e)})),this.events.fatalError$.subscribe(new W("fatalError")),this.events.managedError$.subscribe(new W("managedError")),i.position$.subscribe(new W("position")),i.currentVideoTrack$.pipe(e.map((function(e){return null==e?void 0:e.quality}))).subscribe(new W("quality")),i.currentBuffer$.subscribe(new W("buffer")),i.isBuffering$.subscribe(new W("isBuffering"))].forEach((function(e){return r.subscription.add(e)})),Q("codecs",Object.keys(Gt).filter((function(e){return Gt[e]})))},t}();Object.defineProperty(exports,"Observable",{enumerable:!0,get:function(){return e.Observable}}),Object.defineProperty(exports,"Subject",{enumerable:!0,get:function(){return e.Subject}}),Object.defineProperty(exports,"Subscription",{enumerable:!0,get:function(){return e.Subscription}}),Object.defineProperty(exports,"ValueSubject",{enumerable:!0,get:function(){return e.ValueSubject}}),exports.Player=yr,exports.SDK_VERSION="@vkontakte/videoplayer-core@2.0.39";
|