/** * SimidRpcChannel — low-level SIMID postMessage RPC layer. * * Handles the wire-protocol details for a single SIMID creative session: * - Outgoing message counter and pending-promise map * - Format auto-detection ('plain' objects vs JSON-string encoding) * - Target-origin pinning from the first valid message * - send() / sendResolve() / sendReject() / postMsg() * - Inbound message parsing (handles both plain objects and JSON strings) * - Window message listener lifecycle * * `SimidSession` extends this class and provides the higher-level protocol * logic (session init, creative ready, media bridging, lifecycle). */ import type { SimidMessage, SimidPlayerMessage } from './simid-protocol'; export declare class SimidRpcChannel { protected iframe: HTMLIFrameElement; private onMessage; private msgCounter; private pending; private messageListener; /** * Detected outgoing message format. * 'plain' — post plain JS objects (spec default, works with most creatives) * 'json-string' — post JSON.stringify(payload) as the message value; used when the * creative calls JSON.parse(event.data) to deserialise incoming messages * (e.g. Google's compiled SIMID sample creative) */ private outgoingFormat; private _targetOrigin; /** Authoritative window to postMessage to — pinned from event.source on first valid message. */ private creativeWindow; protected sessionId: string; constructor(iframe: HTMLIFrameElement, onMessage: (data: SimidMessage, event: MessageEvent) => void); protected nextMsgId(): number; /** * Returns the target origin for postMessage calls to the creative iframe. * Prefer the origin captured from the first incoming message (event.origin), * which reflects where the iframe actually landed after any redirects. * Falls back to deriving from iframe.src until the first message arrives. */ protected getTargetOrigin(): string; /** * Post a payload to the creative's iframe using the detected outgoing format. * - 'plain': postMessage(payload, origin) * - 'json-string': postMessage(JSON.stringify(payload), origin) */ protected postMsg(payload: Record): void; /** * Send a player→creative message that expects a resolve/reject response. * Returns a promise that resolves/rejects when the creative responds. */ protected send(type: SimidPlayerMessage, args?: Record): Promise; /** * Send a resolve response to the creative for a message it sent us. * Per spec: type="resolve", args={ messageId: , value: } */ protected sendResolve(resolvedMessageId: number, value?: Record): void; /** * Send a reject response to the creative for a message it sent us. */ protected sendReject(resolvedMessageId: number, errorCode: number, message: string): void; /** * Parse a raw postMessage payload into a SimidMessage. * Handles both plain objects and JSON-encoded strings. * Auto-detects the outgoing format from the first valid message received. */ protected parseMessageData(raw: unknown): SimidMessage | null; /** * Resolve or reject a pending send() promise based on a creative resolve/reject message. * Returns true if the message was a resolve/reject that settled a pending promise. */ protected resolvePending(data: SimidMessage): boolean; private handleRawMessage; /** Remove the window message listener and reject any in-flight send() promises. */ protected destroyChannel(): void; } //# sourceMappingURL=simid-rpc.d.ts.map