/** * WebSocket Transport Adapter * * WebSocket transport for real-time bidirectional streaming. * Provides an alternative to SSE with support for client-to-server messages. * * NOTE: This is a placeholder implementation. Full WebSocket support requires * runtime-specific handling (Node.js 'ws' package, Bun/Deno native WebSocket, etc.) * * For production use: * - Node.js: Use 'ws' package with HTTP upgrade * - Bun: Use Bun.serve with websocket option * - Deno: Use Deno.upgradeWebSocket * - Next.js: WebSocket requires custom server, not supported in serverless */ import type { StreamMessage, StreamTransportAdapterConfig } from '@plyaz/types/core'; import { BaseTransportAdapter } from '../BaseTransportAdapter'; /** * WebSocketTransportAdapter - WebSocket transport * * Features: * - Bidirectional communication * - Automatic heartbeat (ping/pong) * - JSON message formatting * - Connection cleanup on disconnect * * @example * ```ts * // With Bun * const wsAdapter = new WebSocketTransportAdapter(); * * Bun.serve({ * fetch(req, server) { * const success = server.upgrade(req, { data: { connectionId } }); * if (success) return undefined; * return new Response('WebSocket upgrade failed', { status: 400 }); * }, * websocket: { * open(ws) { wsAdapter.registerConnection(connectionId, ws); }, * message(ws, message) { wsAdapter.handleMessage(connectionId, message); }, * close(ws) { wsAdapter.close(connectionId); }, * }, * }); * ``` */ export declare class WebSocketTransportAdapter extends BaseTransportAdapter { private connections; constructor(config?: Partial); /** * Create a new WebSocket connection. * * NOTE: In most runtimes, WebSocket connections are created via HTTP upgrade, * not through this method directly. Use registerConnection() instead. * * @param _connectionId - Unique connection identifier * @returns Response indicating WebSocket upgrade is needed */ createConnection(_connectionId: string): Promise; /** * Register an already-upgraded WebSocket connection. * Call this from your runtime's WebSocket open handler. * * @param connectionId - Unique connection identifier * @param socket - The WebSocket instance */ registerConnection(connectionId: string, socket: WebSocket): void; /** * Handle incoming message from WebSocket. * Call this from your runtime's WebSocket message handler. * * @param _connectionId - Connection that sent the message * @param message - Raw message data * @returns Parsed message or null if invalid */ handleMessage(_connectionId: string, message: string | ArrayBuffer): StreamMessage | null; /** * Send a message to a connection. * * @param connectionId - Connection to send to * @param message - Message to send */ send(connectionId: string, message: StreamMessage): Promise; /** * Close a connection. * * @param connectionId - Connection to close */ close(connectionId: string): Promise; /** * Check if a connection is alive. * * @param connectionId - Connection to check */ isAlive(connectionId: string): boolean; /** * Get current connection count. */ getConnectionCount(): number; /** * Get all connection IDs. */ getConnectionIds(): string[]; /** * Send message immediately to socket. */ private sendImmediate; /** * Cleanup connection resources. */ private cleanup; /** * Close all connections (for shutdown). */ closeAll(): Promise; } //# sourceMappingURL=WebSocketTransportAdapter.d.ts.map