Files
ruo-shan-cloud-pharmacy/miniprogram/package-live/volc-mini-sdk/components/player/stats.js
T
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

1 line
6.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(i),!0).forEach(function(e){_defineProperty(t,e,i[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):ownKeys(Object(i)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))})}return t}function _defineProperty(t,e,i){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,_toPropertyKey(r.key),r)}}function _createClass(t,e,i){return e&&_defineProperties(t.prototype,e),i&&_defineProperties(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,e||"default");if("object"!==_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var HEARTBEAT_EVENT="mini_sdk_play_heartbeat",HEARTBEAT_INTERVAL_MS=1e4,MAX_LIVE_STATE_EVENTS=200,STALL_DURATION_RE=/duration\s*[:]\s*(\d+)\s*ms/i,PlayerStatsReporter=function(){function t(e){_classCallCheck(this,t),this._getSdkInstance=e.getSdkInstance,this._getVideoType=e.getVideoType,this._getCurrentTime=e.getCurrentTime,this._getPlayUrl=e.getPlayUrl,this._getDefinition=e.getDefinition,this._getSelectedDefinition=e.getSelectedDefinition,this._getLiveEngine=e.getLiveEngine,this._getActivityOrientationConfig=e.getActivityOrientationConfig,this._getIsPseudoLive=e.getIsPseudoLive,this._isPlaying=e.isPlaying,this._lastReportAction="",this._init()}return _createClass(t,[{key:"_init",value:function(){this._heartbeatTimer=null,this._liveStateEvents=[],this._stallCount=0,this._stallDurationMs=0,this._waitingCount=0,this._intervalLoadingMs=0,this._intervalStartMs=0,this._loadingStartMs=0,this._lastReportMs=0}},{key:"handleStall",value:function(t){this._stallCount+=1,this._stallDurationMs+=this._parseStallDurationMs(t)}},{key:"startHeartbeat",value:function(){var t=this;this.stopLoading(),this._clearHeartbeatTimer(),this._lastReportMs=0,this.reportHeartbeat("play"),this._heartbeatTimer=setInterval(function(){var e;null!==(e=t._isPlaying)&&void 0!==e&&e.call(t)&&t.reportHeartbeat("tick")},HEARTBEAT_INTERVAL_MS)}},{key:"stopHeartbeat",value:function(t){this._clearHeartbeatTimer(),this.stopLoading();var e="string"==typeof t&&t.length>0;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;