@roochnetwork/rooch-sdk
Version:
42 lines (41 loc) • 1.18 kB
TypeScript
import { EventSource } from 'eventsource';
type SubscriptionRequest<T = any> = {
method: string;
params: any;
onMessage: (event: T) => void;
onError?: (error: Error) => void;
signal?: AbortSignal;
};
/**
* Configuration options for the SSE connection
*/
export type SSEClientOptions = {
/**
* Milliseconds before timing out while calling an RPC method
*/
callTimeout?: number;
/**
* Milliseconds between attempts to connect
*/
reconnectTimeout?: number;
/**
* Maximum number of times to try connecting before giving up
*/
maxReconnects?: number;
};
export declare const DEFAULT_CLIENT_OPTIONS: {
callTimeout: number;
reconnectTimeout: number;
maxReconnects: number;
};
export declare class SSEClient {
#private;
endpoint: string;
options: Required<SSEClientOptions>;
constructor(endpoint: string, options?: SSEClientOptions);
disconnect(id: number): Promise<boolean>;
getSubscribeId(): number;
setupEventSource(request: SubscriptionRequest): Promise<EventSource>;
subscribe<T>(input: SubscriptionRequest<T>): Promise<() => Promise<boolean>>;
}
export {};