@dailymotion/ad-sdk-web
Version:
JavaScript Ad SDK API by Dailymotion
148 lines (138 loc) • 4.16 kB
TypeScript
declare enum AdEvents {
AD_BREAK_START = "AD_BREAK_START",
AD_BREAK_END = "AD_BREAK_END",
AD_LOAD = "AD_LOAD",
AD_START = "AD_START",
AD_PLAY = "AD_PLAY",
AD_PAUSE = "AD_PAUSE",
AD_END = "AD_END",
AD_ERROR = "AD_ERROR",
CONTENT_PAUSE_REQUESTED = "CONTENT_PAUSE_REQUESTED",
CONTENT_RESUME_REQUESTED = "CONTENT_RESUME_REQUESTED"
}
interface VideoState {
id?: string;
isAutoplay: boolean;
type: 'STREAM' | 'LIVE';
isCurrentTimeDVR: boolean;
isSeekable: boolean;
viewId: string;
duration?: number | null;
publisherId: string;
publisherType: string;
publisherReference: string;
}
interface EnvironmentContext {
appName: string;
locale: string;
topDomain: string;
embedder: string;
clientType: string;
deviceId: string;
trafficSegment: number;
v1st: string;
is3rdPartyCookiesAvailable: boolean;
}
interface PlayerContext {
videoTag: HTMLVideoElement;
isPlayerControlsEnabled: boolean;
playedVideosCounter: number;
}
interface Consent {
ccpaConsent?: string;
tcfConsent?: string;
tcf2HasConsentForGoogle?: boolean;
tcf2HasConsentForDailymotion?: boolean;
isGdprApplicable?: boolean;
gppConsentStringFromPlayer?: string;
gppApplicableSectionsFromPlayer?: number[];
}
interface AppState {
consent: Consent;
video: VideoState;
environment: EnvironmentContext;
player: PlayerContext;
}
interface Ad {
skipOffset: number;
duration: number;
mediaFile: string;
impressionTracker: string;
midrollTime: number;
position: 'preroll' | 'midroll' | 'postroll';
}
interface DevelopmentOptions {
useFakeAd: boolean;
}
declare class AdSdkWeb {
private adVideoElement;
private adContainer;
private playerContainer;
private scriptLoaded;
private appState;
constructor();
/**
* Initializes the Ad SDK by loading the external script and preparing the DOM elements.
* @throws If no container is provided or if script fails to load.
* @param playerContainer
*/
initialize(playerContainer: HTMLElement): Promise<void>;
/**
* Loads the ad with the given content video tag.
* @param appState
* @param developmentOptions
* @throws If the Ad SDK is not initialized or ad elements are missing.
*/
loadAdsSequence(appState: AppState, developmentOptions?: DevelopmentOptions): Promise<void>;
/**
* Starts playing the ad.
* @throws If the Ad SDK is not initialized.
*/
playAd(): void;
/**
* Stops playing the ad.
* @throws If the Ad SDK is not initialized.
*/
pauseAd(): void;
/**
* Skips the ad.
* @throws If the Ad SDK is not initialized.
*/
skipAd(): void;
/**
* Retrieves details about the currently loaded ad.
* @returns An object containing the ad position (e.g., pre-roll, mid-roll).
* @throws If the Ad SDK is not initialized.
*/
getAdDetails(): Ad;
/**
* Subscribes to a specific Ad SDK event.
* @param event - The name of the event to listen for.
* @param callback - The event handler callback.
* @throws If the Ad SDK is not initialized.
*/
on(event: AdEvents, callback: () => void): void;
/**
* Unsubscribes from a specific Ad SDK event.
* @param event - The name of the event to stop listening for.
* @param callback - The callback function to remove.
* @throws If the Ad SDK is not initialized.
*/
off(event: AdEvents, callback: () => void): void;
/**
* Updates the current initialization state of the Ad SDK.
* Use these constants to subscribe or unsubscribe from ad lifecycle events.
*/
updateAppState(playerState: AppState): void;
/**
* Provides access to the Ad SDK event names.
* Use these constants to subscribe or unsubscribe from ad lifecycle events.
*/
Events: typeof AdEvents;
private createAdVideoElement;
private createAdContainer;
private loadScript;
private injectCss;
}
export { AdEvents, AdSdkWeb };
export type { Ad, AppState, DevelopmentOptions };