UNPKG

1.46 kBTypeScriptView Raw
1import { SocketProvider } from "./provider-socket.js";
2import type { JsonRpcApiProviderOptions } from "./provider-jsonrpc.js";
3import type { Networkish } from "./network.js";
4/**
5 * A generic interface to a Websocket-like object.
6 */
7export interface WebSocketLike {
8 onopen: null | ((...args: Array<any>) => any);
9 onmessage: null | ((...args: Array<any>) => any);
10 onerror: null | ((...args: Array<any>) => any);
11 readyState: number;
12 send(payload: any): void;
13 close(code?: number, reason?: string): void;
14}
15/**
16 * A function which can be used to re-create a WebSocket connection
17 * on disconnect.
18 */
19export type WebSocketCreator = () => WebSocketLike;
20/**
21 * A JSON-RPC provider which is backed by a WebSocket.
22 *
23 * WebSockets are often preferred because they retain a live connection
24 * to a server, which permits more instant access to events.
25 *
26 * However, this incurs higher server infrasturture costs, so additional
27 * resources may be required to host your own WebSocket nodes and many
28 * third-party services charge additional fees for WebSocket endpoints.
29 */
30export declare class WebSocketProvider extends SocketProvider {
31 #private;
32 get websocket(): WebSocketLike;
33 constructor(url: string | WebSocketLike | WebSocketCreator, network?: Networkish, options?: JsonRpcApiProviderOptions);
34 _write(message: string): Promise<void>;
35 destroy(): Promise<void>;
36}
37//# sourceMappingURL=provider-websocket.d.ts.map
\No newline at end of file