"use strict";function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function ownKeys(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),i.push.apply(i,r)}return i}function _objectSpread(t){for(var e=1;e0;this.reportHeartbeat("stop",e?{reason:t}:void 0)}},{key:"reportHeartbeat",value:function(t,e){var i,r,n,a,s,o,l,u,_=null===(i=this._getSdkInstance)||void 0===i?void 0:i.call(this),v=null==_?void 0:_.reportTea;if("function"==typeof v){var h=Date.now(),c=this._lastReportMs?h-this._lastReportMs:0;this._lastReportMs=h;var f,p=null===(r=this._getVideoType)||void 0===r?void 0:r.call(this),y=null===(n=this._getPlayUrl)||void 0===n?void 0:n.call(this),d=null===(a=this._getDefinition)||void 0===a?void 0:a.call(this),g=null===(s=this._getSelectedDefinition)||void 0===s?void 0:s.call(this),b=null===(o=this._getLiveEngine)||void 0===o?void 0:o.call(this),S=null===(l=this._getActivityOrientationConfig)||void 0===l?void 0:l.call(this),m=null===(u=this._getCurrentTime)||void 0===u?void 0:u.call(this),M=_objectSpread({videoType:p,action:t,intervalMs:"stop"===t&&"stop"===this._lastReportAction?0:c,playUrl:y,playingDefinition:d,selectedDefinition:g,activityOrientationConfig:S},e||{});"live"===p&&(M.liveEngine=b,M.isPseudoLive=!(null===(f=this._getIsPseudoLive)||void 0===f||!f.call(this))),"vod"===p&&"number"==typeof m&&(M.currentTime=m);var E=this._getAndResetIntervalMetrics();this._lastReportAction=t,v(HEARTBEAT_EVENT,_objectSpread(_objectSpread({},M),E))}}},{key:"getLiveStateEvents",value:function(){return this._liveStateEvents&&this._liveStateEvents.length?this._liveStateEvents:void 0}},{key:"isLoading",value:function(){return!!this._loadingStartMs}},{key:"isHeartbeatRunning",value:function(){return!!this._heartbeatTimer}},{key:"_getAndResetIntervalMetrics",value:function(){var t=Date.now();this._intervalStartMs||(this._intervalStartMs=t);var e=this._intervalLoadingMs;if(this._loadingStartMs){var i=Math.max(this._loadingStartMs,this._intervalStartMs);e+=Math.max(0,t-i)}var r={stallCount:this._stallCount,stallDurationMs:this._stallDurationMs,waitingCount:this._waitingCount,loadingMs:e,liveStateEvents:this._liveStateEvents};return this._stallCount=0,this._stallDurationMs=0,this._waitingCount=0,this._intervalLoadingMs=0,this._liveStateEvents=[],this._intervalStartMs=t,r}},{key:"recordWaiting",value:function(){this._waitingCount+=1}},{key:"startLoading",value:function(){var t=Date.now();this._intervalStartMs||(this._intervalStartMs=t),this._loadingStartMs||(this._loadingStartMs=t)}},{key:"stopLoading",value:function(){var t=Date.now();if(this._loadingStartMs){this._intervalStartMs||(this._intervalStartMs=t);var e=Math.max(this._loadingStartMs,this._intervalStartMs),i=Math.max(0,t-e);this._intervalLoadingMs+=i,this._loadingStartMs=0}}},{key:"_clearHeartbeatTimer",value:function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)}},{key:"recordLiveStateEvent",value:function(t,e,i){if("number"==typeof t&&Number.isFinite(t)&&!(this._liveStateEvents.length>=MAX_LIVE_STATE_EVENTS)){var r=Date.now();this._liveStateEvents.push(_objectSpread({code:t,message:e,time:r},i&&"object"===_typeof(i)?i:{}))}}},{key:"_parseStallDurationMs",value:function(t){if("string"!=typeof t||!t)return 0;var e=t.match(STALL_DURATION_RE);if(!e)return 0;var i=Number(e[1]);return!Number.isFinite(i)||i<=0?0:i}},{key:"dispose",value:function(){this._clearHeartbeatTimer(),this.stopLoading(),this._lastReportMs=0}}]),t}();exports.default=PlayerStatsReporter;