woolball-client
Version:
Client-side library for Woolball enabling secure browser resource sharing for distributed AI task processing
55 lines (54 loc) • 1.6 kB
TypeScript
import { Environment } from './TaskAvailability';
type TaskStatus = 'started' | 'success' | 'error' | 'node_count';
type TaskEventData = {
id: string;
type: string;
status: TaskStatus;
nodeCount?: number;
};
type EventListener = (data: TaskEventData) => void;
interface WoolballOptions {
environment?: Environment;
}
declare class Woolball {
private wsConnection;
private clientId;
private eventListeners;
private workerTypes;
private wsUrl;
private activeWorkers;
private options;
private reconnectAttempts;
private maxReconnectAttempts;
private reconnectTimeout;
private reconnectTimer;
private destroyed;
constructor(id: string, url?: string, options?: WoolballOptions);
start(): void;
destroy(): void;
/**
* Establishes WebSocket connection and sets up message handlers
*/
private connectWebSocket;
/**
* Handles incoming WebSocket messages
*/
private handleWebSocketMessage;
/**
* Sends a message to the WebSocket server
*/
private sendWebSocketMessage;
setWorkerSource(type: string, source: string | Function): void;
private createWorker;
/**
* Gets the current environment based on options or detection
* @returns The current environment
*/
private getCurrentEnvironment;
private terminateWorker;
processEvent(type: string, value: any): Promise<any>;
on(status: TaskStatus, listener: EventListener): void;
off(status: TaskStatus, listener: EventListener): void;
private emitEvent;
}
export default Woolball;