@ad-execute-manager/ad 2.0.0-alpha.1 → 2.0.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.
- package/LICENSE +21 -0
- package/README.md +380 -0
- package/dist/{ad/InterstitialAdFather.d.ts → InterstitialAdFather.d.ts} +42 -10
- package/dist/{ad/InterstitialAdNovel.d.ts → InterstitialAdNovel.d.ts} +12 -8
- package/dist/{ad/RewardAdFather.d.ts → RewardAdFather.d.ts} +60 -10
- package/dist/{ad/RewardAdNovel.d.ts → RewardAdNovel.d.ts} +113 -24
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +5 -15
- package/dist/index.js +2 -1
- package/dist/typings/ad.d.ts +28 -8
- package/dist/typings/create-interstitial-ad.d.ts +42 -0
- package/dist/typings/create-rewarded-video-ad.d.ts +42 -0
- package/package.json +54 -10
- package/dist/ad/index.d.ts +0 -4
- package/dist/core/AdExecuteManager.d.ts +0 -129
- package/dist/core/compose.d.ts +0 -12
- package/dist/core/index.d.ts +0 -2
- package/dist/helper/AdAnalyticsJS.d.ts +0 -132
- package/dist/helper/CountRecorder.d.ts +0 -59
- package/dist/helper/EventEmitter.d.ts +0 -15
- package/dist/helper/Logger.d.ts +0 -35
- package/dist/helper/LovelUnlockManager.d.ts +0 -233
- package/dist/helper/PubSub.d.ts +0 -9
- package/dist/helper/RewardAdGlobalRecorder.d.ts +0 -109
- package/dist/helper/RewardAdSceneTriggerManager.d.ts +0 -71
- package/dist/helper/SerializableError.d.ts +0 -9
- package/dist/helper/Storage.d.ts +0 -124
- package/dist/helper/index.d.ts +0 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default RewardAdNovel;
|
|
2
|
-
export type IRewordAdConfig =
|
|
2
|
+
export type IRewordAdConfig = any;
|
|
3
3
|
export type ICallbackArgs = {
|
|
4
4
|
/**
|
|
5
5
|
* 广告执行场景
|
|
@@ -52,6 +52,10 @@ export type IConstructArgs = {
|
|
|
52
52
|
* 初始化标识
|
|
53
53
|
*/
|
|
54
54
|
sign?: string;
|
|
55
|
+
/**
|
|
56
|
+
* 是否开启日志
|
|
57
|
+
*/
|
|
58
|
+
log?: boolean;
|
|
55
59
|
/**
|
|
56
60
|
* 是否保留tt激励视频广告实例
|
|
57
61
|
*/
|
|
@@ -126,6 +130,7 @@ export type IRewardedVideoAd = {
|
|
|
126
130
|
/**
|
|
127
131
|
* @typedef IConstructArgs
|
|
128
132
|
* @property {string} [sign] 初始化标识
|
|
133
|
+
* @property {boolean} [log] 是否开启日志
|
|
129
134
|
* @property {boolean} [preserveOnEnd] 是否保留tt激励视频广告实例
|
|
130
135
|
* @property {boolean} [needEndOnTimeout] 是否需要在超时情况下结束广告
|
|
131
136
|
* @property {IRewordAdConfig=} [adConfig] 激励视频参数 (可选)
|
|
@@ -185,7 +190,6 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
185
190
|
_scene: number;
|
|
186
191
|
_adTypeR: 1;
|
|
187
192
|
_adTimeout: any;
|
|
188
|
-
_adTimeoutTime: number;
|
|
189
193
|
_adBeforeShowTimer: any;
|
|
190
194
|
_adBeforeShowTime: number;
|
|
191
195
|
_adSpeedCloseTimer: any;
|
|
@@ -199,6 +203,7 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
199
203
|
bindApiAdErrorLister: any;
|
|
200
204
|
_bindShiftCloseLister: any;
|
|
201
205
|
_bindShiftErrorLister: any;
|
|
206
|
+
_adConfig: any;
|
|
202
207
|
/**
|
|
203
208
|
* 初始化
|
|
204
209
|
* 子类可以选择覆盖此方法,或使用默认实现
|
|
@@ -217,7 +222,18 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
217
222
|
}): void;
|
|
218
223
|
novelConfig: RewardAdNovelConfig;
|
|
219
224
|
_onInnerExecuteBefore(): any;
|
|
220
|
-
|
|
225
|
+
/**
|
|
226
|
+
* @param {object} _args
|
|
227
|
+
* @param {string} _args.scene 广告执行场景 必填
|
|
228
|
+
* @param {number} [_args.result] 广告执行成功结果 必填
|
|
229
|
+
* @param {import('../typings/ad.js').RecoveredInfo} [_args.recovered] 恢复重试信息
|
|
230
|
+
* @returns
|
|
231
|
+
*/
|
|
232
|
+
_onInnerAdShowSuccess(_args: {
|
|
233
|
+
scene: string;
|
|
234
|
+
result?: number;
|
|
235
|
+
recovered?: any;
|
|
236
|
+
}): any;
|
|
221
237
|
/**
|
|
222
238
|
* 广告展示超时设置
|
|
223
239
|
* @param {object} args
|
|
@@ -230,6 +246,20 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
230
246
|
timeout?: number;
|
|
231
247
|
end: Function;
|
|
232
248
|
}): void;
|
|
249
|
+
/**
|
|
250
|
+
* 子类可以选择覆盖此方法
|
|
251
|
+
* 添加超时情况下结束任务前的回调
|
|
252
|
+
* @param {object} args
|
|
253
|
+
* @param {string} args.scene 广告执行场景 必填
|
|
254
|
+
* @param {number} args.timeout 广告超时时间 单位ms 必填
|
|
255
|
+
*/
|
|
256
|
+
_adTimeoutBeforeEnd(args: {
|
|
257
|
+
scene: string;
|
|
258
|
+
timeout: number;
|
|
259
|
+
}): {
|
|
260
|
+
scene: string;
|
|
261
|
+
timeout: number;
|
|
262
|
+
};
|
|
233
263
|
/**
|
|
234
264
|
* 广告展示前定时器
|
|
235
265
|
* @param {object} args
|
|
@@ -259,13 +289,15 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
259
289
|
* @param {object} _args
|
|
260
290
|
* @param {string} _args.scene 广告执行场景 必填
|
|
261
291
|
* @param {string} [_args.msg] 广告执行成功原因
|
|
262
|
-
* @param {0|1} _args.result 广告执行成功结果
|
|
292
|
+
* @param {0|1} _args.result 广告执行成功结果 必填
|
|
293
|
+
* @param {import('../typings/ad.js').RecoveredInfo} [_args.recovered] 恢复重试信息
|
|
263
294
|
* @returns
|
|
264
295
|
*/
|
|
265
296
|
protected _adShowSuccessAnalytics(_args: {
|
|
266
297
|
scene: string;
|
|
267
298
|
msg?: string;
|
|
268
299
|
result: 0 | 1;
|
|
300
|
+
recovered?: any;
|
|
269
301
|
}): any;
|
|
270
302
|
/**
|
|
271
303
|
* 广告展示失败分析
|
|
@@ -291,13 +323,20 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
291
323
|
* @param {object} _args
|
|
292
324
|
* @param {string} _args.scene 广告执行场景 必填
|
|
293
325
|
* @param {string} [_args.msg] 广告执行成功原因
|
|
294
|
-
* @param {0|1} _args.result 广告执行成功结果
|
|
326
|
+
* @param {0|1} _args.result 广告执行成功结果 必填
|
|
327
|
+
* @param {object} [_args.frequency] 广告执行重试参数
|
|
328
|
+
* @param {number} _args.frequency.total 广告执行总次数 必填
|
|
329
|
+
* @param {number} _args.frequency.current 广告执行当前次数 必填
|
|
295
330
|
* @returns
|
|
296
331
|
*/
|
|
297
332
|
protected _adLoadSuccessAnalytics(_args: {
|
|
298
333
|
scene: string;
|
|
299
334
|
msg?: string;
|
|
300
335
|
result: 0 | 1;
|
|
336
|
+
frequency?: {
|
|
337
|
+
total: number;
|
|
338
|
+
current: number;
|
|
339
|
+
};
|
|
301
340
|
}): any;
|
|
302
341
|
/**
|
|
303
342
|
* 广告加载失败分析
|
|
@@ -329,7 +368,7 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
329
368
|
ad_is_completed: number;
|
|
330
369
|
ad_count: number;
|
|
331
370
|
}): any;
|
|
332
|
-
get rewardAd():
|
|
371
|
+
get rewardAd(): import("./typings/create-rewarded-video-ad.js").RewardedVideoAd;
|
|
333
372
|
/**
|
|
334
373
|
* 确保广告按顺序执行
|
|
335
374
|
* @override
|
|
@@ -340,26 +379,30 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
340
379
|
*/
|
|
341
380
|
override addExecuteManager(ctx?: {
|
|
342
381
|
options?: IRewordAdConfig;
|
|
343
|
-
collection?:
|
|
382
|
+
collection?: any;
|
|
344
383
|
}): Promise<(IEndArgs & ICloseArgs) | undefined>;
|
|
345
384
|
/**
|
|
346
385
|
* @override
|
|
347
386
|
* @param {object} [ctx] 广告执行上下文
|
|
348
387
|
* @param {import('../typings/ad.js').IRewordAdConfig} [ctx.options] 广告执行选项
|
|
349
388
|
* @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
|
|
389
|
+
* @param {import('../typings/ad.js').RecoveredInfo} [ctx.recovered] 恢复重试信息
|
|
350
390
|
* @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
|
|
351
391
|
* @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
|
|
352
392
|
*/
|
|
353
393
|
override ad(ctx?: {
|
|
354
|
-
options?:
|
|
355
|
-
collection?:
|
|
394
|
+
options?: any;
|
|
395
|
+
collection?: any;
|
|
396
|
+
recovered?: any;
|
|
356
397
|
}, next?: Function): Promise<(IEndArgs & ICloseArgs) | undefined>;
|
|
398
|
+
_recovered: any;
|
|
357
399
|
/**
|
|
358
400
|
* @param {object} [ctx] 广告执行上下文
|
|
359
401
|
* @param {object} [ctx.options] 广告执行选项
|
|
360
402
|
* @param {number} [ctx.options.scene] 广告执行场景 必填
|
|
361
403
|
* @param {number} [ctx.options.timeout] 广告超时时间 单位ms
|
|
362
404
|
* @param {object} ctx.collection 回调集合
|
|
405
|
+
* @param {import('../typings/ad.js').RecoveredInfo} [ctx.recovered] 恢复重试信息
|
|
363
406
|
* @param {(v?: unknown) => void} ctx.collection.resolve 广告执行成功的回调函数
|
|
364
407
|
* @param {(v?: unknown) => void} [ctx.collection.reject] 广告执行失败的回调函数
|
|
365
408
|
* @param {(v?: unknown) => void} [ctx.collection.before] 广告执行前的回调函数
|
|
@@ -372,16 +415,11 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
372
415
|
scene?: number;
|
|
373
416
|
timeout?: number;
|
|
374
417
|
};
|
|
375
|
-
collection:
|
|
376
|
-
|
|
377
|
-
reject?: (v?: unknown) => void;
|
|
378
|
-
before?: (v?: unknown) => void;
|
|
379
|
-
success?: (v?: unknown) => void;
|
|
380
|
-
prelude?: (v?: unknown) => void;
|
|
381
|
-
};
|
|
418
|
+
collection: object;
|
|
419
|
+
recovered?: any;
|
|
382
420
|
}, next?: Function): void;
|
|
383
|
-
_before:
|
|
384
|
-
_success:
|
|
421
|
+
_before: any;
|
|
422
|
+
_success: any;
|
|
385
423
|
/**
|
|
386
424
|
* 广告加载
|
|
387
425
|
* @returns
|
|
@@ -396,19 +434,70 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
396
434
|
_outerHalfwayCallback(args: any): void;
|
|
397
435
|
_outerFinishedCallback(args: any): void;
|
|
398
436
|
/**
|
|
399
|
-
*
|
|
400
|
-
*
|
|
437
|
+
* 内部关闭激励视频
|
|
438
|
+
* @private
|
|
401
439
|
* @param {ICloseArgs} args
|
|
402
440
|
*/
|
|
403
|
-
|
|
404
|
-
adErrorLister(e: any): void;
|
|
405
|
-
apiAdErrorLister(e: any): void;
|
|
441
|
+
private __adCloseLister__;
|
|
406
442
|
/**
|
|
443
|
+
* 关闭激励视频
|
|
444
|
+
* 子类可重写该方法
|
|
445
|
+
* @protected
|
|
446
|
+
* @param {object} args
|
|
447
|
+
* @param {boolean} args.isEnded 广告是否完成
|
|
448
|
+
* @param {number} args.count 广告执行次数
|
|
449
|
+
* @param {string} args.scene 广告执行场景
|
|
450
|
+
* @param {number} args.adTypeR 广告类型
|
|
451
|
+
* @param {string} args.end_type 广告关闭类型
|
|
452
|
+
* @param {object} [connection] 广告关闭回调集合
|
|
453
|
+
* @param {(ctx: object) => void} [connection.conn] 调用外部传入的回调
|
|
454
|
+
* @param {(ctx: object) => void} [connection.end] 结束任务的回调
|
|
455
|
+
*
|
|
456
|
+
*/
|
|
457
|
+
protected adCloseLister(args: {
|
|
458
|
+
isEnded: boolean;
|
|
459
|
+
count: number;
|
|
460
|
+
scene: string;
|
|
461
|
+
adTypeR: number;
|
|
462
|
+
end_type: string;
|
|
463
|
+
}, connection?: {
|
|
464
|
+
conn?: (ctx: object) => void;
|
|
465
|
+
end?: (ctx: object) => void;
|
|
466
|
+
}): void;
|
|
467
|
+
/**
|
|
468
|
+
* 激励视频广告组件**失败**时会触发
|
|
469
|
+
* @private
|
|
470
|
+
*/
|
|
471
|
+
private __adErrorLister__;
|
|
472
|
+
/**
|
|
473
|
+
* 激励视频广告组件**失败**时会触发
|
|
474
|
+
* @protected
|
|
475
|
+
*/
|
|
476
|
+
protected adErrorLister(e: any): any;
|
|
477
|
+
/**
|
|
478
|
+
* 激励视频广告组件api**失败**时会触发
|
|
479
|
+
* @private
|
|
480
|
+
*/
|
|
481
|
+
private __apiAdErrorLister__;
|
|
482
|
+
/**
|
|
483
|
+
* 激励视频广告组件api**失败**时会触发
|
|
484
|
+
* @protected
|
|
485
|
+
*/
|
|
486
|
+
protected apiAdErrorLister(e: any): any;
|
|
487
|
+
/**
|
|
488
|
+
* @private
|
|
489
|
+
* 激励视频广告组件**成功**拉取广告素材时会触发
|
|
490
|
+
* 创建激励时候后会自动拉取广告素材,如果广告拉取成功,也会触发此事件,不管是否调用show方法
|
|
491
|
+
* @param {unknown} e
|
|
492
|
+
*/
|
|
493
|
+
private __adLoadLister__;
|
|
494
|
+
/**
|
|
495
|
+
* @protected
|
|
407
496
|
* 激励视频广告组件**成功**拉取广告素材时会触发
|
|
408
497
|
* 创建激励时候后会自动拉取广告素材,如果广告拉取成功,也会触发此事件,不管是否调用show方法
|
|
409
498
|
* @param {unknown} e
|
|
410
499
|
*/
|
|
411
|
-
adLoadLister(e: unknown):
|
|
500
|
+
protected adLoadLister(e: unknown): unknown;
|
|
412
501
|
adDestroy(): void;
|
|
413
502
|
_shiftCloseLister(args: any): void;
|
|
414
503
|
_shiftErrorLister(args: any): void;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +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,i)=>{for(var t in i)__webpack_require__.o(i,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:i[t]})},__webpack_require__.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),__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__,{RewardAdNovel:()=>src_RewardAdNovel,RewardAdFather:()=>src_RewardAdFather,InterstitialAdFather:()=>src_InterstitialAdFather,InterstitialAdNovel:()=>src_InterstitialAdNovel,AdExecuteManager:()=>core_namespaceObject.AdExecuteManager});const core_namespaceObject=require("@ad-execute-manager/core"),helper_namespaceObject=require("@ad-execute-manager/helper");class InterstitialAdFather{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 helper_namespaceObject.Logger({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 t=Object.assign({},InterstitialAdFather.args,this._adConfig,e);if(!t.adUnitId)throw this._logger.error("interstitialAd args The adUnitId is required",t),new helper_namespaceObject.SerializableError("[InterstitialAdFather] interstitialAd args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100003});let r=tt.createInterstitialAd(t);return this._interstitialAd=r,this.__ad__=r,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 InterstitialAdFather.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 helper_namespaceObject.Logger({prefix:"InterstitialAdFather",enable:!0}).error("interstitialAdParams.adUnitId is required"),InterstitialAdFather.args=e}static async executeWithManager(e,i){return e&&e instanceof InterstitialAdFather?core_namespaceObject.AdExecuteManager.getInstance().addTask(e,i):(new helper_namespaceObject.Logger({prefix:"InterstitialAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const src_InterstitialAdFather=InterstitialAdFather;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 helper_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,i){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==i||i(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 helper_namespaceObject.SerializableError("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let r=tt.createRewardedVideoAd(t);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 RewardAdFather.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 helper_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,i){return e&&e instanceof RewardAdFather?core_namespaceObject.AdExecuteManager.getInstance().addTask(e,i):(new helper_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const src_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,i){return!!i&&e.some(e=>RegExp(e,"i").test(i))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[i,t])=>(e[t]=Number(i),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,[i,t])=>(e[t]=i,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;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_adTypeR=AD_TYPE_ENUM.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 i,t,r,l,s;super(e),this._logger=new helper_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._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==(r=e.collection)?void 0:r.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,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=RewardAdNovelConfig.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,r,l;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(r=e.collection)?void 0:r.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._onInnerExecuteBefore(),new Promise(t=>{var r,l,s,n,o;this._adInner({options:{scene:null==e||null==(r=e.options)?void 0:r.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},i)})}_adInner(e,i=null){var t,r,l,s,n;let o=null==e||null==(t=e.collection)?void 0:t.resolve,a=(null==e||null==(r=e.options)?void 0:r.scene)??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,d=null==e||null==(l=e.collection)?void 0:l.before,h=null==e||null==(s=e.collection)?void 0:s.success,u=null==e||null==(n=e.collection)?void 0:n.prelude,_=(null==e?void 0:e.recovered)??this._recovered,c=e=>{this._clearAdTimeout(),this.adDestroy(),null==o||o(Object.assign({scene:a,adTypeR:this._adTypeR},null==e?void 0:e.resolvedValue)),null==i||i(Object.assign({scene:a},null==e?void 0:e.nextValue))},f=()=>{var t,r;this._scene=a,null==d||d({scene:a}),this._before=d,null==(t=this._onShow)||t.call(this,{scene:a}),this._adShowBeforeAnalytics({scene:a}),this._resolve=o,this._next=i,this._setAdTimeout({scene:a,end:c,timeout:null==e||null==(r=e.options)?void 0:r.timeout}),this._adPreludeInterval({scene:a,prelude:u}),this.adShow().then(()=>{this._clearAdTimeout(),null==h||h({scene:a}),this._success=h,this._adShowSuccessAnalytics({scene:a,result:1,recovered:_}),this._onInnerAdShowSuccess({scene:a,result:1,recovered:_})}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:a,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:a,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?c({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}),f()}).catch(e=>{this._adLoadFailureAnalytics({scene:a,msg:null==e?void 0:e.errMsg,result:0}),c({scene:a,resolvedValue:{apiError:e},nextValue:null})}))})};f()}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,r;this.adDestroy(),null==(t=this._resolve)||t.call(this,Object.assign({},i,e)),this._resolve=null,null==(r=this._next)||r.call(this),this._next=null,this._success=null,this._before=null},r=e=>{var t,r,l;let s=Object.assign({},i,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),null==(r=this._onFinish)||r.call(this,s)):(this._outerHalfwayCallback(s),null==(l=this._onHalfway)||l.call(this,s)),this._outerCloseCallback(s),null==(t=this._onAlways)||t.call(this,s)};this.adCloseLister(i,{conn:r,end:t})}adCloseLister(e,i){var t,r;null==i||null==(t=i.conn)||t.call(i,e),null==i||null==(r=i.end)||r.call(i,e)}__adErrorLister__(e){var i,t,r;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==(r=this._next)||r.call(this),this._next=null,this._success=null,this._before=null}adErrorLister(e){return e}__apiAdErrorLister__(e){var i,t,r;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==(r=this._next)||r.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 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;class InterstitialAdNovel extends src_InterstitialAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_adTypeR=AD_TYPE_ENUM.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 i,t,r,l,s;super(e),this._logger=new helper_namespaceObject.Logger({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==(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==(r=e.collection)?void 0:r.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,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=InterstitialAdNovel_RewardAdNovelConfig.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,r,l;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(r=e.collection)?void 0:r.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._onInnerExecuteBefore(),new Promise(t=>{var r,l,s,n;this._adInner({options:{scene:null==e||null==(r=e.options)?void 0:r.scene},collection:{resolve:t,before:null==(l=e.collection)?void 0:l.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,r,l,s,n;let o=null==e||null==(t=e.collection)?void 0:t.resolve,a=(null==e||null==(r=e.options)?void 0:r.scene)??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,d=null==e||null==(l=e.collection)?void 0:l.before,h=null==e||null==(s=e.collection)?void 0:s.success,u=null==e||null==(n=e.collection)?void 0:n.prelude,_=e=>{this._clearAdTimeout(),this.adDestroy(),null==o||o(Object.assign({scene:a,adTypeR:this._adTypeR},null==e?void 0:e.resolvedValue)),null==i||i(Object.assign({scene:a},null==e?void 0:e.nextValue))},c=()=>{var e;this._scene=a,null==d||d({scene:a}),this._before=d,null==(e=this._onShow)||e.call(this,{scene:a}),this._adShowBeforeAnalytics({scene:a}),this._resolve=o,this._next=i,this._setAdTimeout({scene:a,end:_}),this._adPreludeInterval({scene:a,prelude:u}),this.adShow().then(()=>{this._clearAdTimeout(),null==h||h({scene:a}),this._success=h,this._adShowSuccessAnalytics({scene:a,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:a,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))?_({scene:a,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?_({scene:a,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:a,result:1}),c()}).catch(e=>{this._adLoadFailureAnalytics({scene:a,msg:null==e?void 0:e.errMsg,result:0}),_({scene:a,resolvedValue:{apiError:e},nextValue:null})}))})};c()}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 r={scene:this._scene},l=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(r),null==(e=this._onFinish)||e.call(this,r),this._outerHalfwayCallback(r),null==(i=this._onHalfway)||i.call(this,r),this._outerCloseCallback(r),null==(t=this._onAlways)||t.call(this,r),l({end_type:"finished"})}adErrorLister(e){var i,t,r;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==(r=this._next)||r.call(this),this._next=null,this._success=null,this._before=null)}apiAdErrorLister(e){var i,t,r;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==(r=this._next)||r.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 InterstitialAdNovel.instance||(InterstitialAdNovel.instance=new InterstitialAdNovel(e)),InterstitialAdNovel.instance}static getInstance(){if(!InterstitialAdNovel.instance)throw Error("InterstitialAdNovel instance is not init");return InterstitialAdNovel.instance}static new(e){return new InterstitialAdNovel(e)}}class InterstitialAdNovel_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 InterstitialAdNovel_RewardAdNovelConfig(e)}}const src_InterstitialAdNovel=InterstitialAdNovel;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.InterstitialAdFather=__webpack_exports__.InterstitialAdFather,exports.InterstitialAdNovel=__webpack_exports__.InterstitialAdNovel,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["AdExecuteManager","InterstitialAdFather","InterstitialAdNovel","RewardAdFather","RewardAdNovel"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import Storage from './helper/Storage';
|
|
7
|
-
import { CountRecorder } from './helper/CountRecorder';
|
|
8
|
-
import RewardAdGlobalRecorder from './helper/RewardAdGlobalRecorder';
|
|
9
|
-
import RewardAdSceneTriggerManager from './helper/RewardAdSceneTriggerManager';
|
|
10
|
-
import AdAnalyticsJS from './helper/AdAnalyticsJS';
|
|
11
|
-
import RewardAdNovel from './ad/RewardAdNovel';
|
|
12
|
-
import InterstitialAdFather from './ad/InterstitialAdFather';
|
|
13
|
-
import InterstitialAdNovel from './ad/InterstitialAdNovel';
|
|
14
|
-
import PubSub from './helper/PubSub';
|
|
15
|
-
export { AdExecuteManager, RewardAdFather, SerializableError, Logger, Storage, CountRecorder, RewardAdGlobalRecorder, RewardAdSceneTriggerManager, AdAnalyticsJS, RewardAdNovel, InterstitialAdFather, InterstitialAdNovel, PubSub };
|
|
1
|
+
export { AdExecuteManager } from "@ad-execute-manager/core";
|
|
2
|
+
export { default as InterstitialAdFather } from "./InterstitialAdFather";
|
|
3
|
+
export { default as RewardAdFather } from "./RewardAdFather";
|
|
4
|
+
export { default as RewardAdNovel } from "./RewardAdNovel";
|
|
5
|
+
export { default as InterstitialAdNovel } from "./InterstitialAdNovel";
|
package/dist/index.js
CHANGED
|
@@ -1 +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,t)=>{for(var i in t)__webpack_require__.o(t,i)&&!__webpack_require__.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__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__,{RewardAdNovel:()=>ad_RewardAdNovel,RewardAdFather:()=>ad_RewardAdFather,InterstitialAdFather:()=>ad_InterstitialAdFather,InterstitialAdNovel:()=>ad_InterstitialAdNovel});const compose=e=>e.map(e=>(t,i)=>async s=>await e(Object.assign({},t,s),i)).reduce((e,t)=>(i,s)=>e(i,t(i,s))),core_compose=compose;class Logger{constructor(e={}){const{prefix:t="Logger",level:i="log",enabled:s=!0}=e;this.prefix=t,this.enabled=s,this.levels={error:0,warn:1,info:2,log:3,debug:4},this.currentLevel=this.levels[i]||this.levels.log}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}setLevel(e){Object.prototype.hasOwnProperty.call(this.levels,e)&&(this.currentLevel=this.levels[e])}formatMessage(e,t){let i=new Date,s=`${i.getFullYear()}/${i.getMonth()+1}/${i.getDate()} ${i.getHours()}:${i.getMinutes()}:${i.getSeconds()}`;return`[${s}] [${e.toUpperCase()}] [${this.prefix}] ${t}`}_log(e,t,...i){if(!this.enabled)return;let s=this.levels[e];if(void 0!==s&&this.currentLevel>=s){let s=this.formatMessage(e,t);switch(e){case"error":console.error(s,...i);break;case"warn":console.warn(s,...i);break;case"info":console.info(s,...i);break;case"log":default:console.log(s,...i);break;case"debug":console.debug(s,...i)}}}error(e,...t){this._log("error",e,...t)}warn(e,...t){this._log("warn",e,...t)}info(e,...t){this._log("info",e,...t)}log(e,...t){this._log("log",e,...t)}debug(e,...t){this._log("debug",e,...t)}}class AdExecuteManager{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;constructor(e){if(this.logger=new Logger({prefix:"AdExecuteManager",enabled:!!e?.log}),AdExecuteManager._instance)return AdExecuteManager._instance;AdExecuteManager._instance=this}static getInstance(e){return AdExecuteManager._instance||(AdExecuteManager._instance=new AdExecuteManager(e)),AdExecuteManager._instance}static getSafeInstance(){return AdExecuteManager._instance?AdExecuteManager._instance:(this.logger.error("AdExecuteManager实例不存在"),null)}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((i,s)=>{let r={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:i,reject:s,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1};this._taskStack.push(r),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,i)=>{let{adInstance:s,options:r,callbackCollection:n,resolve:l,id:o}=e;if(e._isResolved||e._isRejected)return void await i(t);this._currentTask=e;try{let a=async e=>{await i(Object.assign({},t,e))},d=await s.initialize(r).ad({options:r,collection:n},a),h=Object.assign({id:o},d);this.logger.info(`任务执行成功,成功信息:${JSON.stringify(h)}`),e._isResolved=!0,l(h),s?.record(h)}catch(n){let r=Object.assign({id:o,apiError:n});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(r)}`),e._isRejected=!0;try{s?.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:o,apiError:e})))}l(r),s?.record(r),await i(t)}}),i={roundTasks:t.length};compose(t)(i,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._taskStack=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)}isRunning(){return this._isRunning}getCurrentTaskId(){return this._currentTask?.id||null}whenAllTasksComplete(){return new Promise(e=>{let t=null,i=()=>{let s=0===this._taskStack.length,r=!this._isRunning,n=null===this._currentTask,l=0===this._currentBatchTasks.length||this._currentBatchTasks.every(e=>e._isResolved||e._isRejected);s&&r&&n&&l?(t&&clearTimeout(t),e()):t=setTimeout(i,500)};i()})}}const core_AdExecuteManager=AdExecuteManager;class SerializableError extends Error{constructor(e){super(e),this.name=this.constructor.name,this.stack=Error(e).stack,Object.defineProperty(this,"message",{enumerable:!0}),Object.defineProperty(this,"name",{enumerable:!0}),Object.defineProperty(this,"stack",{enumerable:!0})}toJSON(){return{name:this.name,message:this.message,stack:this.stack}}}class RewardAdFather{static args=null;_initSign="";_preserveOnEnd=!1;_rewardAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._rewardAd)return console.warn("RewardAdFather: rewardAd has been initialized"),t?.(this._rewardAd),this;let i=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!i.adUnitId)throw console.error("[RewardAdFather] reward args adUnitId is required",i),new SerializableError("[RewardAdFather] reward args adUnitId is required");return this._rewardAd=tt.createRewardedVideoAd(i),t?.(this._rewardAd),this}initialized(){return!!this._rewardAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:t}))}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:"rewardAd is null"})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"rewardAd is null"})}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){e?.adUnitId||console.error("[RewardAdFather] RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,t){return e&&e instanceof RewardAdFather?AdExecuteManager.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("RewardAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const ad_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,t){return!!t&&e.some(e=>RegExp(e,"i").test(t))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[t,i])=>(e[i]=Number(t),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,[t,i])=>(e[i]=t,e),{});class RewardAdNovel extends ad_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_adTypeR=AD_TYPE_ENUM.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){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),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:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[RewardAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:e?.scene,msg:i,errorCode:0,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:i}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let t=e?.timeout??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{console.warn("[RewardAdNovel] Ad show timeout, handling fallback ad case,",`scene: ${e?.scene},timeout: ${t}`),this._adShowFailureAnalytics({scene:e?.scene,msg:"ad_show_timeout: normal",errorCode:0,result:0}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal",errorCode:0}},nextValue:null})},t)}}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene: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,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(i=>{this._adInner({options:{scene:e?.options?.scene,timeout:e?.options?.timeout},collection:{resolve:i,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let i=e?.collection?.resolve,s=e?.options?.scene??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,r=e?.collection?.before,n=e?.collection?.success,l=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),i?.(Object.assign({scene:s,adTypeR:this._adTypeR},e?.resolvedValue)),t?.(Object.assign({scene:s},e?.nextValue))},a=()=>{this._scene=s,r?.({scene:s}),this._before=r,this._onShow?.({scene:s}),this._adShowBeforeAnalytics({scene:s}),this._resolve=i,this._next=t,this._setAdTimeout({scene:s,end:o,timeout:e?.options?.timeout}),this._adPreludeInterval({scene:s,prelude:l}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:s}),this._success=n,this._adShowSuccessAnalytics({scene:s,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:s,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,e?.errMsg)||this._ttErrorCodes.includes(e?.errorCode))?o({scene:s,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:s,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:s,result:1}),a()}).catch(e=>{this._adLoadFailureAnalytics({scene:s,msg:e?.errMsg,result:0}),o({scene:s,resolvedValue:{apiError:e},nextValue:null})}))})};a()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let t={...e,scene:this._scene},i=t=>{this.adDestroy(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR},t)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};e?.isEnded?(this._outerFinishedCallback(t),this._onFinish?.(t)):(this._outerHalfwayCallback(t),this._onHalfway?.(t)),this._outerCloseCallback(t),this._onAlways?.(t),i({end_type:e.isEnded?"finished":"halfway"})}adErrorLister(e){this._clearAdTimeout(),console.error("[RewardAdNovel] adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API RewardAdNovel] apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:e?.errMsg}),console.info("[RewardAdNovel] 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){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(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){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(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),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 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=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 ad_RewardAdNovel=RewardAdNovel;class InterstitialAdFather{static args=null;_initSign="";_preserveOnEnd=!1;_interstitialAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302,140502];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._interstitialAd)return console.warn("InterstitialAdFather: interstitialAd has been initialized"),t?.(this._interstitialAd),this;let i=Object.assign({},InterstitialAdFather.args,this._adConfig,e);if(!i.adUnitId)throw console.error("[InterstitialAdFather] interstitialAd args adUnitId is required",i),new SerializableError("[InterstitialAdFather] interstitialAd args adUnitId is required");return this._interstitialAd=tt.createInterstitialAd(i),t?.(this._interstitialAd),this}initialized(){return!!this._interstitialAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return InterstitialAdFather.executeWithManager(this,Object.assign({},e,{options:t}))}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:"interstitialAd is null"})}load(){return this._interstitialAd?this._interstitialAd.load():Promise.reject({errMsg:"interstitialAd is null"})}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){e?.adUnitId||console.error("[InterstitialAdFather] interstitialAdParams.adUnitId is required"),InterstitialAdFather.args=e}static async executeWithManager(e,t){return e&&e instanceof InterstitialAdFather?AdExecuteManager.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("InterstitialAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const ad_InterstitialAdFather=InterstitialAdFather;class InterstitialAdNovel extends ad_InterstitialAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_adTypeR=AD_TYPE_ENUM.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){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),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=InterstitialAdNovel_RewardAdNovelConfig.new({retry:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[InterstitialAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:e?.scene,msg:i,errorCode:0,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:i}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout&&(this._adTimeout=setTimeout(()=>{console.warn("[InterstitialAdNovel] Ad show timeout, handling fallback ad case, scene:",e?.scene),this._adShowFailureAnalytics({scene:e?.scene,msg:"ad_show_timeout: normal",errorCode:0,result:0}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal"}},nextValue:null})},this._adTimeoutTime))}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene: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,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(i=>{this._adInner({options:{scene:e?.options?.scene},collection:{resolve:i,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let i=e?.collection?.resolve,s=e?.options?.scene??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,r=e?.collection?.before,n=e?.collection?.success,l=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),i?.(Object.assign({scene:s,adTypeR:this._adTypeR},e?.resolvedValue)),t?.(Object.assign({scene:s},e?.nextValue))},a=()=>{this._scene=s,r?.({scene:s}),this._before=r,this._onShow?.({scene:s}),this._adShowBeforeAnalytics({scene:s}),this._resolve=i,this._next=t,this._setAdTimeout({scene:s,end:o}),this._adPreludeInterval({scene:s,prelude:l}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:s}),this._success=n,this._adShowSuccessAnalytics({scene:s,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:s,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,e?.errMsg)||this._ttErrorCodes.includes(e?.errorCode))?o({scene:s,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:s,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:s,result:1}),a()}).catch(e=>{this._adLoadFailureAnalytics({scene:s,msg:e?.errMsg,result:0}),o({scene:s,resolvedValue:{apiError:e},nextValue:null})}))})};a()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:1});let e={scene:this._scene},t=e=>{this.adDestroy(),this._resolve?.(Object.assign({},{scene:this._scene,adTypeR:this._adTypeR},e)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};this._outerFinishedCallback(e),this._onFinish?.(e),this._outerHalfwayCallback(e),this._onHalfway?.(e),this._outerCloseCallback(e),this._onAlways?.(e),t({end_type:"finished"})}adErrorLister(e){this._clearAdTimeout(),console.error("[InterstitialAdNovel] adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this._onError?.(e),0>=this.novelConfig.remain()&&(this.adDestroy(),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null)}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API InterstitialAdNovel] apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:e?.errMsg}),console.info("[InterstitialAdNovel] 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){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(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){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(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),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 InterstitialAdNovel.instance||(InterstitialAdNovel.instance=new InterstitialAdNovel(e)),InterstitialAdNovel.instance}static getInstance(){if(!InterstitialAdNovel.instance)throw Error("InterstitialAdNovel instance is not init");return InterstitialAdNovel.instance}static new(e){return new InterstitialAdNovel(e)}}class InterstitialAdNovel_RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=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 InterstitialAdNovel_RewardAdNovelConfig(e)}}const ad_InterstitialAdNovel=InterstitialAdNovel;for(var __rspack_i in exports.InterstitialAdFather=__webpack_exports__.InterstitialAdFather,exports.InterstitialAdNovel=__webpack_exports__.InterstitialAdNovel,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["InterstitialAdFather","InterstitialAdNovel","RewardAdFather","RewardAdNovel"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
|
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{e as AdExecuteManager,r as InterstitialAdFather,A as InterstitialAdNovel,n as RewardAdFather,_ as RewardAdNovel};
|
package/dist/typings/ad.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export type IRewordAdConfig = {
|
|
|
5
5
|
adUnitId: string;
|
|
6
6
|
/**
|
|
7
7
|
* 是否开启进度提醒。开启时广告文案为「再看 n 个xxx」,关闭时为「再看 1 个xxx」。其中 n 表示用户当前还需额外观看广告的次数
|
|
8
|
-
* 再得广告的奖励文案,用户每看完一个广告都会展示,multiton 为 true 时必填。
|
|
9
|
-
* 文案完整内容为「再看 1 个xxx」,其中 xxx 是 multitonRewardMsg 配置的文案内容,最大长度为 7,
|
|
10
|
-
* 文案内容根据 multitonRewardMsg 的配置按顺序展示。若 multitonRewardMsg 长度小于 multitonRewardTimes ,
|
|
11
|
-
* 则后续的激励再得广告文案取 multitonRewardMsg 数组最后一个。
|
|
12
8
|
*/
|
|
13
9
|
progressTip?: boolean | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* - 再得广告的奖励文案,用户每看完一个广告都会展示,multiton 为 true 时必填。
|
|
12
|
+
* - 文案完整内容为「再看 1 个xxx」,其中 xxx 是 multitonRewardMsg 配置的文案内容,最大长度为 7,
|
|
13
|
+
* - 文案内容根据 multitonRewardMsg 的配置按顺序展示。若 multitonRewardMsg 长度小于 multitonRewardTimes ,
|
|
14
|
+
* - 则后续的激励再得广告文案取 multitonRewardMsg 数组最后一个。
|
|
15
|
+
*/
|
|
14
16
|
multitonRewardMsg?: Array<string> | undefined;
|
|
15
17
|
/**
|
|
16
18
|
* 是否开启激励再得广告
|
|
@@ -28,14 +30,14 @@ export type IRewordAdConfig = {
|
|
|
28
30
|
* 广告超时时间 单位ms - 自用参数,非tt API要求的参数
|
|
29
31
|
*/
|
|
30
32
|
timeout?: number | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* 奖励金额 - 自用参数 ,非tt API要求的参数
|
|
33
|
-
*/
|
|
34
|
-
log?: boolean | undefined;
|
|
35
33
|
/**
|
|
36
34
|
* 重试次数 - 自用参数 ,非tt API要求的参数
|
|
37
35
|
*/
|
|
38
36
|
retry: number;
|
|
37
|
+
/**
|
|
38
|
+
* 是否绑定永远的错误事件 - 自用参数,非tt API要求的参数
|
|
39
|
+
*/
|
|
40
|
+
foreverErrorBind?: boolean | undefined;
|
|
39
41
|
};
|
|
40
42
|
export type InterstitialAdConfig = {
|
|
41
43
|
/**
|
|
@@ -99,6 +101,20 @@ export type CallbackCollection = {
|
|
|
99
101
|
*/
|
|
100
102
|
prelude?: (ctx?: unknown) => void;
|
|
101
103
|
};
|
|
104
|
+
export type RecoveredInfo = {
|
|
105
|
+
/**
|
|
106
|
+
* 恢复重试次数
|
|
107
|
+
*/
|
|
108
|
+
count: number;
|
|
109
|
+
/**
|
|
110
|
+
* 是否恢复重试
|
|
111
|
+
*/
|
|
112
|
+
retry: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* 恢复重试原因
|
|
115
|
+
*/
|
|
116
|
+
message: string;
|
|
117
|
+
};
|
|
102
118
|
export type ICallbackArgs = {
|
|
103
119
|
/**
|
|
104
120
|
* 广告执行场景
|
|
@@ -151,6 +167,10 @@ export type IConstructArgs = {
|
|
|
151
167
|
* 初始化标识
|
|
152
168
|
*/
|
|
153
169
|
sign: string;
|
|
170
|
+
/**
|
|
171
|
+
* 是否开启日志
|
|
172
|
+
*/
|
|
173
|
+
log?: boolean | undefined;
|
|
154
174
|
/**
|
|
155
175
|
* 重试次数
|
|
156
176
|
*/
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 回调函数类型
|
|
3
|
+
*/
|
|
4
|
+
export type Callback = () => any;
|
|
5
|
+
export type InterstitialAd = {
|
|
6
|
+
/**
|
|
7
|
+
* 广告创建后默认是隐藏的,可以通过该方法显示广告
|
|
8
|
+
*/
|
|
9
|
+
show: () => Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* 当广告素材加载出现错误时,可以通过 load 方法手动加载
|
|
12
|
+
*/
|
|
13
|
+
load: () => Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* 销毁广告实例
|
|
16
|
+
*/
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* 绑定广告 load 事件的监听器
|
|
20
|
+
*/
|
|
21
|
+
onLoad: (arg0: Callback) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 解除绑定 load 事件的监听器
|
|
24
|
+
*/
|
|
25
|
+
offLoad: (arg0: Callback) => void;
|
|
26
|
+
/**
|
|
27
|
+
* 绑定 error 事件的监听器
|
|
28
|
+
*/
|
|
29
|
+
onError: (arg0: Callback) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 解除绑定 error 事件的监听器
|
|
32
|
+
*/
|
|
33
|
+
offError: (arg0: Callback) => void;
|
|
34
|
+
/**
|
|
35
|
+
* 绑定 close 事件的监听器
|
|
36
|
+
*/
|
|
37
|
+
onClose: (arg0: Callback) => void;
|
|
38
|
+
/**
|
|
39
|
+
* 解除绑定 close 事件的监听器
|
|
40
|
+
*/
|
|
41
|
+
offClose: (arg0: Callback) => void;
|
|
42
|
+
};
|