@jolibox/ads 1.4.3 → 1.4.7

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.
@@ -2,6 +2,7 @@ import { IAFGAdBreakServerParams, IAFGInitServerParams } from './type';
2
2
  declare global {
3
3
  interface Window {
4
4
  adsbygoogle: Array<unknown>;
5
+ NBCallback: any;
5
6
  JoliTesterBridge?: {
6
7
  log: (message: string) => void;
7
8
  };
@@ -0,0 +1,9 @@
1
+ import type { IAbstractAFGProvider, IAdBreakParams, IAdConfigParams } from '../ads-interface';
2
+ import type { INewsBreakAdBreakServerParams, INewsBreakInitServerParams } from './type';
3
+ export declare class NewsBreakProvider implements IAbstractAFGProvider<INewsBreakInitServerParams, INewsBreakAdBreakServerParams> {
4
+ name: string;
5
+ private rewardAdManager?;
6
+ init(): Promise<void>;
7
+ adConfig(params: IAdConfigParams, serverParam: INewsBreakInitServerParams): void;
8
+ adBreak(params: IAdBreakParams, serverParam: INewsBreakAdBreakServerParams): void;
9
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Create a proxy that mirrors window[rootKey] on the parent window.
3
+ * All property access and method calls are forwarded via postMessage.
4
+ *
5
+ * Usage:
6
+ * const GameSDK = createParentProxy('GameSDK');
7
+ * await GameSDK.showRewardAd();
8
+ */
9
+ export declare function createParentProxy(rootKey: string): unknown;
@@ -0,0 +1,12 @@
1
+ export interface INewsBreakInitServerParams {
2
+ provider: 'NEWSBREAK';
3
+ params: {
4
+ gameId: string;
5
+ sdkUrl?: string;
6
+ extra?: Record<string, unknown>;
7
+ };
8
+ }
9
+ export interface INewsBreakAdBreakServerParams {
10
+ provider: 'NEWSBREAK';
11
+ params: never;
12
+ }
@@ -9,10 +9,12 @@ import type { IBannerAsAFGAdBreakServerParams, IBannerAsAFGInitServerParams } fr
9
9
  import type { BannerAsAFGProvider } from './banner-as-afg';
10
10
  import type { INativeAdBreakServerParams, INativeInitServerParams, INativeInternalAdBreakParams, INativeInternalInitParams } from './native/type';
11
11
  import type { NativeProvider } from './native';
12
- export type IAFGInitServerParams = (IGoogleAdSenseInitServerParams | IOKSpinInitServerParams | IAppsRocketsInitServerParams | IGoogleGPTInitServerParams | IBannerAsAFGInitServerParams | INativeInitServerParams | INativeInternalInitParams) & {
12
+ import type { INewsBreakAdBreakServerParams, INewsBreakInitServerParams } from './newsbreak/type';
13
+ import type { NewsBreakProvider } from './newsbreak';
14
+ export type IAFGInitServerParams = (IGoogleAdSenseInitServerParams | IOKSpinInitServerParams | IAppsRocketsInitServerParams | IGoogleGPTInitServerParams | IBannerAsAFGInitServerParams | INativeInitServerParams | INativeInternalInitParams | INewsBreakInitServerParams) & {
13
15
  isNative?: boolean;
14
16
  };
15
- export type IAFGAdBreakServerParams = (IGoogleAdSenseAdBreakServerParams | IOKSpinAdBreakServerParams | IAppsRocketsAdBreakServerParams | IGoogleGPTAdBreakServerParams | IBannerAsAFGAdBreakServerParams | INativeAdBreakServerParams | INativeInternalAdBreakParams) & {
17
+ export type IAFGAdBreakServerParams = (IGoogleAdSenseAdBreakServerParams | IOKSpinAdBreakServerParams | IAppsRocketsAdBreakServerParams | IGoogleGPTAdBreakServerParams | IBannerAsAFGAdBreakServerParams | INativeAdBreakServerParams | INativeInternalAdBreakParams | INewsBreakAdBreakServerParams) & {
16
18
  isNative?: boolean;
17
19
  seq: number;
18
20
  };
@@ -27,4 +29,5 @@ export interface IAFGProviders {
27
29
  GOOGLE_GPT?: GoogleGPTProvider;
28
30
  ADSENSE_BANNER_AS_AFG?: BannerAsAFGProvider;
29
31
  INTERNAL_NATIVE?: NativeProvider;
32
+ NEWSBREAK?: NewsBreakProvider;
30
33
  }
@@ -10,8 +10,15 @@ export declare class JoliboxAdsForVideo {
10
10
  private requestContext;
11
11
  private adsRequest;
12
12
  private initialized;
13
+ /** Preloaded ads info for the next requestAd() call */
14
+ private preloadedAd;
13
15
  constructor(context?: IAdsContext<'DRAMA'>);
14
16
  init(): Promise<void>;
17
+ /**
18
+ * Preload ads info and resolve provider options in advance.
19
+ * If preload fails, requestAd() will fall back to the normal flow.
20
+ */
21
+ private preload;
15
22
  /**
16
23
  * Destroy all providers and reset the initialized state.
17
24
  */
@@ -0,0 +1,3 @@
1
+ export * from './init';
2
+ export * from './reward';
3
+ export type * from './type';
@@ -0,0 +1,46 @@
1
+ declare global {
2
+ interface Window {
3
+ GameSDK?: IGameSDK;
4
+ }
5
+ }
6
+ export interface IGameSDK {
7
+ version: string;
8
+ init(options: {
9
+ gameId: string;
10
+ userId?: string;
11
+ }): Promise<{
12
+ success: boolean;
13
+ config?: Record<string, unknown>;
14
+ error?: string;
15
+ }>;
16
+ onEnter(): void;
17
+ onExit(): void;
18
+ exit(): void;
19
+ isAvailable(type: 'rewarded'): Promise<boolean>;
20
+ createRewardAd(options: {
21
+ platform: string;
22
+ }): Promise<{
23
+ success: boolean;
24
+ ready: boolean;
25
+ error?: string;
26
+ }>;
27
+ isRewardReady(): boolean;
28
+ showRewardAd(): Promise<{
29
+ success: boolean;
30
+ rewardGranted: boolean;
31
+ error?: string;
32
+ detail?: string;
33
+ }>;
34
+ onRewardLoad(callback: () => void): void;
35
+ onRewardError(callback: (err: unknown) => void): void;
36
+ onRewardClose(callback: (res: unknown) => void): void;
37
+ offRewardLoad(callback: () => void): void;
38
+ offRewardError(callback: (err: unknown) => void): void;
39
+ offRewardClose(callback: (res: unknown) => void): void;
40
+ report(event: string, payload?: Record<string, unknown>): void;
41
+ getCommonParams(): {
42
+ sdkVersion: string;
43
+ gameId: string;
44
+ };
45
+ }
46
+ export declare const getGameSDK: () => IGameSDK | undefined;
@@ -0,0 +1,47 @@
1
+ import type { BreakStatus } from './type';
2
+ export interface IRewardAdContext {
3
+ beforeAd?: () => void;
4
+ beforeReward: (showAdFn: () => void) => void;
5
+ adDismissed: () => void;
6
+ adViewed: () => void;
7
+ afterAd?: () => void;
8
+ adBreakDone?: (breakStatus: BreakStatus) => void;
9
+ }
10
+ /**
11
+ * RewardAdManager class for managing NewsBreak rewarded ads.
12
+ *
13
+ * This class handles the lifecycle of rewarded ads, including initialization,
14
+ * preloading, requesting ads, handling events, and cleaning up resources.
15
+ * Follows the same pattern as GoogleGPT RewardAdManager.
16
+ */
17
+ export declare class RewardAdManager {
18
+ private adsContext;
19
+ private _isReady;
20
+ private _isAvailable;
21
+ constructor();
22
+ /**
23
+ * Initializes the reward ad by checking availability and preloading.
24
+ */
25
+ private init;
26
+ /**
27
+ * Destroys the current ad context and triggers adBreakDone callback.
28
+ */
29
+ destroy: (breakStatus: BreakStatus) => void;
30
+ /**
31
+ * Destroys the current state and re-initializes.
32
+ */
33
+ reinit: (breakStatus: BreakStatus) => Promise<void>;
34
+ /**
35
+ * Request ads for the rewarded ad.
36
+ *
37
+ * If a previous request is still active, it destroys and ignores it.
38
+ * If an ad is ready, it proceeds to show. Otherwise attempts to preload first.
39
+ *
40
+ * @param context The context for the rewarded ad, containing callbacks for ad events.
41
+ */
42
+ requestAds: (context: IRewardAdContext) => void;
43
+ /**
44
+ * Shows the rewarded ad by calling beforeReward then showRewardAd.
45
+ */
46
+ private showAd;
47
+ }
@@ -0,0 +1 @@
1
+ export type BreakStatus = 'notReady' | 'timeout' | 'error' | 'noAdPreloaded' | 'frequencyCapped' | 'ignored' | 'other' | 'dismissed' | 'viewed';