video-ad-sdk
Version:
VAST/VPAID SDK that allows video ads to be played on top of any player
170 lines (169 loc) • 5.24 kB
TypeScript
import type { VastChain, VastIcon } from '../types';
import { VideoAdContainer } from '../adContainer';
import { Emitter, type Listener } from './helpers/Emitter';
import { type AddedIcons } from './helpers/icons/addIcons';
import { AdUnitError } from './helpers/adUnitError';
declare const _private: unique symbol;
export declare const _protected: unique symbol;
interface Size {
width: number;
height: number;
viewmode: string;
}
interface Protected extends Partial<AddedIcons> {
started: boolean;
viewable: boolean;
finished: boolean;
size?: Size;
finish(): void;
onErrorCallbacks: Listener[];
onFinishCallbacks: Listener[];
throwIfCalled(): void;
throwIfFinished(): void;
}
/**
* Options map to create a {@link VideoAdUnit}
*/
export interface VideoAdUnitOptions {
/**
* Optional logger instance. Must comply to the [Console interface](https://developer.mozilla.org/es/docs/Web/API/Console).
* Defaults to `window.console`
*/
logger?: Console;
/**
* if true it will pause the ad whenever is not visible for the viewer.
* Defaults to `false`
*/
viewability?: boolean;
/**
* if true it will resize the ad unit whenever the ad container changes sizes
* Defaults to `false`
*/
responsive?: boolean;
/**
* if true it will pause the ad unit whenever a user click on the ad
* Defaults to `true`
*/
pauseOnAdClick?: boolean;
}
/**
* This class provides shared logic among all the ad units.
*/
export declare class VideoAdUnit extends Emitter {
private [_private];
protected [_protected]: Protected;
/** Ad unit type */
type?: string;
/** If an error occurs it will contain the reference to the error otherwise it will be bull */
error?: AdUnitError;
/** If an error occurs it will contain the Vast Error code of the error */
errorCode?: number;
vastChain: VastChain;
videoAdContainer: VideoAdContainer;
icons?: VastIcon[];
pauseOnAdClick: boolean;
/**
* Creates a {@link VideoAdUnit}.
*
* @param vastChain The {@link VastChain} with all the {@link VastResponse}
* @param videoAdContainer container instance to place the ad
* @param options Options Map. The allowed properties are:
*/
constructor(vastChain: VastChain, videoAdContainer: VideoAdContainer, { viewability, responsive, logger, pauseOnAdClick }?: VideoAdUnitOptions);
start(): void;
/**
* Resumes a previously paused ad unit.
*
* @throws if ad unit is not started.
* @throws if ad unit is finished.
*/
resume(): void;
/**
* Pauses the ad unit.
*
* @throws if ad unit is not started.
* @throws if ad unit is finished.
*/
pause(): void;
/**
* Skips the ad unit.
*
* @throws if ad unit is not started.
* @throws if ad unit is finished.
*/
skip(): void;
/**
* Sets the volume of the ad unit.
*
* @throws if ad unit is not started.
* @throws if ad unit is finished.
*
* @param volume must be a value between 0 and 1;
*/
setVolume(_volume: number): void;
/**
* Gets the volume of the ad unit.
*
* @throws if ad unit is not started.
* @throws if ad unit is finished.
*
* @returns the volume of the ad unit.
*/
getVolume(): void;
/**
* Cancels the ad unit.
*
* @throws if ad unit is finished.
*/
cancel(): void;
/**
* Returns the duration of the ad Creative or 0 if there is no creative.
*
* @returns the duration of the ad unit.
*/
duration(): void;
/**
* Returns true if the ad is paused and false otherwise
*/
paused(): void;
/**
* Returns the current time of the ad Creative or 0 if there is no creative.
*
* @returns the current time of the ad unit.
*/
currentTime(): void;
/**
* Register a callback function that will be called whenever the ad finishes. No matter if it was finished because de ad ended, or cancelled or there was an error playing the ad.
*
* @throws if ad unit is finished.
*
* @param callback will be called once the ad unit finished
*/
onFinish(callback: Listener): void;
/**
* Register a callback function that will be called if there is an error while running the ad.
*
* @throws if ad unit is finished.
*
* @param callback will be called on ad unit error passing the Error instance and an object with the adUnit and the {@link VastChain}.
*/
onError(callback: Listener): void;
/**
* @returns true if the ad unit is finished and false otherwise
*/
isFinished(): boolean;
/**
* @returns true if the ad unit has started and false otherwise
*/
isStarted(): boolean;
/**
* This method resizes the ad unit to fit the available space in the passed {@link VideoAdContainer}
*
* @throws if ad unit is not started.
* @throws if ad unit is finished.
*
* @returns Promise that resolves once the unit was resized
*/
resize(width: number, height: number, mode: string): Promise<void>;
}
export {};