UNPKG

@open-game-system/app-bridge-web

Version:

Web-specific implementation of the app-bridge ecosystem

42 lines (39 loc) 1.23 kB
import { Event, BridgeStores, Operation, Bridge } from '@open-game-system/app-bridge-types'; export { BridgeStores, State } from '@open-game-system/app-bridge-types'; /** * Message types for communication */ type WebToNativeMessage = { type: "EVENT"; storeKey: string; event: Event; } | { type: "BRIDGE_READY"; }; type NativeToWebMessage<TStores extends BridgeStores = BridgeStores> = { type: "STATE_INIT"; storeKey: keyof TStores; data: TStores[keyof TStores]["state"]; } | { type: "STATE_UPDATE"; storeKey: keyof TStores; data?: TStores[keyof TStores]["state"]; operations?: Operation[]; }; interface WebViewBridge { postMessage: (message: string) => void; } declare global { interface Window { ReactNativeWebView?: WebViewBridge; } } /** * Creates a web bridge instance for use in web applications * This implementation receives state from the native side through WebView messages * * @template TStores Store definitions for the bridge * @returns A Bridge instance */ declare function createWebBridge<TStores extends BridgeStores>(): Bridge<TStores>; export { type NativeToWebMessage, type WebToNativeMessage, type WebViewBridge, createWebBridge };