"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.requestBackgroundPlayback=exports.getCurrentMediaContextController=exports.canRequestBackgroundPlayback=void 0;var _miniSdkConfig=require("./mini-sdk-config"),_types=require("./types"),_utils=require("./utils"),_backgroundPlayback=require("../../utils/background-playback"),getCurrentMediaContextController=function(e){var r;return e.data.videoType===_types.VideoType.LIVE?{playerType:e.data.liveEngine,context:null===(r=e._getLivePlayerComponent)||void 0===r?void 0:r.call(e)}:e.data.videoType===_types.VideoType.VOD?(e.videoContext||(e.videoContext=wx.createVideoContext("volcVodPlayer",e)),{playerType:"video",context:e.videoContext}):{playerType:e.data.videoType||"",context:null}};exports.getCurrentMediaContextController=getCurrentMediaContextController;var canRequestBackgroundPlayback=function(e){var r=(0,_miniSdkConfig.getMiniSdkBackgroundPlaybackConfig)(e.store);if((0,_utils.isDeviceMatchRulesMatched)(r.enabledDevices))return!0;if((0,_utils.isDeviceMatchRulesMatched)(r.disabledDevices))return!1;var a=getCurrentMediaContextController(e).playerType;return(0,_backgroundPlayback.canRequestBackgroundPlaybackByPlayerType)(a)};exports.canRequestBackgroundPlayback=canRequestBackgroundPlayback;var requestBackgroundPlayback=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"api",a=getCurrentMediaContextController(e),t=a.context,o=a.playerType,n=function(e,a){return{ok:!1,payload:{source:r,playerType:o,errMsg:a,reason:e}}};if(!t)return n("player_not_ready","requestBackgroundPlayback:fail player not ready");if(!canRequestBackgroundPlayback(e))return n("unsupported","requestBackgroundPlayback:fail method not found");try{return t.requestBackgroundPlayback(),{ok:!0,payload:{source:r,playerType:o,errMsg:"requestBackgroundPlayback:ok"}}}catch(e){return n("wechat_fail",(null==e?void 0:e.errMsg)||(null==e?void 0:e.message)||"requestBackgroundPlayback:fail")}};exports.requestBackgroundPlayback=requestBackgroundPlayback;