@plutoxyz/frame-js
Version:
SDK for integrating with Pluto Frame
74 lines (73 loc) • 2.31 kB
TypeScript
import { PlutoStorage } from "../storage";
interface WebSocketClientConfig {
script: string;
hostOrigin: string;
getFingerprint: () => Promise<string> | string;
socketEndpoint?: string;
notaryEndpoint?: string;
}
declare enum WebSocketEvent {
OPEN = "open",
MESSAGE = "message",
ERROR = "error",
CLOSE = "close"
}
export declare enum SocketActionTypes {
REQUEST_PROMPT = "request_prompt",
REQUEST_HINT = "request_hint",
SCRIPT_LOG = "script_log",
REQUEST_OAUTH = "request_oauth",
DONE = "script_done",
CLOSE = "close",
ERROR = "error",
METADATA = "metadata",
FINISHED = "finished",
TIMEOUT = "timeout",
REQUEST_USER_NETWORK = "request_user_network",
REQUEST_USER_NETWORK_DONE = "request_user_network_done",
CDP_TARGET = "cdp_target"
}
interface WebSocketDefaultEvents {
[WebSocketEvent.OPEN]: Event;
[WebSocketEvent.MESSAGE]: MessageEvent;
[WebSocketEvent.ERROR]: Event;
[WebSocketEvent.CLOSE]: CloseEvent;
}
declare class WebSocketClient {
private socket;
private url;
private eventHandlers;
private config;
private storage;
private reconnectAttempts;
private maxReconnectAttempts;
private baseDelay;
private maxDelay;
private wasSessionRestored;
private sessionId;
private stabilityTimer;
private socketEndpoint;
private notaryEndpoint;
private isInitialized;
constructor(urlOrConfig: string | WebSocketClientConfig, storage?: PlutoStorage);
init(): Promise<string>;
private emitRestorationMessage;
connect(sessionId?: string): void;
disconnect(): void;
status(): number;
ack(id: string): void;
send(id: string, message: any): void;
on(event: WebSocketEvent, callback: (event: WebSocketDefaultEvents[WebSocketEvent]) => void): void;
off(event: WebSocketEvent, callback: (event: WebSocketDefaultEvents[WebSocketEvent]) => void): void;
private handleEnhancedOpen;
private handleEnhancedClose;
private waitForFingerprint;
getSessionId(): string;
getWasSessionRestored(): boolean;
private handleMessage;
private handleError;
private handleClose;
private handleOpen;
}
export { WebSocketClient, WebSocketEvent };
export type { WebSocketDefaultEvents, WebSocketClientConfig };