import type { EventBus, PluginContext } from '@openplayerjs/core'; export type AdsEvent = 'ads:requested' | 'ads:break:start' | 'ads:break:end' | 'ads:ad:start' | 'ads:ad:end' | 'ads:loaded' | 'ads:impression' | 'ads:quartile' | 'ads:clickthrough' | 'ads:error' | 'ads:timeupdate' | 'ads:duration' | 'ads:allAdsCompleted' | 'ads:skip' | 'ads:pause' | 'ads:resume' | 'ads:mute' | 'ads:unmute' | 'ads:volumeChange'; export type VastInput = { kind: 'url'; value: string; } | { kind: 'xml'; value: string | XMLDocument | Element; }; export type BreakAt = 'preroll' | 'postroll' | number; export type VastClosedCaption = { type?: string; language?: string; fileURL?: string; }; export type CaptionResource = { src: string; kind: 'captions' | 'subtitles'; srclang?: string; label?: string; type?: string; }; /** A SCTE-35 splice-out cue surfaced by an HLS (or DASH) engine. */ export type ScteOutCue = { id: string; scte35Out: string; plannedDuration?: number; startDate?: Date; }; /** * Duck-typed interface for any engine that fires SCTE-35 cues. * Satisfied by `HlsMediaEngine` without importing that package. */ export type ScteSource = { onCue?: ((cue: ScteOutCue) => void) | undefined; }; /** Selects which ad delivery path AdsPlugin uses. */ export type AdDeliveryMode = 'csai' | 'ssai' | 'hybrid'; /** * Shared contract for CSAI, SSAI, and hybrid delivery strategies. * AdsPlugin is a thin dispatcher; the strategy owns all delivery-specific logic. */ export type AdSessionStrategy = { readonly mode: AdDeliveryMode; /** Called once when the plugin receives a PluginContext. */ init(ctx: PluginContext, config: AdsPluginConfig): void; /** Mirror of PlayerPlugin.destroy — release all subscriptions and DOM state. */ destroy(): void; /** Fetch and play a VAST/VMAP URL as an ad break. */ playAds?(vastUrl: string): Promise; /** Parse and play inline VAST XML as an ad break. */ playAdsFromXml?(vastXml: string): Promise; /** Return all midroll breaks whose cue point is at or before currentTime. */ getDueMidrollBreaks?(currentTime: number): AdsBreakConfig[]; /** Return the earliest unplayed midroll break at or before currentTime. */ getDueMidrollBreak?(currentTime: number): AdsBreakConfig | undefined; /** Skip the currently playing ad. */ requestSkip?(reason?: 'button' | 'close' | 'api'): void; }; export type AdsSourceType = 'VAST' | 'VMAP' | 'NONLINEAR'; export type AdsSource = { type: AdsSourceType; src: string; }; export type AdsBreakConfig = { id?: string; at: BreakAt; source?: AdsSource; sources?: AdsSource[]; once?: boolean; timeOffset?: string; }; export type OmidConfig = { accessMode?: 'domain' | 'limited'; }; /** Options specific to CSAI (client-side ad insertion) delivery. */ export type CsaiAdConfig = { breaks?: AdsBreakConfig[]; interceptPlayForPreroll?: boolean; autoPlayOnReady?: boolean; mountEl?: HTMLElement; mountSelector?: string; nonLinearContainer?: HTMLElement; nonLinearSelector?: string; companionContainer?: HTMLElement; companionSelector?: string; allowNativeControls?: boolean; resumeContent?: boolean; preferredMediaTypes?: string[]; breakTolerance?: number; adSourcesMode?: 'waterfall' | 'playlist'; omid?: OmidConfig; labels?: { skip?: string; advertisement?: string; adEnded?: string; }; requestInterceptor?: (req: AdTagRequest) => AdTagRequest | null | Promise; eventSink?: (event: AdLifecycleEvent) => void; }; /** Options specific to SSAI (server-side ad stitching) delivery. */ export type SsaiAdConfig = { eventSink?: (event: AdLifecycleEvent) => void; }; /** * Options for CSAI + SCTE-35 hybrid delivery. * Inherits all CSAI options; `scteSource` and `resolveScteUrl` are required * (the hybrid bridge only activates when both are provided). */ export type HybridAdConfig = CsaiAdConfig & { scteSource: ScteSource; resolveScteUrl: (cue: ScteOutCue) => string | null | undefined | Promise; }; export type AdsPluginConfig = { /** Ad sources to play at the top level (VAST/VMAP/NONLINEAR). */ sources?: AdsSource | AdsSource[]; /** Enable verbose debug logging. */ debug?: boolean; /** * 'csai' (default) — client-side ad insertion: plugin fetches VAST/VMAP * and renders an ad