@ad-execute-manager/core 2.0.0-alpha.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,131 @@
1
+ export default InterstitialAdFather;
2
+ export type IRewordAdConfig = import("../typings/ad.js").IRewordAdConfig;
3
+ export type CallbackCollection = import("../typings/ad.js").CallbackCollection;
4
+ export type IConstructArgs = import("../typings/ad.js").IConstructArgs;
5
+ export type IRewardedVideoAd = {
6
+ /**
7
+ * 显示激励视频广告
8
+ */
9
+ show: () => Promise<void>;
10
+ };
11
+ /**
12
+ * @typedef IRewardedVideoAd
13
+ * @property {() => Promise.<void>} show 显示激励视频广告
14
+ */
15
+ declare class InterstitialAdFather {
16
+ /** @type {IRewordAdConfig | null} */
17
+ static args: IRewordAdConfig | null;
18
+ /**
19
+ * @param {IRewordAdConfig} args
20
+ */
21
+ static buildArgs(args: IRewordAdConfig): void;
22
+ /**
23
+ * 使用管理器执行广告
24
+ * @param {Object} adInstance 广告实例
25
+ * @param {Object} ctx 上下文对象,用于传递数据和状态
26
+ * @param {Object} ctx.options 广告执行选项
27
+ * @param {Object} ctx.options.log 是否打印日志
28
+ * @param {Object} ctx.collection 回调集合
29
+ * @returns {Promise} 广告执行结果的Promise
30
+ */
31
+ static executeWithManager(adInstance: any, ctx: {
32
+ options: {
33
+ log: any;
34
+ };
35
+ collection: any;
36
+ }): Promise<any>;
37
+ /**
38
+ * @param {IConstructArgs} args
39
+ */
40
+ constructor(args: IConstructArgs);
41
+ _initSign: string;
42
+ _preserveOnEnd: boolean;
43
+ _interstitialAd: any;
44
+ _ttErrorMsgs: string[];
45
+ _ttErrorCodes: number[];
46
+ _adConfig: {};
47
+ /**
48
+ * 初始化
49
+ * 子类可以选择覆盖此方法,或使用默认实现
50
+ * @param {IRewordAdConfig} params
51
+ * @param {(v: IRewardedVideoAd) => void} [callback] 初始化成功回调
52
+ * @returns {this} 当前实例
53
+ */
54
+ initialize(params: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
55
+ initialized(): boolean;
56
+ /**
57
+ * 执行广告展示
58
+ * @abstract
59
+ * @param {Object} [ctx] 上下文对象,用于传递数据和状态
60
+ * @param {IRewordAdConfig} [ctx.options] 广告执行选项
61
+ * @param {CallbackCollection} [ctx.collection] 回调集合
62
+ * @param {Function} next 执行下一个任务的回调函数,在洋葱模型中手动调用以继续执行流程
63
+ * @returns {Promise<unknown>} 广告执行结果的Promise
64
+ * @throws {Error} 子类必须实现此方法
65
+ */
66
+ ad(ctx?: {
67
+ options?: IRewordAdConfig;
68
+ collection?: CallbackCollection;
69
+ }, next?: Function): Promise<unknown>;
70
+ /**
71
+ * 确保广告按顺序执行
72
+ * @param {Object} [ctx] 上下文对象,用于传递数据和状态
73
+ * @param {IRewordAdConfig} [ctx.options] 广告执行选项
74
+ * @param {CallbackCollection} [ctx.collection] 回调集合
75
+ * @returns {Promise.<unknown>} 广告执行结果的Promise
76
+ */
77
+ addExecuteManager(ctx?: {
78
+ options?: IRewordAdConfig;
79
+ collection?: CallbackCollection;
80
+ }): Promise<unknown>;
81
+ destroy(): void;
82
+ /**
83
+ * 清理广告实例
84
+ * @abstract 清理广告实例,子类必须实现此方法
85
+ */
86
+ clear(): void;
87
+ /**
88
+ * 任务执行完成后始终执行的一个方法
89
+ * @abstract 任务执行完成后始终执行的一个方法,子类需要用到时实现此方法
90
+ * @param {object} [_args] 执行结果信息
91
+ */
92
+ record(_args?: object): this;
93
+ /**
94
+ *
95
+ * @param {({isEnded: boolean, count: number}) => void} callback
96
+ */
97
+ onClose(callback: ({ isEnded: boolean, count: number }: any) => void): void;
98
+ /**
99
+ *
100
+ * @param {({isEnded: boolean, count: number}) => void} callback
101
+ */
102
+ offClose(callback: ({ isEnded: boolean, count: number }: any) => void): void;
103
+ /**
104
+ * show
105
+ * @returns { Promise.<void>}
106
+ * @params {{errMsg: string; errCode: number}} err
107
+ */
108
+ show(): Promise<void>;
109
+ /**
110
+ * load
111
+ * @returns { Promise.<void>}
112
+ */
113
+ load(): Promise<void>;
114
+ /**
115
+ *
116
+ * @param {({errMsg: string; errCode: number}) => void} callback
117
+ */
118
+ onError(callback: any): void;
119
+ /**
120
+ *
121
+ * @param {({errMsg: string; errCode: number}) => void} callback
122
+ */
123
+ offError(callback: any): void;
124
+ onLoad(callback: any): void;
125
+ offLoad(callback: any): void;
126
+ /**
127
+ * 站位方法,没有任何左右
128
+ * @returns
129
+ */
130
+ placeholder(): any;
131
+ }
@@ -0,0 +1,457 @@
1
+ export default InterstitialAdNovel;
2
+ export type IRewordAdConfig = import("../typings/ad.js").IRewordAdConfig;
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
+ * 是否保留tt激励视频广告实例
57
+ */
58
+ preserveOnEnd?: boolean;
59
+ /**
60
+ * 是否需要在超时情况下结束广告
61
+ */
62
+ needEndOnTimeout?: boolean;
63
+ /**
64
+ * 激励视频参数 (可选)
65
+ */
66
+ adConfig?: IRewordAdConfig | undefined;
67
+ /**
68
+ * 回调集合
69
+ */
70
+ collection?: IConnection | undefined;
71
+ };
72
+ export type ICloseArgs = {
73
+ /**
74
+ * 是否看完
75
+ */
76
+ isEnded: boolean;
77
+ /**
78
+ * 完整观看次数
79
+ */
80
+ count: number;
81
+ };
82
+ export type IEndArgs = {
83
+ /**
84
+ * 是否解锁全部
85
+ */
86
+ can_unlock_all?: boolean;
87
+ /**
88
+ * 是否解锁小说
89
+ */
90
+ can_unlock_novel?: boolean;
91
+ /**
92
+ * 剩余次数
93
+ */
94
+ remain?: number;
95
+ /**
96
+ * 结束类型
97
+ */
98
+ end_type?: "halfway" | "finished";
99
+ };
100
+ export type IRewardedVideoAd = {
101
+ /**
102
+ * 显示激励视频广告
103
+ */
104
+ show: () => Promise<void>;
105
+ };
106
+ /**
107
+ * @typedef {import('../typings/ad.js').IRewordAdConfig} IRewordAdConfig
108
+ */
109
+ /**
110
+ * @typedef ICallbackArgs
111
+ * @property {number} scene 广告执行场景
112
+ * @property {boolean} isEnded 是否看完
113
+ * @property {number} count 完整观看次数
114
+ * @property {() => void} [end] 执行下一个任务的回调函数,手动调用以继续执行流程[end]
115
+ * @property {(args: {ignoreRemain: boolean, scene: number}) => void} [circle] 执行下一个任务的回调函数, 手动调用以继续执行流程[circle]
116
+ *
117
+ */
118
+ /**
119
+ * @typedef IConnection
120
+ * @property {(args: ICallbackArgs) => void} [onHalfway] 广告中途退出回调
121
+ * @property {(args: ICallbackArgs) => void} [onShow] 广告展示回调
122
+ * @property {(args: ICallbackArgs) => void} [onFinish] 广告执行成功回调
123
+ * @property {(args: ICallbackArgs) => void} [onAlways] 广告执行成功回调
124
+ * @property {(e:unknown) => void} [onError] 广告执行失败回调
125
+ */
126
+ /**
127
+ * @typedef IConstructArgs
128
+ * @property {string} [sign] 初始化标识
129
+ * @property {boolean} [preserveOnEnd] 是否保留tt激励视频广告实例
130
+ * @property {boolean} [needEndOnTimeout] 是否需要在超时情况下结束广告
131
+ * @property {IRewordAdConfig=} [adConfig] 激励视频参数 (可选)
132
+ * @property {IConnection=} [collection] 回调集合
133
+ */
134
+ /**
135
+ * @typedef ICloseArgs
136
+ * @property {boolean} isEnded 是否看完
137
+ * @property {number} count 完整观看次数
138
+ */
139
+ /**
140
+ * @typedef IEndArgs
141
+ * @property {boolean} [can_unlock_all] 是否解锁全部
142
+ * @property {boolean} [can_unlock_novel] 是否解锁小说
143
+ * @property {number} [remain] 剩余次数
144
+ * @property {'halfway' | 'finished'} [end_type] 结束类型
145
+ *
146
+ */
147
+ /**
148
+ * @typedef IRewardedVideoAd
149
+ * @property {() => Promise.<void>} show 显示激励视频广告
150
+ */
151
+ declare class InterstitialAdNovel extends InterstitialAdFather {
152
+ /**
153
+ *
154
+ * @param {IConstructArgs} args
155
+ * @returns {InterstitialAdNovel}
156
+ */
157
+ static build(args: IConstructArgs): InterstitialAdNovel;
158
+ /**
159
+ *
160
+ * @returns {InterstitialAdNovel}
161
+ */
162
+ static getInstance(): InterstitialAdNovel;
163
+ /**
164
+ *
165
+ * @param {IConstructArgs} args
166
+ * @returns {InterstitialAdNovel}
167
+ */
168
+ static "new"(args: IConstructArgs): InterstitialAdNovel;
169
+ /**
170
+ * @param {IConstructArgs} args
171
+ *
172
+ */
173
+ constructor(args: IConstructArgs);
174
+ _onHalfway: any;
175
+ _onShow: any;
176
+ _onFinish: any;
177
+ _onAlways: any;
178
+ _onError: any;
179
+ _alwaysCallback: any;
180
+ _halfwayCallback: any;
181
+ _finishedCallback: any;
182
+ _resolve: any;
183
+ _next: any;
184
+ /** @type {number} 广告执行场景 */
185
+ _scene: number;
186
+ _adTypeR: 2;
187
+ _adTimeout: any;
188
+ _adTimeoutTime: number;
189
+ _adBeforeShowTimer: any;
190
+ _adBeforeShowTime: number;
191
+ _adSpeedCloseTimer: any;
192
+ _adSpeedCloseTime: number;
193
+ _needEndOnTimeout: boolean;
194
+ /** @deprecated TODO 移除 */
195
+ _needSpeedEndOnTimeout: boolean;
196
+ bindAdCloseLister: any;
197
+ bindAdErrorLister: any;
198
+ bindAdLoadLister: any;
199
+ bindApiAdErrorLister: any;
200
+ _bindShiftCloseLister: any;
201
+ _bindShiftErrorLister: any;
202
+ /**
203
+ * 初始化
204
+ * 子类可以选择覆盖此方法,或使用默认实现
205
+ * @param {IRewordAdConfig} args
206
+ * @param {(v: IRewardedVideoAd) => void} [callback] 初始化成功回调
207
+ * @returns {this} 当前实例
208
+ */
209
+ initialize(args: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
210
+ _initAdLister(): void;
211
+ /**
212
+ * @param {object} args
213
+ * @param {number} [args.retry] 重试次数
214
+ */
215
+ _initNovelConfig(args: {
216
+ retry?: number;
217
+ }): void;
218
+ novelConfig: RewardAdNovelConfig;
219
+ _onInnerExecuteBefore(): any;
220
+ _onInnerAdShowSuccess(): any;
221
+ /**
222
+ * 广告展示超时设置
223
+ * @param {object} args
224
+ * @param {string} args.scene 广告执行场景 必填
225
+ * @param {Function} args.end 结束当前广告任务的回调函数 必填
226
+ */
227
+ _setAdTimeout(args: {
228
+ scene: string;
229
+ end: Function;
230
+ }): void;
231
+ /**
232
+ * 广告展示前定时器
233
+ * @param {object} args
234
+ * @param {string} args.scene 广告执行场景 必填
235
+ * @param {Function} args.prelude 广告展示前回调函数 可选
236
+ */
237
+ _adPreludeInterval(args: {
238
+ scene: string;
239
+ prelude: Function;
240
+ }): void;
241
+ _clearAdTimeout(): void;
242
+ /**
243
+ * 广告展示成功前分析
244
+ * 子类需要埋点可以选择覆盖此方法
245
+ * @protected
246
+ * @param {object} _args
247
+ * @param {string} _args.scene 广告执行场景 必填
248
+ * @returns
249
+ */
250
+ protected _adShowBeforeAnalytics(_args: {
251
+ scene: string;
252
+ }): any;
253
+ /**
254
+ * 广告展示成功分析
255
+ * 子类需要埋点可以选择覆盖此方法
256
+ * @protected
257
+ * @param {object} _args
258
+ * @param {string} _args.scene 广告执行场景 必填
259
+ * @param {string} [_args.msg] 广告执行成功原因
260
+ * @param {0|1} _args.result 广告执行成功结果
261
+ * @returns
262
+ */
263
+ protected _adShowSuccessAnalytics(_args: {
264
+ scene: string;
265
+ msg?: string;
266
+ result: 0 | 1;
267
+ }): any;
268
+ /**
269
+ * 广告展示失败分析
270
+ * 子类需要埋点可以选择覆盖此方法
271
+ * @protected
272
+ * @param {object} _args
273
+ * @param {string} _args.scene 广告执行场景 必填
274
+ * @param {string} _args.msg 广告执行失败原因 必填
275
+ * @param {number} _args.errorCode 广告执行失败错误码 必填
276
+ * @param {0|1} _args.result 广告执行失败结果
277
+ * @returns
278
+ */
279
+ protected _adShowFailureAnalytics(_args: {
280
+ scene: string;
281
+ msg: string;
282
+ errorCode: number;
283
+ result: 0 | 1;
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
+ * @returns
294
+ */
295
+ protected _adLoadSuccessAnalytics(_args: {
296
+ scene: string;
297
+ msg?: string;
298
+ result: 0 | 1;
299
+ }): any;
300
+ /**
301
+ * 广告加载失败分析
302
+ * 子类需要埋点可以选择覆盖此方法
303
+ * @protected
304
+ * @param {object} _args
305
+ * @param {string} _args.scene 广告执行场景 必填
306
+ * @param {string} _args.msg 广告执行失败原因 必填
307
+ * @param {0|1} _args.result 广告执行失败结果
308
+ * @returns
309
+ */
310
+ protected _adLoadFailureAnalytics(_args: {
311
+ scene: string;
312
+ msg: string;
313
+ result: 0 | 1;
314
+ }): any;
315
+ /**
316
+ * 广告关闭成功分析
317
+ * 子类需要埋点可以选择覆盖此方法
318
+ * @protected
319
+ * @param {object} _args
320
+ * @param {string} _args.scene 广告执行场景 必填
321
+ * @param {number} _args.ad_is_completed 广告是否完成 必填
322
+ * @returns
323
+ */
324
+ protected _adCloseSuccessAnalytics(_args: {
325
+ scene: string;
326
+ ad_is_completed: number;
327
+ }): any;
328
+ get rewardAd(): any;
329
+ /**
330
+ * 确保广告按顺序执行
331
+ * @override
332
+ * @param {Object} [ctx] 上下文对象,用于传递数据和状态
333
+ * @param {IRewordAdConfig} [ctx.options] 广告执行选项
334
+ * @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
335
+ * @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
336
+ */
337
+ override addExecuteManager(ctx?: {
338
+ options?: IRewordAdConfig;
339
+ collection?: import("../typings/ad.js").CallbackCollection;
340
+ }): Promise<(IEndArgs & ICloseArgs) | undefined>;
341
+ /**
342
+ * @override
343
+ * @param {object} [ctx] 广告执行上下文
344
+ * @param {import('../typings/ad.js').IRewordAdConfig} [ctx.options] 广告执行选项
345
+ * @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
346
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
347
+ * @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
348
+ */
349
+ override ad(ctx?: {
350
+ options?: import("../typings/ad.js").IRewordAdConfig;
351
+ collection?: import("../typings/ad.js").CallbackCollection;
352
+ }, next?: Function): Promise<(IEndArgs & ICloseArgs) | undefined>;
353
+ /**
354
+ * @param {object} [ctx] 广告执行上下文
355
+ * @param {object} [ctx.options] 广告执行选项
356
+ * @param {number} [ctx.options.scene] 广告执行场景
357
+ * @param {object} ctx.collection 回调集合
358
+ * @param {(v?: unknown) => void} ctx.collection.resolve 广告执行成功的回调函数
359
+ * @param {(v?: unknown) => void} [ctx.collection.reject] 广告执行失败的回调函数
360
+ * @param {(v?: unknown) => void} [ctx.collection.before] 广告执行前的回调函数
361
+ * @param {(v?: unknown) => void} [ctx.collection.success] 广告执行成功的回调函数
362
+ * @param {(v?: unknown) => void} [ctx.collection.prelude] 拉起广告前计时的回调函数
363
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
364
+ */
365
+ _adInner(ctx?: {
366
+ options?: {
367
+ scene?: number;
368
+ };
369
+ collection: {
370
+ resolve: (v?: unknown) => void;
371
+ reject?: (v?: unknown) => void;
372
+ before?: (v?: unknown) => void;
373
+ success?: (v?: unknown) => void;
374
+ prelude?: (v?: unknown) => void;
375
+ };
376
+ }, next?: Function): void;
377
+ _before: (v?: unknown) => void;
378
+ _success: (v?: unknown) => void;
379
+ /**
380
+ * 广告加载
381
+ * @returns
382
+ */
383
+ adLoad(): Promise<void>;
384
+ /**
385
+ * 广告展示
386
+ * @returns
387
+ */
388
+ adShow(): Promise<void>;
389
+ _outerCloseCallback(args: any): void;
390
+ _outerHalfwayCallback(args: any): void;
391
+ _outerFinishedCallback(args: any): void;
392
+ /**
393
+ * 关闭激励视频
394
+ * 子类重写该方法时,必须调用this._clearAdTimeout();清除超时定时器
395
+ */
396
+ adCloseLister(): void;
397
+ adErrorLister(e: any): void;
398
+ apiAdErrorLister(e: any): void;
399
+ /**
400
+ * 激励视频广告组件**成功**拉取广告素材时会触发
401
+ * 创建激励时候后会自动拉取广告素材,如果广告拉取成功,也会触发此事件,不管是否调用show方法
402
+ * @param {unknown} e
403
+ */
404
+ adLoadLister(e: unknown): void;
405
+ adDestroy(): void;
406
+ _shiftCloseLister(args: any): void;
407
+ _shiftErrorLister(args: any): void;
408
+ /**
409
+ * 手动出栈
410
+ */
411
+ shift(): void;
412
+ }
413
+ import InterstitialAdFather from './InterstitialAdFather.js';
414
+ declare class RewardAdNovelConfig {
415
+ /**
416
+ *
417
+ * @param {object} args
418
+ * @param {string} args.sign 初始化标识
419
+ * @param {number} [args.retry] 重试次数
420
+ * @returns {RewardAdNovelConfig}
421
+ */
422
+ static "new"(args: {
423
+ sign: string;
424
+ retry?: number;
425
+ }): RewardAdNovelConfig;
426
+ /**
427
+ *
428
+ * @param {object} [args]
429
+ * @param {number} [args.retry]
430
+ */
431
+ constructor(args?: {
432
+ retry?: number;
433
+ });
434
+ frequency: {
435
+ total: number;
436
+ current: number;
437
+ };
438
+ /**
439
+ *
440
+ * @param {object} [args]
441
+ * @param {number} [args.retry]
442
+ */
443
+ _init(args?: {
444
+ retry?: number;
445
+ }): void;
446
+ /**
447
+ *
448
+ * @param {object} [args]
449
+ * @param {number} [args.retry]
450
+ */
451
+ _adTimes(args?: {
452
+ retry?: number;
453
+ }): void;
454
+ reset(): void;
455
+ updateRetry(): void;
456
+ remain(): number;
457
+ }