UNPKG

@iexec/iapp

Version:

A CLI to guide you through the process of building an iExec iApp

55 lines (54 loc) 1.46 kB
import WebSocket, { RawData } from 'ws'; export type WsMessage = { type: 'NEW_SESSION' | 'RECOVERED_SESSION' | 'REQUEST' | 'RESPONSE' | 'INFO' | 'ACK'; /** * message reception acknowledge code */ ack?: number; /** * sent with type REQUEST and RESPONSE */ target?: string; /** * sent with type RESPONSE */ success?: boolean; /** * sent with type RESPONSE when success: false */ error?: string; /** * sent with type RESPONSE when success: false */ code?: number; /** * sent with type RESPONSE when success: true */ result?: object; }; /** * serialize data to send through a websocket */ export declare function serializeData<T extends WsMessage>(data: T): Buffer<ArrayBufferLike>; /** * deserialize data received through a websocket */ export declare function deserializeData<T extends WsMessage>(data: RawData): T; export declare function createReconnectingWs(host: string, options?: { /** * use to register event listeners */ connectCallback?: (ws: WebSocket) => void; /** * use to perform operation that must be done only once when the session is established */ initCallback?: (ws: WebSocket) => void; /** * called when session with server is definitely broken */ errorCallback?: (err: Error) => void; /** * connection headers */ headers?: Record<string, string>; }): void;