@ad-execute-manager/ad 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 RewardAdFather;
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 RewardAdFather {
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
+ _rewardAd: 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,464 @@
1
+ export default RewardAdNovel;
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 RewardAdNovel extends RewardAdFather {
152
+ /**
153
+ *
154
+ * @param {IConstructArgs} args
155
+ * @returns {RewardAdNovel}
156
+ */
157
+ static build(args: IConstructArgs): RewardAdNovel;
158
+ /**
159
+ *
160
+ * @returns {RewardAdNovel}
161
+ */
162
+ static getInstance(): RewardAdNovel;
163
+ /**
164
+ *
165
+ * @param {IConstructArgs} args
166
+ * @returns {RewardAdNovel}
167
+ */
168
+ static "new"(args: IConstructArgs): RewardAdNovel;
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: 1;
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 {number} [args.timeout] 广告超时时间 单位ms
226
+ * @param {Function} args.end 结束当前广告任务的回调函数 必填
227
+ */
228
+ _setAdTimeout(args: {
229
+ scene: string;
230
+ timeout?: number;
231
+ end: Function;
232
+ }): void;
233
+ /**
234
+ * 广告展示前定时器
235
+ * @param {object} args
236
+ * @param {string} args.scene 广告执行场景 必填
237
+ * @param {Function} args.prelude 广告展示前回调函数 可选
238
+ */
239
+ _adPreludeInterval(args: {
240
+ scene: string;
241
+ prelude: Function;
242
+ }): void;
243
+ _clearAdTimeout(): void;
244
+ /**
245
+ * 广告展示成功前分析
246
+ * 子类需要埋点可以选择覆盖此方法
247
+ * @protected
248
+ * @param {object} _args
249
+ * @param {string} _args.scene 广告执行场景 必填
250
+ * @returns
251
+ */
252
+ protected _adShowBeforeAnalytics(_args: {
253
+ scene: string;
254
+ }): any;
255
+ /**
256
+ * 广告展示成功分析
257
+ * 子类需要埋点可以选择覆盖此方法
258
+ * @protected
259
+ * @param {object} _args
260
+ * @param {string} _args.scene 广告执行场景 必填
261
+ * @param {string} [_args.msg] 广告执行成功原因
262
+ * @param {0|1} _args.result 广告执行成功结果
263
+ * @returns
264
+ */
265
+ protected _adShowSuccessAnalytics(_args: {
266
+ scene: string;
267
+ msg?: string;
268
+ result: 0 | 1;
269
+ }): any;
270
+ /**
271
+ * 广告展示失败分析
272
+ * 子类需要埋点可以选择覆盖此方法
273
+ * @protected
274
+ * @param {object} _args
275
+ * @param {string} _args.scene 广告执行场景 必填
276
+ * @param {string} _args.msg 广告执行失败原因 必填
277
+ * @param {number} _args.errorCode 广告执行失败错误码 必填
278
+ * @param {0|1} _args.result 广告执行失败结果
279
+ * @returns
280
+ */
281
+ protected _adShowFailureAnalytics(_args: {
282
+ scene: string;
283
+ msg: string;
284
+ errorCode: number;
285
+ result: 0 | 1;
286
+ }): any;
287
+ /**
288
+ * 广告加载成功分析
289
+ * 子类需要埋点可以选择覆盖此方法
290
+ * @protected
291
+ * @param {object} _args
292
+ * @param {string} _args.scene 广告执行场景 必填
293
+ * @param {string} [_args.msg] 广告执行成功原因
294
+ * @param {0|1} _args.result 广告执行成功结果
295
+ * @returns
296
+ */
297
+ protected _adLoadSuccessAnalytics(_args: {
298
+ scene: string;
299
+ msg?: string;
300
+ result: 0 | 1;
301
+ }): any;
302
+ /**
303
+ * 广告加载失败分析
304
+ * 子类需要埋点可以选择覆盖此方法
305
+ * @protected
306
+ * @param {object} _args
307
+ * @param {string} _args.scene 广告执行场景 必填
308
+ * @param {string} _args.msg 广告执行失败原因 必填
309
+ * @param {0|1} _args.result 广告执行失败结果
310
+ * @returns
311
+ */
312
+ protected _adLoadFailureAnalytics(_args: {
313
+ scene: string;
314
+ msg: string;
315
+ result: 0 | 1;
316
+ }): any;
317
+ /**
318
+ * 广告关闭成功分析
319
+ * 子类需要埋点可以选择覆盖此方法
320
+ * @protected
321
+ * @param {object} _args
322
+ * @param {string} _args.scene 广告执行场景 必填
323
+ * @param {number} _args.ad_is_completed 广告是否完成 必填
324
+ * @param {number} _args.ad_count 广告执行次数 必填
325
+ * @returns
326
+ */
327
+ protected _adCloseSuccessAnalytics(_args: {
328
+ scene: string;
329
+ ad_is_completed: number;
330
+ ad_count: number;
331
+ }): any;
332
+ get rewardAd(): any;
333
+ /**
334
+ * 确保广告按顺序执行
335
+ * @override
336
+ * @param {Object} [ctx] 上下文对象,用于传递数据和状态
337
+ * @param {IRewordAdConfig} [ctx.options] 广告执行选项
338
+ * @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
339
+ * @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
340
+ */
341
+ override addExecuteManager(ctx?: {
342
+ options?: IRewordAdConfig;
343
+ collection?: import("../typings/ad.js").CallbackCollection;
344
+ }): Promise<(IEndArgs & ICloseArgs) | undefined>;
345
+ /**
346
+ * @override
347
+ * @param {object} [ctx] 广告执行上下文
348
+ * @param {import('../typings/ad.js').IRewordAdConfig} [ctx.options] 广告执行选项
349
+ * @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
350
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
351
+ * @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
352
+ */
353
+ override ad(ctx?: {
354
+ options?: import("../typings/ad.js").IRewordAdConfig;
355
+ collection?: import("../typings/ad.js").CallbackCollection;
356
+ }, next?: Function): Promise<(IEndArgs & ICloseArgs) | undefined>;
357
+ /**
358
+ * @param {object} [ctx] 广告执行上下文
359
+ * @param {object} [ctx.options] 广告执行选项
360
+ * @param {number} [ctx.options.scene] 广告执行场景 必填
361
+ * @param {number} [ctx.options.timeout] 广告超时时间 单位ms
362
+ * @param {object} ctx.collection 回调集合
363
+ * @param {(v?: unknown) => void} ctx.collection.resolve 广告执行成功的回调函数
364
+ * @param {(v?: unknown) => void} [ctx.collection.reject] 广告执行失败的回调函数
365
+ * @param {(v?: unknown) => void} [ctx.collection.before] 广告执行前的回调函数
366
+ * @param {(v?: unknown) => void} [ctx.collection.success] 广告执行成功的回调函数
367
+ * @param {(v?: unknown) => void} [ctx.collection.prelude] 拉起广告前计时的回调函数
368
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
369
+ */
370
+ _adInner(ctx?: {
371
+ options?: {
372
+ scene?: number;
373
+ timeout?: number;
374
+ };
375
+ collection: {
376
+ resolve: (v?: unknown) => void;
377
+ reject?: (v?: unknown) => void;
378
+ before?: (v?: unknown) => void;
379
+ success?: (v?: unknown) => void;
380
+ prelude?: (v?: unknown) => void;
381
+ };
382
+ }, next?: Function): void;
383
+ _before: (v?: unknown) => void;
384
+ _success: (v?: unknown) => void;
385
+ /**
386
+ * 广告加载
387
+ * @returns
388
+ */
389
+ adLoad(): Promise<void>;
390
+ /**
391
+ * 广告展示
392
+ * @returns
393
+ */
394
+ adShow(): Promise<void>;
395
+ _outerCloseCallback(args: any): void;
396
+ _outerHalfwayCallback(args: any): void;
397
+ _outerFinishedCallback(args: any): void;
398
+ /**
399
+ * 关闭激励视频
400
+ * 子类重写该方法时,必须调用this._clearAdTimeout();清除超时定时器
401
+ * @param {ICloseArgs} args
402
+ */
403
+ adCloseLister(args: ICloseArgs): void;
404
+ adErrorLister(e: any): void;
405
+ apiAdErrorLister(e: any): void;
406
+ /**
407
+ * 激励视频广告组件**成功**拉取广告素材时会触发
408
+ * 创建激励时候后会自动拉取广告素材,如果广告拉取成功,也会触发此事件,不管是否调用show方法
409
+ * @param {unknown} e
410
+ */
411
+ adLoadLister(e: unknown): void;
412
+ adDestroy(): void;
413
+ _shiftCloseLister(args: any): void;
414
+ _shiftErrorLister(args: any): void;
415
+ /**
416
+ * 手动出栈
417
+ */
418
+ shift(): void;
419
+ }
420
+ import RewardAdFather from './RewardAdFather.js';
421
+ declare class RewardAdNovelConfig {
422
+ /**
423
+ *
424
+ * @param {object} args
425
+ * @param {string} args.sign 初始化标识
426
+ * @param {number} [args.retry] 重试次数
427
+ * @returns {RewardAdNovelConfig}
428
+ */
429
+ static "new"(args: {
430
+ sign: string;
431
+ retry?: number;
432
+ }): RewardAdNovelConfig;
433
+ /**
434
+ *
435
+ * @param {object} [args]
436
+ * @param {number} [args.retry]
437
+ */
438
+ constructor(args?: {
439
+ retry?: number;
440
+ });
441
+ frequency: {
442
+ total: number;
443
+ current: number;
444
+ };
445
+ /**
446
+ *
447
+ * @param {object} [args]
448
+ * @param {number} [args.retry]
449
+ */
450
+ _init(args?: {
451
+ retry?: number;
452
+ }): void;
453
+ /**
454
+ *
455
+ * @param {object} [args]
456
+ * @param {number} [args.retry]
457
+ */
458
+ _adTimes(args?: {
459
+ retry?: number;
460
+ }): void;
461
+ reset(): void;
462
+ updateRetry(): void;
463
+ remain(): number;
464
+ }
@@ -0,0 +1,4 @@
1
+ export { default as RewardAdFather } from "./RewardAdFather.js";
2
+ export { default as RewardAdNovel } from "./RewardAdNovel.js";
3
+ export { default as InterstitialAdFather } from "./InterstitialAdFather.js";
4
+ export { default as InterstitialAdNovel } from "./InterstitialAdNovel.js";
@@ -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;