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

1 line
16 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createLivePlayerController=exports.LivePlayerController=void 0;var _types=require("./types"),_liveUtils=require("./live-utils"),_miniSdkConfig=require("./mini-sdk-config"),_events=_interopRequireDefault(require("../../utils/events"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}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 i=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,r)}return i}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(i),!0).forEach(function(t){_defineProperty(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):ownKeys(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,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 i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,_toPropertyKey(r.key),r)}}function _createClass(e,t,i){return t&&_defineProperties(e.prototype,t),i&&_defineProperties(e,i),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 i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!==_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var LivePlayerController=function(){function e(t){_classCallCheck(this,e),this._getStore=t.getStore,this._getSdkInstance=t.getSdkInstance,this._getStateManager=t.getStateManager,this._getStatsReporter=t.getStatsReporter,this._getLiveSelectedSize=t.getLiveSelectedSize,this._getLiveEngine=t.getLiveEngine,this._getLiveEngineMode=t.getLiveEngineMode,this._getIsPseudoLive=t.getIsPseudoLive,this._switchLiveEngine=t.switchLiveEngine,this._setData=t.setData,this._onSuccess=t.onSuccess,this._onFailure=t.onFailure,this._setPlayError=t.setPlayError,this._liveContextGetter=t.liveContextGetter,this._firstFrameTimer=null,this._loadingTimeoutTimer=null,this._loadingStartMs=0,this._stallTimestamps=[],this._waitingTimeoutTimestamps=[],this._lastPerfTriggerMs=0,this._continuousPerfIssueCount=0,this._latestPlayUrl="",this._networkDisconnectHandledAttemptId=0,this._networkDisconnectHandledUrl=""}return _createClass(e,[{key:"state",get:function(){return this._getStateManager().liveState}},{key:"config",get:function(){return(0,_miniSdkConfig.getMiniSdkLiveConfig)(this._getStore())}},{key:"_reportTea",value:function(e,t){var i,r,n,a,s=null===(i=this._getSdkInstance)||void 0===i||null===(r=i.call(this))||void 0===r?void 0:r.reportTea;if("function"==typeof s){var o=null===(n=this._getStateManager())||void 0===n||null===(a=n.getLiveSessionSnapshot)||void 0===a?void 0:a.call(n);s(e,_objectSpread({videoType:_types.VideoType.LIVE,liveEngine:this._getLiveEngine(),liveEngineMode:this._getLiveEngineMode(),liveSession:o},t||{}))}}},{key:"_getLiveSelectedSizeValue",value:function(){var e;return(null===(e=this._getLiveSelectedSize)||void 0===e?void 0:e.call(this))||"auto"}},{key:"startPlay",value:function(e,t,i,r){var n=this._getStateManager(),a=this._getLiveEngine(),s=(0,_liveUtils.buildLiveCandidatesByEngine)(e,i,a),o=s[0];if(!o)return this._setPlayError(!0,"暂无可用拉流地址"),!1;this._setPlayError(!1,""),n.resetLiveRuntimeState({keepQualityPending:r===_types.SwitchReason.QUALITY_DOWNGRADE}),this._clearPerformanceTimers();var l=n.liveState;return l.lineIndex=t||0,l.line=e||null,l.definition=o.mapDefinition||i||"",l.candidates=s,l.candidateIndex=0,l.roundIndex=1,l.retryIndex=0,l.protocol=o.protocol||"",l.fromPrimary=!1!==o.fromPrimary,l.liveEngine=a,this._setData({liveSrc:o.url,liveUrlList:s.map(function(e){return e.url})}),!0}},{key:"onSrcChange",value:function(e){var t,i=this;this.clearTimers(),this._latestPlayUrl=e||"",this._networkDisconnectHandledAttemptId=0,this._networkDisconnectHandledUrl="";var r=Date.now(),n=this.state;n.attemptId+=1,n.attemptReportedFailed=!1,n.playerParams={startPlay:r,firstFrame:0,playUrl:e,attemptId:n.attemptId},this._reportTea("mini_live_start_play",{startPlay:r,playUrl:e,isPseudoLive:!(null===(t=this._getIsPseudoLive)||void 0===t||!t.call(this))});var a=this.config.stability,s=n.attemptId;this._firstFrameTimer=setTimeout(function(){i.state.playerParams.attemptId===s&&(i.state.playerParams.firstFrame||i.handleFailure({code:1e4,msg:"first frame timeout",url:e},{reason:_types.FailureReason.FAIL_TIMEOUT}))},a.firstFrameTimeoutMs)}},{key:"onSuccess",value:function(e){var t,i,r,n=Date.now(),a=this._getStore(),s=!(null==a||null===(t=a.get)||void 0===t||!t.call(a,"reportInfo.isPlay")),o=!!this.state.playerParams.firstFrame;if(!(o&&s||this.state.playerParams.playUrl!==this._latestPlayUrl)){if(this.clearTimers(),this._networkDisconnectHandledAttemptId=0,this._networkDisconnectHandledUrl="",this.state.playerParams.firstFrame=n,this.handleWaitingEnd(),this._setPlayError(!1,""),this._continuousPerfIssueCount=0,null===(i=this._getStatsReporter())||void 0===i||i.startHeartbeat(),a.set("reportInfo.isPlay",!0),!o){var l,u,d,c=Number(null==a||null===(l=a.get)||void 0===l?void 0:l.call(a,"reportInfo.sdkInitRequestStartMs"))||0,_=c&&c<=this.state.playerParams.startPlay?c:this.state.playerParams.startPlay;this._reportTea("mini_live_start_play_success",{firstFrame:Math.max(0,this.state.playerParams.firstFrame-this.state.playerParams.startPlay),firstFrameEndToEnd:Math.max(0,this.state.playerParams.firstFrame-_),successCode:null==e?void 0:e.code,playUrl:this.state.playerParams.playUrl,isPseudoLive:!(null===(u=this._getIsPseudoLive)||void 0===u||!u.call(this))}),null==a||null===(d=a.set)||void 0===d||d.call(a,"reportInfo.sdkInitRequestStartMs",0),this.state.pendingSwitch&&(this._reportTea("mini_sdk_stream_switch_success",_objectSpread(_objectSpread({},this.state.pendingSwitch),{},{durationMs:n-(this.state.pendingSwitch.startMs||n)})),this.state.pendingSwitch=null),this.state.pendingQuality&&(this._reportTea("mini_sdk_quality_downgrade_success",_objectSpread(_objectSpread({},this.state.pendingQuality),{},{durationMs:n-(this.state.pendingQuality.startMs||n)})),this.state.pendingQuality=null)}null===(r=this._onSuccess)||void 0===r||r.call(this)}}},{key:"handleFailure",value:function(e,t){var i,r,n,a,s,o=Date.now(),l=(null==t?void 0:t.reason)||"unknown",u=l===_types.FailureReason.STALL_THRESHOLD||l===_types.FailureReason.WAITING_THRESHOLD||l===_types.FailureReason.LOADING_TIMEOUT,d=this._getStore(),c=this.state,_=this._getStatsReporter();this._reportTea("mini_live_handle_failure",{error:e,reason:l,isPerfIssue:u,playUrl:null==c||null===(i=c.playerParams)||void 0===i?void 0:i.playUrl,liveStateEvents:null==_||null===(r=_.getLiveStateEvents)||void 0===r?void 0:r.call(_),netStatusInfo:c.lastNetStatusInfo||void 0}),!u&&c.pendingQuality&&(this._reportTea("mini_sdk_quality_downgrade_error",_objectSpread(_objectSpread({},c.pendingQuality),{},{durationMs:o-(c.pendingQuality.startMs||o),error:e,reason:l})),c.pendingQuality=null),u||c.playerParams.firstFrame||c.attemptReportedFailed||(c.attemptReportedFailed=!0,this._reportTea("mini_live_start_play_failed",{error:e,reason:l,duration:o-c.playerParams.startPlay,playUrl:c.playerParams.playUrl,liveStateEvents:null==_||null===(a=_.getLiveStateEvents)||void 0===a?void 0:a.call(_),netStatusInfo:c.lastNetStatusInfo||void 0,retryIndex:c.retryIndex||0,roundIndex:c.roundIndex||1,isPseudoLive:!(null===(s=this._getIsPseudoLive)||void 0===s||!s.call(this))}));var h=this.config,v=h.stability,p=h.strategy;if(u&&o-this._lastPerfTriggerMs<v.perfDebounceMs)l===_types.FailureReason.LOADING_TIMEOUT&&this._loadingStartMs&&!this._loadingTimeoutTimer&&this._startLoadingTimeoutTimer();else{if(u){this._lastPerfTriggerMs=o;var g=!1;if("auto"===this._getLiveSelectedSizeValue()&&p.enableQualityDowngrade&&(g=this.tryQualityDowngrade(l)),g)return void(this._continuousPerfIssueCount=0);if(this._continuousPerfIssueCount+=1,this._continuousPerfIssueCount<2||!p.enableStreamSwitchOnPerfIssue)return void(l===_types.FailureReason.LOADING_TIMEOUT&&this._loadingStartMs&&!this._loadingTimeoutTimer&&this._startLoadingTimeoutTimer());this._continuousPerfIssueCount=0}if(d.set("reportInfo.isPlay",!1),null==_||_.stopHeartbeat(l),p.enableStreamSwitch&&this.switchStream(l,e))return;var m=this._getLiveEngine();if("auto"===this._getLiveEngineMode()&&"video"!==m){var y=this.state.line,f=this.state.definition||this._getLiveSelectedSizeValue();if(((null==y?void 0:y.HlsPlayList)||[]).find(function(e){return e.definition===f})&&"function"==typeof this._switchLiveEngine&&this._switchLiveEngine("video",{reason:l,from:"live-player",to:"video",trigger:"degrade"}))return this._reportTea("mini_sdk_live_engine_degrade",{reason:l,from:"live-player",to:"video",error:e}),void this.startPlay(y,this.state.lineIndex||0,f,"engine_degrade")}if(null===(n=this._onFailure)||void 0===n||n.call(this,e,l),!u){this.clearTimers(),this._setPlayError(!0,"拉流失败,请稍后重试");try{var S,T=null===(S=this._liveContextGetter)||void 0===S?void 0:S.call(this);null==T||T.stop()}catch(e){}}}}},{key:"handleNetworkStatusChange",value:function(e){var t,i,r,n,a,s=null==e?void 0:e.isConnected;if(!0===s)return this._networkDisconnectHandledAttemptId=0,void(this._networkDisconnectHandledUrl="");if(!1===s){var o=Number((null===(t=this.state)||void 0===t||null===(i=t.playerParams)||void 0===i?void 0:i.attemptId)||(null===(r=this.state)||void 0===r?void 0:r.attemptId)||0),l=(null===(n=this.state)||void 0===n||null===(a=n.playerParams)||void 0===a?void 0:a.playUrl)||this._latestPlayUrl||"";l&&(this._networkDisconnectHandledAttemptId===o&&this._networkDisconnectHandledUrl===l||(this._networkDisconnectHandledAttemptId=o,this._networkDisconnectHandledUrl=l,this.handleFailure({code:_types.LiveStateCode.NETWORK_DISCONNECT,msg:"network disconnected",networkInfo:e,url:l},{reason:_types.FailureReason.LIVE_ERROR})))}}},{key:"tryQualityDowngrade",value:function(e){var t,i,r=this.state,n=r.line,a=this._getLiveSelectedSizeValue();if(!n||"auto"!==a)return!1;var s=Array.isArray(null==n?void 0:n.SizeList)?n.SizeList:[],o=r.definition,l=(0,_liveUtils.pickNextLowerDefinition)(o,s);if(!l||l===o)return!1;var u=Date.now();r.pendingQuality={startMs:u,fromLevel:o,toLevel:l,triggerReason:e},this._reportTea("mini_sdk_quality_downgrade_start",r.pendingQuality);var d=this._getSdkInstance();return null==d||null===(t=d.emit)||void 0===t||t.call(d,_events.default.PUBLIC.player.qualityDowngrade,_objectSpread(_objectSpread({},r.pendingQuality),{},{lineIndex:r.lineIndex||0})),null==d||null===(i=d.emit)||void 0===i||i.call(d,_events.default.PUBLIC.player.definitionChange,{size:l,source:"auto_downgrade",reason:e}),this.startPlay(n,r.lineIndex||0,l,_types.SwitchReason.QUALITY_DOWNGRADE),!0}},{key:"switchStream",value:function(e,t){var i,r=Date.now(),n=this.state,a=this._getStore(),s=this._getStatsReporter();n.pendingSwitch&&(this._reportTea("mini_sdk_stream_switch_error",_objectSpread(_objectSpread({},n.pendingSwitch),{},{durationMs:r-(n.pendingSwitch.startMs||r),error:t})),n.pendingSwitch=null);var o=Array.isArray(n.candidates)?n.candidates:[],l=this.config.strategy,u=(0,_liveUtils.pickNextLiveCandidate)({candidates:o,currentIndex:n.candidateIndex,roundIndex:n.roundIndex||1,roundMax:null==l?void 0:l.streamSwitchRoundMax});if(!u)return!1;var d=u.current,c=u.next,_=u.nextIndex,h=u.nextRound,v=(n.retryIndex||0)+1;n.roundIndex=h,n.candidateIndex=_,n.retryIndex=v,n.protocol=c.protocol||"",n.fromPrimary=!1!==c.fromPrimary,n.pendingSwitch=(0,_liveUtils.buildStreamSwitchPayload)({now:r,current:d,next:c,reason:e,retryIndex:v,roundIndex:h}),this._reportTea("mini_sdk_stream_switch_start",n.pendingSwitch);var p=this._getSdkInstance();return null==p||null===(i=p.emit)||void 0===i||i.call(p,_events.default.PUBLIC.player.streamSwitch,_objectSpread(_objectSpread({},n.pendingSwitch),{},{toPrimary:!1!==(null==c?void 0:c.fromPrimary),definition:n.definition||this._getLiveSelectedSizeValue()})),a.set("reportInfo.isPlay",!1),null==s||s.stopHeartbeat(e),this._setData({liveSrc:c.url}),!0}},{key:"handleStateChange",value:function(e){var t=this._getStatsReporter(),i=this._getStore(),r=Number(null==e?void 0:e.code),n=(null==e?void 0:e.message)||(null==e?void 0:e.msg)||(null==e?void 0:e.errMsg)||"";switch(null==t||t.recordLiveStateEvent(r,n,{reason:null==e?void 0:e.reason,source:null==e?void 0:e.source,callbackDetail:null==e?void 0:e.raw}),r){case _types.LiveStateCode.STALL:this._handleStall(),null==t||t.handleStall(n);break;case _types.LiveStateCode.PLAY_ENDED:null==t||t.stopHeartbeat("live_state_".concat(r)),i.set("reportInfo.isPlay",!1)}}},{key:"handleWaiting",value:function(){var e,t=this._getStatsReporter();null==t||null===(e=t.recordWaiting)||void 0===e||e.call(t),this._loadingStartMs||(this._startLoading(),null==t||t.startLoading())}},{key:"handleWaitingEnd",value:function(e){var t=this._getStatsReporter();this._endLoading(),null==t||t.stopLoading(),"video"===this._getLiveEngine()&&this._handleWaitingTimeoutThreshold(e)}},{key:"_startLoading",value:function(){var e=Date.now();this._loadingStartMs||(this._loadingStartMs=e),this._startLoadingTimeoutTimer()}},{key:"_endLoading",value:function(){this._loadingStartMs=0,this._clearLoadingTimeoutTimer()}},{key:"_startLoadingTimeoutTimer",value:function(){var e=this;if(!this._loadingTimeoutTimer){var t=this.config.stability,i=null==t?void 0:t.loadingTimeoutMs;"number"!=typeof i||i<=0||(this._loadingTimeoutTimer=setTimeout(function(){e._loadingTimeoutTimer=null,e._loadingStartMs&&e.handleFailure({code:10001,msg:"loading timeout",url:e._latestPlayUrl},{reason:_types.FailureReason.LOADING_TIMEOUT})},i))}}},{key:"_clearLoadingTimeoutTimer",value:function(){this._loadingTimeoutTimer&&(clearTimeout(this._loadingTimeoutTimer),this._loadingTimeoutTimer=null)}},{key:"_handleStall",value:function(){var e=Date.now();this._stallTimestamps.push(e);var t=this.config.stability||{},i=t.stallWindowMs,r=t.stallThreshold,n=this._getStallCountInWindow(i);"number"==typeof r&&n>r&&(this._stallTimestamps=[e],this.handleFailure({code:2105,msg:"stall frequent",count:n},{reason:_types.FailureReason.STALL_THRESHOLD}))}},{key:"_handleWaitingTimeoutThreshold",value:function(e){if("waiting_timeout"!==(null==e?void 0:e.source)||!0!==(null==e?void 0:e.synthetic))return this._waitingTimeoutTimestamps=[],!1;var t=Date.now();this._waitingTimeoutTimestamps.push(t);var i=this.config.stability||{},r=i.loadingTimeoutMs,n=i.videoWaitingThreshold,a=this._getWaitingCountInWindow(r);return"number"==typeof n&&n>0&&r>0&&a>=n&&(this._waitingTimeoutTimestamps=[t],this.handleFailure({code:10002,msg:"waiting timeout frequent",count:a},{reason:_types.FailureReason.WAITING_THRESHOLD}),!0)}},{key:"_getStallCountInWindow",value:function(e){for(var t=Date.now()-("number"==typeof e&&e>0?e:0),i=this._stallTimestamps;i.length&&i[0]<t;)i.shift();return i.length}},{key:"_getWaitingCountInWindow",value:function(e){for(var t=Date.now()-("number"==typeof e&&e>0?e:0),i=this._waitingTimeoutTimestamps;i.length&&i[0]<t;)i.shift();return i.length}},{key:"_clearPerformanceTimers",value:function(){this._stallTimestamps=[],this._waitingTimeoutTimestamps=[],this._loadingStartMs=0,this._lastPerfTriggerMs=0,this._continuousPerfIssueCount=0,this._clearLoadingTimeoutTimer()}},{key:"clearTimers",value:function(){this._firstFrameTimer&&(clearTimeout(this._firstFrameTimer),this._firstFrameTimer=null),this._clearPerformanceTimers(),this._networkDisconnectHandledAttemptId=0,this._networkDisconnectHandledUrl=""}}]),e}();exports.LivePlayerController=LivePlayerController;var createLivePlayerController=function(e){return new LivePlayerController(e)};exports.createLivePlayerController=createLivePlayerController;