import { type OutboundEnvelope } from "./envelope.js"; import type { Bridge, Envelope, MessageHandler, MessageEventLike, RequestOptions, Transport, WindowLike } from "./types.js"; /** Options passed by subclasses to the base constructor. */ export interface BaseBridgeOptions { /** The protocol version this side runs. */ protocolVersion: number; /** The component id, or `null` until assigned during the handshake. */ componentId: string | null; /** The low-level transport (web `WindowTransport` by default; native for content). */ transport: Transport; /** Short prefix used to namespace generated request ids (e.g. "host"). */ rolePrefix: string; } /** * Transport-agnostic core shared by the host and content bridges. * * It owns handler registration, request/response correlation, the ready lifecycle, * an outbound queue (so `send`/`request` before the channel is open are buffered), * and generic inbound dispatch. Subclasses implement the handshake and the * origin/source validation policy for their side. */ export declare abstract class BaseBridge implements Bridge { protected readonly transport: Transport; protected readonly protocolVersion: number; protected componentId: string | null; /** The window app frames are posted to (set once the channel opens). */ protected peerWindow: WindowLike | null; /** The `targetOrigin` used for outbound frames (set once the channel opens). */ protected peerOrigin: string | null; protected open: boolean; protected destroyed: boolean; protected handshakeError: Error | null; private readonly handlers; private readonly pending; private readonly readyListeners; private readyResolvers; private outbox; private readonly idPrefix; private idCounter; constructor(options: BaseBridgeOptions); on(type: string, handler: MessageHandler): () => void; off(type: string, handler: MessageHandler): void; send(type: string, payload?: unknown): void; request(type: string, payload?: unknown, options?: RequestOptions): Promise; ready(): boolean; onReady(callback: () => void): () => void; whenReady(): Promise; destroy(): void; /** Handle a validated inbound envelope (dispatch handshake + app frames). */ protected abstract receive(envelope: Envelope, event: MessageEventLike): void; /** Is `source` the window this side expects frames to come from? */ protected abstract isExpectedSource(source: unknown): boolean; /** Is `origin` acceptable for an inbound frame on this side? */ protected abstract isAllowedOrigin(origin: string): boolean; /** Build a full envelope from partial fields, applying this side's defaults. */ protected buildEnvelope(fields: OutboundEnvelope): Envelope; /** * Post a frame to the peer via the transport. On web the pinned peer * window/origin are used; on a trusted-peer (native) transport the target is * ignored and the frame is serialized to the native channel. */ protected rawPost(envelope: Envelope): void; /** * Validate and dispatch an open-channel app frame * (`message` / `request` / `response` / `error`). */ protected acceptOpenFrame(envelope: Envelope, event: MessageEventLike): void; /** Mark the channel open, flush the outbox, and notify ready subscribers. */ protected emitReady(): void; /** Abort the handshake: reject `whenReady()` and any queued requests. */ protected failHandshake(error: Error): void; private readonly onFrame; private postEnvelope; private flushOutbox; private dispatchEnvelope; private invokeMessageHandlers; private invokeRequestHandlers; private resolvePending; private rejectPending; private rejectAllPending; private rejectAllReadyResolvers; private nextId; } //# sourceMappingURL=base-bridge.d.ts.map