@ad-execute-manager/ad-reward 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.
@@ -0,0 +1,553 @@
1
+ export default RewardAdNovel;
2
+ export type IRewordAdConfig = any;
3
+ export type ICallbackArgs = {
4
+ /**
5
+ * 广告执行场景
6
+ */
7
+ scene: number;
8
+ /**
9
+ * 是否看完
10
+ */
11
+ isEnded: boolean;
12
+ /**
13
+ * 完整观看次数
14
+ */
15
+ count: number;
16
+ /**
17
+ * 执行下一个任务的回调函数,手动调用以继续执行流程[end]
18
+ */
19
+ end?: () => void;
20
+ /**
21
+ * 执行下一个任务的回调函数, 手动调用以继续执行流程[circle]
22
+ */
23
+ circle?: (args: {
24
+ ignoreRemain: boolean;
25
+ scene: number;
26
+ }) => void;
27
+ };
28
+ export type IConnection = {
29
+ /**
30
+ * 广告中途退出回调
31
+ */
32
+ onHalfway?: (args: ICallbackArgs) => void;
33
+ /**
34
+ * 广告展示回调
35
+ */
36
+ onShow?: (args: ICallbackArgs) => void;
37
+ /**
38
+ * 广告执行成功回调
39
+ */
40
+ onFinish?: (args: ICallbackArgs) => void;
41
+ /**
42
+ * 广告执行成功回调
43
+ */
44
+ onAlways?: (args: ICallbackArgs) => void;
45
+ /**
46
+ * 广告执行失败回调
47
+ */
48
+ onError?: (e: unknown) => void;
49
+ };
50
+ export type IConstructArgs = {
51
+ /**
52
+ * 初始化标识
53
+ */
54
+ sign?: string;
55
+ /**
56
+ * 是否开启日志
57
+ */
58
+ log?: boolean;
59
+ /**
60
+ * 是否保留tt激励视频广告实例
61
+ */
62
+ preserveOnEnd?: boolean;
63
+ /**
64
+ * 是否需要在超时情况下结束广告
65
+ */
66
+ needEndOnTimeout?: boolean;
67
+ /**
68
+ * 激励视频参数 (可选)
69
+ */
70
+ adConfig?: IRewordAdConfig | undefined;
71
+ /**
72
+ * 回调集合
73
+ */
74
+ collection?: IConnection | undefined;
75
+ };
76
+ export type ICloseArgs = {
77
+ /**
78
+ * 是否看完
79
+ */
80
+ isEnded: boolean;
81
+ /**
82
+ * 完整观看次数
83
+ */
84
+ count: number;
85
+ };
86
+ export type IEndArgs = {
87
+ /**
88
+ * 是否解锁全部
89
+ */
90
+ can_unlock_all?: boolean;
91
+ /**
92
+ * 是否解锁小说
93
+ */
94
+ can_unlock_novel?: boolean;
95
+ /**
96
+ * 剩余次数
97
+ */
98
+ remain?: number;
99
+ /**
100
+ * 结束类型
101
+ */
102
+ end_type?: "halfway" | "finished";
103
+ };
104
+ export type IRewardedVideoAd = {
105
+ /**
106
+ * 显示激励视频广告
107
+ */
108
+ show: () => Promise<void>;
109
+ };
110
+ /**
111
+ * @typedef {import('../typings/ad.js').IRewordAdConfig} IRewordAdConfig
112
+ */
113
+ /**
114
+ * @typedef ICallbackArgs
115
+ * @property {number} scene 广告执行场景
116
+ * @property {boolean} isEnded 是否看完
117
+ * @property {number} count 完整观看次数
118
+ * @property {() => void} [end] 执行下一个任务的回调函数,手动调用以继续执行流程[end]
119
+ * @property {(args: {ignoreRemain: boolean, scene: number}) => void} [circle] 执行下一个任务的回调函数, 手动调用以继续执行流程[circle]
120
+ *
121
+ */
122
+ /**
123
+ * @typedef IConnection
124
+ * @property {(args: ICallbackArgs) => void} [onHalfway] 广告中途退出回调
125
+ * @property {(args: ICallbackArgs) => void} [onShow] 广告展示回调
126
+ * @property {(args: ICallbackArgs) => void} [onFinish] 广告执行成功回调
127
+ * @property {(args: ICallbackArgs) => void} [onAlways] 广告执行成功回调
128
+ * @property {(e:unknown) => void} [onError] 广告执行失败回调
129
+ */
130
+ /**
131
+ * @typedef IConstructArgs
132
+ * @property {string} [sign] 初始化标识
133
+ * @property {boolean} [log] 是否开启日志
134
+ * @property {boolean} [preserveOnEnd] 是否保留tt激励视频广告实例
135
+ * @property {boolean} [needEndOnTimeout] 是否需要在超时情况下结束广告
136
+ * @property {IRewordAdConfig=} [adConfig] 激励视频参数 (可选)
137
+ * @property {IConnection=} [collection] 回调集合
138
+ */
139
+ /**
140
+ * @typedef ICloseArgs
141
+ * @property {boolean} isEnded 是否看完
142
+ * @property {number} count 完整观看次数
143
+ */
144
+ /**
145
+ * @typedef IEndArgs
146
+ * @property {boolean} [can_unlock_all] 是否解锁全部
147
+ * @property {boolean} [can_unlock_novel] 是否解锁小说
148
+ * @property {number} [remain] 剩余次数
149
+ * @property {'halfway' | 'finished'} [end_type] 结束类型
150
+ *
151
+ */
152
+ /**
153
+ * @typedef IRewardedVideoAd
154
+ * @property {() => Promise.<void>} show 显示激励视频广告
155
+ */
156
+ declare class RewardAdNovel extends RewardAdFather {
157
+ /**
158
+ *
159
+ * @param {IConstructArgs} args
160
+ * @returns {RewardAdNovel}
161
+ */
162
+ static build(args: IConstructArgs): RewardAdNovel;
163
+ /**
164
+ *
165
+ * @returns {RewardAdNovel}
166
+ */
167
+ static getInstance(): RewardAdNovel;
168
+ /**
169
+ *
170
+ * @param {IConstructArgs} args
171
+ * @returns {RewardAdNovel}
172
+ */
173
+ static "new"(args: IConstructArgs): RewardAdNovel;
174
+ /**
175
+ * @param {IConstructArgs} args
176
+ *
177
+ */
178
+ constructor(args: IConstructArgs);
179
+ _onHalfway: any;
180
+ _onShow: any;
181
+ _onFinish: any;
182
+ _onAlways: any;
183
+ _onError: any;
184
+ _alwaysCallback: any;
185
+ _halfwayCallback: any;
186
+ _finishedCallback: any;
187
+ _resolve: any;
188
+ _next: any;
189
+ /** @type {number} 广告执行场景 */
190
+ _scene: number;
191
+ _adTypeR: 1;
192
+ _adTimeout: any;
193
+ _adBeforeShowTimer: any;
194
+ _adBeforeShowTime: number;
195
+ _adSpeedCloseTimer: any;
196
+ _adSpeedCloseTime: number;
197
+ _needEndOnTimeout: boolean;
198
+ /** @deprecated TODO 移除 */
199
+ _needSpeedEndOnTimeout: boolean;
200
+ bindAdCloseLister: any;
201
+ bindAdErrorLister: any;
202
+ bindAdLoadLister: any;
203
+ bindApiAdErrorLister: any;
204
+ _bindShiftCloseLister: any;
205
+ _bindShiftErrorLister: any;
206
+ _adConfig: any;
207
+ /**
208
+ * 初始化
209
+ * 子类可以选择覆盖此方法,或使用默认实现
210
+ * @param {IRewordAdConfig} args
211
+ * @param {(v: IRewardedVideoAd) => void} [callback] 初始化成功回调
212
+ * @returns {this} 当前实例
213
+ */
214
+ initialize(args: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
215
+ _initAdLister(): void;
216
+ /**
217
+ * @param {object} args
218
+ * @param {number} [args.retry] 重试次数
219
+ */
220
+ _initNovelConfig(args: {
221
+ retry?: number;
222
+ }): void;
223
+ novelConfig: RewardAdNovelConfig;
224
+ _onInnerExecuteBefore(): any;
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;
237
+ /**
238
+ * 广告展示超时设置
239
+ * @param {object} args
240
+ * @param {string} args.scene 广告执行场景 必填
241
+ * @param {number} [args.timeout] 广告超时时间 单位ms
242
+ * @param {Function} args.end 结束当前广告任务的回调函数 必填
243
+ */
244
+ _setAdTimeout(args: {
245
+ scene: string;
246
+ timeout?: number;
247
+ end: Function;
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
+ };
263
+ /**
264
+ * 广告展示前定时器
265
+ * @param {object} args
266
+ * @param {string} args.scene 广告执行场景 必填
267
+ * @param {Function} args.prelude 广告展示前回调函数 可选
268
+ */
269
+ _adPreludeInterval(args: {
270
+ scene: string;
271
+ prelude: Function;
272
+ }): void;
273
+ _clearAdTimeout(): void;
274
+ /**
275
+ * 广告展示成功前分析
276
+ * 子类需要埋点可以选择覆盖此方法
277
+ * @protected
278
+ * @param {object} _args
279
+ * @param {string} _args.scene 广告执行场景 必填
280
+ * @returns
281
+ */
282
+ protected _adShowBeforeAnalytics(_args: {
283
+ scene: string;
284
+ }): any;
285
+ /**
286
+ * 广告展示成功分析
287
+ * 子类需要埋点可以选择覆盖此方法
288
+ * @protected
289
+ * @param {object} _args
290
+ * @param {string} _args.scene 广告执行场景 必填
291
+ * @param {string} [_args.msg] 广告执行成功原因
292
+ * @param {0|1} _args.result 广告执行成功结果 必填
293
+ * @param {import('../typings/ad.js').RecoveredInfo} [_args.recovered] 恢复重试信息
294
+ * @returns
295
+ */
296
+ protected _adShowSuccessAnalytics(_args: {
297
+ scene: string;
298
+ msg?: string;
299
+ result: 0 | 1;
300
+ recovered?: any;
301
+ }): any;
302
+ /**
303
+ * 广告展示失败分析
304
+ * 子类需要埋点可以选择覆盖此方法
305
+ * @protected
306
+ * @param {object} _args
307
+ * @param {string} _args.scene 广告执行场景 必填
308
+ * @param {string} _args.msg 广告执行失败原因 必填
309
+ * @param {number} _args.errorCode 广告执行失败错误码 必填
310
+ * @param {0|1} _args.result 广告执行失败结果
311
+ * @returns
312
+ */
313
+ protected _adShowFailureAnalytics(_args: {
314
+ scene: string;
315
+ msg: string;
316
+ errorCode: number;
317
+ result: 0 | 1;
318
+ }): any;
319
+ /**
320
+ * 广告加载成功分析
321
+ * 子类需要埋点可以选择覆盖此方法
322
+ * @protected
323
+ * @param {object} _args
324
+ * @param {string} _args.scene 广告执行场景 必填
325
+ * @param {string} [_args.msg] 广告执行成功原因
326
+ * @param {0|1} _args.result 广告执行成功结果 必填
327
+ * @param {object} [_args.frequency] 广告执行重试参数
328
+ * @param {number} _args.frequency.total 广告执行总次数 必填
329
+ * @param {number} _args.frequency.current 广告执行当前次数 必填
330
+ * @returns
331
+ */
332
+ protected _adLoadSuccessAnalytics(_args: {
333
+ scene: string;
334
+ msg?: string;
335
+ result: 0 | 1;
336
+ frequency?: {
337
+ total: number;
338
+ current: number;
339
+ };
340
+ }): any;
341
+ /**
342
+ * 广告加载失败分析
343
+ * 子类需要埋点可以选择覆盖此方法
344
+ * @protected
345
+ * @param {object} _args
346
+ * @param {string} _args.scene 广告执行场景 必填
347
+ * @param {string} _args.msg 广告执行失败原因 必填
348
+ * @param {0|1} _args.result 广告执行失败结果
349
+ * @returns
350
+ */
351
+ protected _adLoadFailureAnalytics(_args: {
352
+ scene: string;
353
+ msg: string;
354
+ result: 0 | 1;
355
+ }): any;
356
+ /**
357
+ * 广告关闭成功分析
358
+ * 子类需要埋点可以选择覆盖此方法
359
+ * @protected
360
+ * @param {object} _args
361
+ * @param {string} _args.scene 广告执行场景 必填
362
+ * @param {number} _args.ad_is_completed 广告是否完成 必填
363
+ * @param {number} _args.ad_count 广告执行次数 必填
364
+ * @returns
365
+ */
366
+ protected _adCloseSuccessAnalytics(_args: {
367
+ scene: string;
368
+ ad_is_completed: number;
369
+ ad_count: number;
370
+ }): any;
371
+ get rewardAd(): import("./typings/create-rewarded-video-ad.js").RewardedVideoAd;
372
+ /**
373
+ * 确保广告按顺序执行
374
+ * @override
375
+ * @param {Object} [ctx] 上下文对象,用于传递数据和状态
376
+ * @param {IRewordAdConfig} [ctx.options] 广告执行选项
377
+ * @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
378
+ * @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
379
+ */
380
+ override addExecuteManager(ctx?: {
381
+ options?: IRewordAdConfig;
382
+ collection?: any;
383
+ }): Promise<(IEndArgs & ICloseArgs) | undefined>;
384
+ /**
385
+ * @override
386
+ * @param {object} [ctx] 广告执行上下文
387
+ * @param {import('../typings/ad.js').IRewordAdConfig} [ctx.options] 广告执行选项
388
+ * @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
389
+ * @param {import('../typings/ad.js').RecoveredInfo} [ctx.recovered] 恢复重试信息
390
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
391
+ * @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
392
+ */
393
+ override ad(ctx?: {
394
+ options?: any;
395
+ collection?: any;
396
+ recovered?: any;
397
+ }, next?: Function): Promise<(IEndArgs & ICloseArgs) | undefined>;
398
+ _recovered: any;
399
+ /**
400
+ * @param {object} [ctx] 广告执行上下文
401
+ * @param {object} [ctx.options] 广告执行选项
402
+ * @param {number} [ctx.options.scene] 广告执行场景 必填
403
+ * @param {number} [ctx.options.timeout] 广告超时时间 单位ms
404
+ * @param {object} ctx.collection 回调集合
405
+ * @param {import('../typings/ad.js').RecoveredInfo} [ctx.recovered] 恢复重试信息
406
+ * @param {(v?: unknown) => void} ctx.collection.resolve 广告执行成功的回调函数
407
+ * @param {(v?: unknown) => void} [ctx.collection.reject] 广告执行失败的回调函数
408
+ * @param {(v?: unknown) => void} [ctx.collection.before] 广告执行前的回调函数
409
+ * @param {(v?: unknown) => void} [ctx.collection.success] 广告执行成功的回调函数
410
+ * @param {(v?: unknown) => void} [ctx.collection.prelude] 拉起广告前计时的回调函数
411
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
412
+ */
413
+ _adInner(ctx?: {
414
+ options?: {
415
+ scene?: number;
416
+ timeout?: number;
417
+ };
418
+ collection: object;
419
+ recovered?: any;
420
+ }, next?: Function): void;
421
+ _before: any;
422
+ _success: any;
423
+ /**
424
+ * 广告加载
425
+ * @returns
426
+ */
427
+ adLoad(): Promise<void>;
428
+ /**
429
+ * 广告展示
430
+ * @returns
431
+ */
432
+ adShow(): Promise<void>;
433
+ _outerCloseCallback(args: any): void;
434
+ _outerHalfwayCallback(args: any): void;
435
+ _outerFinishedCallback(args: any): void;
436
+ /**
437
+ * 内部关闭激励视频
438
+ * @private
439
+ * @param {ICloseArgs} args
440
+ */
441
+ private __adCloseLister__;
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
496
+ * 激励视频广告组件**成功**拉取广告素材时会触发
497
+ * 创建激励时候后会自动拉取广告素材,如果广告拉取成功,也会触发此事件,不管是否调用show方法
498
+ * @param {unknown} e
499
+ */
500
+ protected adLoadLister(e: unknown): unknown;
501
+ adDestroy(): void;
502
+ _shiftCloseLister(args: any): void;
503
+ _shiftErrorLister(args: any): void;
504
+ /**
505
+ * 手动出栈
506
+ */
507
+ shift(): void;
508
+ }
509
+ import RewardAdFather from './RewardAdFather.js';
510
+ declare class RewardAdNovelConfig {
511
+ /**
512
+ *
513
+ * @param {object} args
514
+ * @param {string} args.sign 初始化标识
515
+ * @param {number} [args.retry] 重试次数
516
+ * @returns {RewardAdNovelConfig}
517
+ */
518
+ static "new"(args: {
519
+ sign: string;
520
+ retry?: number;
521
+ }): RewardAdNovelConfig;
522
+ /**
523
+ *
524
+ * @param {object} [args]
525
+ * @param {number} [args.retry]
526
+ */
527
+ constructor(args?: {
528
+ retry?: number;
529
+ });
530
+ frequency: {
531
+ total: number;
532
+ current: number;
533
+ };
534
+ /**
535
+ *
536
+ * @param {object} [args]
537
+ * @param {number} [args.retry]
538
+ */
539
+ _init(args?: {
540
+ retry?: number;
541
+ }): void;
542
+ /**
543
+ *
544
+ * @param {object} [args]
545
+ * @param {number} [args.retry]
546
+ */
547
+ _adTimes(args?: {
548
+ retry?: number;
549
+ }): void;
550
+ reset(): void;
551
+ updateRetry(): void;
552
+ remain(): number;
553
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 广告场景类型映射对象
3
+ * @type {import('../typings/ad.js').SceneTypeMap}
4
+ */
5
+ export const DEFAULT_SCENT_TYPE_OBJ: import("../typings/ad.js").SceneTypeMap;
6
+ /**
7
+ * 广告场景文本映射对象
8
+ * @type {import('../typings/ad.js').SceneTextMap}
9
+ */
10
+ export const DEFAULT_SCENT_TEXT_OBJ: import("../typings/ad.js").SceneTextMap;
11
+ /**
12
+ * 用户类型文本映射对象(反向映射)
13
+ * @type {import('../typings/common.js').IAdType}
14
+ */
15
+ export const AD_TYPE_ENUM: import("../typings/common.js").IAdType;
16
+ /**
17
+ * 广告类型文本映射对象(反向映射)
18
+ * @type {import('../typings/common.js').IAdTypeReverse}
19
+ */
20
+ export const AD_TYPE_ENUM_REVERSE: import("../typings/common.js").IAdTypeReverse;
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,r)=>{for(var i in r)__webpack_require__.o(r,i)&&!__webpack_require__.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{AdExecuteManager:()=>core_namespaceObject.AdExecuteManager,RewardAdFather:()=>src_RewardAdFather,RewardAdNovel:()=>src_RewardAdNovel});const core_namespaceObject=require("@ad-execute-manager/core"),logger_namespaceObject=require("@ad-execute-manager/logger"),serializable_error_namespaceObject=require("@ad-execute-manager/serializable-error");class RewardAdFather{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let i=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!i.adUnitId)throw this._logger.error("reward args The adUnitId is required",i),new serializable_error_namespaceObject.SerializableError("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let t=tt.createRewardedVideoAd(i);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==t||t.offError(this.__bindAdErrorForeverHandler),null==t||t.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=t,this.__ad__=t,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(){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 logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,r){return e&&e instanceof RewardAdFather?core_namespaceObject.AdExecuteManager.getInstance().addTask(e,r):(new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const src_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,r){return!!r&&e.some(e=>RegExp(e,"i").test(r))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[r,i])=>(e[i]=Number(r),e),{})}const DEFAULT_SCENT_TYPE_OBJ={9999:"inner_default_other"},DEFAULT_SCENT_TEXT_OBJ=getAdSceneTextObj(DEFAULT_SCENT_TYPE_OBJ),AD_TYPE_ENUM={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2},AD_TYPE_ENUM_REVERSE=Object.entries(AD_TYPE_ENUM).reduce((e,[r,i])=>(e[i]=r,e),{});class RewardAdNovel extends src_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_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 r,i,t,l,s;super(e),this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._onHalfway=(null==e||null==(r=e.collection)?void 0:r.onHalfway)??null,this._onShow=(null==e||null==(i=e.collection)?void 0:i.onShow)??null,this._onFinish=(null==e||null==(t=e.collection)?void 0:t.onFinish)??null,this._onAlways=(null==e||null==(l=e.collection)?void 0:l.onAlways)??null,this._onError=(null==e||null==(s=e.collection)?void 0:s.onError)??null}initialize(e,r){return super.initialize(e,r),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=RewardAdNovelConfig.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,msg:i,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:i,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r}),null==e||e.end({resolvedValue:{apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})},r)}}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,r=null){var i,t,l;return this._alwaysCallback=null==e||null==(i=e.collection)?void 0:i.always,this._halfwayCallback=null==e||null==(t=e.collection)?void 0:t.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._onInnerExecuteBefore(),new Promise(i=>{var t,l,s,n,o;this._adInner({options:{scene:null==e||null==(t=e.options)?void 0:t.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:i,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var i,t,l,s,n;let o=null==e||null==(i=e.collection)?void 0:i.resolve,a=(null==e||null==(t=e.options)?void 0:t.scene)??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,d=null==e||null==(l=e.collection)?void 0:l.before,_=null==e||null==(s=e.collection)?void 0:s.success,h=null==e||null==(n=e.collection)?void 0:n.prelude,u=(null==e?void 0:e.recovered)??this._recovered,c=e=>{this._clearAdTimeout(),this.adDestroy(),null==o||o(Object.assign({scene:a,adTypeR:this._adTypeR},null==e?void 0:e.resolvedValue)),null==r||r(Object.assign({scene:a},null==e?void 0:e.nextValue))},f=()=>{var i,t;this._scene=a,null==d||d({scene:a}),this._before=d,null==(i=this._onShow)||i.call(this,{scene:a}),this._adShowBeforeAnalytics({scene:a}),this._resolve=o,this._next=r,this._setAdTimeout({scene:a,end:c,timeout:null==e||null==(t=e.options)?void 0:t.timeout}),this._adPreludeInterval({scene:a,prelude:h}),this.adShow().then(()=>{this._clearAdTimeout(),null==_||_({scene:a}),this._success=_,this._adShowSuccessAnalytics({scene:a,result:1,recovered:u}),this._onInnerAdShowSuccess({scene:a,result:1,recovered:u})}).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 r;null==(r=this._alwaysCallback)||r.call(this,e)}_outerHalfwayCallback(e){var r;null==(r=this._halfwayCallback)||r.call(this,e)}_outerFinishedCallback(e){var r;null==(r=this._finishedCallback)||r.call(this,e)}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,end_type:e.isEnded?"finished":"halfway"}),i=e=>{var i,t;this.adDestroy(),null==(i=this._resolve)||i.call(this,Object.assign({},r,e)),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null},t=e=>{var i,t,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),null==(t=this._onFinish)||t.call(this,s)):(this._outerHalfwayCallback(s),null==(l=this._onHalfway)||l.call(this,s)),this._outerCloseCallback(s),null==(i=this._onAlways)||i.call(this,s)};this.adCloseLister(r,{conn:t,end:i})}adCloseLister(e,r){var i,t;null==r||null==(i=r.conn)||i.call(r,e),null==r||null==(t=r.end)||t.call(r,e)}__adErrorLister__(e){var r,i,t;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==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,i,t;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null}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 r,i;this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this.offClose(this._bindShiftCloseLister),this.destroy(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){var r,i;this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this.offError(this._bindShiftErrorLister),this.destroy(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return RewardAdNovel.instance||(RewardAdNovel.instance=new RewardAdNovel(e)),RewardAdNovel.instance}static getInstance(){if(!RewardAdNovel.instance)throw Error("RewardAdNovel instance is not init");return RewardAdNovel.instance}static new(e){return new RewardAdNovel(e)}}class RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=(null==e?void 0:e.retry)??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new RewardAdNovelConfig(e)}}const src_RewardAdNovel=RewardAdNovel;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["AdExecuteManager","RewardAdFather","RewardAdNovel"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,3 @@
1
+ export { AdExecuteManager } from "@ad-execute-manager/core";
2
+ export { default as RewardAdFather } from "./RewardAdFather";
3
+ export { default as RewardAdNovel } from "./RewardAdNovel";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{AdExecuteManager as e}from"@ad-execute-manager/core";import{Logger as r}from"@ad-execute-manager/logger";import{SerializableError as i}from"@ad-execute-manager/serializable-error";class l{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new r({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let t=Object.assign({},l.args,this._adConfig,e);if(!t.adUnitId)throw this._logger.error("reward args The adUnitId is required",t),new i("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let s=tt.createRewardedVideoAd(t);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==s||s.offError(this.__bindAdErrorForeverHandler),null==s||s.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=s,this.__ad__=s,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return l.executeWithManager(this,Object.assign({},e,{options:r}))}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 r({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),l.args=e}static async executeWithManager(i,t){return i&&i instanceof l?e.getInstance().addTask(i,t):(new r({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let t=l,s=Object.entries({9999:"inner_default_other"}).reduce((e,[r,i])=>(e[i]=Number(r),e),{}),n={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2};Object.entries(n).reduce((e,[r,i])=>(e[i]=r,e),{});class o extends t{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=s.inner_default_other;_adTypeR=n.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,l,t,s,n;super(e),this._logger=new r({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._onHalfway=(null==e||null==(i=e.collection)?void 0:i.onHalfway)??null,this._onShow=(null==e||null==(l=e.collection)?void 0:l.onShow)??null,this._onFinish=(null==e||null==(t=e.collection)?void 0:t.onFinish)??null,this._onAlways=(null==e||null==(s=e.collection)?void 0:s.onAlways)??null,this._onError=(null==e||null==(n=e.collection)?void 0:n.onError)??null}initialize(e,r){return super.initialize(e,r),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=a.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 r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,msg:i,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:i,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r}),null==e||e.end({resolvedValue:{apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})},r)}}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,r=null){var i,l,t;return this._alwaysCallback=null==e||null==(i=e.collection)?void 0:i.always,this._halfwayCallback=null==e||null==(l=e.collection)?void 0:l.halfway,this._finishedCallback=null==e||null==(t=e.collection)?void 0:t.finished,this._recovered=null==e?void 0:e.recovered,this._onInnerExecuteBefore(),new Promise(i=>{var l,t,s,n,o;this._adInner({options:{scene:null==e||null==(l=e.options)?void 0:l.scene,timeout:null==e||null==(t=e.options)?void 0:t.timeout},collection:{resolve:i,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var i,l,t,n,o;let a=null==e||null==(i=e.collection)?void 0:i.resolve,d=(null==e||null==(l=e.options)?void 0:l.scene)??this._scene??s.inner_default_other,h=null==e||null==(t=e.collection)?void 0:t.before,u=null==e||null==(n=e.collection)?void 0:n.success,_=null==e||null==(o=e.collection)?void 0:o.prelude,c=(null==e?void 0:e.recovered)??this._recovered,f=e=>{this._clearAdTimeout(),this.adDestroy(),null==a||a(Object.assign({scene:d,adTypeR:this._adTypeR},null==e?void 0:e.resolvedValue)),null==r||r(Object.assign({scene:d},null==e?void 0:e.nextValue))},w=()=>{var i,l;this._scene=d,null==h||h({scene:d}),this._before=h,null==(i=this._onShow)||i.call(this,{scene:d}),this._adShowBeforeAnalytics({scene:d}),this._resolve=a,this._next=r,this._setAdTimeout({scene:d,end:f,timeout:null==e||null==(l=e.options)?void 0:l.timeout}),this._adPreludeInterval({scene:d,prelude:_}),this.adShow().then(()=>{this._clearAdTimeout(),null==u||u({scene:d}),this._success=u,this._adShowSuccessAnalytics({scene:d,result:1,recovered:c}),this._onInnerAdShowSuccess({scene:d,result:1,recovered:c})}).catch(e=>{var r,i;(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:d,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),r=this._ttErrorMsgs,(i=null==e?void 0:e.errMsg)&&r.some(e=>RegExp(e,"i").test(i))||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?f({scene:d,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?f({scene:d,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
+ tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:d,result:1,frequency:this.novelConfig.frequency}),w()}).catch(e=>{this._adLoadFailureAnalytics({scene:d,msg:null==e?void 0:e.errMsg,result:0}),f({scene:d,resolvedValue:{apiError:e},nextValue:null})}))})};w()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){var r;null==(r=this._alwaysCallback)||r.call(this,e)}_outerHalfwayCallback(e){var r;null==(r=this._halfwayCallback)||r.call(this,e)}_outerFinishedCallback(e){var r;null==(r=this._finishedCallback)||r.call(this,e)}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,end_type:e.isEnded?"finished":"halfway"}),i=e=>{var i,l;this.adDestroy(),null==(i=this._resolve)||i.call(this,Object.assign({},r,e)),this._resolve=null,null==(l=this._next)||l.call(this),this._next=null,this._success=null,this._before=null},l=e=>{var i,l,t;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),null==(l=this._onFinish)||l.call(this,s)):(this._outerHalfwayCallback(s),null==(t=this._onHalfway)||t.call(this,s)),this._outerCloseCallback(s),null==(i=this._onAlways)||i.call(this,s)};this.adCloseLister(r,{conn:l,end:i})}adCloseLister(e,r){var i,l;null==r||null==(i=r.conn)||i.call(r,e),null==r||null==(l=r.end)||l.call(r,e)}__adErrorLister__(e){var r,i,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==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(l=this._next)||l.call(this),this._next=null,this._success=null,this._before=null}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,i,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==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(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 r,i;this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this.offClose(this._bindShiftCloseLister),this.destroy(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){var r,i;this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this._recovered=null,this.offError(this._bindShiftErrorLister),this.destroy(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return o.instance||(o.instance=new o(e)),o.instance}static getInstance(){if(!o.instance)throw Error("RewardAdNovel instance is not init");return o.instance}static new(e){return new o(e)}}class a{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 a(e)}}let d=o;export{e as AdExecuteManager,t as RewardAdFather,d as RewardAdNovel};