"use strict";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)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.updatePlayerInstance=exports.updateBanStatus=exports.resumePlayer=exports.playerInstance=exports.pausePlayer=exports.isRepeatConsume=exports.handleForceExitMessage=exports.handleBanStatusChange=exports.handleBanContinue=exports.getBanTypeByErrorCode=exports.getBanTipsText=exports.clearExitTimeList=exports.clearCacheUserInfo=void 0;var _constant=require("./constant"),_times=require("./times"),_loop=require("./loop"),_utils=require("./utils");function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(s&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:S(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}function asyncGeneratorStep(e,t,r,n,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function i(e){asyncGeneratorStep(a,n,o,i,s,"next",e)}function s(e){asyncGeneratorStep(a,n,o,i,s,"throw",e)}i(void 0)})}}var playerInstance=null;exports.playerInstance=playerInstance;var clearCacheUserInfo=function(){var e=_asyncToGenerator(_regeneratorRuntime().mark(function e(t){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("clearCacheUserInfo called with errorCode:",null==t?void 0:t.errorCode),e.abrupt("return",!0);case 2:case"end":return e.stop()}},e)}));return function(t){return e.apply(this,arguments)}}();exports.clearCacheUserInfo=clearCacheUserInfo;var updateBanStatus=function(e,t){if(e){var r=e.get("banStatus")||{},n=r.isBanned,o=t.isBanned,a=t.isSoftBan;!0===n&&n===o&&a||e.set("banStatus",_objectSpread(_objectSpread({},r),t))}};exports.updateBanStatus=updateBanStatus;var getBanTypeByErrorCode=function(e){return e===_constant.ErrorCodeEnum.MULTI_DEVICE_LOGIN?_constant.BAN_TYPE.TOPPED:[_constant.ErrorCodeEnum.NOT_PASS_REVIEW,_constant.ErrorCodeEnum.KICK_OUT,_constant.ErrorCodeEnum.IP_BANNED,_constant.ErrorCodeEnum.NOT_IN_AUDIENCE_GROUP].includes(e)?_constant.BAN_TYPE.KICK_OUT:_constant.BAN_TYPE.NONE};exports.getBanTypeByErrorCode=getBanTypeByErrorCode;var getBanTipsText=function(e){var t;return(_defineProperty(t={},_constant.BAN_TYPE.TOPPED,"当前账号已在其他设备登录"),_defineProperty(t,_constant.BAN_TYPE.KICK_OUT,"因扰乱直播间秩序,已暂停观看"),_defineProperty(t,_constant.BAN_TYPE.CHECK_IN,"因长时间未签到,已暂停观看"),_defineProperty(t,_constant.BAN_TYPE.NONE,"因扰乱直播间秩序,已暂停观看"),t)[e]||""};exports.getBanTipsText=getBanTipsText;var isRepeatConsume=function(e){try{var t=wx.getStorageSync("exitTimeList"),r=t?JSON.parse(t):[];if(Array.isArray(r)){if(r.includes(e))return console.log("重复消费",r,e),!0;r.push(e),wx.setStorageSync("exitTimeList",JSON.stringify(r))}else console.warn("exitTimeList in storage is not an array, resetting to empty array"),wx.setStorageSync("exitTimeList",JSON.stringify([]))}catch(t){console.error("Failed to parse or update exitTimeList in storage:",t),wx.setStorageSync("exitTimeList",JSON.stringify([e]))}return!1};exports.isRepeatConsume=isRepeatConsume;var clearExitTimeList=function(){try{wx.removeStorageSync("exitTimeList"),console.log("exitTimeList cleared")}catch(e){console.error("Failed to clear exitTimeList:",e)}};exports.clearExitTimeList=clearExitTimeList;var handleForceExitMessage=function(e,t){var r;if(!e||!t)return!1;var n,o=e.ExitStatus,a=e.ExitTime,i=e.ExitTip;if(o===_constant.BanStatus.SOFT_BAN)return!!(a&&_times.firstEntryTime&&a>_times.firstEntryTime)&&!isRepeatConsume(a)&&(updateBanStatus(t.store,{isBanned:!0,banType:_constant.BAN_TYPE.KICK_OUT,banTips:i,isSoftBan:!0}),null===(n=t.pausePollingForBan)||void 0===n||n.call(t,"soft_ban"),!0);var s=(t.store.get("mainInfo")||{}).disableOfflineModal||!1,c=(_defineProperty(r={},_constant.BanStatus.FORCE_BAN,{banType:_constant.BAN_TYPE.KICK_OUT,errorEvent:_constant.SDKErrorEvent.LIVE_KICK_OUT}),_defineProperty(r,_constant.BanStatus.IP_BAN,{banType:_constant.BAN_TYPE.KICK_OUT,errorEvent:_constant.SDKErrorEvent.LIVE_IP_BANNED}),_defineProperty(r,_constant.BanStatus.MULTI_DEVICE_LOGIN,{banType:_constant.BAN_TYPE.TOPPED,errorEvent:_constant.SDKErrorEvent.LIVE_DUPLICATE_LOGIN}),r)[o];return!!c&&(s||updateBanStatus(t.store,{isBanned:!0,banType:c.banType,banTips:i||c.defaultTips}),"function"==typeof t.pausePollingForBan?t.pausePollingForBan("force_exit"):((0,_loop.clearLoop)(_loop.LOOP_KEY.Activity),(0,_loop.clearLoop)(_loop.LOOP_KEY.Chat),(0,_loop.clearLoop)(_loop.LOOP_KEY.Report)),t.emit(_constant.EVENTS.PUBLIC.error,{code:_constant.SDKErrorCode[c.errorEvent],message:_constant.SDKErrorMessage[c.errorEvent]}),!0)};exports.handleForceExitMessage=handleForceExitMessage;var updatePlayerInstance=function(e){exports.playerInstance=playerInstance=e,console.log("[PlayerInstance] Player instance updated:",playerInstance?"Success":"Cleared")};exports.updatePlayerInstance=updatePlayerInstance;var pausePlayer=function(){playerInstance&&"function"==typeof playerInstance.pause?(console.log("[PlayerControl] Pausing player via global instance"),playerInstance.pause()):console.warn("[PlayerControl] Global player instance not available or pause method unavailable")};exports.pausePlayer=pausePlayer;var resumePlayer=function(){playerInstance&&"function"==typeof playerInstance.play?(console.log("[PlayerControl] Resuming player via global instance"),playerInstance.play()):console.warn("[PlayerControl] Global player instance not available or play method unavailable")};exports.resumePlayer=resumePlayer;var handleBanStatusChange=function(e,t){if(t&&e){var r=t.isBanned,n=t.banType,o=t.isSoftBan,a=n!==_constant.BAN_TYPE.CHECK_IN&&!o;r?(pausePlayer(),a&&(0,_utils.setDataIfChanged)(e,{showPlayer:!1})):(0,_utils.setDataIfChanged)(e,{showPlayer:!0})}};exports.handleBanStatusChange=handleBanStatusChange;var handleBanContinue=function(e,t,r){var n,o;if(e){console.log("[BanControl] User clicked continue watch");var a,i=t||(null===(n=e.data)||void 0===n?void 0:n.sdkInstance)||(null===(o=e.properties)||void 0===o?void 0:o.sdkInstance);r&&!0!==r.isSoftBan||null==i||null===(a=i.resumePollingAfterBan)||void 0===a||a.call(i),(0,_utils.setDataIfChanged)(e,{showPlayer:!0},function(){resumePlayer()})||resumePlayer()}else console.error("[BanControl] Invalid context provided for continue watch")};exports.handleBanContinue=handleBanContinue;