setupad-prebid-react-native 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +325 -0
- package/VeonPrebidReactNative.podspec +59 -0
- package/android/build.gradle +90 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativeModule.kt +130 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativePackage.kt +20 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativeView.kt +425 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativeViewManager.kt +186 -0
- package/ios/RCTFabricComponentsPlugins.h +12 -0
- package/ios/VeonPrebidReactNative-Bridging-Header.h +9 -0
- package/ios/VeonPrebidReactNativeModule.m +17 -0
- package/ios/VeonPrebidReactNativeModule.swift +108 -0
- package/ios/VeonPrebidReactNativeView+Delegates.swift +217 -0
- package/ios/VeonPrebidReactNativeView.h +5 -0
- package/ios/VeonPrebidReactNativeView.swift +381 -0
- package/ios/VeonPrebidReactNativeViewComponentView.h +13 -0
- package/ios/VeonPrebidReactNativeViewComponentView.mm +166 -0
- package/ios/VeonPrebidReactNativeViewManager.m +49 -0
- package/ios/VeonPrebidReactNativeViewManager.swift +105 -0
- package/lib/module/CodegenTypes.d.js +2 -0
- package/lib/module/CodegenTypes.d.js.map +1 -0
- package/lib/module/Commands.js +14 -0
- package/lib/module/Commands.js.map +1 -0
- package/lib/module/VeonPrebidAd.js +112 -0
- package/lib/module/VeonPrebidAd.js.map +1 -0
- package/lib/module/VeonPrebidModule.js +132 -0
- package/lib/module/VeonPrebidModule.js.map +1 -0
- package/lib/module/VeonPrebidReactNativeViewNativeComponent.ts +50 -0
- package/lib/module/VeonPrebidView.js +14 -0
- package/lib/module/VeonPrebidView.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +8 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useVeonPrebidAd.js +154 -0
- package/lib/module/useVeonPrebidAd.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Commands.d.ts +14 -0
- package/lib/typescript/src/Commands.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidAd.d.ts +4 -0
- package/lib/typescript/src/VeonPrebidAd.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidModule.d.ts +59 -0
- package/lib/typescript/src/VeonPrebidModule.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidReactNativeViewNativeComponent.d.ts +40 -0
- package/lib/typescript/src/VeonPrebidReactNativeViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidView.d.ts +5 -0
- package/lib/typescript/src/VeonPrebidView.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +89 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/useVeonPrebidAd.d.ts +52 -0
- package/lib/typescript/src/useVeonPrebidAd.d.ts.map +1 -0
- package/package.json +169 -0
- package/src/CodegenTypes.d.ts +16 -0
- package/src/Commands.ts +25 -0
- package/src/VeonPrebidAd.tsx +159 -0
- package/src/VeonPrebidModule.ts +159 -0
- package/src/VeonPrebidReactNativeViewNativeComponent.ts +50 -0
- package/src/VeonPrebidView.tsx +13 -0
- package/src/index.tsx +12 -0
- package/src/types.ts +64 -0
- package/src/useVeonPrebidAd.ts +156 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
|
+
import type { PrebidConfig } from './types';
|
|
3
|
+
|
|
4
|
+
const LINKING_ERROR =
|
|
5
|
+
`The package 'setupad-prebid-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo Go\n';
|
|
8
|
+
|
|
9
|
+
// Native Module
|
|
10
|
+
const VeonPrebidReactNativeModule = NativeModules.VeonPrebidReactNativeModule
|
|
11
|
+
? NativeModules.VeonPrebidReactNativeModule
|
|
12
|
+
: new Proxy(
|
|
13
|
+
{},
|
|
14
|
+
{
|
|
15
|
+
get() {
|
|
16
|
+
throw new Error(LINKING_ERROR);
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// Event Emitter for SDK events
|
|
22
|
+
const eventEmitter = new NativeEventEmitter(VeonPrebidReactNativeModule);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Veon Prebid SDK Module
|
|
26
|
+
* Handles SDK initialization and global SDK operations
|
|
27
|
+
*/
|
|
28
|
+
class VeonPrebidSDK {
|
|
29
|
+
private static instance: VeonPrebidSDK;
|
|
30
|
+
private isInitialized: boolean = false;
|
|
31
|
+
private initializationPromise: Promise<string> | null = null;
|
|
32
|
+
|
|
33
|
+
private constructor() {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get singleton instance
|
|
37
|
+
*/
|
|
38
|
+
public static getInstance(): VeonPrebidSDK {
|
|
39
|
+
if (!VeonPrebidSDK.instance) {
|
|
40
|
+
VeonPrebidSDK.instance = new VeonPrebidSDK();
|
|
41
|
+
}
|
|
42
|
+
return VeonPrebidSDK.instance;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Initialize Prebid Mobile SDK
|
|
47
|
+
*
|
|
48
|
+
* @param config - Prebid configuration
|
|
49
|
+
* @returns Promise that resolves when SDK is initialized
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* await VeonPrebidSDK.getInstance().initialize({
|
|
54
|
+
* prebidHost: 'https://prebid.veonadx.com/openrtb2/auction',
|
|
55
|
+
* configHost: 'https://config.veonadx.com',
|
|
56
|
+
* accountId: 'YOUR_ACCOUNT_ID',
|
|
57
|
+
* timeoutMillis: 3000,
|
|
58
|
+
* pbsDebug: __DEV__,
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
public async initialize(config: PrebidConfig): Promise<string> {
|
|
63
|
+
// Return existing initialization if in progress
|
|
64
|
+
if (this.initializationPromise !== null) {
|
|
65
|
+
return this.initializationPromise;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Return immediately if already initialized
|
|
69
|
+
if (this.isInitialized) {
|
|
70
|
+
return Promise.resolve('already initialized');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
prebidHost,
|
|
75
|
+
configHost,
|
|
76
|
+
accountId,
|
|
77
|
+
timeoutMillis = 3000,
|
|
78
|
+
pbsDebug = false,
|
|
79
|
+
} = config;
|
|
80
|
+
|
|
81
|
+
console.log('Initializing Veon Prebid SDK...', {
|
|
82
|
+
prebidHost,
|
|
83
|
+
configHost,
|
|
84
|
+
accountId,
|
|
85
|
+
timeoutMillis,
|
|
86
|
+
pbsDebug,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const promise = VeonPrebidReactNativeModule.initializeSDK(
|
|
90
|
+
prebidHost,
|
|
91
|
+
configHost,
|
|
92
|
+
accountId,
|
|
93
|
+
timeoutMillis,
|
|
94
|
+
pbsDebug
|
|
95
|
+
)
|
|
96
|
+
.then((result: string) => {
|
|
97
|
+
console.log('Veon Prebid SDK initialized successfully:', result);
|
|
98
|
+
this.isInitialized = true;
|
|
99
|
+
this.initializationPromise = null;
|
|
100
|
+
return result;
|
|
101
|
+
})
|
|
102
|
+
.catch((error: any) => {
|
|
103
|
+
console.error('Failed to initialize Veon Prebid SDK:', error);
|
|
104
|
+
this.initializationPromise = null;
|
|
105
|
+
throw error;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
this.initializationPromise = promise;
|
|
109
|
+
return promise;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get Prebid SDK version
|
|
114
|
+
*
|
|
115
|
+
* @returns Promise that resolves with SDK version string
|
|
116
|
+
*/
|
|
117
|
+
public async getSDKVersion(): Promise<string> {
|
|
118
|
+
try {
|
|
119
|
+
return await VeonPrebidReactNativeModule.getSDKVersion();
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('Failed to get SDK version:', error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if SDK is initialized
|
|
128
|
+
*/
|
|
129
|
+
public isSDKInitialized(): boolean {
|
|
130
|
+
return this.isInitialized;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Add listener for SDK initialization events
|
|
135
|
+
*
|
|
136
|
+
* @param event - Event name ('prebidSdkInitialized' or 'prebidSdkInitializeFailed')
|
|
137
|
+
* @param listener - Callback function
|
|
138
|
+
* @returns Subscription object with remove() method
|
|
139
|
+
*/
|
|
140
|
+
public addListener(
|
|
141
|
+
event: 'prebidSdkInitialized' | 'prebidSdkInitializeFailed',
|
|
142
|
+
listener: (data: any) => void
|
|
143
|
+
) {
|
|
144
|
+
return eventEmitter.addListener(event, listener);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Remove all listeners for specific event
|
|
149
|
+
*
|
|
150
|
+
* @param event - Event name
|
|
151
|
+
*/
|
|
152
|
+
public removeAllListeners(
|
|
153
|
+
event: 'prebidSdkInitialized' | 'prebidSdkInitializeFailed'
|
|
154
|
+
) {
|
|
155
|
+
eventEmitter.removeAllListeners(event);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export default VeonPrebidSDK;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import type {
|
|
3
|
+
Int32,
|
|
4
|
+
DirectEventHandler,
|
|
5
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Event payload for ad events
|
|
10
|
+
*/
|
|
11
|
+
export interface AdEventPayload {
|
|
12
|
+
adId?: string;
|
|
13
|
+
sdk?: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Native Props for VeonPrebidReactNativeView
|
|
19
|
+
*/
|
|
20
|
+
export interface NativeProps extends ViewProps {
|
|
21
|
+
/** Ad type: banner, interstitial, or rewardVideo */
|
|
22
|
+
adType?: string;
|
|
23
|
+
|
|
24
|
+
/** Prebid config ID */
|
|
25
|
+
configId?: string;
|
|
26
|
+
|
|
27
|
+
/** Google Ad Manager ad unit ID */
|
|
28
|
+
adUnitId?: string;
|
|
29
|
+
|
|
30
|
+
/** Ad width (required for banners) */
|
|
31
|
+
width?: Int32;
|
|
32
|
+
|
|
33
|
+
/** Ad height (required for banners) */
|
|
34
|
+
height?: Int32;
|
|
35
|
+
|
|
36
|
+
/** Refresh interval in seconds (30-120, for banners only) */
|
|
37
|
+
refreshInterval?: Int32;
|
|
38
|
+
|
|
39
|
+
// Event handlers
|
|
40
|
+
onAdLoaded?: DirectEventHandler<AdEventPayload>;
|
|
41
|
+
onAdDisplayed?: DirectEventHandler<AdEventPayload>;
|
|
42
|
+
onAdFailed?: DirectEventHandler<AdEventPayload>;
|
|
43
|
+
onAdClicked?: DirectEventHandler<AdEventPayload>;
|
|
44
|
+
onAdClosed?: DirectEventHandler<AdEventPayload>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Native component for Veon Prebid ads
|
|
49
|
+
*/
|
|
50
|
+
export default codegenNativeComponent<NativeProps>('VeonPrebidReactNativeView');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import VeonPrebidReactNativeViewNative from './VeonPrebidReactNativeViewNativeComponent';
|
|
3
|
+
import type { VeonPrebidViewProps } from './types';
|
|
4
|
+
|
|
5
|
+
export const VeonPrebidView = React.forwardRef<any, VeonPrebidViewProps>(
|
|
6
|
+
(props, ref) => {
|
|
7
|
+
return <VeonPrebidReactNativeViewNative ref={ref} {...props} />;
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
VeonPrebidView.displayName = 'VeonPrebidView';
|
|
12
|
+
|
|
13
|
+
export default VeonPrebidView;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { VeonPrebidView } from './VeonPrebidView';
|
|
2
|
+
export { VeonPrebidCommands } from './Commands';
|
|
3
|
+
export { default as VeonPrebidAd } from './VeonPrebidAd';
|
|
4
|
+
export { default as VeonPrebidSDK } from './VeonPrebidModule';
|
|
5
|
+
export { AdType } from './types';
|
|
6
|
+
export type {
|
|
7
|
+
VeonPrebidViewProps,
|
|
8
|
+
AdEventData,
|
|
9
|
+
AdController,
|
|
10
|
+
VeonPrebidAdProps,
|
|
11
|
+
PrebidConfig
|
|
12
|
+
} from './types';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const AdType = {
|
|
2
|
+
BANNER: 'banner' as const,
|
|
3
|
+
INTERSTITIAL: 'interstitial' as const,
|
|
4
|
+
REWARD_VIDEO: 'rewardvideo' as const,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type AdType = typeof AdType[keyof typeof AdType];
|
|
8
|
+
|
|
9
|
+
export interface VeonPrebidViewProps {
|
|
10
|
+
adType: AdType;
|
|
11
|
+
configId: string;
|
|
12
|
+
adUnitId: string;
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
refreshInterval?: number;
|
|
16
|
+
style?: any;
|
|
17
|
+
onAdLoaded?: (event: { nativeEvent: { adId?: string; sdk?: string; message?: string } }) => void;
|
|
18
|
+
onAdDisplayed?: (event: { nativeEvent: { adId?: string; sdk?: string; message?: string } }) => void;
|
|
19
|
+
onAdFailed?: (event: { nativeEvent: { adId?: string; sdk?: string; message?: string } }) => void;
|
|
20
|
+
onAdClicked?: (event: { nativeEvent: { adId?: string; sdk?: string; message?: string } }) => void;
|
|
21
|
+
onAdClosed?: (event: { nativeEvent: { adId?: string; sdk?: string; message?: string } }) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AdEventData {
|
|
25
|
+
configId?: string;
|
|
26
|
+
adUnitId?: string;
|
|
27
|
+
sdkType?: string;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AdController {
|
|
32
|
+
loadBanner: () => void;
|
|
33
|
+
showBanner: () => void;
|
|
34
|
+
hideBanner: () => void;
|
|
35
|
+
loadInterstitial: () => void;
|
|
36
|
+
showInterstitial: () => void;
|
|
37
|
+
hideInterstitial: () => void;
|
|
38
|
+
pauseAuction: () => void;
|
|
39
|
+
resumeAuction: () => void;
|
|
40
|
+
destroyAuction: () => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface VeonPrebidAdProps {
|
|
44
|
+
adType: AdType;
|
|
45
|
+
configId: string;
|
|
46
|
+
adUnitId: string;
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
refreshInterval?: number;
|
|
50
|
+
style?: any;
|
|
51
|
+
onAdLoaded?: (data: AdEventData) => void;
|
|
52
|
+
onAdDisplayed?: (data: AdEventData) => void;
|
|
53
|
+
onAdFailed?: (data: AdEventData) => void;
|
|
54
|
+
onAdClicked?: (data: AdEventData) => void;
|
|
55
|
+
onAdClosed?: (data: AdEventData) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface PrebidConfig {
|
|
59
|
+
prebidHost: string;
|
|
60
|
+
configHost: string;
|
|
61
|
+
accountId: string;
|
|
62
|
+
timeoutMillis?: number;
|
|
63
|
+
pbsDebug?: boolean;
|
|
64
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
2
|
+
import type { AdController, VeonPrebidAdProps } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook for managing Veon Prebid ads programmatically
|
|
6
|
+
*
|
|
7
|
+
* @param config - Ad configuration
|
|
8
|
+
* @param eventListener - Optional event listener
|
|
9
|
+
* @returns AdController reference and helper functions
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* function MyComponent() {
|
|
14
|
+
* const { adRef, loadBanner, showBanner } = useVeonPrebidAd(
|
|
15
|
+
* {
|
|
16
|
+
* adType: AdType.BANNER,
|
|
17
|
+
* configId: 'YOUR_CONFIG_ID',
|
|
18
|
+
* adUnitId: 'YOUR_AD_UNIT_ID',
|
|
19
|
+
* width: 300,
|
|
20
|
+
* height: 250,
|
|
21
|
+
* },
|
|
22
|
+
* {
|
|
23
|
+
* onAdLoaded: (data) => console.log('Ad loaded', data),
|
|
24
|
+
* onAdFailed: (error) => console.error('Ad failed', error),
|
|
25
|
+
* }
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* useEffect(() => {
|
|
29
|
+
* loadBanner();
|
|
30
|
+
* }, []);
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <VeonPrebidAd
|
|
34
|
+
* ref={adRef}
|
|
35
|
+
* {...config}
|
|
36
|
+
* {...eventListener}
|
|
37
|
+
* />
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function useVeonPrebidAd(
|
|
43
|
+
config: Pick<VeonPrebidAdProps, 'adType' | 'configId' | 'adUnitId' | 'width' | 'height' | 'refreshInterval'>
|
|
44
|
+
) {
|
|
45
|
+
const adRef = useRef<AdController>(null);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Load banner ad
|
|
49
|
+
*/
|
|
50
|
+
const loadBanner = useCallback(() => {
|
|
51
|
+
if (config.adType !== 'banner') {
|
|
52
|
+
console.warn('loadBanner called but ad type is not banner');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
adRef.current?.loadBanner();
|
|
56
|
+
}, [config.adType]);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Show banner ad
|
|
60
|
+
*/
|
|
61
|
+
const showBanner = useCallback(() => {
|
|
62
|
+
if (config.adType !== 'banner') {
|
|
63
|
+
console.warn('showBanner called but ad type is not banner');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
adRef.current?.showBanner();
|
|
67
|
+
}, [config.adType]);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Hide banner ad
|
|
71
|
+
*/
|
|
72
|
+
const hideBanner = useCallback(() => {
|
|
73
|
+
if (config.adType !== 'banner') {
|
|
74
|
+
console.warn('hideBanner called but ad type is not banner');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
adRef.current?.hideBanner();
|
|
78
|
+
}, [config.adType]);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Load interstitial ad
|
|
82
|
+
*/
|
|
83
|
+
const loadInterstitial = useCallback(() => {
|
|
84
|
+
if (config.adType !== 'interstitial') {
|
|
85
|
+
console.warn('loadInterstitial called but ad type is not interstitial');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
adRef.current?.loadInterstitial();
|
|
89
|
+
}, [config.adType]);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Show interstitial ad
|
|
93
|
+
*/
|
|
94
|
+
const showInterstitial = useCallback(() => {
|
|
95
|
+
if (config.adType !== 'interstitial') {
|
|
96
|
+
console.warn('showInterstitial called but ad type is not interstitial');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
adRef.current?.showInterstitial();
|
|
100
|
+
}, [config.adType]);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Hide interstitial ad
|
|
104
|
+
*/
|
|
105
|
+
const hideInterstitial = useCallback(() => {
|
|
106
|
+
if (config.adType !== 'interstitial') {
|
|
107
|
+
console.warn('hideInterstitial called but ad type is not interstitial');
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
adRef.current?.hideInterstitial();
|
|
111
|
+
}, [config.adType]);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Pause ad auction (for banners)
|
|
115
|
+
*/
|
|
116
|
+
const pauseAuction = useCallback(() => {
|
|
117
|
+
adRef.current?.pauseAuction();
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Resume ad auction (for banners)
|
|
122
|
+
*/
|
|
123
|
+
const resumeAuction = useCallback(() => {
|
|
124
|
+
adRef.current?.resumeAuction();
|
|
125
|
+
}, []);
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Destroy ad and free resources
|
|
129
|
+
*/
|
|
130
|
+
const destroyAuction = useCallback(() => {
|
|
131
|
+
adRef.current?.destroyAuction();
|
|
132
|
+
}, []);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Cleanup on unmount
|
|
136
|
+
*/
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
return () => {
|
|
139
|
+
// Optional: destroy ad on unmount
|
|
140
|
+
// adRef.current?.destroyAuction();
|
|
141
|
+
};
|
|
142
|
+
}, []);
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
adRef,
|
|
146
|
+
loadBanner,
|
|
147
|
+
showBanner,
|
|
148
|
+
hideBanner,
|
|
149
|
+
loadInterstitial,
|
|
150
|
+
showInterstitial,
|
|
151
|
+
hideInterstitial,
|
|
152
|
+
pauseAuction,
|
|
153
|
+
resumeAuction,
|
|
154
|
+
destroyAuction,
|
|
155
|
+
};
|
|
156
|
+
}
|