@vkontakte/videoplayer-core 2.0.38-dev.232ba7c.0 → 2.0.38-dev.9d78ba4.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @vkontakte/videoplayer-core v2.0.38-dev.232ba7c.0
3
- * Thu, 23 Dec 2021 12:10:32 GMT
2
+ * @vkontakte/videoplayer-core v2.0.38-dev.9d78ba4.0
3
+ * Thu, 23 Dec 2021 18:35:54 GMT
4
4
  * https://st.mycdn.me/static/playersdk/2-0-38/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=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_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";var d=function(){return(d=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 l(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 c(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 p(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 h(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 f(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 v,m,S={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},dash:{extraInitSize:1e3,forwardBufferTarget:3e4,segmentRequestSize:1048576,representationSwitchForwardBufferGap:3e3},enableTelemetryAtStart:!1,formatsToAvoid:[exports.VideoFormat.DASH_WEBM_VK],disableChromecast:!1,chromecastReceiverId:void 0,useWebmBigRequest:!0,bigRequestMinInitSize:51200,bigRequestMinDataSize:1048576,stripRangeHeader:!0,flushShortLoopedBuffers:!0,insufficientBufferRuleMargin:1e4,dashSeekInSegmentDurationThreshold:18e4,dashSeekInSegmentAlwaysSeekDelta:1e4,endGapTolerance:300},b=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(g),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}(),g=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"}(v||(v={})),function(e){e.NONE="none",e.DOWNLOADING="downloading",e.DOWNLOADED="downloaded",e.FED="fed"}(m||(m={}));var y,T,E=function(e){return l(void 0,void 0,void 0,(function(){var t,r,i;return c(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]}}))}))},P=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},k=function(t,r,i){return P(r,(function(){return t.loop}),(function(r){e.isNonNullable(r)&&(t.loop=r)}),{onError:i})},w=function(t,r,i,a){return P(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})},A=function(e,t){if(e.id===t)return!0;var r=h(t.split("|"),3);r[0];var i=r[1],a=r[2];return e.language===i&&e.label===a},x=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(P(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(P(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(P(r.textTrackCuesSettings,(function(){return{}}),(function(){var e,t;if(a.video)try{for(var r=p(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=p(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=f([],h(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=p(this.htmlTextTracksAsArray(!0)),n=a.next();!n.done;n=a.next()){var s=n.value;e.isNonNullable(t)&&A(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=p(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}(),N=function(e){var t=document.createElement("video");return t.setAttribute("crossorigin","anonymous"),t.setAttribute("playsinline","playsinline"),e.appendChild(t),t},$=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())},D=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}(),_=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}},I=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())},R=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,f([],h(["waiting","pause","canplay","canplaythrough","playing","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 _(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{play$:r("play"),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$:I(t),firstFrame$:$(t)}},C=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,(y=exports.VideoQuality||(exports.VideoQuality={})).INVARIANT="Invariant quality",y.Q_144P="144p",y.Q_240P="240p",y.Q_360P="360p",y.Q_480P="480p",y.Q_720P="720p",y.Q_1080P="1080p",y.Q_1440P="1440p",y.Q_2160P="2160p",y.Q_4320P="4320p";var L,O=((T={})[exports.VideoQuality.Q_144P]=144,T[exports.VideoQuality.Q_240P]=240,T[exports.VideoQuality.Q_360P]=360,T[exports.VideoQuality.Q_480P]=480,T[exports.VideoQuality.Q_720P]=720,T[exports.VideoQuality.Q_1080P]=1080,T[exports.VideoQuality.Q_1440P]=1440,T[exports.VideoQuality.Q_2160P]=2160,T[exports.VideoQuality.Q_4320P]=4320,T),V=function(e,t){return O[e]>O[t]},M=function(e,t){return O[e]<O[t]},B=Object.keys(O).sort((function(e,t){return M(e,t)?-1:1})),U=function(e,t){var r=e.width,i=e.height;return function(e,t){return void 0===t&&(t=.02),f([],h(B),!1).find((function(r){return O[r]*(1+t)>=e}))}(Math.min(r,i),t)},F=function(e){return e===exports.VideoQuality.INVARIANT},q=!1,H={},G=function(e){e(H)},Y=function(e,t){var r;q&&(H.meta=null!==(r=H.meta)&&void 0!==r?r:{},H.meta[e]=t)},j=function(){function e(e){this.name=e}return e.prototype.next=function(e){var t,r;if(q){H.series=null!==(t=H.series)&&void 0!==t?t:{};var i=null!==(r=H.series[this.name])&&void 0!==r?r:[];i.push([Date.now(),e]),H.series[this.name]=i}},e}(),z=new j("best_bitrate"),Q=function(t,r){var i,a,n=r.container,s=r.throughput,o=r.tuning,u=r.forwardBufferHealth,d=o.usePixelRatio&&null!==(i=window.devicePixelRatio)&&void 0!==i?i:1,l=o.limitByContainer&&n&&n.width>0&&n.height>0&&{width:n.width*d*o.containerSizeFactor,height:n.height*d*o.containerSizeFactor},c=l&&U(l,0),p=t.filter((function(e){return!F(e.quality)})).sort((function(e,t){return V(e.quality,t.quality)?-1:1})),h=p.filter((function(t){var r,i,a,n=!c||M(t.quality,c),d=!(e.isNonNullable(s)&&isFinite(s)&&e.isNonNullable(t.bitrate))||s>=t.bitrate*(r=null!=u?u:.5,i=o.bitrateFactorAtEmptyBuffer,a=o.bitrateFactorAtFullBuffer,(i-a)*Math.pow(2,-10*r)+a);return n&&d}))[0];return h&&h.bitrate&&z.next(h.bitrate),null!==(a=null!=h?h:p[p.length-1])&&void 0!==a?a:t[0]},W=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)},J=function(e){return new URL(e).hostname},K=function(t,r){return void 0===r&&(r=300),window.ResizeObserver?new e.Observable((function(i){var a=new ResizeObserver(u.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 a.observe(t),function(){return a.disconnect()}})):new e.Observable((function(e){var r=t.getBoundingClientRect(),i=r.width,a=r.height;e.next({width:i,height:a})}))},X=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}();!function(e){e[e.HEADER=0]="HEADER",e[e.PARAM=1]="PARAM"}(L||(L={}));var Z,ee,te,re=function(t,r,i,a,n,s){return void 0===a&&(a=L.HEADER),l(void 0,void 0,void 0,(function(){var o,u,p,f,v,m,S,b,g,y,T,E,P,k,w,A,x,N,$,D,_,I,R;return c(this,(function(C){switch(C.label){case 0:switch(o=new Headers(null===(x=null==s?void 0:s.fetchInit)||void 0===x?void 0:x.headers),u=t,a){case L.HEADER:o.append("Range",r+"-"+i);break;case L.PARAM:(p=new URL(u,location.href)).searchParams.append("bytes",r+"-"+i),u=p.toString();break;default:e.assertNever(a)}return f=null!==(N=null===performance||void 0===performance?void 0:performance.now())&&void 0!==N?N:Date.now(),[4,fetch(u,d(d({},null!==($=null==s?void 0:s.fetchInit)&&void 0!==$?$:{}),{headers:o}))];case 1:return v=C.sent(),m=null!==(D=null===performance||void 0===performance?void 0:performance.now())&&void 0!==D?D:Date.now(),null===(_=null==s?void 0:s.throughputEstimator)||void 0===_||_.addRawRtt(m-f),v.ok&&v.body?(S=h(v.body.tee(),2),b=S[0],g=S[1],y=b.getReader(),null===(I=null==s?void 0:s.throughputEstimator)||void 0===I||I.trackStream(g),T=parseInt(null!==(R=v.headers.get("Content-Length"))&&void 0!==R?R:"",10),E=0,P=new ArrayBuffer(T),k=new Uint8Array(P),w=new DataView(P),A=function(e){var t=e.done,r=e.value;return l(void 0,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return t?(null==n||n(w,E),[3,3]):[3,1];case 1:return r?(k.set(r,E),E+=r.byteLength,null==n||n(w,E),[4,null==y?void 0:y.read().then(A)]):[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},[4,null==y?void 0:y.read().then(A)]):[2,Promise.reject(new Error("Fetch error "+v.status+": "+v.statusText))];case 2:return C.sent(),[2,P]}}))}))},ie=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"}(ee||(ee={})),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"}(te||(te={}));var ae,ne=((Z={})[ee.EBML]={type:te.Master},Z[ee.EBMLVersion]={type:te.UnsignedInteger},Z[ee.EBMLReadVersion]={type:te.UnsignedInteger},Z[ee.EBMLMaxIDLength]={type:te.UnsignedInteger},Z[ee.EBMLMaxSizeLength]={type:te.UnsignedInteger},Z[ee.DocType]={type:te.String},Z[ee.DocTypeVersion]={type:te.UnsignedInteger},Z[ee.DocTypeReadVersion]={type:te.UnsignedInteger},Z[ee.Void]={type:te.Binary},Z[ee.Segment]={type:te.Master},Z[ee.SeekHead]={type:te.Master},Z[ee.Seek]={type:te.Master},Z[ee.SeekID]={type:te.Binary},Z[ee.SeekPosition]={type:te.UnsignedInteger},Z[ee.Info]={type:te.Master},Z[ee.TimestampScale]={type:te.UnsignedInteger},Z[ee.Duration]={type:te.Float},Z[ee.Tracks]={type:te.Master},Z[ee.Chapters]={type:te.Master},Z[ee.Cluster]={type:te.Master},Z[ee.Attachments]={type:te.Master},Z[ee.Tags]={type:te.Master},Z[ee.Cues]={type:te.Master},Z[ee.CuePoint]={type:te.Master},Z[ee.CueTime]={type:te.UnsignedInteger},Z[ee.CueTrackPositions]={type:te.Master},Z[ee.CueTrack]={type:te.UnsignedInteger},Z[ee.CueClusterPosition]={type:te.UnsignedInteger},Z[ee.CueRelativePosition]={type:te.UnsignedInteger},Z[ee.CueDuration]={type:te.UnsignedInteger},Z[ee.CueBlockNumber]={type:te.UnsignedInteger},Z[ee.CueCodecState]={type:te.UnsignedInteger},Z[ee.CueReference]={type:te.Master},Z[ee.CueRefTime]={type:te.UnsignedInteger},Z),se=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=oe(e,r),a=i in ne,n=a?ne[i].type:te.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))+oe(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}},oe=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},ue=function(t,r){switch(r){case te.SignedInteger:return t.getInt8(0);case te.UnsignedInteger:return oe(t);case te.Float:return 4===t.byteLength?t.getFloat32(0):t.getFloat64(0);case te.String:return new TextDecoder("ascii").decode(t);case te.UTF8:return new TextDecoder("utf-8").decode(t);case te.Date:return new Date(Date.UTC(2001,0)+t.getInt8(0)).getTime();case te.Master:case te.Binary:return t;default:e.assertNever(r)}},de=function(e,t){for(var r=0;r<e.byteLength;){var i=new DataView(e.buffer,e.byteOffset+r),a=se(i);if(!t(a))return;a.type===te.Master&&de(a.value,t),r=a.value.byteOffset-e.byteOffset+a.valueSize}},le=[ee.Info,ee.SeekHead,ee.Tracks,ee.Chapters,ee.Cluster,ee.Cues,ee.Attachments,ee.Tags],ce=function(e,t,r){return void 0===t&&(t=0),l(void 0,void 0,void 0,(function(){var i,a,n,s,o,u,d,l,p,h,f,v,m,S,b;return c(this,(function(c){switch(c.label){case 0:return i=e.initRange,a=i.from,n=i.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+=t,[4,re(e.url,s,o,L.PARAM,void 0,{throughputEstimator:r})];case 1:if(p=c.sent(),!function(e){if(e.getUint32(0)!==ee.EBML)return!1;var t=void 0,r=void 0,i=void 0,a=se(e);return de(a.value,(function(e){var a=e.tag,n=e.type,s=e.value;return a===ee.EBMLReadVersion?t=ue(s,n):a===ee.DocType?r=ue(s,n):a===ee.DocTypeReadVersion&&(i=ue(s,n)),!0})),(void 0===t||t<=1)&&void 0!==r&&"webm"===r&&(void 0===i||i<=2)}(h=new DataView(p,a-s,n-s)))throw new Error("Not a valid webm file");return f=pe(h),u&&void 0!==d&&void 0!==l?(v=new DataView(p,d-s,l-d),[3,5]):[3,2];case 2:return void 0===f.cuesSeekPosition?[3,4]:(m=f.segmentStart+f.cuesSeekPosition,1048576,[4,re(e.url,m,m+1048576,L.PARAM)]);case 3:return S=c.sent(),v=new DataView(S),[3,5];case 4:throw new ReferenceError("No way to load representation index");case 5:return b=he(v,f),[2,{dataView:new DataView(p),init:f,segments:b}]}}))}))},pe=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 de(t,(function(e){var t=e.tag,c=e.type,p=e.value,h=e.valueSize;if(t===ee.SeekID){var f=ue(p,c);l=oe(f)}else t!==ee.SeekPosition&&(l=void 0);return t===ee.Segment?(r=p.byteOffset,i=p.byteOffset+h):t===ee.Info?s=!0:t===ee.SeekHead?o=!0:t===ee.TimestampScale?a=ue(p,c):t===ee.Duration?n=ue(p,c):t===ee.SeekPosition&&l===ee.Cues?d=ue(p,c):s&&o&&le.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}},he=function(t,r){var i,a=!1,n=!1,s=function(t){return e.isNonNullable(t.time)&&e.isNonNullable(t.position)},o=[];return de(t,(function(e){var t=e.tag,r=e.type,u=e.value;switch(t){case ee.Cues:a=!0;break;case ee.CuePoint:i&&s(i)&&o.push(i),i={};break;case ee.CueTime:i&&(i.time=ue(u,r));break;case ee.CueTrackPositions:break;case ee.CueClusterPosition:i&&(i.position=ue(u,r));break;default:a&&le.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:m.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}}}))},fe=function(){function t(t,r,i,a){var n=a.throughputEstimator,s=a.tuning;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.throughputEstimator=n,this.tuning=s,this.initData=new Map,this.segments=new Map,this.representations=new Map(i.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 l(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,l,p,h=this;return c(this,(function(c){switch(c.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,ce(r,i,this.throughputEstimator)];case 1:return a=c.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})),l=u.at(-1),p=new DataView(n.buffer,n.byteOffset,u.length&&l?Math.min(l.byte.to-n.byteOffset+1,n.byteLength):n.byteLength-i),[4,this.appendDataToBuffer(p)];case 2:return c.sent(),this.segments.set(t,s.map((function(e){return d(d({},e),{status:e.byte.from>=n.byteOffset&&e.byte.to<n.byteOffset+n.byteLength?m.FED:m.NONE})}))),this.maintain(0),[2]}}))}))},t.prototype.switchTo=function(t){var r;return l(this,void 0,void 0,(function(){var i,a,n,s,o,u;return c(this,(function(d){switch(d.label){case 0:return t===this.downloadingRepresentationId?[2]:this.initData.has(t)?[3,4]:this.loadAllInitsPromise?[4,this.loadAllInitsPromise]:[3,2];case 1:return d.sent(),[3,4];case 2:return i=this.representations.get(t),e.assertNonNullable(i),[4,ce(i)];case 3:a=d.sent(),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),d.label=4;case 4:u=this.initData.get(t),e.assertNonNullable(u,"No init buffer for "+t),e.assertNonNullable(this.sourceBuffer),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 d.sent(),e.isNonNullable(this.playingRepresentationId)&&(null===(r=this.segments.get(this.playingRepresentationId))||void 0===r||r.forEach((function(e){e.status===m.FED&&(e.status=m.NONE)}))),this.downloadingRepresentationId=t,[2]}}))}))},t.prototype.maintain=function(t){return l(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d=this;return c(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=W(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!==m.FED||o.length||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===m.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===m.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===m.NONE)n.push(o);else if([m.DOWNLOADING,m.DOWNLOADED,m.FED].includes(o.status))break}return n},t.prototype.loadSegments=function(e,t){return l(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d=this;return c(this,(function(h){if(!e.length)return[2];r=e.at(0).byte.from,i=e.at(-1).byte.to;try{for(a=p(e),n=a.next();!n.done;n=a.next())n.value.status=m.DOWNLOADING}catch(e){o={error:e}}finally{try{n&&!n.done&&(u=a.return)&&u.call(a)}finally{if(o)throw o.error}}return s=this.abortController.signal,this.segmentDownloadPromise=this.segmentDownloadPromise.then((function(){return l(d,void 0,void 0,(function(){var a,n,o,u,d,l=this;return c(this,(function(c){switch(c.label){case 0:return[4,re(t.url,r,i,L.PARAM,(function(i,a){var n,o,u=function(e){if(e.status===m.DOWNLOADING&&e.byte.from-r>=0&&e.byte.to+1-r<=a){e.status=m.DOWNLOADED;var n=new DataView(i.buffer,i.byteOffset+e.byte.from-r,e.byte.to+1-e.byte.from);l.appendDataToBuffer(n,s).then((function(){l.playingRepresentationId=t.id,l.playingRepresentation$.next(l.playingRepresentationId),e.status=m.FED}))}};try{for(var d=p(e),c=d.next();!c.done;c=d.next()){u(c.value)}}catch(e){n={error:e}}finally{try{c&&!c.done&&(o=d.return)&&o.call(d)}finally{if(n)throw n.error}}}),{throughputEstimator:this.throughputEstimator,fetchInit:{signal:s}})];case 1:return a=c.sent(),n=e.at(-1),o=null===(d=this.segments.get(t.id))||void 0===d?void 0:d.at(-1),n&&o&&n.status===m.DOWNLOADING&&n===o&&(n.status=m.DOWNLOADED,u=new DataView(a,n.byte.from-r),this.appendDataToBuffer(u,s).then((function(){l.playingRepresentationId=t.id,l.playingRepresentation$.next(l.playingRepresentationId),n.status=m.FED}))),[2]}}))}))})).catch((function(t){var r,i;try{for(var a=p(e),n=a.next();!n.done;n=a.next()){var s=n.value;s.status===m.DOWNLOADING&&(s.status=m.NONE)}}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}ie(t)})).catch((function(e){return d.error$.next({id:"SegmentDownload",message:"Error when fetching segments",thrown:e})})),[2,this.segmentDownloadPromise]}))}))},t.prototype.loadAllInits=function(){return l(this,void 0,void 0,(function(){var e=this;return c(this,(function(t){return this.loadAllInitsPromise||(this.loadAllInitsPromise=Promise.all(Array.from(this.representations.entries()).map((function(t){var r=h(t,2),i=r[0],a=r[1];return e.initData.has(i)?Promise.resolve():ce(a).then((function(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 l(this,void 0,void 0,(function(){return c(this,(function(a){switch(a.label){case 0:if(e.assertNonNullable(this.sourceBuffer),i&&i.aborted)return[2];if(this.sourceBuffer.updating)return[3,2];try{this.sourceBuffer.appendBuffer(r)}catch(e){this.error$.next({id:"AppendBuffer",message:"Error appending data to buffer",thrown:e})}return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 1:return a.sent(),[3,5];case 2:return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 3:return a.sent(),[4,this.appendDataToBuffer(r,i)];case 4:a.sent(),a.label=5;case 5:return[2]}}))}))},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!==m.FED||t||(e.status=m.NONE)};try{for(var l=p(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 l(this,void 0,void 0,(function(){return c(this,(function(t){return[2,new Promise((function(t){return e?e.addEventListener("update",(function(){return t()})):t()}))]}))}))},t}(),ve=["timeupdate","progress","play","seeked","stalled"];!function(e){e.NONE="none",e.MANIFEST_LOADED="manifest_loaded",e.REPRESENTATION_SELECTED="representation_selected"}(ae||(ae={}));var me,Se=function(){function t(t){var r=this;this.element=null,this.source=null,this.manifest=null,this.subscription=new e.Subscription,this.state$=new X(ae.NONE),this.currentVideoRepresentation$=new e.ValueSubject(void 0),this.error$=new e.Subject,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}return t.prototype.initManifest=function(t,r){return l(this,void 0,void 0,(function(){var i,a=this;return c(this,(function(n){switch(n.label){case 0:return this.element=t,this.subscription.add(e.fromEvent(t,"waiting").subscribe((function(){t.duration-t.currentTime<a.tuning.endGapTolerance/1e3&&a.forceEnded$.next()}),(function(e){return a.error$.next({id:"ForceEnd",message:"Error when forcing stream end",thrown:e})}))),this.state$.startTransitionTo(ae.MANIFEST_LOADED),[4,(s=r,l(void 0,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return[4,fetch(s,null==o?void 0:o.fetchInit)];case 1:return[2,e.sent().text()]}}))}))).catch(ie)];case 1:return i=n.sent(),this.manifest=function(e,t){var r,i,a,n,s,o,u,d,l,c,f,m,S,b,g,y,T,E,P,k,w={representations:{video:[],audio:[],text:[]}},A=(new DOMParser).parseFromString(e,"application/xml").children[0].children[0].children,x=0;try{for(var N=p(A),$=N.next();!$.done;$=N.next()){var D=$.value,_=D.getAttribute("mimeType"),I=D.getAttribute("codecs"),R=null!==(s=D.getAttribute("contentType"))&&void 0!==s?s:null==_?void 0:_.split("/")[0],C=D.querySelectorAll("Representation");try{for(var L=(a=void 0,p(C)),O=L.next();!O.done;O=L.next()){var V=O.value,M=null!==(o=V.getAttribute("mimeType"))&&void 0!==o?o:_,B=null!==(d=null!==(u=V.getAttribute("codecs"))&&void 0!==u?u:I)&&void 0!==d?d:"",U=null!==(c=null!==(l=V.getAttribute("contentType"))&&void 0!==l?l:null==M?void 0:M.split("/")[0])&&void 0!==c?c:R,F=parseInt(null!==(f=V.getAttribute("width"))&&void 0!==f?f:"",10),q=parseInt(null!==(m=V.getAttribute("height"))&&void 0!==m?m:"",10),H=parseInt(null!==(S=V.getAttribute("bandwidth"))&&void 0!==S?S:"",10)/1e3,G=(null!==(b=V.getAttribute("id"))&&void 0!==b?b:(x++).toString(10))+"@"+("video"===U?q+"p":"audio"===U?H+"Kbps":B),Y=null!==(T=null===(y=null===(g=V.querySelector("BaseURL"))||void 0===g?void 0:g.textContent)||void 0===y?void 0:y.trim())&&void 0!==T?T:"",j=new URL(Y,t).toString(),z=h((null!==(P=null===(E=V.querySelector("SegmentBase Initialization"))||void 0===E?void 0:E.getAttribute("range"))&&void 0!==P?P:"").split("-").map((function(e){return parseInt(e,10)})),2),Q={from:z[0],to:z[1]},W=null===(k=V.querySelector("SegmentBase"))||void 0===k?void 0:k.getAttribute("indexRange"),J=h(W?W.split("-").map((function(e){return parseInt(e,10)})):[],2),K=J[0],X=J[1],Z=W?{from:K,to:X}:void 0;if(U&&M){var ee={video:v.VIDEO,audio:v.AUDIO,text:v.TEXT}[U];ee&&w.representations[ee].push({id:G,kind:ee,initRange:Q,indexRange:Z,bitrate:H,mime:M,codecs:B,width:F,height:q,url:j})}}}catch(e){a={error:e}}finally{try{O&&!O.done&&(n=L.return)&&n.call(L)}finally{if(a)throw a.error}}}}catch(e){r={error:e}}finally{try{$&&!$.done&&(i=N.return)&&i.call(N)}finally{if(r)throw r.error}}return w}(null!=i?i:"",r),this.state$.setState(ae.MANIFEST_LOADED),[2,this.manifest]}var s,o}))}))},t.prototype.initRepresentations=function(t,r){return l(this,void 0,void 0,(function(){var i,a,n,s,o,u,d=this;return c(this,(function(l){switch(l.label){case 0:return e.assertNonNullable(this.manifest),e.assertNonNullable(this.element),this.state$.startTransitionTo(ae.REPRESENTATION_SELECTED),this.source=new MediaSource,this.element.src=URL.createObjectURL(this.source),i={throughputEstimator:this.throughputEstimator,tuning:this.tuning.dash},this.videoBufferManager=new fe(v.VIDEO,this.source,this.manifest.representations.video,i),this.audioBufferManager=new fe(v.AUDIO,this.source,this.manifest.representations.audio,i),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=d.source)||void 0===e?void 0:e.readyState))try{null===(t=d.source)||void 0===t||t.endOfStream()}catch(e){d.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=d.source)||void 0===t?void 0:t.addEventListener("sourceopen",e)}))];case 1:l.sent(),l.label=2;case 2:return[4,Promise.all([this.videoBufferManager.startWith(t),this.audioBufferManager.startWith(r)])];case 3:l.sent(),this.state$.setState(ae.REPRESENTATION_SELECTED);try{for(a=p(ve),n=a.next();!n.done;n=a.next())s=n.value,this.subscription.add(e.fromEvent(this.element,s).subscribe(this.tick,(function(e){d.error$.next({id:"DashVKPlayer",message:"Internal logic error",thrown:e})})))}catch(e){o={error:e}}finally{try{n&&!n.done&&(u=a.return)&&u.call(a)}finally{if(o)throw o.error}}return this.tick(),[2]}}))}))},t.prototype.switchRepresentation=function(t,r){return l(this,void 0,void 0,(function(){var i,a;return c(this,(function(n){return i=(a={},a[v.VIDEO]=this.videoBufferManager,a[v.AUDIO]=this.audioBufferManager,a[v.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(ae.NONE)},t.prototype.destroy=function(){var e,t,r;this.subscription.unsubscribe(),this.stop();try{for(var i=p(ve),a=i.next();!a.done;a=i.next()){var n=a.value;null===(r=this.element)||void 0===r||r.removeEventListener(n,this.tick)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}this.source=null},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(me||(me={}));var be,ge=function(e){var t=e.id,r=e.width,i=e.height,a=e.bitrate,n=U({width:r,height:i});return n&&{id:t,quality:n,bitrate:a,size:{width:r,height:i}}},ye=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)},Te=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(me.STOPPED),this.elementSize$=new e.ValueSubject(void 0),this.textTracksManager=new x,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!==me.STOPPED&&i!==exports.PlaybackState.STOPPED&&r.seek(s),i!==exports.PlaybackState.STOPPED){if(t===me.STOPPED)return r.videoState.startTransitionTo(me.READY),void r.prepare();switch(t){case me.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(me.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(me.PLAYING),r.playIfAllowed()));case me.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(me.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case me.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(me.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}else t!==me.STOPPED&&(r.videoState.startTransitionTo(me.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(me.STOPPED),C(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))}},this.params=t,this.video=N(this.params.container),this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(J(this.params.source.url)),this.params.output.isLive$.next(!1),this.player=new Se({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=R(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.firstBytes$,i.firstBytesEvent$),o(n.firstFrame$,i.firstFrameEvent$),this.subscription.add(n.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}),s)),this.subscription.add(k(this.video,a.isLooped,s)),this.subscription.add(w(this.video,a.volume,n.volumeState$,s)),this.subscription.add(n.volumeState$.subscribe(this.params.output.volume$,s)),this.subscription.add(n.play$.subscribe((function(){t.videoState.setState(me.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),s)).add(n.pause$.subscribe((function(){t.videoState.setState(me.PAUSED),C(a.playbackState,exports.PlaybackState.PAUSED)}),s)).add(n.canplay$.subscribe((function(){t.videoState.getState()===me.PLAYING&&t.playIfAllowed()}),s)),this.subscription.add(this.player.state$.stateChangeEnded$.pipe(e.filter((function(e){return e.to===ae.REPRESENTATION_SELECTED}))).subscribe((function(){t.videoState.setState(me.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!==ae.NONE&&t.videoTracks.length){var u=s===ae.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=W(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=Q(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});if(u){var m=null!=c?c:f,S=m&&(null===(i=t.videoTracks.find((function(e){return e.track===m})))||void 0===i?void 0:i.representation);e.assertNonNullable(S);var b=ye(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);e.assertNonNullable(b),t.player.initRepresentations(S.id,b.id)}else{var g=d?null!=f?f:c:null!=c?c:f;if(S=g&&(null===(n=t.videoTracks.find((function(e){return e.track===g})))||void 0===n?void 0:n.representation)){b=ye(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);t.player.switchRepresentation(v.VIDEO,S.id),b&&t.player.switchRepresentation(v.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$)),o(K(this.video),this.elementSize$),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 l(this,void 0,void 0,(function(){var e,t,r,i,a,n,s;return c(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=p(e.representations.video),r=t.next();!r.done;r=t.next())i=r.value,(a=ge(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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),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;E(this.video).then((function(t){t||(e.videoState.setState(me.PAUSED),C(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"}(be||(be={}));var Ee,Pe=function(t,r,i){switch(void 0===r&&(r=0),void 0===i&&(i=be.OFFSET_P),i){case be.OFFSET_P:return t.replace("_offset_p",0===r?"":"_"+r.toFixed(0));case be.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"}(Ee||(Ee={}));var ke,we=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.loadMediaTimeoutSubscription=new e.Subscription,this.videoState=new X(Ee.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!==Ee.STOPPED)return r.params.desiredState.seekPosition.setState(o),r.params.desiredState.seekPosition.startTransitionTo(void 0),void r.seek(o);switch(a){case exports.PlaybackState.PLAYING:switch(t){case Ee.PLAYING:break;case Ee.PAUSED:case Ee.READY:r.videoState.startTransitionTo(Ee.PLAYING),r.params.connection.remotePlayerController.playOrPause();break;case Ee.STOPPED:r.videoState.startTransitionTo(Ee.READY),r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case Ee.PLAYING:r.videoState.startTransitionTo(Ee.PAUSED),r.params.connection.remotePlayerController.playOrPause();break;case Ee.PAUSED:break;case Ee.READY:r.videoState.startTransitionTo(Ee.PAUSED),r.videoState.setState(Ee.PAUSED);break;case Ee.STOPPED:r.videoState.startTransitionTo(Ee.READY),r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(a)}}}else t!==Ee.STOPPED&&(r.videoState.startTransitionTo(Ee.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_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(e){t.params.desiredState.seekPosition.setState(e),t.params.desiredState.seekPosition.startTransitionTo(void 0),t.params.desiredState.seekPosition.setState(void 0)})));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)?t.params.desiredState.seekPosition.setState(void 0):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(),C(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(Ee.PAUSED),C(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):(this.videoState.setState(Ee.PLAYING),C(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)!==Ee.PAUSED&&e!==Ee.PLAYING||(this.videoState.setState(Ee.PAUSED),C(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)!==Ee.PLAYING&&e!==Ee.PAUSED||(this.videoState.setState(Ee.PLAYING),C(this.params.desiredState.playbackState,exports.PlaybackState.PLAYING))},t.prototype.handleRemoteReady=function(){var e=this.videoState.getTransition();(null==e?void 0:e.to)===Ee.READY&&this.videoState.setState(Ee.READY)},t.prototype.handleRemoteStop=function(){this.videoState.getState()!==Ee.STOPPED&&this.videoState.setState(Ee.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){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:M(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_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=Pe(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"}(ke||(ke={}));var Ae,xe=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(ke.STOPPED),this.trackUrls={},this.textTracksManager=new x,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===ke.STOPPED)return r.videoState.startTransitionTo(ke.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 ke.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(ke.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(ke.PLAYING),r.playIfAllowed()));case ke.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(ke.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case ke.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(ke.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==ke.STOPPED&&(r.videoState.startTransitionTo(ke.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(ke.STOPPED),C(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=N(t.container),this.params.output.element$.next(this.video),Object.entries(this.params.source).forEach((function(e,t){var i=h(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=R(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$),this.subscription.add(s.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}),n)),this.subscription.add(k(this.video,a.isLooped,n)),this.subscription.add(w(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.subscription.add(s.play$.subscribe((function(){t.videoState.setState(ke.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(ke.PAUSED),C(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)===ke.READY&&t.videoState.setState(ke.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()===ke.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(J(a))},t.prototype.playIfAllowed=function(){var e=this;E(this.video).then((function(t){t||(e.videoState.setState(ke.PAUSED),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),this.video.currentTime=e},t}(),Ne=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{t._xhr.readyState>=2&&!r&&(r=!0,null===(o=t._headersCb)||void 0===o||o.call(t)),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,r,i;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 a=void 0;t._failoverIndex>=t._failoverHosts.length?(a=t._url,t._failoverIndex=0):(a=t._url.replace((r=t._url,(i=document.createElement("a")).href=r,i.host),t._failoverHosts[t._failoverIndex]),t._failoverIndex++),t._xhr.open("GET",a,!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}(),$e=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=Date.now(),p=0,h=i-r+1,f=function(t){a(e._str2ua(t.substr(d))),d=t.length};u._lastXhr=new Ne(t.baseURL+"&bytes="+r+"-"+i,t.failoverHosts,(function(e){u._lastXhr=void 0,f(e);var t=Date.now()-l;u._params.onBandwidthChange({size:h,duration:t,speed:8*h/(t/1e3)}),u._onDashCallback("loading",{size:e.length,done:!0}),null==n||n()}),(function(e){e.length-d>o&&f(e);var t=e.length-p,r=Date.now()-c;p&&u._params.onBandwidthChange({size:t,duration:r,speed:8*t/(r/1e3)}),p=e.length,c=Date.now(),u._onDashCallback("loading",{size:e.length,done:!1})}),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._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}(),De=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 Ne(e,t,(function(i){var a,n;r.attachManifest(i,t,(a=e,(n=document.createElement("a")).href=a,n.origin))}),void 0,void 0,(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],A=w&&n(w,"range").split("-");if(A&&k){var x=Number(null===(p=e.attributes.getNamedItem("bandwidth"))||void 0===p?void 0:p.value),N=(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:x,baseURL:N,failoverHosts:t,indexFrom:Number(k[0]),indexTo:Number(k[1]),initFrom:Number(A[0]),initTo:Number(A[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*x/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 $=e.parentElement;if("text"===(null==$?void 0:$.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),I=null!==(c=$.getAttribute("lang"))&&void 0!==c?c:void 0;_&&o.push({id:D,url:_,language:I})}}})),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(){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 $e({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()}),void 0,e.bufferSize)}}))},t.prototype.setQualityByRepresentation=function(e){var t=this,r=this._buffer.getByTime(this._video.currentTime),i=this._findRef(this._video.currentTime);if(r&&i){var a=.1;if(i.toTime<r.end+a){var n=this._findRef(i.toTime);n&&n.toTime<r.end+a?(this._buffer.smartRemove(i.fromTime-a,n.toTime+a,(function(e,r){return t._stream.remove(e,r)})),this._loadRef(e,n.toTime)):(this._buffer.smartRemove(i.fromTime-a,i.toTime+a,(function(e,r){return t._stream.remove(e,r)})),this._loadRef(e,i.toTime))}}},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"}(Ae||(Ae={}));var _e,Ie=[Ae.PAUSED,Ae.PLAYING],Re=function(){function t(t){var r=this;this.videoState=new X(Ae.STOPPED),this.subscription=new e.Subscription,this.representations$=new e.ValueSubject([]),this.currentRepresentation$=new e.ValueSubject(void 0),this.textTracksManager=new x,this.elementSize$=new e.ValueSubject(void 0),this.dashLiteEvents={idxRequestPing$: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=p(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=U(d),h=d.bandwidth/1e3,f={width:d.width,height:d.height};if(c){var v={id:l,quality:c,bitrate:h,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(Ae.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)&&Ie.includes(t)&&r.seek(o),t){case Ae.STOPPED:return r.videoState.startTransitionTo(Ae.MANIFEST_LOADED),void r.prepare();case Ae.MANIFEST_LOADED:return void r.videoState.startTransitionTo(Ae.INITIAL_REPRESENTATION_SELECTED);case Ae.INITIAL_REPRESENTATION_SELECTED:return r.videoState.startTransitionTo(Ae.METADATA_LOADED),void r.dash.startPlay(r.selectRepresentation());case Ae.METADATA_LOADED:return r.videoState.startTransitionTo(Ae.READY),void r.dash.seek(null!=o?o:0);case Ae.READY:return void(a===exports.PlaybackState.PAUSED?(r.videoState.setState(Ae.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):a===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Ae.PLAYING),r.playIfAllowed()));case Ae.PLAYING:return void(a===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(Ae.PAUSED),r.video.pause()):(null==n?void 0:n.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case Ae.PAUSED:return void(a===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(Ae.PLAYING),r.playIfAllowed()):(null==n?void 0:n.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==Ae.STOPPED&&(r.videoState.startTransitionTo(Ae.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(Ae.STOPPED),C(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=N(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(J(this.params.source.url)),this.buffer=new D(this.video),this.dash=new De({video:this.video,buffer:this.buffer,selectRepresentation:this.selectRepresentation,onIdxRequestPing:function(e){return r.dashLiteEvents.idxRequestPing$.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=R(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.firstFrame$,i.firstFrameEvent$),this.subscription.add(s.seeking$.subscribe((function(){e.isNullable(t.params.desiredState.seekPosition.getTransition())&&(t.videoState.getState()===Ae.PLAYING||t.videoState.getState()===Ae.PAUSED)&&t.dash.updateRefsForCurrentTime()}))),this.subscription.add(s.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}))),this.subscription.add(k(this.video,a.isLooped,n)),this.subscription.add(w(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$)),this.textTracksManager.connect(this.video,a,i),o(K(this.video),this.elementSize$),this.subscription.add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===Ae.READY&&t.videoState.setState(Ae.READY)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(Ae.PAUSED),C(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED)}))).add(s.play$.subscribe((function(){t.videoState.setState(Ae.PLAYING),C(t.params.desiredState.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.loadedMetadata$.subscribe((function(){t.videoState.setState(Ae.METADATA_LOADED)}),n)).add(s.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$).pipe(e.map((function(){var r,i,a,n=t.representations$.getValue(),s=t.params.desiredState.autoVideoTrackSwitching.getState(),o=t.params.desiredState.autoVideoTrackSwitching.getTransition(),u=t.params.desiredState.videoTrack.getState(),d=t.params.desiredState.videoTrack.getTransition(),l=t.params.dependencies.throughputEstimator.rttAdjustedThroughput$.getValue(),c=t.elementSize$.getValue(),p=o?o.to:s;if(o&&t.params.desiredState.autoVideoTrackSwitching.setState(o.to),!p&&e.isNonNullable(u))a=u;else{var h=W(t.video.buffered,1e3*t.video.currentTime),f=Math.min(h/t.params.tuning.dash.forwardBufferTarget,1);a=d?d.to:null===(r=Q(n.map((function(e){return e.track})),{container:c,throughput:l,tuning:t.params.tuning.autoTrackSelection,forwardBufferHealth:f}))||void 0===r?void 0:r.id}return e.isNonNullable(a)?null===(i=n.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===Ae.INITIAL_REPRESENTATION_SELECTED}))),currentRepresentationSelected:this.currentRepresentation$.pipe(e.filter(e.isNonNullable))}).pipe(e.once()).subscribe((function(){return t.videoState.setState(Ae.INITIAL_REPRESENTATION_SELECTED)}),n)).add(this.currentRepresentation$.pipe(e.filter(e.isNonNullable),e.filterChanged()).subscribe((function(e){t.dash.setQualityByRepresentation(e),t.params.output.hostname$.next(J(e.baseURL))}),n)).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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),this.dash.seek(e)},t.prototype.playIfAllowed=function(){var e=this;E(this.video).then((function(t){t||(e.videoState.setState(Ae.PAUSED),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t}(),Ce=function(e){return e.range?e.range.split("-").map((function(e){return parseInt(e,10)})):[NaN,NaN]},Le=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 l(this,void 0,void 0,(function(){var e,t,r,i,a,n,s,o,u,d,l,f,v;return c(this,(function(c){try{for(e=p(this.dashJsRequestQueue.entries()),t=e.next();!t.done;t=e.next()){if(r=h(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=h(Ce(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){f={error:e}}finally{try{t&&!t.done&&(v=e.return)&&v.call(e)}finally{if(f)throw f.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=p(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(Ce),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 p=d.toString(),f=new AbortController,v=f.signal,m={url:t,from:n,to:s,loaded:0,data:null,abortController:f};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(p,{signal:v}).then((function(t){var r,a,n;if(t.ok&&t.body){var s=h(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(),p=parseInt(null!==(n=t.headers.get("Content-Length"))&&void 0!==n?n:"",10);m.data=new ArrayBuffer(p);var f=new Uint8Array(m.data),v=function(t){var r=t.done,a=t.value;return l(i,void 0,void 0,(function(){return c(this,(function(t){switch(t.label){case 0:return r?(this.onBigRequestProgress(m),[3,3]):[3,1];case 1:return a?(f.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,f=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=h(Ce(t),2),i=r[0],p=r[1],S=i>=c&&p<=c+v,b=c>=i&&c+v<p,y=m.slice(i-c,Math.min(p-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=f-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:f-c,lengthComputable:!0,stream:!0}))},g=this;try{for(var y=p(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 f=p(c),v=f.next();!v.done;v=f.next()){var m=v.value,S=h(Ce(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=f.return)&&i.call(f)}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=p(u),l=d.next();!l.done;l=d.next()){var c=l.value,f=h(Ce(c.request),2),v=f[0],m=f[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}(),Oe=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}(),Ve=function(e,t){var r=new Le(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 Oe(a,t,i)}}}}(e(t),r)}}}),!0),function(){return r.destroy()}},Me=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,f([],h(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,f([],h(e),!1))},a=Date.now(),n=!1}return t(e)}}}),!0),{playbackDuration$:r,ping$:i}},Be=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}(),Ue={};!function(e){e.DOWNLOADING_LIB="downloading_lib",e.STOPPED="stopped",e.STREAM_INITIALIZED="stream_initialized",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(_e||(_e={}));var Fe=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)}}))},qe=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(_e.DOWNLOADING_LIB),this.textTracksManager=new x,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 Be,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!==_e.DOWNLOADING_LIB&&t!==_e.STREAM_INITIALIZED){var o=null==n?void 0:n.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&t!==_e.STOPPED&&i!==exports.PlaybackState.STOPPED&&(s?r.seek(o+He(r.liveOffset.getTotalPausedTime())):r.seek(o)),i){case exports.PlaybackState.STOPPED:switch(t){case _e.STOPPED:break;case _e.PLAYING:case _e.PAUSED:case _e.READY:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case _e.PLAYING:break;case _e.PAUSED:s&&(r.liveOffset.getTotalPausedTime()<r.params.config.maxPausedTime&&r.liveOffset.getTotalOffset()<r.maxSeekBackTime$.getValue()?(r.liveOffset.resume(),r.params.output.position$.next(He(r.liveOffset.getTotalOffset()))):r.seek(He(r.liveOffset.getTotalOffset()))),r.play();break;case _e.READY:r.play();break;case _e.STOPPED:r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case _e.PLAYING:r.pause(),r.liveOffset.pause();break;case _e.PAUSED:break;case _e.READY:r.videoState.setState(_e.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case _e.STOPPED:r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=N(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(J(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||(Ue.MediaPlayer=r.MediaPlayer,Ue.Debug=r.Debug,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){var t=this;e.assertNonNullable(Ue.MediaPlayer,"dashjs not loaded"),e.assertNonNullable(Ue.Debug,"dashjs not loaded"),this.player=Ue.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=Ve(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=h(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),this.player.clearDefaultUTCTimingSources(),this.subscribe(),this.videoState.setState(_e.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(K(this.video),this.elementSize$),s(Fe(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(Fe(this.player,"playbackError").pipe(e.map((function(e){return{id:"DashJSPlayback",message:e.error}}))),i.error$);var o=Fe(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===_e.STREAM_INITIALIZED})),e.once()).subscribe((function(){t.subscription.add(P(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(P(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(Fe(this.player,"bufferStateChanged").pipe(e.filter((function(e){return"video"===e.mediaType})),e.map((function(e){return"bufferStalled"===e.state}))),i.isBuffering$),s(Fe(this.player,"fragmentLoadingStarted").pipe(e.map((function(e){return J(e.request.url)}))),i.hostname$),s(Fe(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 h=p(t.player.getBitrateInfoListFor("video")),f=h.next();!f.done;f=h.next()){var v=f.value,m=v.qualityIndex.toString(10),S=U(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=h.return)&&a.call(h)}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(_e.STREAM_INITIALIZED),t.videoState.startTransitionTo(_e.READY)})),s(Fe(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=Q(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 He(t)}))),this.params.output.duration$);var u=Fe(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(Fe(this.player,"playbackSeeked"),(function(){return a.seekPosition.setState(void 0)})),s(Fe(this.player,"playbackEnded"),i.endedEvent$),s(Fe(this.player,"playbackProgress").pipe(e.map((function(){return _(t.video.buffered,t.video.currentTime)}))),i.currentBuffer$),s(Fe(this.player,"playbackPlaying"),(function(){t.videoState.setState(_e.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)})),s(Fe(this.player,"playbackNotAllowed"),(function(){t.player.isMuted()?(t.player.setMute(!1),t.videoState.setState(_e.PAUSED),C(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)):(t.player.setMute(!0),t.player.play())})),s(Fe(this.player,"playbackPaused"),(function(){t.videoState.setState(_e.PAUSED),C(a.playbackState,exports.PlaybackState.PAUSED)})),s(Fe(this.player,"canPlay"),(function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===_e.READY&&t.videoState.setState(_e.READY)})),s(this.isLive$,i.isLive$),s(K(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=Me(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(Fe(this.player,"manifestLoaded").pipe(e.once()).subscribe((function(){var r=Date.now();t.subscription.add(Fe(t.player,"playbackPlaying").pipe(e.once()).subscribe((function(){return i.firstFrameEvent$.next(Date.now()-r)}),n))}),n)),this.subscription.add(k(this.video,a.isLooped,n));var h=R(this.video).volumeState$;this.subscription.add(w(this.video,a.volume,h,n)),this.subscription.add(h.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(_e.STOPPED),C(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t.prototype.prepare=function(){this.videoState.startTransitionTo(_e.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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),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(He(r));var i=Pe(this.params.source.url,this.liveOffset.getTotalOffset()/1e3,be.PLAYBACK_SHIFT);this.player.attachSource(i)}else this.player.seek(e)},t.prototype.play=function(){this.videoState.startTransitionTo(_e.PLAYING),this.player.play()},t.prototype.pause=function(){this.videoState.startTransitionTo(_e.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}(),He=function(e){return-e/1e3};function Ge(){return window.performance?window.performance.now():Date.now()}function Ye(e){return Ge()-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 ze(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=Ye(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=Ge(),(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=Ge();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=Ge(),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 Qe,We=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}(),Je=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=Ge();e._request=ze(t,(function(a){e._complete=1,e._responseData=a,e._downloadTime=Ge()-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=Ge()},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=Ge();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}(),Ke=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 We(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 Je(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=Ge()-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=ze(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,A=m(t.jidxUrl),x=0,N=function(){f&&(clearTimeout(f),f=void 0);var e=Math.max(500,1e3*(r._getBufferSizeSec()-r.sourceJitter-5)),t=x+e,i=Ge(),a=Math.min(1e4,t-i);x=i;var n=function(){c||h()&&A.seek((function(){h()&&(x=Ge(),$(),N())}))};a>0?f=window.setTimeout((function(){r.paused?N():n()}),a):n()},$=function(){for(var e;e=A.nextChunk(p);)p=e,C(e);var i=A.nextChunk(s);if(i){if(s&&i.discontinuity)return w("Detected discontinuity; restarting playback"),void(r.paused?N():(S(),r._initPlayerWith(t)));R(i)}else N()},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=Ge(),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,$()})))},I=function(e){return t.fragUrlTemplate.replace("%%id%%",e.chunkIdx)},R=function(t){var i,a,o;h()&&(i=I(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(I(t),!1)))},L=function(e){h()&&(t.cachedHeader=e,D(e,(function(){a=!0,_()})))};o=!0,A.seek((function(t){h()&&(x=Ge(),t?(p=t,!e.isNullable(i)||t.startTS>i?R(t):(s=t,$())):N())}),i),t.cachedHeader?L(t.cachedHeader):(y=t.headerUrl,T=L,E=function(){return r._handleNetworkError()},l&&l.abort(),l=ze(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=Ge();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&&Ye(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=Ge();t<e&&(s=r),e=t}}},t.prototype._fetchManifest=function(e,t,r){var i=this;this.manifestRequest=ze(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;E(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"}(Qe||(Qe={}));var Xe,Ze=[Qe.PAUSED,Qe.PLAYING,Qe.READY],et=[Qe.PAUSED,Qe.PLAYING,Qe.READY],tt=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(Qe.STOPPED),this.representations$=new e.ValueSubject([]),this.textTracksManager=new x,this.maxSeekBackTime$=new e.ValueSubject(1/0),this.zeroTime$=new e.ValueSubject(void 0),this.liveOffset=new Be,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 l=t.manifest,c=[];try{for(var h=p(l),f=h.next();!f.done;f=h.next()){var v=f.value,m=null!==(n=v.name)&&void 0!==n?n:v.index.toString(10),S=U(v.video),b=v.bitrate/1e3,g=d({},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=h.return)&&a.call(h)}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)===Qe.MANIFEST_READY&&r.videoState.setState(Qe.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(et.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)&&Ze.includes(i))r.seek(l+rt(r.liveOffset.getTotalPausedTime()));else switch(i){case Qe.STOPPED:return r.videoState.startTransitionTo(Qe.MANIFEST_READY),void r.dash.attachSource(Pe(r.params.source.url));case Qe.MANIFEST_READY:r.videoState.startTransitionTo(Qe.READY),r.prepare();break;case Qe.READY:return void(n===exports.PlaybackState.PAUSED?r.videoState.setState(Qe.PAUSED):n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Qe.PLAYING),r.dash.play((function(){r.liveOffset.pause(),r.videoState.setState(Qe.PAUSED)}))));case Qe.PLAYING:return void(n===exports.PlaybackState.PAUSED&&(r.videoState.startTransitionTo(Qe.PAUSED),r.liveOffset.pause(),r.dash.pause()));case Qe.PAUSED:return void(n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Qe.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(Qe.PAUSED)})),r.params.output.position$.next(rt(r.liveOffset.getTotalOffset()))):r.seek(rt(r.liveOffset.getTotalOffset()))));default:return e.assertNever(i)}}}else i!==Qe.STOPPED&&(r.videoState.startTransitionTo(Qe.STOPPED),r.dash.destroy(),r.video.setAttribute("src",""),r.video.load(),r.videoState.setState(Qe.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=N(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(J(this.params.source.url)),this.textTracksManager.connect(this.video,this.params.desiredState,this.params.output);var a=R(this.video);this.subscription.add(a.canplay$.subscribe((function(){var e;(null===(e=r.videoState.getTransition())||void 0===e?void 0:e.to)===Qe.READY&&r.videoState.setState(Qe.READY)}),i)).add(a.pause$.subscribe((function(){r.videoState.setState(Qe.PAUSED)}),i)).add(a.play$.subscribe((function(){r.videoState.setState(Qe.PLAYING)}),i)).add(a.error$.subscribe(this.params.output.error$)).add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(rt)).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(k(this.video,this.params.desiredState.isLooped,i)).add(w(this.video,this.params.desiredState.volume,a.volumeState$,i)).add(a.volumeState$.subscribe(this.params.output.volume$,i)).add(I(this.video).subscribe(this.params.output.firstBytesEvent$)).add($(this.video).subscribe(this.params.output.firstFrameEvent$)).add(this.videoState.stateChangeEnded$.subscribe((function(t){switch(t.to){case Qe.STOPPED:r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.desiredState.playbackState.setState(exports.PlaybackState.STOPPED);break;case Qe.MANIFEST_READY:case Qe.READY:break;case Qe.PAUSED:r.params.desiredState.playbackState.setState(exports.PlaybackState.PAUSED);break;case Qe.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 Ke({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=Q(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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0);var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(rt(r)),this.dash.reinit(Pe(this.params.source.url,r)),this.params.desiredState.seekPosition.setState(void 0)},t}(),rt=function(e){return-e/1e3},it=function(e){if(e.QUALITY)switch(e.QUALITY){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}if(e.RESOLUTION){var t=h(e.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),r=t[0],i=t[1],a=U({width:r,height:i});if(a)return a}return null},at=function(e,t){return void 0===t&&(t=e),l(void 0,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,l,p,f,v,m,S,b,g;return c(this,(function(c){switch(c.label){case 0:return[4,fetch(e)];case 1:return[4,c.sent().text()];case 2:for(r=c.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=it(u),p=void 0,u.BANDWIDTH&&(p=parseInt(u.BANDWIDTH,10)/1e3||void 0),!p&&u["AVERAGE-BANDWIDTH"]&&(p=parseInt(u["AVERAGE-BANDWIDTH"],10)/1e3||void 0),f=void 0,u.RESOLUTION&&(v=h(u.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),m=v[0],S=v[1],m&&S&&(f={width:m,height:S})),b=new URL(i[++n],t).toString(),l&&a.push({id:d,quality:l,url:b,bandwidth:p,size:f}));return[2,a]}}))}))};!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(Xe||(Xe={}));var nt,st=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(Xe.STOPPED),this.textTracksManager=new x,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===Xe.STOPPED)return r.videoState.startTransitionTo(Xe.READY),void r.prepare();if(n||s){var u=r.videoState.getState();r.videoState.setState(Xe.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 Xe.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(Xe.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Xe.PLAYING),r.playIfAllowed()));case Xe.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(Xe.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case Xe.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(Xe.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));case Xe.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==Xe.STOPPED&&(r.videoState.startTransitionTo(Xe.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(Xe.STOPPED),C(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=N(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(J(this.params.source.url)),at(this.params.source.url).then((function(e){r.manifests$.next(f([i],h(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=R(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$),this.subscription.add(s.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}),n)),this.subscription.add(k(this.video,a.isLooped,n)),this.subscription.add(w(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.play$.subscribe((function(){t.videoState.setState(Xe.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(Xe.PAUSED),C(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)===Xe.READY&&t.videoState.setState(Xe.READY),t.videoState.getState()===Xe.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(J(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===Xe.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;E(this.video).then((function(t){t||(e.videoState.setState(Xe.PAUSED),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),this.video.currentTime=e},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(nt||(nt={}));var ot,ut=function(){function t(t){var r,i=this;this.subscription=new e.Subscription,this.videoState=new X(nt.STOPPED),this.textTracksManager=new x,this.manifests$=new e.ValueSubject([]),this.liveOffset=new Be,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===nt.STOPPED)return i.videoState.startTransitionTo(nt.READY),void i.prepare();if(n||s){var u=i.videoState.getState();i.videoState.setState(nt.CHANGING_MANIFEST),i.videoState.startTransitionTo(u);var d=dt(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(nt.READY),i.seek(l+dt(i.liveOffset.getTotalPausedTime())),void i.prepare();switch(t){case nt.READY:return void(r===exports.PlaybackState.PAUSED?(i.videoState.setState(nt.PAUSED),i.liveOffset.pause(),C(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):r===exports.PlaybackState.PLAYING&&(i.videoState.startTransitionTo(nt.PLAYING),i.playIfAllowed()));case nt.PLAYING:return void(r===exports.PlaybackState.PAUSED?(i.videoState.startTransitionTo(nt.PAUSED),i.liveOffset.pause(),i.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(i.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case nt.PAUSED:return void(r===exports.PlaybackState.PLAYING?(i.videoState.startTransitionTo(nt.PLAYING),i.liveOffset.getTotalPausedTime()<i.params.config.maxPausedTime&&i.liveOffset.getTotalOffset()<i.maxSeekBackTime$.getValue()?(i.liveOffset.resume(),i.playIfAllowed(),i.params.output.position$.next(dt(i.liveOffset.getTotalOffset()))):i.seek(dt(i.liveOffset.getTotalOffset()))):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&(C(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED),i.liveOffset.pause()));case nt.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==nt.STOPPED&&(i.videoState.startTransitionTo(nt.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(nt.STOPPED),C(i.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=N(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]),at(Pe(this.params.source.url)).then((function(e){i.manifests$.next(f([a],h(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(J(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=R(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(w(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.play$.subscribe((function(){t.videoState.setState(nt.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(nt.PAUSED),C(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)===nt.READY&&t.videoState.setState(nt.READY),t.videoState.getState()===nt.PLAYING&&t.playIfAllowed()}),n)),this.subscription.add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(dt)).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(J(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===nt.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=Pe(r.url,this.liveOffset.getTotalOffset());this.video.setAttribute("src",a),this.video.load(),(i=a,l(void 0,void 0,void 0,(function(){var e;return c(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;E(this.video).then((function(t){t||(e.videoState.setState(nt.PAUSED),e.liveOffset.pause(),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0);var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(dt(r)),this.params.desiredState.seekPosition.setState(void 0)},t}(),dt=function(e){return-e/1e3},lt={};!function(e){e.INITIALIZING="initializing",e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(ot||(ot={}));var ct,pt,ht,ft,vt,mt,St,bt,gt,yt,Tt,Et,Pt,kt,wt,At,xt,Nt,$t,Dt,_t=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)}}))},It=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(ot.INITIALIZING),this.textTracksManager=new x,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!==ot.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 ot.STOPPED:break;case ot.READY:case ot.PLAYING:case ot.PAUSED:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case ot.PLAYING:break;case ot.STOPPED:r.prepare();break;case ot.READY:case ot.PAUSED:r.playIfAllowed();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case ot.PAUSED:break;case ot.STOPPED:r.prepare();break;case ot.READY:r.videoState.setState(ot.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case ot.PLAYING:r.pause();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=N(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.isLive$.next(!1),this.params.output.hostname$.next(J(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||(lt.Hls=r.default,lt.Events=r.default.Events,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){e.assertNonNullable(lt.Hls,"hls.js not loaded"),this.hls=new lt.Hls({fragLoadingMaxRetry:5,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetryTimeout:16e3,manifestLoadingMaxRetryTimeout:2e3,levelLoadingMaxRetryTimeout:2e3}),this.subscribe(),this.videoState.setState(ot.STOPPED)},t.prototype.subscribe=function(){var t=this;e.assertNonNullable(lt.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=R(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$),this.subscription.add(s.seeked$.subscribe((function(){return i.seekPosition.setState(void 0)}),n)),this.subscription.add(k(this.video,i.isLooped,n)),this.subscription.add(w(this.video,i.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$)),this.subscription.add(_t(this.hls,lt.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.play$.subscribe((function(){t.videoState.setState(ot.PLAYING),C(i.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(ot.PAUSED),C(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)===ot.READY&&t.videoState.setState(ot.READY),t.videoState.getState()===ot.PLAYING&&t.playIfAllowed()}),n)),o(_t(this.hls,lt.Events.MANIFEST_PARSED).pipe(e.map((function(e){return e.levels.reduce((function(e,r){var i=r.name||r.height.toString(10),a=r.width,n=r.height,s=U({width:a,height:n});if(!s)return e;var o={id:i.toString(),quality:s,bitrate:r.bitrate/1e3,size:{width:a,height:n}};return t.trackLevels.set(i,{track:o,level:r}),e.push(o),e}),[])}))),a.availableVideoTracks$),o(_t(this.hls,lt.Events.LEVEL_LOADING).pipe(e.map((function(e){var t=e.url;return J(t)}))),a.hostname$),this.subscription.add(P(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=_t(this.hls,lt.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(P(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(ot.READY),this.hls.attachMedia(this.video),this.hls.loadSource(this.params.source.url)},t.prototype.playIfAllowed=function(){return l(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return this.videoState.startTransitionTo(ot.PLAYING),[4,E(this.video)];case 1:return e.sent()||(this.videoState.setState(ot.PAUSED),C(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)),[2]}}))}))},t.prototype.pause=function(){this.videoState.startTransitionTo(ot.PAUSED),this.video.pause()},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),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(ot.STOPPED),C(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t}(),Rt=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}(),Ct=($t=window.navigator.userAgent,!/chrome/i.test($t)&&/webkit|safari|khtml/i.test($t)),Lt=(null===(pt=null===(ct=navigator)||void 0===ct?void 0:ct.userAgentData)||void 0===pt?void 0:pt.mobile)||/Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(navigator.appVersion),Ot=document.createElement("video"),Vt={mse:Boolean(window.MediaSource&&window.MediaStreamTrack&&(null===(ft=null===(ht=window.SourceBuffer)||void 0===ht?void 0:ht.prototype)||void 0===ft?void 0:ft.appendBuffer)),hls:Boolean((null===(vt=Ot.canPlayType)||void 0===vt?void 0:vt.call(Ot,"application/x-mpegurl"))||(null===(mt=Ot.canPlayType)||void 0===mt?void 0:mt.call(Ot,"vnd.apple.mpegURL")))},Mt={mp4:Boolean(null===(St=Ot.canPlayType)||void 0===St?void 0:St.call(Ot,"video/mp4")),webm:Boolean(null===(bt=Ot.canPlayType)||void 0===bt?void 0:bt.call(Ot,"video/webm"))},Bt={h264:Boolean(null===(yt=null===(gt=window.MediaSource)||void 0===gt?void 0:gt.isTypeSupported)||void 0===yt?void 0:yt.call(gt,'video/mp4; codecs="avc1.42000a,mp4a.40.2"')),h265:Boolean(null===(Et=null===(Tt=window.MediaSource)||void 0===Tt?void 0:Tt.isTypeSupported)||void 0===Et?void 0:Et.call(Tt,'video/mp4; codecs="hev1.1.6.L93.B0"')),vp9:Boolean(null===(kt=null===(Pt=window.MediaSource)||void 0===Pt?void 0:Pt.isTypeSupported)||void 0===kt?void 0:kt.call(Pt,'video/webm; codecs="vp9"')),aac:Boolean(null===(At=null===(wt=window.MediaSource)||void 0===wt?void 0:wt.isTypeSupported)||void 0===At?void 0:At.call(wt,'audio/mp4; codecs="mp4a.40.2"')),opus:Boolean(null===(Nt=null===(xt=window.MediaSource)||void 0===xt?void 0:xt.isTypeSupported)||void 0===Nt?void 0:Nt.call(xt,'audio/webm; codecs="opus"'))},Ut=(Bt.h264||Bt.h265)&&Bt.aac,Ft=!Ct,qt=Lt||Ct,Ht=!Vt.hls||!qt,Gt=3e4,Yt=18e4,jt=3,zt=100,Qt={cacheDuration:12e4},Wt={maxPausedTime:3e4,chunkDuration:5e3,optimalBufferDuration:1e4,maxParallelRequests:5},Jt={maxPausedTime:3e4},Kt={maxPausedTime:3e4},Xt=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,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),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?f(f([],h(t.screenFormatsPriority.filter((function(e){return!r.includes(e)}))),!1),h(t.screenFormatsPriority.filter((function(e){return r.includes(e)}))),!1):t.screenFormatsPriority;this.screenFormatsIterator=new Rt(i.filter((function(r){return e.isNonNullable(t.sources[r])})).filter((function(t){switch(t){case exports.VideoFormat.DASH:return Vt.mse&&Mt.mp4&&Ut&&Ft;case exports.VideoFormat.DASH_SEP:return Vt.mse&&Mt.mp4&&Ut;case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.DASH_LIVE_WEBM:return Vt.mse&&Mt.webm&&Bt.vp9&&Bt.opus;case exports.VideoFormat.DASH_LIVE:case exports.VideoFormat.DASH_ONDEMAND:return Vt.mse&&Mt.mp4&&Ut;case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_LIVE:case exports.VideoFormat.HLS_ONDEMAND:return Vt.hls&&Mt.mp4&&qt;case exports.VideoFormat.HLS_JS:return Vt.mse&&Mt.mp4&&Ut&&Ht;case exports.VideoFormat.MPEG:return Mt.mp4;default:return e.assertNever(t)}}))),this.chromecastFormatsIterator=new Rt(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 e=this.current$.getValue().provider;if(e){this.log({message:"destroyProvider"});var t=this.params.desiredState.seekPosition;t.getTransition()||t.startTransitionTo(this.providerOutput.position$.getValue()),e.destroy();var r=this.providerOutput.isBuffering$;r.getValue()||r.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 Re({container:a,source:o,desiredState:n,output:s,config:Qt,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_WEBM_VK:o=i[t];return e.assertNonNullable(o),new Te({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 qe({container:a,source:o,desiredState:n,output:s,format:t,config:Kt,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 st({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 ut({container:a,source:o,desiredState:n,output:s,config:Jt,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS_JS:o=i[t];return e.assertNonNullable(o),new It({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 xe({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 tt({container:a,source:o,desiredState:n,output:s,config:Wt,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 we({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:Gt,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(zt,{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]+Yt?(i=[],r.switchToNextProvider()):(i[a]=t,r.reinitProvider()),a=(a+1)%jt}))),s},t}(),Zt=function(e,t,r){return r*t+(1-r)*e},er=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 j("raw_"+i),this.smoothedSeries$=new j("smoothed_"+i),this.reportedSeries$=new j("reported_"+i)}return t.prototype.next=function(t){this.slow=Zt(this.slow,t,this.params.emaAlphaSlow),this.fast=Zt(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"}(Dt||(Dt={}));var tr=new Map,rr=Dt.RUNTIME,ir="vk-videoplayer-dummy-key-"+Math.random();!function(){try{localStorage.setItem(ir,"test"),localStorage.removeItem(ir),rr=Dt.LOCAL_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;try{sessionStorage.getItem(ir),rr=Dt.SESSION_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;rr=Dt.RUNTIME}}}();var ar,nr=function(t,r){switch(rr){case Dt.LOCAL_STORAGE:return localStorage.setItem(t,r);case Dt.SESSION_STORAGE:return sessionStorage.setItem(t,r);case Dt.RUNTIME:return void tr.set(t,r);default:e.assertNever(rr)}},sr=function(){var e,t;return null!==(t=null===(e=window.performance)||void 0===e?void 0:e.now())&&void 0!==t?t:Date.now()},or=window.navigator.connection,ur=function(){var t=null==or?void 0:or.downlink;if(e.isNonNullable(t)&&10!==t)return 1e3*t},dr=function(){var t=null==or?void 0:or.rtt;if(e.isNonNullable(t)&&3e3!==t)return t},lr=function(e,t,r){var i=8*r;return i/(i/e+t)},cr=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?ur():void 0)||5e3,o=null!==(a=null!==(i=t.load("one_video_rtt"))&&void 0!==i?i:r.useBrowserEstimation?dr():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(lr(s,o,r.rttPenaltyRequestSize)),this.throughput=new er({initial:s,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:-1,label:"throughput"}),this.rtt=new er({initial:o,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:1,label:"rtt"}),r.useBrowserEstimation){var u=function(){var t=ur();t&&n.throughput.next(t);var r=dr();e.isNonNullable(r)&&n.rtt.next(r)};or&&"onchange"in or&&this.subscription.add(e.fromEvent(or,"change").subscribe(u)),u()}this.subscription.add(this.throughput.smoothed$.subscribe((function(e){nr("one_video_throughput",e.toFixed(0))}))),this.subscription.add(this.rtt.smoothed$.subscribe((function(e){nr("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 lr(t,i,r.rttPenaltyRequestSize)})),e.filterChanged((function(e,t){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=sr(),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(e){i=e.loaded,a=sr()})));break;case 1:case 0:n.add(e.fromEvent(t,"loadstart").subscribe((function(){i=0,a=sr()})))}n.add(e.fromEvent(t,"loadend").subscribe((function(e){if(200===t.status){var s=e.loaded,o=sr(),u=s-i,d=o-a;r.addRawSpeed(u,d)}n.unsubscribe()})))},t.prototype.trackStream=function(e){var t=this,r=e.getReader();if(r){var i=0,a=sr(),n=0,s=sr(),o=function(t){r.releaseLock(),e.cancel("Throughput Estimator error: "+t).catch((function(){}))},u=function(e){var d=e.done,p=e.value;return l(t,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return d?(this.addRawSpeed(i,sr()-a),[3,3]):[3,1];case 1:return p?(i+=p.byteLength,(n+=p.byteLength)>=this.tuningConfig.streamMinSampleSize&&sr()-s>=this.tuningConfig.streamMinSampleTime&&(this.addRawSpeed(n,sr()-s),n=0,s=sr()),[4,null==r?void 0:r.read().then(u,o)]):[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))};null==r||r.read().then(u,o)}else e.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<1024)&&!(t<=50))))},t.load=function(t){var r,i=function(t){var r,i;switch(rr){case Dt.LOCAL_STORAGE:return null!==(r=localStorage.getItem(t))&&void 0!==r?r:void 0;case Dt.SESSION_STORAGE:return null!==(i=sessionStorage.getItem(t))&&void 0!==i?i:void 0;case Dt.RUNTIME:return tr.get(t);default:e.assertNever(rr)}}(t);if(e.isNonNullable(i))return null!==(r=parseInt(i,10))&&void 0!==r?r:void 0},t}(),pr=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)}})))}))}},hr=pr((function(e){return e})),fr=pr((function(e){return Math.round(1e3*e)+Date.now()})),vr=((ar={})[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,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]},ar[n.CHROMECAST]={vod:[exports.VideoFormat.DASH_WEBM_VK,exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_ONDEMAND,exports.VideoFormat.HLS,exports.VideoFormat.HLS_ONDEMAND,exports.VideoFormat.MPEG],live:[exports.VideoFormat.HLS_LIVE]},ar),mr=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 X(exports.PlaybackState.STOPPED),seekPosition:new X(void 0),volume:new X({volume:1,muted:!1}),videoTrack:new X(void 0),autoVideoTrackSwitching:new X(!0),isLooped:new X(!1),externalTextTracks:new X([]),currentTextTrack:new X(void 0),textTrackCuesSettings:new X({})},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),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),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:G},this.initLogs(),this.tuning=function(e){var t,r,i={};try{for(var a=p(Object.keys(S)),n=a.next();!n.done;n=a.next()){var s=n.value,o=S[s],u=e[s];Array.isArray(o)&&Array.isArray(u)?i[s]=u:i[s]="object"==typeof o&&"object"==typeof u?d(d({},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 b({receiverApplicationId:t.chromecastReceiverId,isDisabled:t.disableChromecast,dependencies:{logger:this.logger}}),this.throughputEstimator=new cr(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 Xt({screenFormatsPriority:f(f([],h(vr[n.SCREEN].live),!1),h(vr[n.SCREEN].vod),!1),chromecastFormatsPriority:f(f([],h(vr[n.CHROMECAST].live),!1),h(vr[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 d({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$)).add(this.desiredState.seekPosition.stateChangeEnded$.pipe(e.filter((function(e){return void 0===e.to})),e.mapTo(void 0)).subscribe(this.events.seeked$));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.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 F(e)?1:F(t)?-1:V(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.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)),this.desiredState.seekPosition.stateChangeEnded$.pipe(e.filter((function(e){return void 0!==e.from})),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.Subscription;this.subscription.add(i);var a=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),i.unsubscribe(),t){case!0:i.add(fr({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:a,position$:r.providerContainer.providerOutput.position$}).subscribe(r.events.watchCoverageLive$));break;case!1:i.add(hr({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:a,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=Q(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),H={},this.experimental.enableDebugTelemetry$.next(this.tuning.enableTelemetryAtStart),[this.experimental.enableDebugTelemetry$.subscribe((function(e){q=e})),this.providerContainer.current$.subscribe((function(e){var t=e.type;return Y("provider",t)})),i.duration$.subscribe((function(e){return Y("duration",e)})),i.availableVideoTracks$.pipe(e.filter((function(e){return!!e.length})),e.once()).subscribe((function(e){return Y("tracks",e)})),this.events.fatalError$.subscribe(new j("fatalError")),this.events.managedError$.subscribe(new j("managedError")),i.position$.subscribe(new j("position")),i.currentVideoTrack$.pipe(e.map((function(e){return null==e?void 0:e.quality}))).subscribe(new j("quality")),i.currentBuffer$.subscribe(new j("buffer")),i.isBuffering$.subscribe(new j("isBuffering"))].forEach((function(e){return r.subscription.add(e)})),Y("codecs",Object.keys(Bt).filter((function(e){return Bt[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=mr,exports.SDK_VERSION="@vkontakte/videoplayer-core@2.0.38-dev.232ba7c.0";
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=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_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";var d=function(){return(d=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 l(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 c(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 p(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 h(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 f(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 v,m,S={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},dash:{extraInitSize:1e3,forwardBufferTarget:3e4,segmentRequestSize:1048576,representationSwitchForwardBufferGap:3e3},enableTelemetryAtStart:!1,formatsToAvoid:[exports.VideoFormat.DASH_WEBM_VK],disableChromecast:!1,chromecastReceiverId:void 0,useWebmBigRequest:!0,bigRequestMinInitSize:51200,bigRequestMinDataSize:1048576,stripRangeHeader:!0,flushShortLoopedBuffers:!0,insufficientBufferRuleMargin:1e4,dashSeekInSegmentDurationThreshold:18e4,dashSeekInSegmentAlwaysSeekDelta:1e4,endGapTolerance:300},b=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(g),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}(),g=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"}(v||(v={})),function(e){e.NONE="none",e.DOWNLOADING="downloading",e.DOWNLOADED="downloaded",e.FED="fed"}(m||(m={}));var y,T,E=function(e){return l(void 0,void 0,void 0,(function(){var t,r,i;return c(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]}}))}))},P=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},k=function(t,r,i){return P(r,(function(){return t.loop}),(function(r){e.isNonNullable(r)&&(t.loop=r)}),{onError:i})},w=function(t,r,i,a){return P(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})},A=function(e,t){if(e.id===t)return!0;var r=h(t.split("|"),3);r[0];var i=r[1],a=r[2];return e.language===i&&e.label===a},x=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(P(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(P(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(P(r.textTrackCuesSettings,(function(){return{}}),(function(){var e,t;if(a.video)try{for(var r=p(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=p(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=f([],h(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=p(this.htmlTextTracksAsArray(!0)),n=a.next();!n.done;n=a.next()){var s=n.value;e.isNonNullable(t)&&A(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=p(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}(),N=function(e){var t=document.createElement("video");return t.setAttribute("crossorigin","anonymous"),t.setAttribute("playsinline","playsinline"),e.appendChild(t),t},$=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())},D=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}(),_=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}},I=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())},R=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,f([],h(["waiting","pause","canplay","canplaythrough","playing","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 _(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{play$:r("play"),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$:I(t),firstFrame$:$(t)}},C=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,(y=exports.VideoQuality||(exports.VideoQuality={})).INVARIANT="Invariant quality",y.Q_144P="144p",y.Q_240P="240p",y.Q_360P="360p",y.Q_480P="480p",y.Q_720P="720p",y.Q_1080P="1080p",y.Q_1440P="1440p",y.Q_2160P="2160p",y.Q_4320P="4320p";var L,O=((T={})[exports.VideoQuality.Q_144P]=144,T[exports.VideoQuality.Q_240P]=240,T[exports.VideoQuality.Q_360P]=360,T[exports.VideoQuality.Q_480P]=480,T[exports.VideoQuality.Q_720P]=720,T[exports.VideoQuality.Q_1080P]=1080,T[exports.VideoQuality.Q_1440P]=1440,T[exports.VideoQuality.Q_2160P]=2160,T[exports.VideoQuality.Q_4320P]=4320,T),V=function(e,t){return O[e]>O[t]},M=function(e,t){return O[e]<O[t]},B=Object.keys(O).sort((function(e,t){return M(e,t)?-1:1})),U=function(e,t){var r=e.width,i=e.height;return function(e,t){return void 0===t&&(t=.02),f([],h(B),!1).find((function(r){return O[r]*(1+t)>=e}))}(Math.min(r,i),t)},F=function(e){return e===exports.VideoQuality.INVARIANT},q=!1,H={},G=function(e){e(H)},Y=function(e,t){var r;q&&(H.meta=null!==(r=H.meta)&&void 0!==r?r:{},H.meta[e]=t)},j=function(){function e(e){this.name=e}return e.prototype.next=function(e){var t,r;if(q){H.series=null!==(t=H.series)&&void 0!==t?t:{};var i=null!==(r=H.series[this.name])&&void 0!==r?r:[];i.push([Date.now(),e]),H.series[this.name]=i}},e}(),z=new j("best_bitrate"),Q=function(t,r){var i,a,n=r.container,s=r.throughput,o=r.tuning,u=r.forwardBufferHealth,d=o.usePixelRatio&&null!==(i=window.devicePixelRatio)&&void 0!==i?i:1,l=o.limitByContainer&&n&&n.width>0&&n.height>0&&{width:n.width*d*o.containerSizeFactor,height:n.height*d*o.containerSizeFactor},c=l&&U(l,0),p=t.filter((function(e){return!F(e.quality)})).sort((function(e,t){return V(e.quality,t.quality)?-1:1})),h=p.filter((function(t){var r,i,a,n=!c||M(t.quality,c),d=!(e.isNonNullable(s)&&isFinite(s)&&e.isNonNullable(t.bitrate))||s>=t.bitrate*(r=null!=u?u:.5,i=o.bitrateFactorAtEmptyBuffer,a=o.bitrateFactorAtFullBuffer,(i-a)*Math.pow(2,-10*r)+a);return n&&d}))[0];return h&&h.bitrate&&z.next(h.bitrate),null!==(a=null!=h?h:p[p.length-1])&&void 0!==a?a:t[0]},W=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)},J=function(e){return new URL(e).hostname},K=function(t,r){return void 0===r&&(r=300),window.ResizeObserver?new e.Observable((function(i){var a=new ResizeObserver(u.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 a.observe(t),function(){return a.disconnect()}})):new e.Observable((function(e){var r=t.getBoundingClientRect(),i=r.width,a=r.height;e.next({width:i,height:a})}))},X=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}();!function(e){e[e.HEADER=0]="HEADER",e[e.PARAM=1]="PARAM"}(L||(L={}));var Z,ee,te,re=function(t,r,i,a,n,s){return void 0===a&&(a=L.HEADER),l(void 0,void 0,void 0,(function(){var o,u,p,f,v,m,S,b,g,y,T,E,P,k,w,A,x,N,$,D,_,I,R;return c(this,(function(C){switch(C.label){case 0:switch(o=new Headers(null===(x=null==s?void 0:s.fetchInit)||void 0===x?void 0:x.headers),u=t,a){case L.HEADER:o.append("Range",r+"-"+i);break;case L.PARAM:(p=new URL(u,location.href)).searchParams.append("bytes",r+"-"+i),u=p.toString();break;default:e.assertNever(a)}return f=null!==(N=null===performance||void 0===performance?void 0:performance.now())&&void 0!==N?N:Date.now(),[4,fetch(u,d(d({},null!==($=null==s?void 0:s.fetchInit)&&void 0!==$?$:{}),{headers:o}))];case 1:return v=C.sent(),m=null!==(D=null===performance||void 0===performance?void 0:performance.now())&&void 0!==D?D:Date.now(),null===(_=null==s?void 0:s.throughputEstimator)||void 0===_||_.addRawRtt(m-f),v.ok&&v.body?(S=h(v.body.tee(),2),b=S[0],g=S[1],y=b.getReader(),null===(I=null==s?void 0:s.throughputEstimator)||void 0===I||I.trackStream(g),T=parseInt(null!==(R=v.headers.get("Content-Length"))&&void 0!==R?R:"",10),E=0,P=new ArrayBuffer(T),k=new Uint8Array(P),w=new DataView(P),A=function(e){var t=e.done,r=e.value;return l(void 0,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return t?(null==n||n(w,E),[3,3]):[3,1];case 1:return r?(k.set(r,E),E+=r.byteLength,null==n||n(w,E),[4,null==y?void 0:y.read().then(A)]):[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},[4,null==y?void 0:y.read().then(A)]):[2,Promise.reject(new Error("Fetch error "+v.status+": "+v.statusText))];case 2:return C.sent(),[2,P]}}))}))},ie=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"}(ee||(ee={})),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"}(te||(te={}));var ae,ne=((Z={})[ee.EBML]={type:te.Master},Z[ee.EBMLVersion]={type:te.UnsignedInteger},Z[ee.EBMLReadVersion]={type:te.UnsignedInteger},Z[ee.EBMLMaxIDLength]={type:te.UnsignedInteger},Z[ee.EBMLMaxSizeLength]={type:te.UnsignedInteger},Z[ee.DocType]={type:te.String},Z[ee.DocTypeVersion]={type:te.UnsignedInteger},Z[ee.DocTypeReadVersion]={type:te.UnsignedInteger},Z[ee.Void]={type:te.Binary},Z[ee.Segment]={type:te.Master},Z[ee.SeekHead]={type:te.Master},Z[ee.Seek]={type:te.Master},Z[ee.SeekID]={type:te.Binary},Z[ee.SeekPosition]={type:te.UnsignedInteger},Z[ee.Info]={type:te.Master},Z[ee.TimestampScale]={type:te.UnsignedInteger},Z[ee.Duration]={type:te.Float},Z[ee.Tracks]={type:te.Master},Z[ee.Chapters]={type:te.Master},Z[ee.Cluster]={type:te.Master},Z[ee.Attachments]={type:te.Master},Z[ee.Tags]={type:te.Master},Z[ee.Cues]={type:te.Master},Z[ee.CuePoint]={type:te.Master},Z[ee.CueTime]={type:te.UnsignedInteger},Z[ee.CueTrackPositions]={type:te.Master},Z[ee.CueTrack]={type:te.UnsignedInteger},Z[ee.CueClusterPosition]={type:te.UnsignedInteger},Z[ee.CueRelativePosition]={type:te.UnsignedInteger},Z[ee.CueDuration]={type:te.UnsignedInteger},Z[ee.CueBlockNumber]={type:te.UnsignedInteger},Z[ee.CueCodecState]={type:te.UnsignedInteger},Z[ee.CueReference]={type:te.Master},Z[ee.CueRefTime]={type:te.UnsignedInteger},Z),se=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=oe(e,r),a=i in ne,n=a?ne[i].type:te.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))+oe(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}},oe=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},ue=function(t,r){switch(r){case te.SignedInteger:return t.getInt8(0);case te.UnsignedInteger:return oe(t);case te.Float:return 4===t.byteLength?t.getFloat32(0):t.getFloat64(0);case te.String:return new TextDecoder("ascii").decode(t);case te.UTF8:return new TextDecoder("utf-8").decode(t);case te.Date:return new Date(Date.UTC(2001,0)+t.getInt8(0)).getTime();case te.Master:case te.Binary:return t;default:e.assertNever(r)}},de=function(e,t){for(var r=0;r<e.byteLength;){var i=new DataView(e.buffer,e.byteOffset+r),a=se(i);if(!t(a))return;a.type===te.Master&&de(a.value,t),r=a.value.byteOffset-e.byteOffset+a.valueSize}},le=[ee.Info,ee.SeekHead,ee.Tracks,ee.Chapters,ee.Cluster,ee.Cues,ee.Attachments,ee.Tags],ce=function(e,t,r){return void 0===t&&(t=0),l(void 0,void 0,void 0,(function(){var i,a,n,s,o,u,d,l,p,h,f,v,m,S,b;return c(this,(function(c){switch(c.label){case 0:return i=e.initRange,a=i.from,n=i.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+=t,[4,re(e.url,s,o,L.PARAM,void 0,{throughputEstimator:r})];case 1:if(p=c.sent(),!function(e){if(e.getUint32(0)!==ee.EBML)return!1;var t=void 0,r=void 0,i=void 0,a=se(e);return de(a.value,(function(e){var a=e.tag,n=e.type,s=e.value;return a===ee.EBMLReadVersion?t=ue(s,n):a===ee.DocType?r=ue(s,n):a===ee.DocTypeReadVersion&&(i=ue(s,n)),!0})),(void 0===t||t<=1)&&void 0!==r&&"webm"===r&&(void 0===i||i<=2)}(h=new DataView(p,a-s,n-s)))throw new Error("Not a valid webm file");return f=pe(h),u&&void 0!==d&&void 0!==l?(v=new DataView(p,d-s,l-d),[3,5]):[3,2];case 2:return void 0===f.cuesSeekPosition?[3,4]:(m=f.segmentStart+f.cuesSeekPosition,1048576,[4,re(e.url,m,m+1048576,L.PARAM)]);case 3:return S=c.sent(),v=new DataView(S),[3,5];case 4:throw new ReferenceError("No way to load representation index");case 5:return b=he(v,f),[2,{dataView:new DataView(p),init:f,segments:b}]}}))}))},pe=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 de(t,(function(e){var t=e.tag,c=e.type,p=e.value,h=e.valueSize;if(t===ee.SeekID){var f=ue(p,c);l=oe(f)}else t!==ee.SeekPosition&&(l=void 0);return t===ee.Segment?(r=p.byteOffset,i=p.byteOffset+h):t===ee.Info?s=!0:t===ee.SeekHead?o=!0:t===ee.TimestampScale?a=ue(p,c):t===ee.Duration?n=ue(p,c):t===ee.SeekPosition&&l===ee.Cues?d=ue(p,c):s&&o&&le.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}},he=function(t,r){var i,a=!1,n=!1,s=function(t){return e.isNonNullable(t.time)&&e.isNonNullable(t.position)},o=[];return de(t,(function(e){var t=e.tag,r=e.type,u=e.value;switch(t){case ee.Cues:a=!0;break;case ee.CuePoint:i&&s(i)&&o.push(i),i={};break;case ee.CueTime:i&&(i.time=ue(u,r));break;case ee.CueTrackPositions:break;case ee.CueClusterPosition:i&&(i.position=ue(u,r));break;default:a&&le.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:m.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}}}))},fe=function(){function t(t,r,i,a){var n=a.throughputEstimator,s=a.tuning;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.throughputEstimator=n,this.tuning=s,this.initData=new Map,this.segments=new Map,this.representations=new Map(i.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 l(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,l,p,h=this;return c(this,(function(c){switch(c.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,ce(r,i,this.throughputEstimator)];case 1:return a=c.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})),l=u.at(-1),p=new DataView(n.buffer,n.byteOffset,u.length&&l?Math.min(l.byte.to-n.byteOffset+1,n.byteLength):n.byteLength-i),[4,this.appendDataToBuffer(p)];case 2:return c.sent(),this.segments.set(t,s.map((function(e){return d(d({},e),{status:e.byte.from>=n.byteOffset&&e.byte.to<n.byteOffset+n.byteLength?m.FED:m.NONE})}))),this.maintain(0),[2]}}))}))},t.prototype.switchTo=function(t){var r;return l(this,void 0,void 0,(function(){var i,a,n,s,o,u;return c(this,(function(d){switch(d.label){case 0:return t===this.downloadingRepresentationId?[2]:this.initData.has(t)?[3,4]:this.loadAllInitsPromise?[4,this.loadAllInitsPromise]:[3,2];case 1:return d.sent(),[3,4];case 2:return i=this.representations.get(t),e.assertNonNullable(i),[4,ce(i)];case 3:a=d.sent(),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),d.label=4;case 4:u=this.initData.get(t),e.assertNonNullable(u,"No init buffer for "+t),e.assertNonNullable(this.sourceBuffer),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 d.sent(),e.isNonNullable(this.playingRepresentationId)&&(null===(r=this.segments.get(this.playingRepresentationId))||void 0===r||r.forEach((function(e){e.status===m.FED&&(e.status=m.NONE)}))),this.downloadingRepresentationId=t,[2]}}))}))},t.prototype.maintain=function(t){return l(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d=this;return c(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=W(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!==m.FED||o.length||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===m.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===m.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===m.NONE)n.push(o);else if([m.DOWNLOADING,m.DOWNLOADED,m.FED].includes(o.status))break}return n},t.prototype.loadSegments=function(e,t){return l(this,void 0,void 0,(function(){var r,i,a,n,s,o,u,d=this;return c(this,(function(h){if(!e.length)return[2];r=e.at(0).byte.from,i=e.at(-1).byte.to;try{for(a=p(e),n=a.next();!n.done;n=a.next())n.value.status=m.DOWNLOADING}catch(e){o={error:e}}finally{try{n&&!n.done&&(u=a.return)&&u.call(a)}finally{if(o)throw o.error}}return s=this.abortController.signal,this.segmentDownloadPromise=this.segmentDownloadPromise.then((function(){return l(d,void 0,void 0,(function(){var a,n,o,u,d,l=this;return c(this,(function(c){switch(c.label){case 0:return[4,re(t.url,r,i,L.PARAM,(function(i,a){var n,o,u=function(e){if(e.status===m.DOWNLOADING&&e.byte.from-r>=0&&e.byte.to+1-r<=a){e.status=m.DOWNLOADED;var n=new DataView(i.buffer,i.byteOffset+e.byte.from-r,e.byte.to+1-e.byte.from);l.appendDataToBuffer(n,s).then((function(){l.playingRepresentationId=t.id,l.playingRepresentation$.next(l.playingRepresentationId),e.status=m.FED}))}};try{for(var d=p(e),c=d.next();!c.done;c=d.next()){u(c.value)}}catch(e){n={error:e}}finally{try{c&&!c.done&&(o=d.return)&&o.call(d)}finally{if(n)throw n.error}}}),{throughputEstimator:this.throughputEstimator,fetchInit:{signal:s}})];case 1:return a=c.sent(),n=e.at(-1),o=null===(d=this.segments.get(t.id))||void 0===d?void 0:d.at(-1),n&&o&&n.status===m.DOWNLOADING&&n===o&&(n.status=m.DOWNLOADED,u=new DataView(a,n.byte.from-r),this.appendDataToBuffer(u,s).then((function(){l.playingRepresentationId=t.id,l.playingRepresentation$.next(l.playingRepresentationId),n.status=m.FED}))),[2]}}))}))})).catch((function(t){var r,i;try{for(var a=p(e),n=a.next();!n.done;n=a.next()){var s=n.value;s.status===m.DOWNLOADING&&(s.status=m.NONE)}}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}ie(t)})).catch((function(e){return d.error$.next({id:"SegmentDownload",message:"Error when fetching segments",thrown:e})})),[2,this.segmentDownloadPromise]}))}))},t.prototype.loadAllInits=function(){return l(this,void 0,void 0,(function(){var e=this;return c(this,(function(t){return this.loadAllInitsPromise||(this.loadAllInitsPromise=Promise.all(Array.from(this.representations.entries()).map((function(t){var r=h(t,2),i=r[0],a=r[1];return e.initData.has(i)?Promise.resolve():ce(a).then((function(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 l(this,void 0,void 0,(function(){return c(this,(function(a){switch(a.label){case 0:if(e.assertNonNullable(this.sourceBuffer),i&&i.aborted)return[2];if(this.sourceBuffer.updating)return[3,2];try{this.sourceBuffer.appendBuffer(r)}catch(e){this.error$.next({id:"AppendBuffer",message:"Error appending data to buffer",thrown:e})}return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 1:return a.sent(),[3,5];case 2:return[4,t.waitForBufferUpdate(this.sourceBuffer)];case 3:return a.sent(),[4,this.appendDataToBuffer(r,i)];case 4:a.sent(),a.label=5;case 5:return[2]}}))}))},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!==m.FED||t||(e.status=m.NONE)};try{for(var l=p(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 l(this,void 0,void 0,(function(){return c(this,(function(t){return[2,new Promise((function(t){return e?e.addEventListener("update",(function(){return t()})):t()}))]}))}))},t}(),ve=["timeupdate","progress","play","seeked","stalled"];!function(e){e.NONE="none",e.MANIFEST_LOADED="manifest_loaded",e.REPRESENTATION_SELECTED="representation_selected"}(ae||(ae={}));var me,Se=function(){function t(t){var r=this;this.element=null,this.source=null,this.manifest=null,this.subscription=new e.Subscription,this.state$=new X(ae.NONE),this.currentVideoRepresentation$=new e.ValueSubject(void 0),this.error$=new e.Subject,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}return t.prototype.initManifest=function(t,r){return l(this,void 0,void 0,(function(){var i,a=this;return c(this,(function(n){switch(n.label){case 0:return this.element=t,this.subscription.add(e.fromEvent(t,"waiting").subscribe((function(){t.duration-t.currentTime<a.tuning.endGapTolerance/1e3&&a.forceEnded$.next()}),(function(e){return a.error$.next({id:"ForceEnd",message:"Error when forcing stream end",thrown:e})}))),this.state$.startTransitionTo(ae.MANIFEST_LOADED),[4,(s=r,l(void 0,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return[4,fetch(s,null==o?void 0:o.fetchInit)];case 1:return[2,e.sent().text()]}}))}))).catch(ie)];case 1:return i=n.sent(),this.manifest=function(e,t){var r,i,a,n,s,o,u,d,l,c,f,m,S,b,g,y,T,E,P,k,w={representations:{video:[],audio:[],text:[]}},A=(new DOMParser).parseFromString(e,"application/xml").children[0].children[0].children,x=0;try{for(var N=p(A),$=N.next();!$.done;$=N.next()){var D=$.value,_=D.getAttribute("mimeType"),I=D.getAttribute("codecs"),R=null!==(s=D.getAttribute("contentType"))&&void 0!==s?s:null==_?void 0:_.split("/")[0],C=D.querySelectorAll("Representation");try{for(var L=(a=void 0,p(C)),O=L.next();!O.done;O=L.next()){var V=O.value,M=null!==(o=V.getAttribute("mimeType"))&&void 0!==o?o:_,B=null!==(d=null!==(u=V.getAttribute("codecs"))&&void 0!==u?u:I)&&void 0!==d?d:"",U=null!==(c=null!==(l=V.getAttribute("contentType"))&&void 0!==l?l:null==M?void 0:M.split("/")[0])&&void 0!==c?c:R,F=parseInt(null!==(f=V.getAttribute("width"))&&void 0!==f?f:"",10),q=parseInt(null!==(m=V.getAttribute("height"))&&void 0!==m?m:"",10),H=parseInt(null!==(S=V.getAttribute("bandwidth"))&&void 0!==S?S:"",10)/1e3,G=(null!==(b=V.getAttribute("id"))&&void 0!==b?b:(x++).toString(10))+"@"+("video"===U?q+"p":"audio"===U?H+"Kbps":B),Y=null!==(T=null===(y=null===(g=V.querySelector("BaseURL"))||void 0===g?void 0:g.textContent)||void 0===y?void 0:y.trim())&&void 0!==T?T:"",j=new URL(Y,t).toString(),z=h((null!==(P=null===(E=V.querySelector("SegmentBase Initialization"))||void 0===E?void 0:E.getAttribute("range"))&&void 0!==P?P:"").split("-").map((function(e){return parseInt(e,10)})),2),Q={from:z[0],to:z[1]},W=null===(k=V.querySelector("SegmentBase"))||void 0===k?void 0:k.getAttribute("indexRange"),J=h(W?W.split("-").map((function(e){return parseInt(e,10)})):[],2),K=J[0],X=J[1],Z=W?{from:K,to:X}:void 0;if(U&&M){var ee={video:v.VIDEO,audio:v.AUDIO,text:v.TEXT}[U];ee&&w.representations[ee].push({id:G,kind:ee,initRange:Q,indexRange:Z,bitrate:H,mime:M,codecs:B,width:F,height:q,url:j})}}}catch(e){a={error:e}}finally{try{O&&!O.done&&(n=L.return)&&n.call(L)}finally{if(a)throw a.error}}}}catch(e){r={error:e}}finally{try{$&&!$.done&&(i=N.return)&&i.call(N)}finally{if(r)throw r.error}}return w}(null!=i?i:"",r),this.state$.setState(ae.MANIFEST_LOADED),[2,this.manifest]}var s,o}))}))},t.prototype.initRepresentations=function(t,r){return l(this,void 0,void 0,(function(){var i,a,n,s,o,u,d=this;return c(this,(function(l){switch(l.label){case 0:return e.assertNonNullable(this.manifest),e.assertNonNullable(this.element),this.state$.startTransitionTo(ae.REPRESENTATION_SELECTED),this.source=new MediaSource,this.element.src=URL.createObjectURL(this.source),i={throughputEstimator:this.throughputEstimator,tuning:this.tuning.dash},this.videoBufferManager=new fe(v.VIDEO,this.source,this.manifest.representations.video,i),this.audioBufferManager=new fe(v.AUDIO,this.source,this.manifest.representations.audio,i),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=d.source)||void 0===e?void 0:e.readyState))try{null===(t=d.source)||void 0===t||t.endOfStream()}catch(e){d.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=d.source)||void 0===t?void 0:t.addEventListener("sourceopen",e)}))];case 1:l.sent(),l.label=2;case 2:return[4,Promise.all([this.videoBufferManager.startWith(t),this.audioBufferManager.startWith(r)])];case 3:l.sent(),this.state$.setState(ae.REPRESENTATION_SELECTED);try{for(a=p(ve),n=a.next();!n.done;n=a.next())s=n.value,this.subscription.add(e.fromEvent(this.element,s).subscribe(this.tick,(function(e){d.error$.next({id:"DashVKPlayer",message:"Internal logic error",thrown:e})})))}catch(e){o={error:e}}finally{try{n&&!n.done&&(u=a.return)&&u.call(a)}finally{if(o)throw o.error}}return this.tick(),[2]}}))}))},t.prototype.switchRepresentation=function(t,r){return l(this,void 0,void 0,(function(){var i,a;return c(this,(function(n){return i=(a={},a[v.VIDEO]=this.videoBufferManager,a[v.AUDIO]=this.audioBufferManager,a[v.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(ae.NONE)},t.prototype.destroy=function(){var e,t,r;this.subscription.unsubscribe(),this.stop();try{for(var i=p(ve),a=i.next();!a.done;a=i.next()){var n=a.value;null===(r=this.element)||void 0===r||r.removeEventListener(n,this.tick)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}this.source=null},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(me||(me={}));var be,ge=function(e){var t=e.id,r=e.width,i=e.height,a=e.bitrate,n=U({width:r,height:i});return n&&{id:t,quality:n,bitrate:a,size:{width:r,height:i}}},ye=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)},Te=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(me.STOPPED),this.elementSize$=new e.ValueSubject(void 0),this.textTracksManager=new x,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!==me.STOPPED&&i!==exports.PlaybackState.STOPPED&&r.seek(s),i!==exports.PlaybackState.STOPPED){if(t===me.STOPPED)return r.videoState.startTransitionTo(me.READY),void r.prepare();switch(t){case me.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(me.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(me.PLAYING),r.playIfAllowed()));case me.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(me.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case me.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(me.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}else t!==me.STOPPED&&(r.videoState.startTransitionTo(me.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(me.STOPPED),C(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))}},this.params=t,this.video=N(this.params.container),this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(J(this.params.source.url)),this.params.output.isLive$.next(!1),this.player=new Se({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=R(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.firstBytes$,i.firstBytesEvent$),o(n.firstFrame$,i.firstFrameEvent$),this.subscription.add(n.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}),s)),this.subscription.add(k(this.video,a.isLooped,s)),this.subscription.add(w(this.video,a.volume,n.volumeState$,s)),this.subscription.add(n.volumeState$.subscribe(this.params.output.volume$,s)),this.subscription.add(n.play$.subscribe((function(){t.videoState.setState(me.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),s)).add(n.pause$.subscribe((function(){t.videoState.setState(me.PAUSED),C(a.playbackState,exports.PlaybackState.PAUSED)}),s)).add(n.canplay$.subscribe((function(){t.videoState.getState()===me.PLAYING&&t.playIfAllowed()}),s)),this.subscription.add(this.player.state$.stateChangeEnded$.pipe(e.filter((function(e){return e.to===ae.REPRESENTATION_SELECTED}))).subscribe((function(){t.videoState.setState(me.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!==ae.NONE&&t.videoTracks.length){var u=s===ae.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=W(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=Q(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});if(u){var m=null!=c?c:f,S=m&&(null===(i=t.videoTracks.find((function(e){return e.track===m})))||void 0===i?void 0:i.representation);e.assertNonNullable(S);var b=ye(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);e.assertNonNullable(b),t.player.initRepresentations(S.id,b.id)}else{var g=d?null!=f?f:c:null!=c?c:f;if(S=g&&(null===(n=t.videoTracks.find((function(e){return e.track===g})))||void 0===n?void 0:n.representation)){b=ye(t.audioRepresentations,t.videoTracks.map((function(e){return e.representation})),S);t.player.switchRepresentation(v.VIDEO,S.id),b&&t.player.switchRepresentation(v.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$)),o(K(this.video),this.elementSize$),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 l(this,void 0,void 0,(function(){var e,t,r,i,a,n,s;return c(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=p(e.representations.video),r=t.next();!r.done;r=t.next())i=r.value,(a=ge(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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),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;E(this.video).then((function(t){t||(e.videoState.setState(me.PAUSED),C(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"}(be||(be={}));var Ee,Pe=function(t,r,i){switch(void 0===r&&(r=0),void 0===i&&(i=be.OFFSET_P),i){case be.OFFSET_P:return t.replace("_offset_p",0===r?"":"_"+r.toFixed(0));case be.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"}(Ee||(Ee={}));var ke,we=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.loadMediaTimeoutSubscription=new e.Subscription,this.videoState=new X(Ee.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!==Ee.STOPPED)return r.params.desiredState.seekPosition.setState(o),r.params.desiredState.seekPosition.startTransitionTo(void 0),void r.seek(o);switch(a){case exports.PlaybackState.PLAYING:switch(t){case Ee.PLAYING:break;case Ee.PAUSED:case Ee.READY:r.videoState.startTransitionTo(Ee.PLAYING),r.params.connection.remotePlayerController.playOrPause();break;case Ee.STOPPED:r.videoState.startTransitionTo(Ee.READY),r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case Ee.PLAYING:r.videoState.startTransitionTo(Ee.PAUSED),r.params.connection.remotePlayerController.playOrPause();break;case Ee.PAUSED:break;case Ee.READY:r.videoState.startTransitionTo(Ee.PAUSED),r.videoState.setState(Ee.PAUSED);break;case Ee.STOPPED:r.videoState.startTransitionTo(Ee.READY),r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(a)}}}else t!==Ee.STOPPED&&(r.videoState.startTransitionTo(Ee.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_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(e){t.params.desiredState.seekPosition.setState(e),t.params.desiredState.seekPosition.startTransitionTo(void 0),t.params.desiredState.seekPosition.setState(void 0)})));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)?t.params.desiredState.seekPosition.setState(void 0):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(),C(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(Ee.PAUSED),C(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):(this.videoState.setState(Ee.PLAYING),C(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)!==Ee.PAUSED&&e!==Ee.PLAYING||(this.videoState.setState(Ee.PAUSED),C(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)!==Ee.PLAYING&&e!==Ee.PAUSED||(this.videoState.setState(Ee.PLAYING),C(this.params.desiredState.playbackState,exports.PlaybackState.PLAYING))},t.prototype.handleRemoteReady=function(){var e=this.videoState.getTransition();(null==e?void 0:e.to)===Ee.READY&&this.videoState.setState(Ee.READY)},t.prototype.handleRemoteStop=function(){this.videoState.getState()!==Ee.STOPPED&&this.videoState.setState(Ee.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){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:M(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_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=Pe(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"}(ke||(ke={}));var Ae,xe=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(ke.STOPPED),this.trackUrls={},this.textTracksManager=new x,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===ke.STOPPED)return r.videoState.startTransitionTo(ke.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 ke.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(ke.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(ke.PLAYING),r.playIfAllowed()));case ke.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(ke.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case ke.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(ke.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==ke.STOPPED&&(r.videoState.startTransitionTo(ke.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(ke.STOPPED),C(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=N(t.container),this.params.output.element$.next(this.video),Object.entries(this.params.source).forEach((function(e,t){var i=h(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=R(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$),this.subscription.add(s.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}),n)),this.subscription.add(k(this.video,a.isLooped,n)),this.subscription.add(w(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$,n)),this.subscription.add(s.play$.subscribe((function(){t.videoState.setState(ke.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(ke.PAUSED),C(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)===ke.READY&&t.videoState.setState(ke.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()===ke.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(J(a))},t.prototype.playIfAllowed=function(){var e=this;E(this.video).then((function(t){t||(e.videoState.setState(ke.PAUSED),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),this.video.currentTime=e},t}(),Ne=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{t._xhr.readyState>=2&&!r&&(r=!0,null===(o=t._headersCb)||void 0===o||o.call(t)),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,r,i;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 a=void 0;t._failoverIndex>=t._failoverHosts.length?(a=t._url,t._failoverIndex=0):(a=t._url.replace((r=t._url,(i=document.createElement("a")).href=r,i.host),t._failoverHosts[t._failoverIndex]),t._failoverIndex++),t._xhr.open("GET",a,!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}(),$e=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 Ne(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._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}(),De=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 Ne(e,t,(function(i){var a,n;r.attachManifest(i,t,(a=e,(n=document.createElement("a")).href=a,n.origin))}),void 0,void 0,(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],A=w&&n(w,"range").split("-");if(A&&k){var x=Number(null===(p=e.attributes.getNamedItem("bandwidth"))||void 0===p?void 0:p.value),N=(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:x,baseURL:N,failoverHosts:t,indexFrom:Number(k[0]),indexTo:Number(k[1]),initFrom:Number(A[0]),initTo:Number(A[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*x/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 $=e.parentElement;if("text"===(null==$?void 0:$.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),I=null!==(c=$.getAttribute("lang"))&&void 0!==c?c:void 0;_&&o.push({id:D,url:_,language:I})}}})),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(){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 $e({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()}),void 0,e.bufferSize)}}))},t.prototype.setQualityByRepresentation=function(e){var t=this,r=this._buffer.getByTime(this._video.currentTime),i=this._findRef(this._video.currentTime);if(r&&i){var a=.1;if(i.toTime<r.end+a){var n=this._findRef(i.toTime);n&&n.toTime<r.end+a?(this._buffer.smartRemove(i.fromTime-a,n.toTime+a,(function(e,r){return t._stream.remove(e,r)})),this._loadRef(e,n.toTime)):(this._buffer.smartRemove(i.fromTime-a,i.toTime+a,(function(e,r){return t._stream.remove(e,r)})),this._loadRef(e,i.toTime))}}},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"}(Ae||(Ae={}));var _e,Ie=[Ae.PAUSED,Ae.PLAYING],Re=function(){function t(t){var r=this;this.videoState=new X(Ae.STOPPED),this.subscription=new e.Subscription,this.representations$=new e.ValueSubject([]),this.currentRepresentation$=new e.ValueSubject(void 0),this.textTracksManager=new x,this.elementSize$=new e.ValueSubject(void 0),this.dashLiteEvents={idxRequestPing$: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=p(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=U(d),h=d.bandwidth/1e3,f={width:d.width,height:d.height};if(c){var v={id:l,quality:c,bitrate:h,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(Ae.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)&&Ie.includes(t)&&r.seek(o),t){case Ae.STOPPED:return r.videoState.startTransitionTo(Ae.MANIFEST_LOADED),void r.prepare();case Ae.MANIFEST_LOADED:return void r.videoState.startTransitionTo(Ae.INITIAL_REPRESENTATION_SELECTED);case Ae.INITIAL_REPRESENTATION_SELECTED:return r.videoState.startTransitionTo(Ae.METADATA_LOADED),void r.dash.startPlay(r.selectRepresentation());case Ae.METADATA_LOADED:return r.videoState.startTransitionTo(Ae.READY),void r.dash.seek(null!=o?o:0);case Ae.READY:return void(a===exports.PlaybackState.PAUSED?(r.videoState.setState(Ae.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):a===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Ae.PLAYING),r.playIfAllowed()));case Ae.PLAYING:return void(a===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(Ae.PAUSED),r.video.pause()):(null==n?void 0:n.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case Ae.PAUSED:return void(a===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(Ae.PLAYING),r.playIfAllowed()):(null==n?void 0:n.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));default:return e.assertNever(t)}}}else t!==Ae.STOPPED&&(r.videoState.startTransitionTo(Ae.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(Ae.STOPPED),C(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=N(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(J(this.params.source.url)),this.buffer=new D(this.video),this.dash=new De({video:this.video,buffer:this.buffer,selectRepresentation:this.selectRepresentation,onIdxRequestPing:function(e){return r.dashLiteEvents.idxRequestPing$.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=R(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.firstFrame$,i.firstFrameEvent$),this.subscription.add(s.seeking$.subscribe((function(){e.isNullable(t.params.desiredState.seekPosition.getTransition())&&(t.videoState.getState()===Ae.PLAYING||t.videoState.getState()===Ae.PAUSED)&&t.dash.updateRefsForCurrentTime()}))),this.subscription.add(s.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}))),this.subscription.add(k(this.video,a.isLooped,n)),this.subscription.add(w(this.video,a.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$)),this.textTracksManager.connect(this.video,a,i),o(K(this.video),this.elementSize$),this.subscription.add(s.canplay$.subscribe((function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===Ae.READY&&t.videoState.setState(Ae.READY)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(Ae.PAUSED),C(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED)}))).add(s.play$.subscribe((function(){t.videoState.setState(Ae.PLAYING),C(t.params.desiredState.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.loadedMetadata$.subscribe((function(){t.videoState.setState(Ae.METADATA_LOADED)}),n)).add(s.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$).pipe(e.map((function(){var r,i,a,n=t.representations$.getValue(),s=t.params.desiredState.autoVideoTrackSwitching.getState(),o=t.params.desiredState.autoVideoTrackSwitching.getTransition(),u=t.params.desiredState.videoTrack.getState(),d=t.params.desiredState.videoTrack.getTransition(),l=t.params.dependencies.throughputEstimator.rttAdjustedThroughput$.getValue(),c=t.elementSize$.getValue(),p=o?o.to:s;if(o&&t.params.desiredState.autoVideoTrackSwitching.setState(o.to),!p&&e.isNonNullable(u))a=u;else{var h=W(t.video.buffered,1e3*t.video.currentTime),f=Math.min(h/t.params.tuning.dash.forwardBufferTarget,1);a=d?d.to:null===(r=Q(n.map((function(e){return e.track})),{container:c,throughput:l,tuning:t.params.tuning.autoTrackSelection,forwardBufferHealth:f}))||void 0===r?void 0:r.id}return e.isNonNullable(a)?null===(i=n.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===Ae.INITIAL_REPRESENTATION_SELECTED}))),currentRepresentationSelected:this.currentRepresentation$.pipe(e.filter(e.isNonNullable))}).pipe(e.once()).subscribe((function(){return t.videoState.setState(Ae.INITIAL_REPRESENTATION_SELECTED)}),n)).add(this.currentRepresentation$.pipe(e.filter(e.isNonNullable),e.filterChanged()).subscribe((function(e){t.dash.setQualityByRepresentation(e),t.params.output.hostname$.next(J(e.baseURL))}),n)).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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),this.dash.seek(e)},t.prototype.playIfAllowed=function(){var e=this;E(this.video).then((function(t){t||(e.videoState.setState(Ae.PAUSED),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t}(),Ce=function(e){return e.range?e.range.split("-").map((function(e){return parseInt(e,10)})):[NaN,NaN]},Le=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 l(this,void 0,void 0,(function(){var e,t,r,i,a,n,s,o,u,d,l,f,v;return c(this,(function(c){try{for(e=p(this.dashJsRequestQueue.entries()),t=e.next();!t.done;t=e.next()){if(r=h(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=h(Ce(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){f={error:e}}finally{try{t&&!t.done&&(v=e.return)&&v.call(e)}finally{if(f)throw f.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=p(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(Ce),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 p=d.toString(),f=new AbortController,v=f.signal,m={url:t,from:n,to:s,loaded:0,data:null,abortController:f};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(p,{signal:v}).then((function(t){var r,a,n;if(t.ok&&t.body){var s=h(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(),p=parseInt(null!==(n=t.headers.get("Content-Length"))&&void 0!==n?n:"",10);m.data=new ArrayBuffer(p);var f=new Uint8Array(m.data),v=function(t){var r=t.done,a=t.value;return l(i,void 0,void 0,(function(){return c(this,(function(t){switch(t.label){case 0:return r?(this.onBigRequestProgress(m),[3,3]):[3,1];case 1:return a?(f.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,f=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=h(Ce(t),2),i=r[0],p=r[1],S=i>=c&&p<=c+v,b=c>=i&&c+v<p,y=m.slice(i-c,Math.min(p-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=f-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:f-c,lengthComputable:!0,stream:!0}))},g=this;try{for(var y=p(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 f=p(c),v=f.next();!v.done;v=f.next()){var m=v.value,S=h(Ce(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=f.return)&&i.call(f)}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=p(u),l=d.next();!l.done;l=d.next()){var c=l.value,f=h(Ce(c.request),2),v=f[0],m=f[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}(),Oe=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}(),Ve=function(e,t){var r=new Le(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 Oe(a,t,i)}}}}(e(t),r)}}}),!0),function(){return r.destroy()}},Me=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,f([],h(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,f([],h(e),!1))},a=Date.now(),n=!1}return t(e)}}}),!0),{playbackDuration$:r,ping$:i}},Be=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}(),Ue={};!function(e){e.DOWNLOADING_LIB="downloading_lib",e.STOPPED="stopped",e.STREAM_INITIALIZED="stream_initialized",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(_e||(_e={}));var Fe=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)}}))},qe=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(_e.DOWNLOADING_LIB),this.textTracksManager=new x,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 Be,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!==_e.DOWNLOADING_LIB&&t!==_e.STREAM_INITIALIZED){var o=null==n?void 0:n.to;switch((null==a?void 0:a.to)!==exports.PlaybackState.PAUSED&&e.isNonNullable(o)&&t!==_e.STOPPED&&i!==exports.PlaybackState.STOPPED&&(s?r.seek(o+He(r.liveOffset.getTotalPausedTime())):r.seek(o)),i){case exports.PlaybackState.STOPPED:switch(t){case _e.STOPPED:break;case _e.PLAYING:case _e.PAUSED:case _e.READY:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case _e.PLAYING:break;case _e.PAUSED:s&&(r.liveOffset.getTotalPausedTime()<r.params.config.maxPausedTime&&r.liveOffset.getTotalOffset()<r.maxSeekBackTime$.getValue()?(r.liveOffset.resume(),r.params.output.position$.next(He(r.liveOffset.getTotalOffset()))):r.seek(He(r.liveOffset.getTotalOffset()))),r.play();break;case _e.READY:r.play();break;case _e.STOPPED:r.prepare();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case _e.PLAYING:r.pause(),r.liveOffset.pause();break;case _e.PAUSED:break;case _e.READY:r.videoState.setState(_e.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case _e.STOPPED:r.prepare();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=N(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.availableVideoTracks$.next([]),this.params.output.hostname$.next(J(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||(Ue.MediaPlayer=r.MediaPlayer,Ue.Debug=r.Debug,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){var t=this;e.assertNonNullable(Ue.MediaPlayer,"dashjs not loaded"),e.assertNonNullable(Ue.Debug,"dashjs not loaded"),this.player=Ue.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=Ve(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=h(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),this.player.clearDefaultUTCTimingSources(),this.subscribe(),this.videoState.setState(_e.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(K(this.video),this.elementSize$),s(Fe(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(Fe(this.player,"playbackError").pipe(e.map((function(e){return{id:"DashJSPlayback",message:e.error}}))),i.error$);var o=Fe(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===_e.STREAM_INITIALIZED})),e.once()).subscribe((function(){t.subscription.add(P(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(P(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(Fe(this.player,"bufferStateChanged").pipe(e.filter((function(e){return"video"===e.mediaType})),e.map((function(e){return"bufferStalled"===e.state}))),i.isBuffering$),s(Fe(this.player,"fragmentLoadingStarted").pipe(e.map((function(e){return J(e.request.url)}))),i.hostname$),s(Fe(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 h=p(t.player.getBitrateInfoListFor("video")),f=h.next();!f.done;f=h.next()){var v=f.value,m=v.qualityIndex.toString(10),S=U(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=h.return)&&a.call(h)}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(_e.STREAM_INITIALIZED),t.videoState.startTransitionTo(_e.READY)})),s(Fe(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=Q(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 He(t)}))),this.params.output.duration$);var u=Fe(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(Fe(this.player,"playbackSeeked"),(function(){return a.seekPosition.setState(void 0)})),s(Fe(this.player,"playbackEnded"),i.endedEvent$),s(Fe(this.player,"playbackProgress").pipe(e.map((function(){return _(t.video.buffered,t.video.currentTime)}))),i.currentBuffer$),s(Fe(this.player,"playbackPlaying"),(function(){t.videoState.setState(_e.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)})),s(Fe(this.player,"playbackNotAllowed"),(function(){t.player.isMuted()?(t.player.setMute(!1),t.videoState.setState(_e.PAUSED),C(t.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)):(t.player.setMute(!0),t.player.play())})),s(Fe(this.player,"playbackPaused"),(function(){t.videoState.setState(_e.PAUSED),C(a.playbackState,exports.PlaybackState.PAUSED)})),s(Fe(this.player,"canPlay"),(function(){var e;(null===(e=t.videoState.getTransition())||void 0===e?void 0:e.to)===_e.READY&&t.videoState.setState(_e.READY)})),s(this.isLive$,i.isLive$),s(K(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=Me(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(Fe(this.player,"manifestLoaded").pipe(e.once()).subscribe((function(){var r=Date.now();t.subscription.add(Fe(t.player,"playbackPlaying").pipe(e.once()).subscribe((function(){return i.firstFrameEvent$.next(Date.now()-r)}),n))}),n)),this.subscription.add(k(this.video,a.isLooped,n));var h=R(this.video).volumeState$;this.subscription.add(w(this.video,a.volume,h,n)),this.subscription.add(h.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(_e.STOPPED),C(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t.prototype.prepare=function(){this.videoState.startTransitionTo(_e.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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),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(He(r));var i=Pe(this.params.source.url,this.liveOffset.getTotalOffset()/1e3,be.PLAYBACK_SHIFT);this.player.attachSource(i)}else this.player.seek(e)},t.prototype.play=function(){this.videoState.startTransitionTo(_e.PLAYING),this.player.play()},t.prototype.pause=function(){this.videoState.startTransitionTo(_e.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}(),He=function(e){return-e/1e3};function Ge(){return window.performance?window.performance.now():Date.now()}function Ye(e){return Ge()-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 ze(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=Ye(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=Ge(),(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=Ge();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=Ge(),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 Qe,We=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}(),Je=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=Ge();e._request=ze(t,(function(a){e._complete=1,e._responseData=a,e._downloadTime=Ge()-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=Ge()},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=Ge();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}(),Ke=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 We(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 Je(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=Ge()-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=ze(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,A=m(t.jidxUrl),x=0,N=function(){f&&(clearTimeout(f),f=void 0);var e=Math.max(500,1e3*(r._getBufferSizeSec()-r.sourceJitter-5)),t=x+e,i=Ge(),a=Math.min(1e4,t-i);x=i;var n=function(){c||h()&&A.seek((function(){h()&&(x=Ge(),$(),N())}))};a>0?f=window.setTimeout((function(){r.paused?N():n()}),a):n()},$=function(){for(var e;e=A.nextChunk(p);)p=e,C(e);var i=A.nextChunk(s);if(i){if(s&&i.discontinuity)return w("Detected discontinuity; restarting playback"),void(r.paused?N():(S(),r._initPlayerWith(t)));R(i)}else N()},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=Ge(),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,$()})))},I=function(e){return t.fragUrlTemplate.replace("%%id%%",e.chunkIdx)},R=function(t){var i,a,o;h()&&(i=I(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(I(t),!1)))},L=function(e){h()&&(t.cachedHeader=e,D(e,(function(){a=!0,_()})))};o=!0,A.seek((function(t){h()&&(x=Ge(),t?(p=t,!e.isNullable(i)||t.startTS>i?R(t):(s=t,$())):N())}),i),t.cachedHeader?L(t.cachedHeader):(y=t.headerUrl,T=L,E=function(){return r._handleNetworkError()},l&&l.abort(),l=ze(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=Ge();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&&Ye(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=Ge();t<e&&(s=r),e=t}}},t.prototype._fetchManifest=function(e,t,r){var i=this;this.manifestRequest=ze(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;E(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"}(Qe||(Qe={}));var Xe,Ze=[Qe.PAUSED,Qe.PLAYING,Qe.READY],et=[Qe.PAUSED,Qe.PLAYING,Qe.READY],tt=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(Qe.STOPPED),this.representations$=new e.ValueSubject([]),this.textTracksManager=new x,this.maxSeekBackTime$=new e.ValueSubject(1/0),this.zeroTime$=new e.ValueSubject(void 0),this.liveOffset=new Be,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 l=t.manifest,c=[];try{for(var h=p(l),f=h.next();!f.done;f=h.next()){var v=f.value,m=null!==(n=v.name)&&void 0!==n?n:v.index.toString(10),S=U(v.video),b=v.bitrate/1e3,g=d({},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=h.return)&&a.call(h)}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)===Qe.MANIFEST_READY&&r.videoState.setState(Qe.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(et.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)&&Ze.includes(i))r.seek(l+rt(r.liveOffset.getTotalPausedTime()));else switch(i){case Qe.STOPPED:return r.videoState.startTransitionTo(Qe.MANIFEST_READY),void r.dash.attachSource(Pe(r.params.source.url));case Qe.MANIFEST_READY:r.videoState.startTransitionTo(Qe.READY),r.prepare();break;case Qe.READY:return void(n===exports.PlaybackState.PAUSED?r.videoState.setState(Qe.PAUSED):n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Qe.PLAYING),r.dash.play((function(){r.liveOffset.pause(),r.videoState.setState(Qe.PAUSED)}))));case Qe.PLAYING:return void(n===exports.PlaybackState.PAUSED&&(r.videoState.startTransitionTo(Qe.PAUSED),r.liveOffset.pause(),r.dash.pause()));case Qe.PAUSED:return void(n===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Qe.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(Qe.PAUSED)})),r.params.output.position$.next(rt(r.liveOffset.getTotalOffset()))):r.seek(rt(r.liveOffset.getTotalOffset()))));default:return e.assertNever(i)}}}else i!==Qe.STOPPED&&(r.videoState.startTransitionTo(Qe.STOPPED),r.dash.destroy(),r.video.setAttribute("src",""),r.video.load(),r.videoState.setState(Qe.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=N(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(J(this.params.source.url)),this.textTracksManager.connect(this.video,this.params.desiredState,this.params.output);var a=R(this.video);this.subscription.add(a.canplay$.subscribe((function(){var e;(null===(e=r.videoState.getTransition())||void 0===e?void 0:e.to)===Qe.READY&&r.videoState.setState(Qe.READY)}),i)).add(a.pause$.subscribe((function(){r.videoState.setState(Qe.PAUSED)}),i)).add(a.play$.subscribe((function(){r.videoState.setState(Qe.PLAYING)}),i)).add(a.error$.subscribe(this.params.output.error$)).add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(rt)).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(k(this.video,this.params.desiredState.isLooped,i)).add(w(this.video,this.params.desiredState.volume,a.volumeState$,i)).add(a.volumeState$.subscribe(this.params.output.volume$,i)).add(I(this.video).subscribe(this.params.output.firstBytesEvent$)).add($(this.video).subscribe(this.params.output.firstFrameEvent$)).add(this.videoState.stateChangeEnded$.subscribe((function(t){switch(t.to){case Qe.STOPPED:r.params.output.position$.next(0),r.params.output.duration$.next(1/0),r.params.desiredState.playbackState.setState(exports.PlaybackState.STOPPED);break;case Qe.MANIFEST_READY:case Qe.READY:break;case Qe.PAUSED:r.params.desiredState.playbackState.setState(exports.PlaybackState.PAUSED);break;case Qe.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 Ke({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=Q(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.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0);var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(rt(r)),this.dash.reinit(Pe(this.params.source.url,r)),this.params.desiredState.seekPosition.setState(void 0)},t}(),rt=function(e){return-e/1e3},it=function(e){if(e.QUALITY)switch(e.QUALITY){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}if(e.RESOLUTION){var t=h(e.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),r=t[0],i=t[1],a=U({width:r,height:i});if(a)return a}return null},at=function(e,t){return void 0===t&&(t=e),l(void 0,void 0,void 0,(function(){var r,i,a,n,s,o,u,d,l,p,f,v,m,S,b,g;return c(this,(function(c){switch(c.label){case 0:return[4,fetch(e)];case 1:return[4,c.sent().text()];case 2:for(r=c.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=it(u),p=void 0,u.BANDWIDTH&&(p=parseInt(u.BANDWIDTH,10)/1e3||void 0),!p&&u["AVERAGE-BANDWIDTH"]&&(p=parseInt(u["AVERAGE-BANDWIDTH"],10)/1e3||void 0),f=void 0,u.RESOLUTION&&(v=h(u.RESOLUTION.split("x").map((function(e){return parseInt(e,10)})),2),m=v[0],S=v[1],m&&S&&(f={width:m,height:S})),b=new URL(i[++n],t).toString(),l&&a.push({id:d,quality:l,url:b,bandwidth:p,size:f}));return[2,a]}}))}))};!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(Xe||(Xe={}));var nt,st=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(Xe.STOPPED),this.textTracksManager=new x,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===Xe.STOPPED)return r.videoState.startTransitionTo(Xe.READY),void r.prepare();if(n||s){var u=r.videoState.getState();r.videoState.setState(Xe.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 Xe.READY:return void(i===exports.PlaybackState.PAUSED?(r.videoState.setState(Xe.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):i===exports.PlaybackState.PLAYING&&(r.videoState.startTransitionTo(Xe.PLAYING),r.playIfAllowed()));case Xe.PLAYING:return void(i===exports.PlaybackState.PAUSED?(r.videoState.startTransitionTo(Xe.PAUSED),r.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(r.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case Xe.PAUSED:return void(i===exports.PlaybackState.PLAYING?(r.videoState.startTransitionTo(Xe.PLAYING),r.playIfAllowed()):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED));case Xe.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==Xe.STOPPED&&(r.videoState.startTransitionTo(Xe.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(Xe.STOPPED),C(r.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=N(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(J(this.params.source.url)),at(this.params.source.url).then((function(e){r.manifests$.next(f([i],h(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=R(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$),this.subscription.add(s.seeked$.subscribe((function(){return a.seekPosition.setState(void 0)}),n)),this.subscription.add(k(this.video,a.isLooped,n)),this.subscription.add(w(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.play$.subscribe((function(){t.videoState.setState(Xe.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(Xe.PAUSED),C(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)===Xe.READY&&t.videoState.setState(Xe.READY),t.videoState.getState()===Xe.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(J(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===Xe.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;E(this.video).then((function(t){t||(e.videoState.setState(Xe.PAUSED),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),this.video.currentTime=e},t}();!function(e){e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.CHANGING_MANIFEST="changing_manifest",e.PAUSED="paused"}(nt||(nt={}));var ot,ut=function(){function t(t){var r,i=this;this.subscription=new e.Subscription,this.videoState=new X(nt.STOPPED),this.textTracksManager=new x,this.manifests$=new e.ValueSubject([]),this.liveOffset=new Be,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===nt.STOPPED)return i.videoState.startTransitionTo(nt.READY),void i.prepare();if(n||s){var u=i.videoState.getState();i.videoState.setState(nt.CHANGING_MANIFEST),i.videoState.startTransitionTo(u);var d=dt(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(nt.READY),i.seek(l+dt(i.liveOffset.getTotalPausedTime())),void i.prepare();switch(t){case nt.READY:return void(r===exports.PlaybackState.PAUSED?(i.videoState.setState(nt.PAUSED),i.liveOffset.pause(),C(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED)):r===exports.PlaybackState.PLAYING&&(i.videoState.startTransitionTo(nt.PLAYING),i.playIfAllowed()));case nt.PLAYING:return void(r===exports.PlaybackState.PAUSED?(i.videoState.startTransitionTo(nt.PAUSED),i.liveOffset.pause(),i.video.pause()):(null==a?void 0:a.to)===exports.PlaybackState.PLAYING&&C(i.params.desiredState.playbackState,exports.PlaybackState.PLAYING));case nt.PAUSED:return void(r===exports.PlaybackState.PLAYING?(i.videoState.startTransitionTo(nt.PLAYING),i.liveOffset.getTotalPausedTime()<i.params.config.maxPausedTime&&i.liveOffset.getTotalOffset()<i.maxSeekBackTime$.getValue()?(i.liveOffset.resume(),i.playIfAllowed(),i.params.output.position$.next(dt(i.liveOffset.getTotalOffset()))):i.seek(dt(i.liveOffset.getTotalOffset()))):(null==a?void 0:a.to)===exports.PlaybackState.PAUSED&&(C(i.params.desiredState.playbackState,exports.PlaybackState.PAUSED),i.liveOffset.pause()));case nt.CHANGING_MANIFEST:break;default:return e.assertNever(t)}}}else t!==nt.STOPPED&&(i.videoState.startTransitionTo(nt.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(nt.STOPPED),C(i.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0))},this.params=t,this.video=N(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]),at(Pe(this.params.source.url)).then((function(e){i.manifests$.next(f([a],h(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(J(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=R(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(w(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.play$.subscribe((function(){t.videoState.setState(nt.PLAYING),C(a.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(nt.PAUSED),C(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)===nt.READY&&t.videoState.setState(nt.READY),t.videoState.getState()===nt.PLAYING&&t.playIfAllowed()}),n)),this.subscription.add(this.maxSeekBackTime$.pipe(e.filterChanged(),e.map(dt)).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(J(o.url)))}n&&t.params.desiredState.autoVideoTrackSwitching.setState(n.to),i&&i.from===nt.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=Pe(r.url,this.liveOffset.getTotalOffset());this.video.setAttribute("src",a),this.video.load(),(i=a,l(void 0,void 0,void 0,(function(){var e;return c(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;E(this.video).then((function(t){t||(e.videoState.setState(nt.PAUSED),e.liveOffset.pause(),C(e.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0))}))},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0);var t=-Math.round(1e3*e),r=t<this.maxSeekBackTime$.getValue()?t:0;this.liveOffset.resetTo(r),this.params.output.position$.next(dt(r)),this.params.desiredState.seekPosition.setState(void 0)},t}(),dt=function(e){return-e/1e3},lt={};!function(e){e.INITIALIZING="initializing",e.STOPPED="stopped",e.READY="ready",e.PLAYING="playing",e.PAUSED="paused"}(ot||(ot={}));var ct,pt,ht,ft,vt,mt,St,bt,gt,yt,Tt,Et,Pt,kt,wt,At,xt,Nt,$t,Dt,_t=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)}}))},It=function(){function t(t){var r=this;this.subscription=new e.Subscription,this.videoState=new X(ot.INITIALIZING),this.textTracksManager=new x,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!==ot.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 ot.STOPPED:break;case ot.READY:case ot.PLAYING:case ot.PAUSED:r.stop();break;default:e.assertNever(t)}break;case exports.PlaybackState.PLAYING:switch(t){case ot.PLAYING:break;case ot.STOPPED:r.prepare();break;case ot.READY:case ot.PAUSED:r.playIfAllowed();break;default:e.assertNever(t)}break;case exports.PlaybackState.PAUSED:switch(t){case ot.PAUSED:break;case ot.STOPPED:r.prepare();break;case ot.READY:r.videoState.setState(ot.PAUSED),C(r.params.desiredState.playbackState,exports.PlaybackState.PAUSED);break;case ot.PLAYING:r.pause();break;default:e.assertNever(t)}break;default:e.assertNever(i)}}},this.video=N(t.container),this.params=t,this.params.output.element$.next(this.video),this.params.output.isLive$.next(!1),this.params.output.hostname$.next(J(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||(lt.Hls=r.default,lt.Events=r.default.Events,e.init())}),i).finally((function(){window.clearTimeout(a),t=!0}))},t.prototype.init=function(){e.assertNonNullable(lt.Hls,"hls.js not loaded"),this.hls=new lt.Hls({fragLoadingMaxRetry:5,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetryTimeout:16e3,manifestLoadingMaxRetryTimeout:2e3,levelLoadingMaxRetryTimeout:2e3}),this.subscribe(),this.videoState.setState(ot.STOPPED)},t.prototype.subscribe=function(){var t=this;e.assertNonNullable(lt.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=R(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$),this.subscription.add(s.seeked$.subscribe((function(){return i.seekPosition.setState(void 0)}),n)),this.subscription.add(k(this.video,i.isLooped,n)),this.subscription.add(w(this.video,i.volume,s.volumeState$,n)),this.subscription.add(s.volumeState$.subscribe(this.params.output.volume$)),this.subscription.add(_t(this.hls,lt.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.play$.subscribe((function(){t.videoState.setState(ot.PLAYING),C(i.playbackState,exports.PlaybackState.PLAYING)}),n)).add(s.pause$.subscribe((function(){t.videoState.setState(ot.PAUSED),C(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)===ot.READY&&t.videoState.setState(ot.READY),t.videoState.getState()===ot.PLAYING&&t.playIfAllowed()}),n)),o(_t(this.hls,lt.Events.MANIFEST_PARSED).pipe(e.map((function(e){return e.levels.reduce((function(e,r){var i=r.name||r.height.toString(10),a=r.width,n=r.height,s=U({width:a,height:n});if(!s)return e;var o={id:i.toString(),quality:s,bitrate:r.bitrate/1e3,size:{width:a,height:n}};return t.trackLevels.set(i,{track:o,level:r}),e.push(o),e}),[])}))),a.availableVideoTracks$),o(_t(this.hls,lt.Events.LEVEL_LOADING).pipe(e.map((function(e){var t=e.url;return J(t)}))),a.hostname$),this.subscription.add(P(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=_t(this.hls,lt.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(P(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(ot.READY),this.hls.attachMedia(this.video),this.hls.loadSource(this.params.source.url)},t.prototype.playIfAllowed=function(){return l(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return this.videoState.startTransitionTo(ot.PLAYING),[4,E(this.video)];case 1:return e.sent()||(this.videoState.setState(ot.PAUSED),C(this.params.desiredState.playbackState,exports.PlaybackState.PAUSED,!0)),[2]}}))}))},t.prototype.pause=function(){this.videoState.startTransitionTo(ot.PAUSED),this.video.pause()},t.prototype.seek=function(e){this.params.desiredState.seekPosition.setState(e),this.params.desiredState.seekPosition.startTransitionTo(void 0),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(ot.STOPPED),C(this.params.desiredState.playbackState,exports.PlaybackState.STOPPED,!0)},t}(),Rt=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}(),Ct=($t=window.navigator.userAgent,!/chrome/i.test($t)&&/webkit|safari|khtml/i.test($t)),Lt=(null===(pt=null===(ct=navigator)||void 0===ct?void 0:ct.userAgentData)||void 0===pt?void 0:pt.mobile)||/Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(navigator.appVersion),Ot=document.createElement("video"),Vt={mse:Boolean(window.MediaSource&&window.MediaStreamTrack&&(null===(ft=null===(ht=window.SourceBuffer)||void 0===ht?void 0:ht.prototype)||void 0===ft?void 0:ft.appendBuffer)),hls:Boolean((null===(vt=Ot.canPlayType)||void 0===vt?void 0:vt.call(Ot,"application/x-mpegurl"))||(null===(mt=Ot.canPlayType)||void 0===mt?void 0:mt.call(Ot,"vnd.apple.mpegURL")))},Mt={mp4:Boolean(null===(St=Ot.canPlayType)||void 0===St?void 0:St.call(Ot,"video/mp4")),webm:Boolean(null===(bt=Ot.canPlayType)||void 0===bt?void 0:bt.call(Ot,"video/webm"))},Bt={h264:Boolean(null===(yt=null===(gt=window.MediaSource)||void 0===gt?void 0:gt.isTypeSupported)||void 0===yt?void 0:yt.call(gt,'video/mp4; codecs="avc1.42000a,mp4a.40.2"')),h265:Boolean(null===(Et=null===(Tt=window.MediaSource)||void 0===Tt?void 0:Tt.isTypeSupported)||void 0===Et?void 0:Et.call(Tt,'video/mp4; codecs="hev1.1.6.L93.B0"')),vp9:Boolean(null===(kt=null===(Pt=window.MediaSource)||void 0===Pt?void 0:Pt.isTypeSupported)||void 0===kt?void 0:kt.call(Pt,'video/webm; codecs="vp9"')),aac:Boolean(null===(At=null===(wt=window.MediaSource)||void 0===wt?void 0:wt.isTypeSupported)||void 0===At?void 0:At.call(wt,'audio/mp4; codecs="mp4a.40.2"')),opus:Boolean(null===(Nt=null===(xt=window.MediaSource)||void 0===xt?void 0:xt.isTypeSupported)||void 0===Nt?void 0:Nt.call(xt,'audio/webm; codecs="opus"'))},Ut=(Bt.h264||Bt.h265)&&Bt.aac,Ft=!Ct,qt=Lt||Ct,Ht=!Vt.hls||!qt,Gt=3e4,Yt=18e4,jt=3,zt=100,Qt={cacheDuration:12e4},Wt={maxPausedTime:3e4,chunkDuration:5e3,optimalBufferDuration:1e4,maxParallelRequests:5},Jt={maxPausedTime:3e4},Kt={maxPausedTime:3e4},Xt=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,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),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?f(f([],h(t.screenFormatsPriority.filter((function(e){return!r.includes(e)}))),!1),h(t.screenFormatsPriority.filter((function(e){return r.includes(e)}))),!1):t.screenFormatsPriority;this.screenFormatsIterator=new Rt(i.filter((function(r){return e.isNonNullable(t.sources[r])})).filter((function(t){switch(t){case exports.VideoFormat.DASH:return Vt.mse&&Mt.mp4&&Ut&&Ft;case exports.VideoFormat.DASH_SEP:return Vt.mse&&Mt.mp4&&Ut;case exports.VideoFormat.DASH_WEBM:case exports.VideoFormat.DASH_WEBM_VK:case exports.VideoFormat.DASH_LIVE_WEBM:return Vt.mse&&Mt.webm&&Bt.vp9&&Bt.opus;case exports.VideoFormat.DASH_LIVE:case exports.VideoFormat.DASH_ONDEMAND:return Vt.mse&&Mt.mp4&&Ut;case exports.VideoFormat.HLS:case exports.VideoFormat.HLS_LIVE:case exports.VideoFormat.HLS_ONDEMAND:return Vt.hls&&Mt.mp4&&qt;case exports.VideoFormat.HLS_JS:return Vt.mse&&Mt.mp4&&Ut&&Ht;case exports.VideoFormat.MPEG:return Mt.mp4;default:return e.assertNever(t)}}))),this.chromecastFormatsIterator=new Rt(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 e=this.current$.getValue().provider;if(e){this.log({message:"destroyProvider"});var t=this.params.desiredState.seekPosition;t.getTransition()||t.startTransitionTo(this.providerOutput.position$.getValue()),e.destroy();var r=this.providerOutput.isBuffering$;r.getValue()||r.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 Re({container:a,source:o,desiredState:n,output:s,config:Qt,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.DASH_WEBM_VK:o=i[t];return e.assertNonNullable(o),new Te({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 qe({container:a,source:o,desiredState:n,output:s,format:t,config:Kt,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 st({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 ut({container:a,source:o,desiredState:n,output:s,config:Jt,dependencies:this.params.dependencies,tuning:this.params.tuning});case exports.VideoFormat.HLS_JS:o=i[t];return e.assertNonNullable(o),new It({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 xe({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 tt({container:a,source:o,desiredState:n,output:s,config:Wt,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 we({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:Gt,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(zt,{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]+Yt?(i=[],r.switchToNextProvider()):(i[a]=t,r.reinitProvider()),a=(a+1)%jt}))),s},t}(),Zt=function(e,t,r){return r*t+(1-r)*e},er=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 j("raw_"+i),this.smoothedSeries$=new j("smoothed_"+i),this.reportedSeries$=new j("reported_"+i)}return t.prototype.next=function(t){this.slow=Zt(this.slow,t,this.params.emaAlphaSlow),this.fast=Zt(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"}(Dt||(Dt={}));var tr=new Map,rr=Dt.RUNTIME,ir="vk-videoplayer-dummy-key-"+Math.random();!function(){try{localStorage.setItem(ir,"test"),localStorage.removeItem(ir),rr=Dt.LOCAL_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;try{sessionStorage.getItem(ir),rr=Dt.SESSION_STORAGE}catch(e){if(!(e instanceof DOMException))throw e;rr=Dt.RUNTIME}}}();var ar,nr=function(t,r){switch(rr){case Dt.LOCAL_STORAGE:return localStorage.setItem(t,r);case Dt.SESSION_STORAGE:return sessionStorage.setItem(t,r);case Dt.RUNTIME:return void tr.set(t,r);default:e.assertNever(rr)}},sr=function(){var e,t;return null!==(t=null===(e=window.performance)||void 0===e?void 0:e.now())&&void 0!==t?t:Date.now()},or=window.navigator.connection,ur=function(){var t=null==or?void 0:or.downlink;if(e.isNonNullable(t)&&10!==t)return 1e3*t},dr=function(){var t=null==or?void 0:or.rtt;if(e.isNonNullable(t)&&3e3!==t)return t},lr=function(e,t,r){var i=8*r;return i/(i/e+t)},cr=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?ur():void 0)||5e3,o=null!==(a=null!==(i=t.load("one_video_rtt"))&&void 0!==i?i:r.useBrowserEstimation?dr():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(lr(s,o,r.rttPenaltyRequestSize)),this.throughput=new er({initial:s,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:-1,label:"throughput"}),this.rtt=new er({initial:o,emaAlphaSlow:r.emaAlphaSlow,emaAlphaFast:r.emaAlphaFast,changeThreshold:r.changeThreshold,fastDirection:1,label:"rtt"}),r.useBrowserEstimation){var u=function(){var t=ur();t&&n.throughput.next(t);var r=dr();e.isNonNullable(r)&&n.rtt.next(r)};or&&"onchange"in or&&this.subscription.add(e.fromEvent(or,"change").subscribe(u)),u()}this.subscription.add(this.throughput.smoothed$.subscribe((function(e){nr("one_video_throughput",e.toFixed(0))}))),this.subscription.add(this.rtt.smoothed$.subscribe((function(e){nr("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 lr(t,i,r.rttPenaltyRequestSize)})),e.filterChanged((function(e,t){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=sr(),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(e){i=e.loaded,a=sr()})));break;case 1:case 0:n.add(e.fromEvent(t,"loadstart").subscribe((function(){i=0,a=sr()})))}n.add(e.fromEvent(t,"loadend").subscribe((function(e){if(200===t.status){var s=e.loaded,o=sr(),u=s-i,d=o-a;r.addRawSpeed(u,d)}n.unsubscribe()})))},t.prototype.trackStream=function(e){var t=this,r=e.getReader();if(r){var i=0,a=sr(),n=0,s=sr(),o=function(t){r.releaseLock(),e.cancel("Throughput Estimator error: "+t).catch((function(){}))},u=function(e){var d=e.done,p=e.value;return l(t,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return d?(this.addRawSpeed(i,sr()-a),[3,3]):[3,1];case 1:return p?(i+=p.byteLength,(n+=p.byteLength)>=this.tuningConfig.streamMinSampleSize&&sr()-s>=this.tuningConfig.streamMinSampleTime&&(this.addRawSpeed(n,sr()-s),n=0,s=sr()),[4,null==r?void 0:r.read().then(u,o)]):[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))};null==r||r.read().then(u,o)}else e.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<1024)&&!(t<=50))))},t.load=function(t){var r,i=function(t){var r,i;switch(rr){case Dt.LOCAL_STORAGE:return null!==(r=localStorage.getItem(t))&&void 0!==r?r:void 0;case Dt.SESSION_STORAGE:return null!==(i=sessionStorage.getItem(t))&&void 0!==i?i:void 0;case Dt.RUNTIME:return tr.get(t);default:e.assertNever(rr)}}(t);if(e.isNonNullable(i))return null!==(r=parseInt(i,10))&&void 0!==r?r:void 0},t}(),pr=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)}})))}))}},hr=pr((function(e){return e})),fr=pr((function(e){return Math.round(1e3*e)+Date.now()})),vr=((ar={})[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,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]},ar[n.CHROMECAST]={vod:[exports.VideoFormat.DASH_WEBM_VK,exports.VideoFormat.DASH_WEBM,exports.VideoFormat.DASH_SEP,exports.VideoFormat.DASH_ONDEMAND,exports.VideoFormat.HLS,exports.VideoFormat.HLS_ONDEMAND,exports.VideoFormat.MPEG],live:[exports.VideoFormat.HLS_LIVE]},ar),mr=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 X(exports.PlaybackState.STOPPED),seekPosition:new X(void 0),volume:new X({volume:1,muted:!1}),videoTrack:new X(void 0),autoVideoTrackSwitching:new X(!0),isLooped:new X(!1),externalTextTracks:new X([]),currentTextTrack:new X(void 0),textTrackCuesSettings:new X({})},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),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),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:G},this.initLogs(),this.tuning=function(e){var t,r,i={};try{for(var a=p(Object.keys(S)),n=a.next();!n.done;n=a.next()){var s=n.value,o=S[s],u=e[s];Array.isArray(o)&&Array.isArray(u)?i[s]=u:i[s]="object"==typeof o&&"object"==typeof u?d(d({},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 b({receiverApplicationId:t.chromecastReceiverId,isDisabled:t.disableChromecast,dependencies:{logger:this.logger}}),this.throughputEstimator=new cr(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 Xt({screenFormatsPriority:f(f([],h(vr[n.SCREEN].live),!1),h(vr[n.SCREEN].vod),!1),chromecastFormatsPriority:f(f([],h(vr[n.CHROMECAST].live),!1),h(vr[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 d({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$)).add(this.desiredState.seekPosition.stateChangeEnded$.pipe(e.filter((function(e){return void 0===e.to})),e.mapTo(void 0)).subscribe(this.events.seeked$));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.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 F(e)?1:F(t)?-1:V(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.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)),this.desiredState.seekPosition.stateChangeEnded$.pipe(e.filter((function(e){return void 0!==e.from})),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.Subscription;this.subscription.add(i);var a=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),i.unsubscribe(),t){case!0:i.add(fr({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:a,position$:r.providerContainer.providerOutput.position$}).subscribe(r.events.watchCoverageLive$));break;case!1:i.add(hr({seekPosition:r.desiredState.seekPosition,playbackState:r.desiredState.playbackState,playbackAbort$:a,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=Q(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),H={},this.experimental.enableDebugTelemetry$.next(this.tuning.enableTelemetryAtStart),[this.experimental.enableDebugTelemetry$.subscribe((function(e){q=e})),this.providerContainer.current$.subscribe((function(e){var t=e.type;return Y("provider",t)})),i.duration$.subscribe((function(e){return Y("duration",e)})),i.availableVideoTracks$.pipe(e.filter((function(e){return!!e.length})),e.once()).subscribe((function(e){return Y("tracks",e)})),this.events.fatalError$.subscribe(new j("fatalError")),this.events.managedError$.subscribe(new j("managedError")),i.position$.subscribe(new j("position")),i.currentVideoTrack$.pipe(e.map((function(e){return null==e?void 0:e.quality}))).subscribe(new j("quality")),i.currentBuffer$.subscribe(new j("buffer")),i.isBuffering$.subscribe(new j("isBuffering"))].forEach((function(e){return r.subscription.add(e)})),Y("codecs",Object.keys(Bt).filter((function(e){return Bt[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=mr,exports.SDK_VERSION="@vkontakte/videoplayer-core@2.0.38-dev.9d78ba4.0";