@ad-execute-manager/ad 2.0.0-alpha.4 → 2.0.2
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.
- package/LICENSE +21 -21
- package/README.md +380 -149
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -2
- package/package.json +8 -4
- package/dist/InterstitialAdFather.d.ts +0 -163
- package/dist/InterstitialAdNovel.d.ts +0 -461
- package/dist/RewardAdFather.d.ts +0 -181
- package/dist/RewardAdNovel.d.ts +0 -553
- package/dist/const/const.d.ts +0 -20
- package/dist/typings/ad.d.ts +0 -208
- package/dist/typings/common.d.ts +0 -14
- package/dist/typings/create-interstitial-ad.d.ts +0 -42
- package/dist/typings/create-rewarded-video-ad.d.ts +0 -42
- package/dist/typings/tracker.d.ts +0 -1
- package/dist/utils/functional.d.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{AdExecuteManager as e}from"@ad-execute-manager/core";import{Logger as i,SerializableError as t}from"@ad-execute-manager/helper";class l{static args=null;_logger=null;_initSign="";_preserveOnEnd=!1;_interstitialAd=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,140502];constructor(e){this._logger=new i({prefix:"InterstitialAdFather",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,i){if(this._interstitialAd)return this._logger.warn("interstitialAd has been initialized"),null==i||i(this._interstitialAd),this;let r=Object.assign({},l.args,this._adConfig,e);if(!r.adUnitId)throw this._logger.error("interstitialAd args The adUnitId is required",r),new t("[InterstitialAdFather] interstitialAd args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100003});let s=tt.createInterstitialAd(r);return this._interstitialAd=s,this.__ad__=s,null==i||i(this._interstitialAd),this}initialized(){return!!this._interstitialAd}async ad(e,i=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let i=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return l.executeWithManager(this,Object.assign({},e,{options:i}))}destroy(){this._interstitialAd&&!this._preserveOnEnd&&(this._interstitialAd.destroy(),this._interstitialAd=null)}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._interstitialAd&&this._interstitialAd.onClose(e)}offClose(e){this._interstitialAd&&this._interstitialAd.offClose(e)}show(){return this._interstitialAd?this._interstitialAd.show():Promise.reject({errMsg:"[InterstitialAdFather] can not show,interstitialAd is null",errorCode:120001})}load(){return this._interstitialAd?this._interstitialAd.load():Promise.reject({errMsg:"[InterstitialAdFather] can not load,interstitialAd is null",errorCode:120002})}onError(e){this._interstitialAd&&this._interstitialAd.onError(e)}offError(e){this._interstitialAd&&this._interstitialAd.offError(e)}onLoad(e){this._interstitialAd&&this._interstitialAd.onLoad(e)}offLoad(e){this._interstitialAd&&this._interstitialAd.offLoad(e)}placeholder(){return null}static buildArgs(e){(null==e?void 0:e.adUnitId)||new i({prefix:"InterstitialAdFather",enable:!0}).error("interstitialAdParams.adUnitId is required"),l.args=e}static async executeWithManager(t,r){return t&&t instanceof l?e.getInstance().addTask(t,r):(new i({prefix:"InterstitialAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let r=l;class s{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 i({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,i){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==i||i(this._rewardAd),this;let l=Object.assign({},s.args,this._adConfig,e);if(!l.adUnitId)throw this._logger.error("reward args The adUnitId is required",l),new t("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let r=tt.createRewardedVideoAd(l);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==r||r.offError(this.__bindAdErrorForeverHandler),null==r||r.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=r,this.__ad__=r,null==i||i(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,i=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let i=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return s.executeWithManager(this,Object.assign({},e,{options:i}))}destroy(){this._rewardAd&&!this._preserveOnEnd&&(this._rewardAd.destroy(),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 i({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),s.args=e}static async executeWithManager(t,l){return t&&t instanceof s?e.getInstance().addTask(t,l):(new i({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let n=s;function o(e,i){return!!i&&e.some(e=>RegExp(e,"i").test(i))}let a=Object.entries({9999:"inner_default_other"}).reduce((e,[i,t])=>(e[t]=Number(i),e),{}),d={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2};Object.entries(d).reduce((e,[i,t])=>(e[t]=i,e),{});class h extends n{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=a.inner_default_other;_adTypeR=d.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_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);constructor(e){var t,l,r,s,n;super(e),this._logger=new i({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._onHalfway=(null==e||null==(t=e.collection)?void 0:t.onHalfway)??null,this._onShow=(null==e||null==(l=e.collection)?void 0:l.onShow)??null,this._onFinish=(null==e||null==(r=e.collection)?void 0:r.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,i){return super.initialize(e,i),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=u.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let i=()=>{tt.offAppShow(i),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,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(i)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let i=(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: ${i}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:i}),null==e||e.end({resolvedValue:{apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${i}`,errorCode:1e5,timeout:i}},nextValue:null})},i)}}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var i;null==(i=e.prelude)||i.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var i;null==(i=e.prelude)||i.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}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,i=null){var t,l,r;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(l=e.collection)?void 0:l.halfway,this._finishedCallback=null==e||null==(r=e.collection)?void 0:r.finished,this._recovered=null==e?void 0:e.recovered,this._onInnerExecuteBefore(),new Promise(t=>{var l,r,s,n,o;this._adInner({options:{scene:null==e||null==(l=e.options)?void 0:l.scene,timeout:null==e||null==(r=e.options)?void 0:r.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},i)})}_adInner(e,i=null){var t,l,r,s,n;let d=null==e||null==(t=e.collection)?void 0:t.resolve,h=(null==e||null==(l=e.options)?void 0:l.scene)??this._scene??a.inner_default_other,u=null==e||null==(r=e.collection)?void 0:r.before,_=null==e||null==(s=e.collection)?void 0:s.success,c=null==e||null==(n=e.collection)?void 0:n.prelude,f=(null==e?void 0:e.recovered)??this._recovered,A=e=>{this._clearAdTimeout(),this.adDestroy(),null==d||d(Object.assign({scene:h,adTypeR:this._adTypeR},null==e?void 0:e.resolvedValue)),null==i||i(Object.assign({scene:h},null==e?void 0:e.nextValue))},w=()=>{var t,l;this._scene=h,null==u||u({scene:h}),this._before=u,null==(t=this._onShow)||t.call(this,{scene:h}),this._adShowBeforeAnalytics({scene:h}),this._resolve=d,this._next=i,this._setAdTimeout({scene:h,end:A,timeout:null==e||null==(l=e.options)?void 0:l.timeout}),this._adPreludeInterval({scene:h,prelude:c}),this.adShow().then(()=>{this._clearAdTimeout(),null==_||_({scene:h}),this._success=_,this._adShowSuccessAnalytics({scene:h,result:1,recovered:f}),this._onInnerAdShowSuccess({scene:h,result:1,recovered:f})}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:h,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),o(this._ttErrorMsgs,null==e?void 0:e.errMsg)||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?A({scene:h,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?A({scene:h,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:h,result:1,frequency:this.novelConfig.frequency}),w()}).catch(e=>{this._adLoadFailureAnalytics({scene:h,msg:null==e?void 0:e.errMsg,result:0}),A({scene:h,resolvedValue:{apiError:e},nextValue:null})}))})};w()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){var i;null==(i=this._alwaysCallback)||i.call(this,e)}_outerHalfwayCallback(e){var i;null==(i=this._halfwayCallback)||i.call(this,e)}_outerFinishedCallback(e){var i;null==(i=this._finishedCallback)||i.call(this,e)}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let i=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,end_type:e.isEnded?"finished":"halfway"}),t=e=>{var t,l;this.adDestroy(),null==(t=this._resolve)||t.call(this,Object.assign({},i,e)),this._resolve=null,null==(l=this._next)||l.call(this),this._next=null,this._success=null,this._before=null},l=e=>{var t,l,r;let s=Object.assign({},i,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),null==(l=this._onFinish)||l.call(this,s)):(this._outerHalfwayCallback(s),null==(r=this._onHalfway)||r.call(this,s)),this._outerCloseCallback(s),null==(t=this._onAlways)||t.call(this,s)};this.adCloseLister(i,{conn:l,end:t})}adCloseLister(e,i){var t,l;null==i||null==(t=i.conn)||t.call(i,e),null==i||null==(l=i.end)||l.call(i,e)}__adErrorLister__(e){var i,t,l;this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e),this.adDestroy(),null==(i=this._onError)||i.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(l=this._next)||l.call(this),this._next=null,this._success=null,this._before=null}adErrorLister(e){return e}__apiAdErrorLister__(e){var i,t,l;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(i=this._onError)||i.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(l=this._next)||l.call(this),this._next=null,this._success=null,this._before=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}adDestroy(){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.destroy()}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.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){var i,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.offClose(this._bindShiftCloseLister),this.destroy(),null==(i=this._resolve)||i.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}_shiftErrorLister(e){var i,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.offError(this._bindShiftErrorLister),this.destroy(),null==(i=this._resolve)||i.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}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return h.instance||(h.instance=new h(e)),h.instance}static getInstance(){if(!h.instance)throw Error("RewardAdNovel instance is not init");return h.instance}static new(e){return new h(e)}}class u{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 u(e)}}let _=h;class c extends r{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=a.inner_default_other;_adTypeR=d.AD_TYPE_INTERSTITIAL;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_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);constructor(e){var t,l,r,s,n;super(e),this._logger=new i({prefix:"InterstitialAdNovel",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._onHalfway=(null==e||null==(t=e.collection)?void 0:t.onHalfway)??null,this._onShow=(null==e||null==(l=e.collection)?void 0:l.onShow)??null,this._onFinish=(null==e||null==(r=e.collection)?void 0:r.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,i){return super.initialize(e,i),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=f.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let i=()=>{tt.offAppShow(i),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,msg:t,errorCode:100001,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:t,errorCode:100001}},nextValue:null})};tt.onAppShow(i)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout&&(this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case, scene:",null==e?void 0:e.scene),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,msg:`ad_show_timeout: normal, interstitial ad, timeout: ${this._adTimeoutTime}`,errorCode:100001,result:0}),null==e||e.end({resolvedValue:{apiError:{errMsg:`ad_show_timeout: normal, interstitial ad, timeout: ${this._adTimeoutTime}`,errorCode:100001}},nextValue:null})},this._adTimeoutTime))}_adPreludeInterval(e){var i;null==(i=e.prelude)||i.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var i;null==(i=e.prelude)||i.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&&(clearTimeout(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}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,i=null){var t,l,r;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(l=e.collection)?void 0:l.halfway,this._finishedCallback=null==e||null==(r=e.collection)?void 0:r.finished,this._onInnerExecuteBefore(),new Promise(t=>{var l,r,s,n;this._adInner({options:{scene:null==e||null==(l=e.options)?void 0:l.scene},collection:{resolve:t,before:null==(r=e.collection)?void 0:r.before,success:null==(s=e.collection)?void 0:s.success,prelude:null==(n=e.collection)?void 0:n.prelude}},i)})}_adInner(e,i=null){var t,l,r,s,n;let d=null==e||null==(t=e.collection)?void 0:t.resolve,h=(null==e||null==(l=e.options)?void 0:l.scene)??this._scene??a.inner_default_other,u=null==e||null==(r=e.collection)?void 0:r.before,_=null==e||null==(s=e.collection)?void 0:s.success,c=null==e||null==(n=e.collection)?void 0:n.prelude,f=e=>{this._clearAdTimeout(),this.adDestroy(),null==d||d(Object.assign({scene:h,adTypeR:this._adTypeR},null==e?void 0:e.resolvedValue)),null==i||i(Object.assign({scene:h},null==e?void 0:e.nextValue))},A=()=>{var e;this._scene=h,null==u||u({scene:h}),this._before=u,null==(e=this._onShow)||e.call(this,{scene:h}),this._adShowBeforeAnalytics({scene:h}),this._resolve=d,this._next=i,this._setAdTimeout({scene:h,end:f}),this._adPreludeInterval({scene:h,prelude:c}),this.adShow().then(()=>{this._clearAdTimeout(),null==_||_({scene:h}),this._success=_,this._adShowSuccessAnalytics({scene:h,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:h,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),o(this._ttErrorMsgs,null==e?void 0:e.errMsg)||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?f({scene:h,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?f({scene:h,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:h,result:1}),A()}).catch(e=>{this._adLoadFailureAnalytics({scene:h,msg:null==e?void 0:e.errMsg,result:0}),f({scene:h,resolvedValue:{apiError:e},nextValue:null})}))})};A()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){var i;null==(i=this._alwaysCallback)||i.call(this,e)}_outerHalfwayCallback(e){var i;null==(i=this._halfwayCallback)||i.call(this,e)}_outerFinishedCallback(e){var i;null==(i=this._finishedCallback)||i.call(this,e)}adCloseLister(){var e,i,t;this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:1});let l={scene:this._scene},r=e=>{var i,t;this.adDestroy(),null==(i=this._resolve)||i.call(this,Object.assign({},{scene:this._scene,adTypeR:this._adTypeR},e)),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null};this._outerFinishedCallback(l),null==(e=this._onFinish)||e.call(this,l),this._outerHalfwayCallback(l),null==(i=this._onHalfway)||i.call(this,l),this._outerCloseCallback(l),null==(t=this._onAlways)||t.call(this,l),r({end_type:"finished"})}adErrorLister(e){var i,t,l;this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),null==(i=this._onError)||i.call(this,e),0>=this.novelConfig.remain()&&(this.adDestroy(),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(l=this._next)||l.call(this),this._next=null,this._success=null,this._before=null)}apiAdErrorLister(e){var i,t,l;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adDestroy(),null==(i=this._onError)||i.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(l=this._next)||l.call(this),this._next=null,this._success=null,this._before=null}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}))}adDestroy(){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.destroy()}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.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){var i,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.offClose(this._bindShiftCloseLister),this.destroy(),null==(i=this._resolve)||i.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}_shiftErrorLister(e){var i,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.offError(this._bindShiftErrorLister),this.destroy(),null==(i=this._resolve)||i.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}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return c.instance||(c.instance=new c(e)),c.instance}static getInstance(){if(!c.instance)throw Error("InterstitialAdNovel instance is not init");return c.instance}static new(e){return new c(e)}}class f{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 f(e)}}let A=c;export{r as InterstitialAdFather,A as InterstitialAdNovel,n as RewardAdFather,_ as RewardAdNovel};
|
|
1
|
+
import{AdExecuteManager as e}from"@ad-execute-manager/core";import{InterstitialAdFather as a,InterstitialAdNovel as r}from"@ad-execute-manager/ad-interstitial";import{RewardAdFather as t,RewardAdNovel as d}from"@ad-execute-manager/ad-reward";export{e as AdExecuteManager,a as InterstitialAdFather,r as InterstitialAdNovel,t as RewardAdFather,d as RewardAdNovel};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ad-execute-manager/ad",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Ad-related classes including InterstitialAdFather, InterstitialAdNovel, RewardAdFather, and RewardAdNovel for ad management.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://github.com/singcl"
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"homepage": "https://npmjs.com/package/@
|
|
24
|
+
"homepage": "https://npmjs.com/package/@ad-execute-manager/ad",
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git+https://github.com/singcl/ad-execute-manager.git"
|
|
@@ -50,8 +50,12 @@
|
|
|
50
50
|
"prepublishOnly": "npm run build"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@ad-execute-manager/
|
|
54
|
-
"@ad-execute-manager/
|
|
53
|
+
"@ad-execute-manager/ad-interstitial": "^2.0.2",
|
|
54
|
+
"@ad-execute-manager/ad-reward": "^2.0.2"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@ad-execute-manager/core": "^2.0.2",
|
|
58
|
+
"@ad-execute-manager/logger": "^2.0.2"
|
|
55
59
|
},
|
|
56
60
|
"devDependencies": {
|
|
57
61
|
"@babel/eslint-parser": "^7.28.5",
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
export default InterstitialAdFather;
|
|
2
|
-
export type IRewordAdConfig = import("./typings/ad.js").IRewordAdConfig;
|
|
3
|
-
export type CallbackCollection = import("./typings/ad.js").CallbackCollection;
|
|
4
|
-
export type IConstructArgs = import("./typings/ad.js").IConstructArgs;
|
|
5
|
-
/**
|
|
6
|
-
* 激励视频实例
|
|
7
|
-
*/
|
|
8
|
-
export type InterstitialAd = import("./typings/create-interstitial-ad.js").InterstitialAd;
|
|
9
|
-
export type IRewardedVideoAd = {
|
|
10
|
-
/**
|
|
11
|
-
* 显示激励视频广告
|
|
12
|
-
*/
|
|
13
|
-
show: () => Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* @typedef IRewardedVideoAd
|
|
17
|
-
* @property {() => Promise.<void>} show 显示激励视频广告
|
|
18
|
-
*/
|
|
19
|
-
declare class InterstitialAdFather {
|
|
20
|
-
/** @type {IRewordAdConfig | null} */
|
|
21
|
-
static args: IRewordAdConfig | null;
|
|
22
|
-
/**
|
|
23
|
-
* @param {IRewordAdConfig} args
|
|
24
|
-
*/
|
|
25
|
-
static buildArgs(args: IRewordAdConfig): void;
|
|
26
|
-
/**
|
|
27
|
-
* 使用管理器执行广告
|
|
28
|
-
* @param {Object} adInstance 广告实例
|
|
29
|
-
* @param {Object} ctx 上下文对象,用于传递数据和状态
|
|
30
|
-
* @param {Object} ctx.options 广告执行选项
|
|
31
|
-
* @param {Object} ctx.collection 回调集合
|
|
32
|
-
* @returns {Promise} 广告执行结果的Promise
|
|
33
|
-
*/
|
|
34
|
-
static executeWithManager(adInstance: any, ctx: {
|
|
35
|
-
options: any;
|
|
36
|
-
collection: any;
|
|
37
|
-
}): Promise<any>;
|
|
38
|
-
/**
|
|
39
|
-
* @param {IConstructArgs} args
|
|
40
|
-
*/
|
|
41
|
-
constructor(args: IConstructArgs);
|
|
42
|
-
/** @private */
|
|
43
|
-
/** @type {Logger} */
|
|
44
|
-
_logger: Logger;
|
|
45
|
-
_initSign: string;
|
|
46
|
-
_preserveOnEnd: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* 激励视频实例
|
|
49
|
-
* @type {InterstitialAd | null}
|
|
50
|
-
*/
|
|
51
|
-
_interstitialAd: InterstitialAd | null;
|
|
52
|
-
/**
|
|
53
|
-
* 激励视频实例
|
|
54
|
-
* @type {InterstitialAd | null}
|
|
55
|
-
*/
|
|
56
|
-
__ad__: InterstitialAd | null;
|
|
57
|
-
_ttErrorMsgs: string[];
|
|
58
|
-
_ttErrorCodes: number[];
|
|
59
|
-
_adConfig: {};
|
|
60
|
-
/**
|
|
61
|
-
* 初始化
|
|
62
|
-
* 子类可以选择覆盖此方法,或使用默认实现
|
|
63
|
-
* @param {IRewordAdConfig} params
|
|
64
|
-
* @param {(v: IRewardedVideoAd) => void} [callback] 初始化成功回调
|
|
65
|
-
* @returns {this} 当前实例
|
|
66
|
-
*/
|
|
67
|
-
initialize(params: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
|
|
68
|
-
initialized(): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* 执行广告展示
|
|
71
|
-
* @abstract
|
|
72
|
-
* @param {Object} [ctx] 上下文对象,用于传递数据和状态
|
|
73
|
-
* @param {IRewordAdConfig} [ctx.options] 广告执行选项
|
|
74
|
-
* @param {CallbackCollection} [ctx.collection] 回调集合
|
|
75
|
-
* @param {Function} next 执行下一个任务的回调函数,在洋葱模型中手动调用以继续执行流程
|
|
76
|
-
* @returns {Promise<unknown>} 广告执行结果的Promise
|
|
77
|
-
* @throws {Error} 子类必须实现此方法
|
|
78
|
-
*/
|
|
79
|
-
ad(ctx?: {
|
|
80
|
-
options?: IRewordAdConfig;
|
|
81
|
-
collection?: CallbackCollection;
|
|
82
|
-
}, next?: Function): Promise<unknown>;
|
|
83
|
-
/**
|
|
84
|
-
* 确保广告按顺序执行
|
|
85
|
-
* @param {Object} [ctx] 上下文对象,用于传递数据和状态
|
|
86
|
-
* @param {IRewordAdConfig} [ctx.options] 广告执行选项
|
|
87
|
-
* @param {CallbackCollection} [ctx.collection] 回调集合
|
|
88
|
-
* @returns {Promise.<unknown>} 广告执行结果的Promise
|
|
89
|
-
*/
|
|
90
|
-
addExecuteManager(ctx?: {
|
|
91
|
-
options?: IRewordAdConfig;
|
|
92
|
-
collection?: CallbackCollection;
|
|
93
|
-
}): Promise<unknown>;
|
|
94
|
-
destroy(): void;
|
|
95
|
-
/**
|
|
96
|
-
* 清理广告实例
|
|
97
|
-
* @abstract 清理广告实例,子类必须实现此方法
|
|
98
|
-
*/
|
|
99
|
-
clear(): void;
|
|
100
|
-
/**
|
|
101
|
-
* 任务执行完成后始终执行的一个方法
|
|
102
|
-
* @abstract 任务执行完成后始终执行的一个方法,子类需要用到时实现此方法
|
|
103
|
-
* @param {object} [_args] 执行结果信息
|
|
104
|
-
* @param {number} [_args.scene] 场景信息
|
|
105
|
-
* @param {string} _args.id 任务id
|
|
106
|
-
* @param {object} [_args.apiError] 广告api错误信息
|
|
107
|
-
* @param {number} [_args.adTypeR] 广告类型 1 激励视频 2插屏广告
|
|
108
|
-
* @param {object} _args.recovered 后台恢复重试
|
|
109
|
-
* @param {boolean} [_args.recovered.retry] 后台恢复预估是否重试
|
|
110
|
-
* @param {number} [_args.recovered.count] 后台恢复预估重试次数
|
|
111
|
-
* @param {string} [_args.recovered.message] 后台恢复预估重试原因
|
|
112
|
-
*/
|
|
113
|
-
record(_args?: {
|
|
114
|
-
scene?: number;
|
|
115
|
-
id: string;
|
|
116
|
-
apiError?: object;
|
|
117
|
-
adTypeR?: number;
|
|
118
|
-
recovered: {
|
|
119
|
-
retry?: boolean;
|
|
120
|
-
count?: number;
|
|
121
|
-
message?: string;
|
|
122
|
-
};
|
|
123
|
-
}): this;
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
* @param {({isEnded: boolean, count: number}) => void} callback
|
|
127
|
-
*/
|
|
128
|
-
onClose(callback: ({ isEnded: boolean, count: number }: any) => void): void;
|
|
129
|
-
/**
|
|
130
|
-
*
|
|
131
|
-
* @param {({isEnded: boolean, count: number}) => void} callback
|
|
132
|
-
*/
|
|
133
|
-
offClose(callback: ({ isEnded: boolean, count: number }: any) => void): void;
|
|
134
|
-
/**
|
|
135
|
-
* show
|
|
136
|
-
* @returns { Promise.<void>}
|
|
137
|
-
* @params {{errMsg: string; errCode: number}} err
|
|
138
|
-
*/
|
|
139
|
-
show(): Promise<void>;
|
|
140
|
-
/**
|
|
141
|
-
* load
|
|
142
|
-
* @returns { Promise.<void>}
|
|
143
|
-
*/
|
|
144
|
-
load(): Promise<void>;
|
|
145
|
-
/**
|
|
146
|
-
*
|
|
147
|
-
* @param {({errMsg: string; errCode: number}) => void} callback
|
|
148
|
-
*/
|
|
149
|
-
onError(callback: any): void;
|
|
150
|
-
/**
|
|
151
|
-
*
|
|
152
|
-
* @param {({errMsg: string; errCode: number}) => void} callback
|
|
153
|
-
*/
|
|
154
|
-
offError(callback: any): void;
|
|
155
|
-
onLoad(callback: any): void;
|
|
156
|
-
offLoad(callback: any): void;
|
|
157
|
-
/**
|
|
158
|
-
* 站位方法,没有任何左右
|
|
159
|
-
* @returns
|
|
160
|
-
*/
|
|
161
|
-
placeholder(): any;
|
|
162
|
-
}
|
|
163
|
-
import { Logger } from '@ad-execute-manager/helper';
|