import type { RefObject } from 'react'; import type WebView from 'react-native-webview'; export interface BridgeEnvelope { __boltBridge: true; direction: 'inbound' | 'outbound'; type: 'postMessage' | 'portMessage' | 'bridgeReady'; data?: unknown; virtualPortId?: string; } type MessageListener = (data: unknown, virtualPortId?: string) => void; type PortMessageListener = (data: unknown, portId: string) => void; /** * Manages communication between React Native and a Bolt WebView. * * Responsibilities: * - Receives raw strings from WebView via onMessage callback * - Detects bridge envelopes (__boltBridge field) vs raw Bolt messages * - Routes events by type to registered listeners * - Manages virtual MessagePort channels * - Queues messages before bridge is ready, flushes on bridgeReady signal * - Provides sendMessage() to send envelopes to the WebView */ export declare class BoltBridgeDispatcher { private webViewRef; private ready; private pendingMessages; private messageListeners; private portListeners; private readyListeners; private bridgeReadySpan; constructor(webViewRef: RefObject); /** * Handle raw message from WebView's onMessage event. * Called by BoltPaymentWebView's onMessage prop. */ handleMessage: (event: { nativeEvent: { data: string; }; }) => void; /** * Send a postMessage to the WebView iframe code. * Data should be a JSON string (matching Bolt's serialization format). */ sendMessage(data: unknown, virtualPortId?: string): void; /** * Deliver a virtual MessagePort to the iframe via a window-level * postMessage. Queues until the bridge is ready. */ sendBootstrapPort(virtualPortId: string, data: unknown): void; /** * Register a listener for postMessage events from the iframe. */ onMessage(listener: MessageListener): () => void; /** * Register a listener for messages on a specific virtual port. */ onPortMessage(portId: string, listener: PortMessageListener): () => void; /** * Register a listener that fires every time the bridge becomes ready. * If the bridge is already ready, fires immediately. Continues to fire on * subsequent ready transitions (e.g., after reset() + reload) until the * returned unsubscribe function is called. */ onReady(listener: () => void): () => void; /** * Returns whether the bridge is ready. */ isReady(): boolean; /** * Set the WebView instance the dispatcher sends messages to. */ setWebView(webView: WebView | null): void; /** * Reset the dispatcher state (e.g., when WebView reloads). */ reset(): void; private handleEnvelope; private notifyMessageListeners; private flushPendingMessages; private injectEnvelope; } export {}; //# sourceMappingURL=BoltBridgeDispatcher.d.ts.map