"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlayerStateManager=exports.PlayerStateManager=void 0;var _types=require("./types");function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,i)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){_defineProperty(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,_toPropertyKey(i.key),i)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!==_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var createInitialLiveState=function(){return{lineIndex:0,line:null,definition:"",candidates:null,candidateIndex:0,roundIndex:1,retryIndex:0,protocol:"",fromPrimary:!0,attemptId:0,attemptReportedFailed:!1,pendingSwitch:null,pendingQuality:null,lastPerfTriggerMs:0,lastNetStatusInfo:null,playerParams:{startPlay:0,firstFrame:0,playUrl:"",attemptId:0}}},createInitialVodState=function(){return{params:{startPlay:0,firstFrame:0,vid:"",playUrl:""},attemptId:0,attemptReportedFailed:!1,switchPending:null,switchRetryIndex:0,backupUrl:"",usingBackup:!1,backupMap:null}},PlayerStateManager=function(){function e(){_classCallCheck(this,e),this._liveState=createInitialLiveState(),this._vodState=createInitialVodState(),this._videoType="",this._lastVideoType=""}return _createClass(e,[{key:"videoType",get:function(){return this._videoType},set:function(e){this._lastVideoType=this._videoType,this._videoType=e}},{key:"lastVideoType",get:function(){return this._lastVideoType}},{key:"liveState",get:function(){return this._liveState}},{key:"vodState",get:function(){return this._vodState}},{key:"getLiveSessionSnapshot",value:function(){return{lineIndex:this._liveState.lineIndex||0,line:this._liveState.line||null,definition:this._liveState.definition||"",candidates:Array.isArray(this._liveState.candidates)?this._liveState.candidates:[],candidateIndex:this._liveState.candidateIndex||0,roundIndex:this._liveState.roundIndex||0,retryIndex:this._liveState.retryIndex||0,protocol:this._liveState.protocol||"",fromPrimary:!1!==this._liveState.fromPrimary}}},{key:"resetLiveRuntimeState",value:function(e){var t=null!=e&&e.keepQualityPending?this._liveState.pendingQuality:null;this._liveState=_objectSpread(_objectSpread({},createInitialLiveState()),{},{pendingQuality:t})}},{key:"resetVodRuntimeState",value:function(){this._vodState=createInitialVodState()}},{key:"updateLiveState",value:function(e){this._liveState=_objectSpread(_objectSpread({},this._liveState),e)}},{key:"updateVodState",value:function(e){this._vodState=_objectSpread(_objectSpread({},this._vodState),e)}},{key:"isLivePlaying",value:function(){return this._videoType===_types.VideoType.LIVE}},{key:"isVodPlaying",value:function(){return this._videoType===_types.VideoType.VOD}},{key:"isPrevPlayable",value:function(){return this._lastVideoType===_types.VideoType.LIVE||this._lastVideoType===_types.VideoType.VOD}}]),e}();exports.PlayerStateManager=PlayerStateManager;var createPlayerStateManager=function(){return new PlayerStateManager};exports.createPlayerStateManager=createPlayerStateManager;