UNPKG

flutter-webview-bridge

Version:

A TypeScript/React bridge for seamless communication between Flutter WebView and web applications

60 lines (59 loc) 1.71 kB
/** * @fileoverview Provides a bridge for communication between web applications and Flutter WebView. * This script captures a MessagePort sent from Flutter and facilitates two-way communication. * * @singleton */ export type MessageCallback = (data: unknown) => void; export interface ConnectionStatus { hasPort: boolean; subscribersCount: number; } export interface FlutterBridgeOptions { debug?: boolean; captureCommand?: string; confirmationMessage?: string; } /** * Manages the MessagePort connection with the Flutter host. */ export declare class FlutterBridge { private port; private subscribers; private options; /** * Initializes the bridge and starts listening for the port from Flutter. */ constructor(options?: FlutterBridgeOptions); /** * Captures the MessagePort sent from Flutter. */ private capturePort; /** * Handles incoming messages from the Flutter port and notifies subscribers. */ private handleMessage; /** * Sends a message to the Flutter application. */ sendMessage(data: unknown): void; /** * Subscribes a callback to listen for messages from Flutter. */ subscribe(callback: MessageCallback): () => void; /** * Проверяет состояние подключения */ getConnectionStatus(): ConnectionStatus; /** * Проверяет, инициализирован ли порт */ isConnected(): boolean; /** * Отключает bridge и очищает все подписки */ disconnect(): void; private log; private warn; } export declare const flutterBridge: FlutterBridge;