@ad-execute-manager/ad-reward 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -219,11 +219,13 @@ declare class RewardAdNovel extends RewardAdFather {
219
219
  * @param {object} _args
220
220
  * @param {string} _args.scene 广告执行场景 必填
221
221
  * @param {number} [_args.timeout] 广告超时时间 单位ms
222
+ * @param {string} _args.eId 广告执行唯一ID 必填
222
223
  * @param {Function} _args.end 结束当前广告任务的回调函数 必填
223
224
  */
224
225
  protected customExecuteAfterTimeout(_args: {
225
226
  scene: string;
226
227
  timeout?: number;
228
+ eId: string;
227
229
  end: Function;
228
230
  }): void;
229
231
  /**
@@ -232,22 +234,27 @@ declare class RewardAdNovel extends RewardAdFather {
232
234
  * @param {object} args
233
235
  * @param {string} args.scene 广告执行场景 必填
234
236
  * @param {number} args.timeout 广告超时时间 单位ms 必填
237
+ * @param {string} args.eId 广告执行唯一ID 必填
235
238
  */
236
239
  _adTimeoutBeforeEnd(args: {
237
240
  scene: string;
238
241
  timeout: number;
242
+ eId: string;
239
243
  }): {
240
244
  scene: string;
241
245
  timeout: number;
246
+ eId: string;
242
247
  };
243
248
  /**
244
249
  * 广告展示前定时器
245
250
  * @param {object} args
246
251
  * @param {string} args.scene 广告执行场景 必填
252
+ * @param {string} args.eId 广告执行唯一ID 必填
247
253
  * @param {Function} args.prelude 广告展示前回调函数 可选
248
254
  */
249
255
  _adPreludeInterval(args: {
250
256
  scene: string;
257
+ eId: string;
251
258
  prelude: Function;
252
259
  }): void;
253
260
  _clearAdTimeout(): void;
@@ -346,12 +353,14 @@ declare class RewardAdNovel extends RewardAdFather {
346
353
  * @protected
347
354
  * @param {object} _args
348
355
  * @param {string} _args.scene 广告执行场景 必填
356
+ * @param {string} _args.eId 广告执行唯一ID 必填
349
357
  * @param {number} _args.ad_is_completed 广告是否完成 必填
350
358
  * @param {number} _args.ad_count 广告执行次数 必填
351
359
  * @returns
352
360
  */
353
361
  protected _adCloseSuccessAnalytics(_args: {
354
362
  scene: string;
363
+ eId: string;
355
364
  ad_is_completed: number;
356
365
  ad_count: number;
357
366
  }): any;
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{AdExecuteManager:()=>core_namespaceObject.AdExecuteManager,RewardAdFather:()=>src_RewardAdFather,RewardAdNovel:()=>src_RewardAdNovel});const core_namespaceObject=require("@ad-execute-manager/core"),logger_namespaceObject=require("@ad-execute-manager/logger"),serializable_error_namespaceObject=require("@ad-execute-manager/serializable-error");class RewardAdFather{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let t=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!t.adUnitId)throw this._logger.error("reward args The adUnitId is required",t),new serializable_error_namespaceObject.SerializableError("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let i=tt.createRewardedVideoAd(t);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==i||i.offError(this.__bindAdErrorForeverHandler),null==i||i.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=i,this.__ad__=i,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,t;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(t=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=t.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{this._rewardAd=null})}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){(null==e?void 0:e.adUnitId)||new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,r){return e&&e instanceof RewardAdFather?core_namespaceObject.AdExecuteManager.getInstance().addTask(e,r):(new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const src_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,r){return!!r&&e.some(e=>RegExp(e,"i").test(r))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[r,t])=>(e[t]=Number(r),e),{})}const DEFAULT_SCENT_TYPE_OBJ={9999:"inner_default_other"},DEFAULT_SCENT_TEXT_OBJ=getAdSceneTextObj(DEFAULT_SCENT_TYPE_OBJ),AD_TYPE_ENUM={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2},AD_TYPE_ENUM_REVERSE=Object.entries(AD_TYPE_ENUM).reduce((e,[r,t])=>(e[t]=r,e),{});class RewardAdNovel extends src_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_eId=null;_adTypeR=AD_TYPE_ENUM.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.__adCloseLister__.bind(this);bindAdErrorLister=this.__adErrorLister__.bind(this);bindAdLoadLister=this.__adLoadLister__.bind(this);bindApiAdErrorLister=this.__apiAdErrorLister__.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var r,t,i,l,s;super(e),this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(r=e.collection)?void 0:r.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(i=e.collection)?void 0:i.onFinish)??null,this._onAlways=(null==e||null==(l=e.collection)?void 0:l.onAlways)??null,this._onError=(null==e||null==(s=e.collection)?void 0:s.onError)??null}initialize(e,r){return super.initialize(e,r),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=RewardAdNovelConfig.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let t="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:t,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:t,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let t=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,end:t})}catch(e){this._logger.warn("use default timeout end task logic:",e),t()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var t,i,l,s;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(i=e.collection)?void 0:i.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(t=>{var i,l,s,n,o;this._resolve=t,this._adInner({options:{scene:null==e||null==(i=e.options)?void 0:i.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:t,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var t,i,l,s,n;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let o=null==e||null==(t=e.collection)?void 0:t.resolve,d=(null==e||null==(i=e.options)?void 0:i.scene)??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,a=null==e||null==(l=e.collection)?void 0:l.before,_=null==e||null==(s=e.collection)?void 0:s.success,u=null==e||null==(n=e.collection)?void 0:n.prelude,h=(null==e?void 0:e.recovered)??this._recovered,c=e=>{this._clearAdTimeout(),this.adDestroy(null==e?void 0:e.preserved),null==o||o(Object.assign({scene:d,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:d},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var t,i;this._scene=d,null==a||a({scene:d}),this._before=a,null==(t=this._onShow)||t.call(this,{scene:d}),this._adShowBeforeAnalytics({scene:d,eId:this._eId}),this._resolve=o,this._next=r,this._setAdTimeout({scene:d,end:c,timeout:null==e||null==(i=e.options)?void 0:i.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:d,prelude:u}),this.adShow().then(()=>{this._clearAdTimeout(),null==_||_({scene:d}),this._success=_,this._adShowSuccessAnalytics({scene:d,eId:this._eId,result:1,recovered:h}),this._onInnerAdShowSuccess({scene:d,eId:this._eId,result:1,recovered:h})}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:d,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,null==e?void 0:e.errMsg)||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?c({scene:d,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?c({scene:d,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
- tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:d,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:d,msg:null==e?void 0:e.errMsg,result:0}),c({scene:d,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,t,i,l,s,n,o,d,a,_,u,h,c,v,f,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(i=this._adExecuteArgs)||null==(t=i.options)?void 0:t.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},E={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(_=e.collection)?void 0:_.success)??(null==(h=this._adExecuteArgs)||null==(u=h.collection)?void 0:u.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(f=this._adExecuteArgs)||null==(v=f.collection)?void 0:v.prelude)};this._adInner({options:w,collection:E,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after task end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),t=e=>{var t,i;this.adDestroy(),null==(t=this._resolve)||t.call(this,Object.assign({},r,e)),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},i=e=>{var t,i,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(i=this._onFinish)||i.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(t=this._onAlways)||t.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:i,end:t})}adCloseLister(e,r){var t,i;null==r||null==(t=r.conn)||t.call(r,e),null==r||null==(i=r.end)||i.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,t,i;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,t,i;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e=!1){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:e})}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,t;this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,t;this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return RewardAdNovel.instance||(RewardAdNovel.instance=new RewardAdNovel(e)),RewardAdNovel.instance}static getInstance(){if(!RewardAdNovel.instance)throw Error("RewardAdNovel instance is not init");return RewardAdNovel.instance}static new(e){return new RewardAdNovel(e)}}class RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=(null==e?void 0:e.retry)??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new RewardAdNovelConfig(e)}}const src_RewardAdNovel=RewardAdNovel;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["AdExecuteManager","RewardAdFather","RewardAdNovel"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
1
+ "use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{AdExecuteManager:()=>core_namespaceObject.AdExecuteManager,RewardAdFather:()=>src_RewardAdFather,RewardAdNovel:()=>src_RewardAdNovel});const core_namespaceObject=require("@ad-execute-manager/core"),logger_namespaceObject=require("@ad-execute-manager/logger"),serializable_error_namespaceObject=require("@ad-execute-manager/serializable-error");class RewardAdFather{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let t=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!t.adUnitId)throw this._logger.error("reward args The adUnitId is required",t),new serializable_error_namespaceObject.SerializableError("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let i=tt.createRewardedVideoAd(t);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==i||i.offError(this.__bindAdErrorForeverHandler),null==i||i.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=i,this.__ad__=i,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,t;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(t=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=t.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{this._rewardAd=null})}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){(null==e?void 0:e.adUnitId)||new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,r){return e&&e instanceof RewardAdFather?core_namespaceObject.AdExecuteManager.getInstance().addTask(e,r):(new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const src_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,r){return!!r&&e.some(e=>RegExp(e,"i").test(r))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[r,t])=>(e[t]=Number(r),e),{})}const DEFAULT_SCENT_TYPE_OBJ={9999:"inner_default_other"},DEFAULT_SCENT_TEXT_OBJ=getAdSceneTextObj(DEFAULT_SCENT_TYPE_OBJ),AD_TYPE_ENUM={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2},AD_TYPE_ENUM_REVERSE=Object.entries(AD_TYPE_ENUM).reduce((e,[r,t])=>(e[t]=r,e),{});class RewardAdNovel extends src_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_eId=null;_adTypeR=AD_TYPE_ENUM.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.__adCloseLister__.bind(this);bindAdErrorLister=this.__adErrorLister__.bind(this);bindAdLoadLister=this.__adLoadLister__.bind(this);bindApiAdErrorLister=this.__apiAdErrorLister__.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var r,t,i,l,s;super(e),this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(r=e.collection)?void 0:r.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(i=e.collection)?void 0:i.onFinish)??null,this._onAlways=(null==e||null==(l=e.collection)?void 0:l.onAlways)??null,this._onError=(null==e||null==(s=e.collection)?void 0:s.onError)??null}initialize(e,r){return super.initialize(e,r),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=RewardAdNovelConfig.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let t="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:t,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:t,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}, eId: ${this._eId}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let t=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{eId:this._eId,apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId,end:t})}catch(e){this._logger.warn(`${this._eId} use default timeout end task logic:`,e),t()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var t,i,l,s;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(i=e.collection)?void 0:i.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(t=>{var i,l,s,n,o;this._resolve=t,this._adInner({options:{scene:null==e||null==(i=e.options)?void 0:i.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:t,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var t,i,l,s,n;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let o=null==e||null==(t=e.collection)?void 0:t.resolve,d=(null==e||null==(i=e.options)?void 0:i.scene)??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,a=null==e||null==(l=e.collection)?void 0:l.before,_=null==e||null==(s=e.collection)?void 0:s.success,h=null==e||null==(n=e.collection)?void 0:n.prelude,u=(null==e?void 0:e.recovered)??this._recovered,c=e=>{this._clearAdTimeout(),this.adDestroy(null==e?void 0:e.preserved),null==o||o(Object.assign({scene:d,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:d},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var t,i;this._scene=d,null==a||a({scene:d,eId:this._eId}),this._before=a,null==(t=this._onShow)||t.call(this,{scene:d,eId:this._eId}),this._adShowBeforeAnalytics({scene:d,eId:this._eId}),this._resolve=o,this._next=r,this._setAdTimeout({scene:d,end:c,timeout:null==e||null==(i=e.options)?void 0:i.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:d,prelude:h,eId:this._eId}),this.adShow().then(()=>{this._clearAdTimeout(),null==_||_({scene:d,eId:this._eId}),this._success=_,this._adShowSuccessAnalytics({scene:d,eId:this._eId,result:1,recovered:u}),this._onInnerAdShowSuccess({scene:d,eId:this._eId,result:1,recovered:u})}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:d,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,null==e?void 0:e.errMsg)||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?c({scene:d,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?c({scene:d,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
+ tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:d,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:d,msg:null==e?void 0:e.errMsg,result:0}),c({scene:d,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,t,i,l,s,n,o,d,a,_,h,u,c,v,f,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(i=this._adExecuteArgs)||null==(t=i.options)?void 0:t.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},E={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(_=e.collection)?void 0:_.success)??(null==(u=this._adExecuteArgs)||null==(h=u.collection)?void 0:h.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(f=this._adExecuteArgs)||null==(v=f.collection)?void 0:v.prelude)};this._adInner({options:w,collection:E,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after task end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,eId:this._eId,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),t=e=>{var t,i;this.adDestroy(),null==(t=this._resolve)||t.call(this,Object.assign({},r,e)),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},i=e=>{var t,i,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(i=this._onFinish)||i.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(t=this._onAlways)||t.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:i,end:t})}adCloseLister(e,r){var t,i;null==r||null==(t=r.conn)||t.call(r,e),null==r||null==(i=r.end)||i.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,t,i;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,t,i;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e=!1){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:e})}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,t;this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,t;this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return RewardAdNovel.instance||(RewardAdNovel.instance=new RewardAdNovel(e)),RewardAdNovel.instance}static getInstance(){if(!RewardAdNovel.instance)throw Error("RewardAdNovel instance is not init");return RewardAdNovel.instance}static new(e){return new RewardAdNovel(e)}}class RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=(null==e?void 0:e.retry)??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new RewardAdNovelConfig(e)}}const src_RewardAdNovel=RewardAdNovel;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["AdExecuteManager","RewardAdFather","RewardAdNovel"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{AdExecuteManager as e}from"@ad-execute-manager/core";import{Logger as r}from"@ad-execute-manager/logger";import{SerializableError as i}from"@ad-execute-manager/serializable-error";class t{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new r({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let l=Object.assign({},t.args,this._adConfig,e);if(!l.adUnitId)throw this._logger.error("reward args The adUnitId is required",l),new i("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let s=tt.createRewardedVideoAd(l);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==s||s.offError(this.__bindAdErrorForeverHandler),null==s||s.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=s,this.__ad__=s,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return t.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,i;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(i=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=i.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{this._rewardAd=null})}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){(null==e?void 0:e.adUnitId)||new r({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),t.args=e}static async executeWithManager(i,l){return i&&i instanceof t?e.getInstance().addTask(i,l):(new r({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let l=t,s=Object.entries({9999:"inner_default_other"}).reduce((e,[r,i])=>(e[i]=Number(r),e),{}),n={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2};Object.entries(n).reduce((e,[r,i])=>(e[i]=r,e),{});class o extends l{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=s.inner_default_other;_eId=null;_adTypeR=n.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.__adCloseLister__.bind(this);bindAdErrorLister=this.__adErrorLister__.bind(this);bindAdLoadLister=this.__adLoadLister__.bind(this);bindApiAdErrorLister=this.__apiAdErrorLister__.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var i,t,l,s,n;super(e),this._logger=new r({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(i=e.collection)?void 0:i.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(l=e.collection)?void 0:l.onFinish)??null,this._onAlways=(null==e||null==(s=e.collection)?void 0:s.onAlways)??null,this._onError=(null==e||null==(n=e.collection)?void 0:n.onError)??null}initialize(e,r){return super.initialize(e,r),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=d.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:i,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:i,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let i=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,end:i})}catch(e){this._logger.warn("use default timeout end task logic:",e),i()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var i,t,l,s;return this._alwaysCallback=null==e||null==(i=e.collection)?void 0:i.always,this._halfwayCallback=null==e||null==(t=e.collection)?void 0:t.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(i=>{var t,l,s,n,o;this._resolve=i,this._adInner({options:{scene:null==e||null==(t=e.options)?void 0:t.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:i,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var i,t,l,n,o;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let d=null==e||null==(i=e.collection)?void 0:i.resolve,a=(null==e||null==(t=e.options)?void 0:t.scene)??this._scene??s.inner_default_other,h=null==e||null==(l=e.collection)?void 0:l.before,u=null==e||null==(n=e.collection)?void 0:n.success,_=null==e||null==(o=e.collection)?void 0:o.prelude,c=(null==e?void 0:e.recovered)??this._recovered,f=e=>{this._clearAdTimeout(),this.adDestroy(null==e?void 0:e.preserved),null==d||d(Object.assign({scene:a,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:a},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var i,t;this._scene=a,null==h||h({scene:a}),this._before=h,null==(i=this._onShow)||i.call(this,{scene:a}),this._adShowBeforeAnalytics({scene:a,eId:this._eId}),this._resolve=d,this._next=r,this._setAdTimeout({scene:a,end:f,timeout:null==e||null==(t=e.options)?void 0:t.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:a,prelude:_}),this.adShow().then(()=>{this._clearAdTimeout(),null==u||u({scene:a}),this._success=u,this._adShowSuccessAnalytics({scene:a,eId:this._eId,result:1,recovered:c}),this._onInnerAdShowSuccess({scene:a,eId:this._eId,result:1,recovered:c})}).catch(e=>{var r,i;(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:a,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),r=this._ttErrorMsgs,(i=null==e?void 0:e.errMsg)&&r.some(e=>RegExp(e,"i").test(i))||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?f({scene:a,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?f({scene:a,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
- tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:a,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:a,msg:null==e?void 0:e.errMsg,result:0}),f({scene:a,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,i,t,l,s,n,o,d,a,h,u,_,c,f,v,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(t=this._adExecuteArgs)||null==(i=t.options)?void 0:i.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},m={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(h=e.collection)?void 0:h.success)??(null==(_=this._adExecuteArgs)||null==(u=_.collection)?void 0:u.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(v=this._adExecuteArgs)||null==(f=v.collection)?void 0:f.prelude)};this._adInner({options:w,collection:m,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after task end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),i=e=>{var i,t;this.adDestroy(),null==(i=this._resolve)||i.call(this,Object.assign({},r,e)),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},t=e=>{var i,t,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(t=this._onFinish)||t.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(i=this._onAlways)||i.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:t,end:i})}adCloseLister(e,r){var i,t;null==r||null==(i=r.conn)||i.call(r,e),null==r||null==(t=r.end)||t.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,i,t;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,i,t;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e=!1){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:e})}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,i;this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,i;this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return o.instance||(o.instance=new o(e)),o.instance}static getInstance(){if(!o.instance)throw Error("RewardAdNovel instance is not init");return o.instance}static new(e){return new o(e)}}class d{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=(null==e?void 0:e.retry)??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new d(e)}}let a=o;export{e as AdExecuteManager,l as RewardAdFather,a as RewardAdNovel};
1
+ import{AdExecuteManager as e}from"@ad-execute-manager/core";import{Logger as r}from"@ad-execute-manager/logger";import{SerializableError as i}from"@ad-execute-manager/serializable-error";class t{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new r({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let l=Object.assign({},t.args,this._adConfig,e);if(!l.adUnitId)throw this._logger.error("reward args The adUnitId is required",l),new i("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let s=tt.createRewardedVideoAd(l);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==s||s.offError(this.__bindAdErrorForeverHandler),null==s||s.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=s,this.__ad__=s,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return t.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,i;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(i=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=i.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{this._rewardAd=null})}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){(null==e?void 0:e.adUnitId)||new r({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),t.args=e}static async executeWithManager(i,l){return i&&i instanceof t?e.getInstance().addTask(i,l):(new r({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let l=t,s=Object.entries({9999:"inner_default_other"}).reduce((e,[r,i])=>(e[i]=Number(r),e),{}),n={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2};Object.entries(n).reduce((e,[r,i])=>(e[i]=r,e),{});class o extends l{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=s.inner_default_other;_eId=null;_adTypeR=n.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.__adCloseLister__.bind(this);bindAdErrorLister=this.__adErrorLister__.bind(this);bindAdLoadLister=this.__adLoadLister__.bind(this);bindApiAdErrorLister=this.__apiAdErrorLister__.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var i,t,l,s,n;super(e),this._logger=new r({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(i=e.collection)?void 0:i.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(l=e.collection)?void 0:l.onFinish)??null,this._onAlways=(null==e||null==(s=e.collection)?void 0:s.onAlways)??null,this._onError=(null==e||null==(n=e.collection)?void 0:n.onError)??null}initialize(e,r){return super.initialize(e,r),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=d.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:i,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:i,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}, eId: ${this._eId}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let i=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{eId:this._eId,apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId,end:i})}catch(e){this._logger.warn(`${this._eId} use default timeout end task logic:`,e),i()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var i,t,l,s;return this._alwaysCallback=null==e||null==(i=e.collection)?void 0:i.always,this._halfwayCallback=null==e||null==(t=e.collection)?void 0:t.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(i=>{var t,l,s,n,o;this._resolve=i,this._adInner({options:{scene:null==e||null==(t=e.options)?void 0:t.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:i,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var i,t,l,n,o;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let d=null==e||null==(i=e.collection)?void 0:i.resolve,a=(null==e||null==(t=e.options)?void 0:t.scene)??this._scene??s.inner_default_other,h=null==e||null==(l=e.collection)?void 0:l.before,u=null==e||null==(n=e.collection)?void 0:n.success,_=null==e||null==(o=e.collection)?void 0:o.prelude,c=(null==e?void 0:e.recovered)??this._recovered,f=e=>{this._clearAdTimeout(),this.adDestroy(null==e?void 0:e.preserved),null==d||d(Object.assign({scene:a,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:a},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var i,t;this._scene=a,null==h||h({scene:a,eId:this._eId}),this._before=h,null==(i=this._onShow)||i.call(this,{scene:a,eId:this._eId}),this._adShowBeforeAnalytics({scene:a,eId:this._eId}),this._resolve=d,this._next=r,this._setAdTimeout({scene:a,end:f,timeout:null==e||null==(t=e.options)?void 0:t.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:a,prelude:_,eId:this._eId}),this.adShow().then(()=>{this._clearAdTimeout(),null==u||u({scene:a,eId:this._eId}),this._success=u,this._adShowSuccessAnalytics({scene:a,eId:this._eId,result:1,recovered:c}),this._onInnerAdShowSuccess({scene:a,eId:this._eId,result:1,recovered:c})}).catch(e=>{var r,i;(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:a,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),r=this._ttErrorMsgs,(i=null==e?void 0:e.errMsg)&&r.some(e=>RegExp(e,"i").test(i))||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?f({scene:a,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?f({scene:a,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
+ tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:a,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:a,msg:null==e?void 0:e.errMsg,result:0}),f({scene:a,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,i,t,l,s,n,o,d,a,h,u,_,c,f,v,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(t=this._adExecuteArgs)||null==(i=t.options)?void 0:i.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},m={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(h=e.collection)?void 0:h.success)??(null==(_=this._adExecuteArgs)||null==(u=_.collection)?void 0:u.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(v=this._adExecuteArgs)||null==(f=v.collection)?void 0:f.prelude)};this._adInner({options:w,collection:m,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after task end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,eId:this._eId,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),i=e=>{var i,t;this.adDestroy(),null==(i=this._resolve)||i.call(this,Object.assign({},r,e)),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},t=e=>{var i,t,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(t=this._onFinish)||t.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(i=this._onAlways)||i.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:t,end:i})}adCloseLister(e,r){var i,t;null==r||null==(i=r.conn)||i.call(r,e),null==r||null==(t=r.end)||t.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,i,t;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,i,t;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e=!1){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:e})}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,i;this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,i;this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return o.instance||(o.instance=new o(e)),o.instance}static getInstance(){if(!o.instance)throw Error("RewardAdNovel instance is not init");return o.instance}static new(e){return new o(e)}}class d{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=(null==e?void 0:e.retry)??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new d(e)}}let a=o;export{e as AdExecuteManager,l as RewardAdFather,a as RewardAdNovel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ad-execute-manager/ad-reward",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Reward ad-related classes including RewardAdFather and RewardAdNovel for ad management.",
5
5
  "type": "module",
6
6
  "exports": {