UNPKG

woolball-client

Version:

Client-side library for Woolball enabling secure browser resource sharing for distributed AI task processing

54 lines (53 loc) 1.37 kB
/** * WebSocket connection module * Provides utilities to connect to WebSocket server and handle messages */ export type WorkerEvent = { Id: string; Key: string; Value: string; }; export type WebSocketMessage = { type: string; data: any; }; type WebSocketConfig = { url: string; id: string; onMessage?: (message: WorkerEvent) => void; onError?: (error: Event) => void; onClose?: (event: CloseEvent) => void; onOpen?: () => void; }; export declare class WebSocketConnection { private socket; private config; private reconnectAttempts; private maxReconnectAttempts; private reconnectTimeout; constructor(config: WebSocketConfig); /** * Establishes connection to WebSocket server */ private connect; /** * Attempts to reconnect to the WebSocket server with exponential backoff */ private attemptReconnect; /** * Sends a message to the WebSocket server * @param message The message to send * @returns True if message was sent, false otherwise */ sendMessage(message: WebSocketMessage): boolean; /** * Closes the WebSocket connection */ disconnect(): void; /** * Checks if the WebSocket connection is open * @returns True if connection is open, false otherwise */ isConnected(): boolean; } export {};