/** * SimidSession — IAB SIMID 1.2 (Secure Interactive Media Interface Definition) implementation. * * SIMID 1.2 session initialization sequence: * 1. Creative → Player : createSession (with sessionId) * 2. Player → Creative: resolve (acks createSession) * 3. Player → Creative: SIMID:Player:init (environmentData + creativeData) * 4. Creative → Player : resolve (acks init) * 5. Creative → Player : SIMID:Creative:ready * 6. Player → Creative: SIMID:Player:startCreative * 7. Creative → Player : resolve (acks startCreative) * * The low-level postMessage wire protocol (message counter, format detection, * origin pinning, send/resolve/reject, inbound parsing) lives in the * `SimidRpcChannel` base class; this file owns the higher-level session logic * (init handshake, creative-ready, media bridging, lifecycle). * * Message format notes: * - Some SIMID creatives post messages as JSON-encoded strings rather than plain objects. * SimidRpcChannel handles both and auto-detects the outgoing format. * - Older creatives may skip createSession and go straight to SIMID:Creative:ready. * onCreativeReady() falls back to sending init + startCreative in that case. * * Spec: https://iabtechlab.com/standards/simid/ */ import { SimidRpcChannel } from './simid-rpc'; export { SIMID_CREATIVE, SIMID_MEDIA, SIMID_PLAYER } from './simid-protocol'; export type SimidCallbacks = { onSkip: () => void; onStop: () => void; onPause: () => void; onPlay: () => void; onClickThrough: (url: string) => void; onTrackingEvent: (event: string, data?: unknown) => void; onFatal: (errorCode: number, reason: string) => void; onLog?: (data: unknown) => void; /** * Called when the creative requests a duration change (SIMID:Creative:requestChangeAdDuration). * The handler receives the requested delta in seconds and resolve/reject callbacks. * If omitted the player auto-rejects the request. */ onRequestChangeAdDuration?: (durationChange: number, resolve: () => void, reject: (errorCode: number, reason: string) => void) => void; }; /** Creative-specific metadata extracted from the VAST creative object. */ export type SimidCreativeInfo = { /** VAST content (required by spec, use '' when absent). */ adParameters?: string; /** VAST URL for the ad. */ clickThruUri?: string; }; export declare class SimidSession extends SimidRpcChannel { private adVideo; private callbacks; private creativeInfo?; private initSent; private initPromise; private started; private destroyed; private mediaListeners; private visibilityHandler; constructor(iframe: HTMLIFrameElement, adVideo: HTMLVideoElement, callbacks: SimidCallbacks, creativeInfo?: SimidCreativeInfo | undefined); private handleMessage; /** * SIMID 1.2: creative sends createSession first. * Player responds with resolve, then immediately sends init. */ private onCreateSession; /** * Creative signals it is ready for startCreative. * If no createSession was received (older creatives), init is sent here as a fallback. */ private onCreativeReady; private buildEnvironmentData; private buildCreativeData; /** Current media state snapshot, used to respond to SIMID:Creative:getMediaState. */ private getMediaState; /** Manually send SIMID:Player:init (e.g. when not using the automatic handshake). */ init(creativeData: Record, environmentData: Record): Promise; /** Manually send SIMID:Player:startCreative. */ start(): Promise; progress(currentTime: number, duration: number): void; pause(): void; resume(): void; stop(): Promise; skip(): void; volumeChange(volume: number, muted: boolean): void; adDurationChange(duration: number): void; resize(width: number, height: number): Promise; fatal(errorCode: number, reason: string): void; /** * Bridge ad video DOM events to SIMID:Media:* postMessages and * document visibility changes to SIMID:Player:appBackgrounded/Foregrounded. * Called once from the constructor; listeners are cleaned up in destroy(). */ private bindMediaEvents; destroy(): void; } //# sourceMappingURL=simid.d.ts.map