import type { HlsInterstitialAssetList, JumpPolicy, RestrictValue, SeekingRestriction, TriggerPolicy } from './HlsInterstitialsTypes'; import type { AdTrackingEvent, AdTrackingEventTrigger } from './SgaiAdTrackerTypes'; import type { SgaiAd } from './SgaiConfigAPI'; /** * Representation of an HLS interstitial ad. */ export interface HlsInterstitial extends SgaiAd { /** * An absolute URL for a single interstitial asset. Parsed from X-ASSET-URI. * If `assetListUri` is defined, this property should be ignored. */ assetUri?: string; /** * The URL to a JSON object containing a list of interstitials “ASSETS”. Parsed from X-ASSET-LIST. * If defined, this takes precedence over `assetUri`. */ assetListUri?: string; /** * Asset list data, if present. * The parsed JSON object returned by the URL in `assetListUri`. */ assetList?: HlsInterstitialAssetList; /** * The actual duration of the interstitial in seconds, if known, otherwise undefined. * May differ from end - start, as the end time is always populated with a default of +1. */ duration?: number; /** * The expected duration in seconds of the interstitial if duration is not yet known. * Usually populated if the interstitial is dynamically updated or features an asset list. */ plannedDuration?: number; /** * Value from X-PLAYOUT-LIMIT header. * Defines how long the interstitial is expected to play for, in seconds. * Should be intended as a way to exit an interstitial early. */ playoutLimit?: number; /** * Value from X-RESUME-OFFSET header. * Defines how much content should be replaced by the interstitial ad. * If undefined, the duration of the ad(s) should be used. */ resumeOffset?: number; /** * Values from X-RESTRICT header (enumerated-string-list). * Defines restrictions on seeking/playback behavior during the interstitial. * Can contain multiple restriction values (e.g., [SKIP, JUMP]). */ restrict?: RestrictValue[]; /** * Jump policy for the ad. Determines if at least one ad must play when jumping over multiple ads. * Converted from X-RESTRICT attribute by HlsInterstitialsProvider. */ jumpPolicy?: JumpPolicy; /** * Seeking restriction for the ad. Determines if seeking is allowed during ad playback. * Converted from X-RESTRICT attribute by HlsInterstitialsProvider. */ seekingRestriction?: SeekingRestriction; /** * Trigger policy for the interstitial. Defines when the interstitial should be triggered. * Converted from CUE attribute by HlsInterstitialsProvider. */ triggerPolicy?: TriggerPolicy[]; /** * Ad creative signaling data, if present. * The data could be present either on ASSET-LIST level or DATE-RANGE level based on SVTA spec. */ adCreativeSignaling?: any; /** * Any attributes that is not known in the HLS interstitial spec. * The tracking information could be present here, X-AD-CREATIVE-SIGNALING in case of SVTA. */ customAttributes?: { [key: string]: any; }; } /** * Tracking data common to all interstitial tracking levels */ export interface InterstitialMappingData { customAttributes: { [key: string]: any; }; } /** * Tracking data on DATE-RANGE tag */ export interface InterstitialData extends InterstitialMappingData { id: string; } /** * Tracking data on ASSET-LIST root level */ export interface InterstitialAssetListData extends InterstitialMappingData { } /** * Tracking data on ASSET level in the ASSET-LIST */ export interface InterstitialAssetData extends InterstitialMappingData { uri: string; duration?: number; } /** * Registry to register and retrieve interstitial tracking events */ export interface InterstitialMappingRegistry { /** * Register tracking events for a given trigger * @param trigger The trigger for which to register tracking events * @param trackingEvents The tracking events to register */ register(trigger: AdTrackingEventTrigger, trackingEvents: AdTrackingEvent[]): void; /** * Get tracking events for a given trigger * @param trigger The trigger for which to get tracking events * @returns Array of registered tracking events for the given trigger */ getTrackingEventsForTrigger(trigger: AdTrackingEventTrigger): AdTrackingEvent[]; } /** * Registry to map custom attributes from interstitial tracking data */ export interface InterstitialCustomAttributesMappingRegistry { /** * Get the mapping registry for tracking events */ get tracking(): InterstitialMappingRegistry; /** * Get the click through URL for the interstitial */ get clickThroughUrl(): string | undefined; /** * Set the click through URL for the interstitial */ set clickThroughUrl(url: string | undefined); } /** * Macro for custom value replacement in tracking URLs */ export interface InterstitialMacro { name: string; value: string; } export interface InterstitialViewabilityConfig { /** * The amount of consecutive seconds the interstitial should stay visible in order to emit the `viewable` tracking event. * * Default: `2` */ viewableDuration?: number; /** * Maximum time window in seconds within which the viewability decision must be made. * * If no `viewable` decision is made within this window, the tracker emits `notViewable`. * When omitted, defaults to the ad's duration. * * Default: ad duration */ decisionTimeout?: number; } /** * Presets for standard custom attributes mapping */ export declare enum CustomAttributesMappingPresets { /** * No standard mapping applied. */ NONE = "NONE", /** * Standard mapping based on the "X-AD-CREATIVE-SIGNALING" SVTA specification. */ AD_CREATIVE_SIGNALING = "AD-CREATIVE-SIGNALING" } /** * Configuration options for HLS interstitials handling */ export interface InterstitialsConfig { /** * Preset for standard custom attributes mapping * When set, the player will automatically map standard custom attributes based on the selected preset. * * Default is `CustomAttributesMappingPresets.NONE` * * When InterstitialsConfig.customAttributesMapping is set, this property is ignored. * When set to `CustomAttributesMappingPresets.AD_CREATIVE_SIGNALING`, SVTA "X-AD-CREATIVE-SIGNALING" mapping is applied. */ customAttributesMappingPreset?: CustomAttributesMappingPresets; /** * Custom attributes mapping callback to map tracking payload data to interstitial tracking registry * @param mappingData Parsed tracking data present in the interstitial tags * @param mappingRegistry Registry to register tracking events * * Example: * ```js * const playerConfig = { * hls: { * interstitials: { * customAttributesMapping(mappingData, mappingRegistry) { * const adCreativeSignaling = mappingData.customAttributes['X-AD-CREATIVE-SIGNALING']; * const payload = adCreativeSignaling.payload; * * if (!payload) { * return; * } * * const firstPayload = payload[0]; * const clickThroughUrl = firstPayload.clickThrough; * if (clickThroughUrl) { * mappingRegistry.clickThroughUrl = clickThroughUrl; * } * * const trackingData = firstPayload.tracking; * if (trackingData) { * for (const trackingEvent of trackingData) { * const eventType = trackingEvent.type; * const urls = trackingEvent.urls; * const offset = trackingEvent.offset; * * if (!eventType || !urls) { * continue; * } * * switch (eventType) { * case InterstitialTrackingEventTrigger.IMPRESSION: * mappingRegistry.tracking.register( * InterstitialTrackingEventTrigger.IMPRESSION, * { urls, offset }, * ); * break; * } * } * } * }, * }, * }, * }; * ``` */ customAttributesMapping?: (mappingData: InterstitialData | InterstitialAssetListData | InterstitialAssetData, mappingRegistry: InterstitialCustomAttributesMappingRegistry) => void; /** * Macro value provider callback to resolve macros present in tracking URLs * * @param macro The macro to be resolved * @returns Array of string values for the given macro * * @hidden */ macroValueProvider?: (macro: InterstitialMacro) => string[]; /** * Callback to determine if an interstitial ASSET-LIST should be loaded. * The callback will be called for every interstitial ASSET-LIST before loading. * * @param interstitial The interstitial to be evaluated * @returns Whether the interstitial should be loaded * * Example: * ```js * const playerConfig = { * hls: { * interstitials: { * shouldLoadInterstitial: (interstitial) => { * // Only load interstitials with a specific id * return interstitial.id === 'pre-roll-1'; * }, * }, * }, * }; * ``` */ shouldLoadInterstitial?: (interstitial: HlsInterstitial) => boolean; /** * Callback to determine if an interstitial should be played. * The callback will be called for every interstitial before playback. * * @param interstitial The interstitial to be evaluated * @returns Whether the interstitial should be played * * Example: * ```js * const playerConfig = { * hls: { * interstitials: { * shouldPlayInterstitial: (interstitial) => { * // Only play interstitials with a specific id * return interstitial.id === 'pre-roll-1'; * }, * }, * }, * }; * ``` */ shouldPlayInterstitial?: (interstitial: HlsInterstitial) => boolean; /** * Callback to determine which interstitials should be played when multiple interstitials are skipped using jump * * @param interstitials A list of interstitials to be evaluated * @param fromTime The start time of the jump operation in seconds * @param toTime The end time of the jump operation in seconds * @returns A filtered list of interstitials that should be played * * Example: * ```js * const playerConfig = { * hls: { * interstitials: { * shouldPlayJumpedOverInterstitials: (interstitials, fromTime, toTime) => { * // Play only interstitials with duration greater than 15 seconds * return interstitials.filter(interstitial => interstitial.duration > 15); * }, * }, * }, * }; * ``` */ shouldPlayJumpedOverInterstitials?: (interstitials: HlsInterstitial[], fromTime: number, toTime: number) => HlsInterstitial[]; /** * Viewability tracking configuration for SGAI interstitial ads. */ viewability?: InterstitialViewabilityConfig; }