@jolibox/ads 1.3.3 → 1.3.5-beta.10
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/README.md +119 -1
- package/dist/afg/ads-interface.d.ts +1 -1
- package/dist/afg/index.d.ts +1 -1
- package/dist/afg/native/index.d.ts +15 -0
- package/dist/afg/native/type.d.ts +25 -0
- package/dist/afg/type.d.ts +12 -2
- package/dist/components/ads-request.d.ts +1 -3
- package/dist/components/native/index.d.ts +3 -0
- package/dist/components/native/interstitial.d.ts +55 -0
- package/dist/components/native/native-helper.d.ts +60 -0
- package/dist/components/native/reward.d.ts +56 -0
- package/dist/components/native/type.d.ts +1 -0
- package/dist/index.js +3043 -1342
- package/dist/type/base.d.ts +7 -3
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jolibox/ads
|
|
2
|
+
|
|
3
|
+
## 1. 背景
|
|
4
|
+
|
|
5
|
+
`@jolibox/ads` 是 Jolibox JSSDK 的核心包之一,主要负责业务层面的广告调用与聚合。它为不同类型的接入方提供了统一的广告接入规范:
|
|
6
|
+
|
|
7
|
+
- **游戏接入方**:对外暴露 AdSense for Game (AFG) 接口,支持激励视频、插屏广告及 Preroll 等格式。
|
|
8
|
+
- **短剧接入方**:对外暴露特定的 AFV (AdSense for Video) 接口,主要用于视频流中的广告插入。
|
|
9
|
+
|
|
10
|
+
为了最大化广告收益并保证填充率,该包实现了一套高效的广告聚合逻辑,支持从多个广告源 (Provider) 进行瀑布流式的广告加载。
|
|
11
|
+
|
|
12
|
+
## 2. 目的
|
|
13
|
+
|
|
14
|
+
- **统一接口**:为前端业务屏蔽底层不同广告供应商(如 Google AdSense, OKSpin, AppsRockets 等)的 API 差异。
|
|
15
|
+
- **聚合下发**:通过后端下发的配置,动态决定广告供应商的优先级和调用顺序。
|
|
16
|
+
- **高填充率**:通过“瀑布流” (Waterfall) 机制,在一间供应商失败时自动尝试下一间,确保广告展示机会。
|
|
17
|
+
- **解耦业务**:将复杂的广告加载、超检测、埋点监控等逻辑封装内部,业务方只需关注简单的 `adBreak` 或 `requestAd` 调用。
|
|
18
|
+
|
|
19
|
+
## 3. 技术选型
|
|
20
|
+
|
|
21
|
+
- **TypeScript**: 核心逻辑编写,提供强类型定义。
|
|
22
|
+
- **Preact & @preact/signals**: 部分 native 广告 UI 组件的渲染与状态管理。
|
|
23
|
+
- **Vite & Esbuild**: 高性能的构建工具链,支持 ESM/CJS/IIFE 多种输出格式。
|
|
24
|
+
- **Async/Await Hooks**: 利用 Promise 封装异步回调,简化瀑布流逻辑。
|
|
25
|
+
|
|
26
|
+
## 4. 架构
|
|
27
|
+
|
|
28
|
+
项目采用 **Provider 模式** 结合 **Orchestrator (协调者)** 的架构:
|
|
29
|
+
|
|
30
|
+
- **Providers**: 每个广告平台(如 Google, OKSpin)都被实现为一个独立的 Provider 子类,遵循统一的接口契约 (`IAbstractAFGProvider` / `IAbstractAFVProvider`)。
|
|
31
|
+
- **Async Proxies**: `AdBreakAsyncProxy` 和 `AdRequestAsyncProxy` 作为中间件,负责包装 Provider 的回调函数,并将异步回调转化为 Promise 状态,从而支持在循环中按序等待。
|
|
32
|
+
- **Orchestrator**: `JoliboxAdsForGame` 和 `JoliboxAdsForVideo` 作为入口类,负责初始化各 Provider,并根据后端下发的序列执行循环调用。
|
|
33
|
+
|
|
34
|
+
```mermaid
|
|
35
|
+
graph TD
|
|
36
|
+
User([业务方调用]) --> Main[JoliboxAdsForGame / Video]
|
|
37
|
+
Main --> FetchConfig[AdsRequest: 获取广告策略]
|
|
38
|
+
FetchConfig --> Loop{瀑布流循环}
|
|
39
|
+
Loop --> Proxy[Async Proxy: 包装回调]
|
|
40
|
+
Proxy --> Provider[Concrete Provider: Google/OKSpin...]
|
|
41
|
+
Provider -- 失败/超时 --> Loop
|
|
42
|
+
Provider -- 成功渲染 --> Done([流程结束])
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 5. 目录结构
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
src/
|
|
49
|
+
├── afg/ # AdSense for Game 相关实现
|
|
50
|
+
│ ├── adsense/ # Google AdSense Provider
|
|
51
|
+
│ ├── okspin/ # OKSpin Provider
|
|
52
|
+
│ ├── native/ # Native 广告逻辑
|
|
53
|
+
│ ├── adbreak-async-proxy.ts # AFG 异步代理逻辑
|
|
54
|
+
│ └── index.ts # AFG 入口及瀑布流编排
|
|
55
|
+
├── afv/ # AdSense for Video 相关实现
|
|
56
|
+
│ ├── ima/ # Google IMA Provider
|
|
57
|
+
│ ├── adrequest-async-proxy.ts # AFV 异步代理逻辑
|
|
58
|
+
│ └── index.ts # AFV 入口
|
|
59
|
+
├── components/ # 公共组件(如 AdsRequest 请求封装)
|
|
60
|
+
├── type/ # 公共类型定义
|
|
61
|
+
└── utils/ # 工具函数
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 6. 业务分层
|
|
65
|
+
|
|
66
|
+
- **接入层 (Access Layer)**:`JoliboxAdsForGame` / `JoliboxAdsForVideo` 类,负责面向接入方提供标准的、归一化的 API 接口(如 `adBreak`, `requestAd`)。
|
|
67
|
+
- **调度与代理层 (Orchestration & Proxy Layer)**:通过 `AsyncProxy` 将异步回调模式转化为同步 `await` 语义,并实现核心的瀑布流调度逻辑。
|
|
68
|
+
- **委派与适配层 (Delegation & Adaptation Layer)**:
|
|
69
|
+
- **二级委派机制**:这是实现的核心。外露接口不直接参与具体的广告加载逻辑,而是将其委派给具体的 `Provider`。
|
|
70
|
+
- 某些复杂的 Provider(如 `GoogleGPT` 或 `Native`)会进行二次委派给专有的 `AdManager`,从而实现**统一外露接口**与**不同广告源具体实现细节**的彻底分离。
|
|
71
|
+
- **基础层 (Base Layer)**:`AdsContext` 提供埋点、请求、环境感知的底层支撑。
|
|
72
|
+
|
|
73
|
+
## 7. 一些实现细节
|
|
74
|
+
|
|
75
|
+
### Async-Proxy 的实现
|
|
76
|
+
|
|
77
|
+
为了让分布在不同回调函数(如 `beforeAd`, `adBreakDone` 等)中的逻辑能像同步代码一样在一个循环中执行,我们使用了 `AsyncProxy` 模式:
|
|
78
|
+
|
|
79
|
+
1. `callAdBreakAndContinue` 返回一个 `Promise`。
|
|
80
|
+
2. 内部通过 `wrapAdBreakDone` 等闭包捕获原始回调。
|
|
81
|
+
3. 当广告完成、出错或超时时,调用 `resolve` 并返回一个 `continueLoop` 标志。
|
|
82
|
+
|
|
83
|
+
### 超时处理
|
|
84
|
+
|
|
85
|
+
在 `AdBreakAsyncProxy` 中内置了 5 秒的保护性超时。如果 Provider 在规定时间内没有触发任何有效回调(如 `beforeAd`),代理层会自动触发 `timeout` 并让瀑布流进入下一个节点。
|
|
86
|
+
|
|
87
|
+
### Native 广告集成
|
|
88
|
+
|
|
89
|
+
对于 Native 环境,通过 `NativeProvider` 与客户端通信。在 Web 端,则通过 `AppsRockets` 或 `GoogleGPT` 渲染特定的 UI 组件。
|
|
90
|
+
|
|
91
|
+
## 8. Provider 重组逻辑 (Reorganization)
|
|
92
|
+
|
|
93
|
+
在 `init` 和获取广告策略 (`getAFGAdsInfo`/`getAFVAdsInfo`) 阶段,SDK 会对后端下发的 Provider 列表进行重组。其核心目的是**将所有 Native 类型的 Provider 虚拟化为一个统一的 `INTERNAL_NATIVE` 节点**。
|
|
94
|
+
|
|
95
|
+
### 为什么需要重组?
|
|
96
|
+
|
|
97
|
+
1. **统一调度语义**:在 JS 层的瀑布流逻辑中,不需要感知 Native 侧具体包含多少个三方 SDK(如 Mintegral, AppLovin 等)。通过重组,JS 侧只需与一个 `NativeProvider` 交互。
|
|
98
|
+
2. **职责分离**:JS 侧负责处理 Web 端的多个渠道(Google, OKSpin 等)与 Native 整体之间的优先级;而 Native 侧则利用原生 SDK 的优势,在 `NativeProvider` 内部处理其子级的广告竞价与切换。
|
|
99
|
+
3. **简化序列管理**:后端下发的 `seq`(优先级)可以在重组后被重新映射。所有 Native 广告通常被视为一个高优先级的整体块(Block),这保证了在原生 APP 环境下,原生广告始终能被优先调用。
|
|
100
|
+
|
|
101
|
+
## 9. 广告源实现详情
|
|
102
|
+
|
|
103
|
+
针对各个广告源的具体实现细节,请参阅以下文档:
|
|
104
|
+
|
|
105
|
+
- [Google AdSense & BannerAsAFG](docs/adsense.md)
|
|
106
|
+
- [OKSpin (AFG & AFV)](docs/okspin.md)
|
|
107
|
+
- [AppsRockets (AFG & AFV)](docs/appsrockets.md)
|
|
108
|
+
- [Google GPT (AFG & AFV)](docs/googlegpt.md)
|
|
109
|
+
- [Google IMA (AFV)](docs/ima.md)
|
|
110
|
+
- [Native Provider (Internal)](docs/native.md)
|
|
111
|
+
|
|
112
|
+
## 10. 开发者深度指南 (AI/Developer Onboarding)
|
|
113
|
+
|
|
114
|
+
如果你需要在此包上进行二次开发或接入新的广告源,请务必阅读以下规范文档:
|
|
115
|
+
|
|
116
|
+
- [开发与贡献指南](./docs/CONTRIBUTING.md) - 环境搭建与编码准则。
|
|
117
|
+
- [New Provider 接入规范](docs/PROVIDER_SPEC.md) - 定义了接口契约与事件流。
|
|
118
|
+
- [跨端通信与原生桥接协议](docs/MESSAGING_PROTOCOL.md) - 定义了 Iframe 与 Native Bridge 的交互细节。
|
|
119
|
+
- [后端配置与数据规范](docs/SERVER_CONFIG_SPEC.md) - 详细说明了广告策略接口的字段含义。
|
|
@@ -191,7 +191,7 @@ export interface IAdUnitParams {
|
|
|
191
191
|
*/
|
|
192
192
|
style?: string;
|
|
193
193
|
}
|
|
194
|
-
export interface IAbstractAFGProvider<AdInitServerParam extends IAFGInitServerParams = any, AdBreakServerParam extends IAFGAdBreakServerParams = any> {
|
|
194
|
+
export interface IAbstractAFGProvider<AdInitServerParam extends IAFGInitServerParams = any, AdBreakServerParam extends Omit<IAFGAdBreakServerParams, 'seq'> = any> {
|
|
195
195
|
name: string;
|
|
196
196
|
init(): void;
|
|
197
197
|
adConfig(params: IAdConfigParams, serverParam: AdInitServerParam): void;
|
package/dist/afg/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class JoliboxAdsForGame {
|
|
|
15
15
|
private adsIsShowing;
|
|
16
16
|
private lastAdBreak?;
|
|
17
17
|
private initializedTimeStamp;
|
|
18
|
-
constructor(context?: IAdsContext<'GAME'>);
|
|
18
|
+
constructor(context?: IAdsContext<'GAME' | 'TASK'>);
|
|
19
19
|
init(_config?: IAdsInitParams): Promise<void>;
|
|
20
20
|
adConfig(params: IAdConfigParams): void;
|
|
21
21
|
adBreak(params: IAdBreakParams): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IAdsContext } from '@/type/base';
|
|
2
|
+
import type { IAbstractAFGProvider, IAdBreakParams, IAdConfigParams } from '../ads-interface';
|
|
3
|
+
import type { INativeInternalAdBreakParams, INativeInternalInitParams } from './type';
|
|
4
|
+
export declare class NativeProvider implements IAbstractAFGProvider<INativeInternalInitParams, INativeInternalAdBreakParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
private context;
|
|
7
|
+
private rewardAdManager?;
|
|
8
|
+
private interstitialManager?;
|
|
9
|
+
private initProviders;
|
|
10
|
+
constructor(context: IAdsContext, params: INativeInternalInitParams['params']);
|
|
11
|
+
private getConfigsByTypes;
|
|
12
|
+
init(): Promise<void>;
|
|
13
|
+
adConfig(params: IAdConfigParams, serverParam: INativeInternalInitParams): void;
|
|
14
|
+
adBreak(params: IAdBreakParams, serverParam: INativeInternalAdBreakParams): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface INativeInitServerParams {
|
|
2
|
+
provider: 'ADMOB' | 'APPLOVIN';
|
|
3
|
+
params: {
|
|
4
|
+
adUnitId: {
|
|
5
|
+
reward: string;
|
|
6
|
+
rewardInterstitial: string;
|
|
7
|
+
interstitial: string;
|
|
8
|
+
};
|
|
9
|
+
extra?: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface INativeAdBreakServerParams {
|
|
13
|
+
provider: 'ADMOB' | 'APPLOVIN';
|
|
14
|
+
params: never;
|
|
15
|
+
}
|
|
16
|
+
export interface INativeInternalInitParams {
|
|
17
|
+
provider: 'INTERNAL_NATIVE';
|
|
18
|
+
params: {
|
|
19
|
+
providers: INativeInitServerParams[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface INativeInternalAdBreakParams {
|
|
23
|
+
provider: 'INTERNAL_NATIVE';
|
|
24
|
+
params: INativeAdBreakServerParams[];
|
|
25
|
+
}
|
package/dist/afg/type.d.ts
CHANGED
|
@@ -7,13 +7,23 @@ import type { IGoogleGPTAdBreakServerParams, IGoogleGPTInitServerParams } from '
|
|
|
7
7
|
import type { GoogleGPTProvider } from './googlegpt';
|
|
8
8
|
import type { IBannerAsAFGAdBreakServerParams, IBannerAsAFGInitServerParams } from './banner-as-afg/type';
|
|
9
9
|
import type { BannerAsAFGProvider } from './banner-as-afg';
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import type { INativeAdBreakServerParams, INativeInitServerParams, INativeInternalAdBreakParams, INativeInternalInitParams } from './native/type';
|
|
11
|
+
import type { NativeProvider } from './native';
|
|
12
|
+
export type IAFGInitServerParams = (IGoogleAdSenseInitServerParams | IOKSpinInitServerParams | IAppsRocketsInitServerParams | IGoogleGPTInitServerParams | IBannerAsAFGInitServerParams | INativeInitServerParams | INativeInternalInitParams) & {
|
|
13
|
+
isNative?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type IAFGAdBreakServerParams = (IGoogleAdSenseAdBreakServerParams | IOKSpinAdBreakServerParams | IAppsRocketsAdBreakServerParams | IGoogleGPTAdBreakServerParams | IBannerAsAFGAdBreakServerParams | INativeAdBreakServerParams | INativeInternalAdBreakParams) & {
|
|
16
|
+
isNative?: boolean;
|
|
17
|
+
seq: number;
|
|
18
|
+
};
|
|
12
19
|
export interface IAFGProviders {
|
|
20
|
+
ADMOB?: never;
|
|
21
|
+
APPLOVIN?: never;
|
|
13
22
|
ADSENSE?: GoogleAdSenseProvider;
|
|
14
23
|
ADSENSE_ADMOB?: GoogleAdSenseProvider;
|
|
15
24
|
OKSPIN?: OKSpinForGameProvider;
|
|
16
25
|
APPSROCKETS?: AppsRocketsForGameProvider;
|
|
17
26
|
GOOGLE_GPT?: GoogleGPTProvider;
|
|
18
27
|
ADSENSE_BANNER_AS_AFG?: BannerAsAFGProvider;
|
|
28
|
+
INTERNAL_NATIVE?: NativeProvider;
|
|
19
29
|
}
|
|
@@ -58,9 +58,7 @@ export declare class AdsRequest {
|
|
|
58
58
|
*/
|
|
59
59
|
getAFGAdsInfo: (type: IAdBreakParams["type"]) => Promise<{
|
|
60
60
|
code: "SUCCESS" | "BYPASS_ADS" | "TOO_FREQUENT_REQUEST";
|
|
61
|
-
data:
|
|
62
|
-
seq: number;
|
|
63
|
-
})[];
|
|
61
|
+
data: IAFGAdBreakServerParams[];
|
|
64
62
|
} | null>;
|
|
65
63
|
/**
|
|
66
64
|
* Fetches the ads info for Drama.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IAdsContext } from '@/type/base';
|
|
2
|
+
import { NativeProviderConfig } from './native-helper';
|
|
3
|
+
import { BreakStatus } from './type';
|
|
4
|
+
export interface INativeInterstitialAdContext {
|
|
5
|
+
beforeAd?: () => void;
|
|
6
|
+
afterAd?: () => void;
|
|
7
|
+
onEnd?: (endReason: BreakStatus) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* NativeInterstitialAdManager class for managing native interstitial ads.
|
|
11
|
+
*
|
|
12
|
+
* This class handles the lifecycle of native interstitial ads, including initialization,
|
|
13
|
+
* requesting ads, handling events, and cleaning up resources.
|
|
14
|
+
* It follows the implementation style of NativeRewardAdManager.
|
|
15
|
+
*/
|
|
16
|
+
export declare class NativeInterstitialAdManager {
|
|
17
|
+
private providers;
|
|
18
|
+
private helper;
|
|
19
|
+
private adsContext;
|
|
20
|
+
private _isAdsReady;
|
|
21
|
+
get isAdsReady(): boolean;
|
|
22
|
+
constructor(context: IAdsContext, providers: NativeProviderConfig[]);
|
|
23
|
+
/**
|
|
24
|
+
* Initializes the native ad loading process.
|
|
25
|
+
*/
|
|
26
|
+
private init;
|
|
27
|
+
/**
|
|
28
|
+
* Resets the ad manager state and potentially re-initializes it.
|
|
29
|
+
*
|
|
30
|
+
* @param endReason The reason for ending the current ad session.
|
|
31
|
+
* @param clearContext Whether to clear the adsContext.
|
|
32
|
+
*/
|
|
33
|
+
destroy: (endReason: BreakStatus, clearContext?: boolean) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Re-initializes the ad manager.
|
|
36
|
+
*
|
|
37
|
+
* @param endReason The reason for re-init.
|
|
38
|
+
* @param clearContext Whether to clear the adsContext.
|
|
39
|
+
*/
|
|
40
|
+
reinit: (endReason: BreakStatus, clearContext?: boolean) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Request ads for the native interstitial ad.
|
|
43
|
+
*
|
|
44
|
+
* This method ensures the loading process is complete and then checks
|
|
45
|
+
* the readiness state to show the ad.
|
|
46
|
+
*
|
|
47
|
+
* @param context The context for the interstitial ad, containing callbacks for ad events.
|
|
48
|
+
* @param providers (Optional) updated provider list for this request.
|
|
49
|
+
*/
|
|
50
|
+
requestAds: (context: INativeInterstitialAdContext, providers?: NativeProviderConfig[]) => Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Private method to handle the actual showing of the ad.
|
|
53
|
+
*/
|
|
54
|
+
private showAd;
|
|
55
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { StandardResponse } from '@jolibox/types';
|
|
2
|
+
import { IAdsContext } from '@/type/base';
|
|
3
|
+
export interface NativeProviderConfig {
|
|
4
|
+
provider: 'ADMOB' | 'APPLOVIN';
|
|
5
|
+
params: {
|
|
6
|
+
placementId: string;
|
|
7
|
+
adsType: 'INTERSTITIAL' | 'REWARD' | 'REWARD_INTERSTITIAL';
|
|
8
|
+
extra?: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface StandardAdsParams {
|
|
12
|
+
providers: NativeProviderConfig[];
|
|
13
|
+
}
|
|
14
|
+
export interface AdEventCallbacks {
|
|
15
|
+
onAdShow?: (event: AdsStateChangeEvent) => void;
|
|
16
|
+
onAdError?: (event: AdsStateChangeEvent) => void;
|
|
17
|
+
onAdClosed?: (event: AdsStateChangeEvent) => void;
|
|
18
|
+
onAdClicked?: (event: AdsStateChangeEvent) => void;
|
|
19
|
+
onAdRewarded?: (event: AdsStateChangeEvent) => void;
|
|
20
|
+
onAdDismissed?: (event: AdsStateChangeEvent) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface ShowAdParams {
|
|
23
|
+
providers: NativeProviderConfig[];
|
|
24
|
+
callbacks?: AdEventCallbacks;
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}
|
|
27
|
+
export type IsAdsReadyParams = StandardAdsParams;
|
|
28
|
+
export type LoadAdsParams = StandardAdsParams;
|
|
29
|
+
export type AdsEventType = 'onAdShow' | 'onAdError' | 'onAdClosed' | 'onAdClicked' | 'onAdRewarded' | 'onAdDismissed';
|
|
30
|
+
export interface AdsStateChangeEvent {
|
|
31
|
+
placementId: string;
|
|
32
|
+
provider: string;
|
|
33
|
+
}
|
|
34
|
+
export declare class AdmobNativeHelper {
|
|
35
|
+
readonly context: IAdsContext;
|
|
36
|
+
private readonly canIUseHelper;
|
|
37
|
+
constructor(context: IAdsContext);
|
|
38
|
+
/**
|
|
39
|
+
* Load ads from native providers
|
|
40
|
+
* @param params - Parameters containing provider configurations
|
|
41
|
+
* @returns StandardResponse with success or failure
|
|
42
|
+
*/
|
|
43
|
+
loadAdsAsync(params: LoadAdsParams): Promise<StandardResponse<void>>;
|
|
44
|
+
canIUse(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Show a loaded ad
|
|
47
|
+
* @param params - Parameters containing provider configuration and optional callbacks
|
|
48
|
+
* @returns StandardResponse with ad UUID
|
|
49
|
+
*/
|
|
50
|
+
showAdAsync(params: ShowAdParams): Promise<StandardResponse<{
|
|
51
|
+
UUID: string;
|
|
52
|
+
}>>;
|
|
53
|
+
/**
|
|
54
|
+
* Check if ads are ready to be shown
|
|
55
|
+
* @param params - Parameters containing provider configurations
|
|
56
|
+
* @returns StandardResponse with ready status
|
|
57
|
+
*/
|
|
58
|
+
isAdsReadySync(params: IsAdsReadyParams): boolean;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { IAdsContext } from '@/type/base';
|
|
2
|
+
import { NativeProviderConfig } from './native-helper';
|
|
3
|
+
import { BreakStatus } from './type';
|
|
4
|
+
export interface INativeRewardAdContext {
|
|
5
|
+
beforeAd?: () => void;
|
|
6
|
+
beforeReward: (showAdFn: () => void) => void;
|
|
7
|
+
adDismissed: () => void;
|
|
8
|
+
adViewed: () => void;
|
|
9
|
+
afterAd?: () => void;
|
|
10
|
+
adBreakDone?: (breakStatus: BreakStatus) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* NativeRewardAdManager class for managing native rewarded ads.
|
|
14
|
+
*
|
|
15
|
+
* This class handles the lifecycle of native rewarded ads, including initialization,
|
|
16
|
+
* requesting ads, handling events, and cleaning up resources.
|
|
17
|
+
* It is designed to be similar to the GoogleGPT RewardAdManager.
|
|
18
|
+
*/
|
|
19
|
+
export declare class NativeRewardAdManager {
|
|
20
|
+
private providers;
|
|
21
|
+
private helper;
|
|
22
|
+
private adsContext;
|
|
23
|
+
private _isAdsReady;
|
|
24
|
+
get isAdsReady(): boolean;
|
|
25
|
+
constructor(context: IAdsContext, providers: NativeProviderConfig[]);
|
|
26
|
+
/**
|
|
27
|
+
* Initializes the native ad loading process.
|
|
28
|
+
*/
|
|
29
|
+
private init;
|
|
30
|
+
/**
|
|
31
|
+
* Resets the ad manager state and potentially re-initializes it.
|
|
32
|
+
*
|
|
33
|
+
* @param breakStatus The reason for ending the current ad session.
|
|
34
|
+
*/
|
|
35
|
+
destroy: (breakStatus: BreakStatus) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Re-initializes the ad manager.
|
|
38
|
+
*
|
|
39
|
+
* @param breakStatus The reason for re-init.
|
|
40
|
+
*/
|
|
41
|
+
reinit: (breakStatus: BreakStatus) => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Request ads for the native rewarded ad.
|
|
44
|
+
*
|
|
45
|
+
* This method ensures the loading process is complete and then checks
|
|
46
|
+
* the readiness state to show the ad.
|
|
47
|
+
*
|
|
48
|
+
* @param context The context for the rewarded ad, containing callbacks for ad events.
|
|
49
|
+
* @param providers (Optional) updated provider list for this request.
|
|
50
|
+
*/
|
|
51
|
+
requestAds: (context: INativeRewardAdContext, providers?: NativeProviderConfig[]) => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Private method to handle the actual showing of the ad.
|
|
54
|
+
*/
|
|
55
|
+
private showAd;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type BreakStatus = 'notReady' | 'timeout' | 'error' | 'noAdPreloaded' | 'frequencyCapped' | 'ignored' | 'other' | 'dismissed' | 'viewed';
|