2023-03-03 18:25:07 -07:00
|
|
|
import { SocketProvider } from "./provider-socket.js";
|
2023-11-27 06:11:49 -05:00
|
|
|
import type { JsonRpcApiProviderOptions } from "./provider-jsonrpc.js";
|
2023-03-03 18:25:07 -07:00
|
|
|
import type { Networkish } from "./network.js";
|
2023-06-01 17:52:58 -04:00
|
|
|
/**
|
|
|
|
* A generic interface to a Websocket-like object.
|
|
|
|
*/
|
2023-03-03 18:25:07 -07:00
|
|
|
export interface WebSocketLike {
|
|
|
|
onopen: null | ((...args: Array<any>) => any);
|
|
|
|
onmessage: null | ((...args: Array<any>) => any);
|
|
|
|
onerror: null | ((...args: Array<any>) => any);
|
|
|
|
readyState: number;
|
|
|
|
send(payload: any): void;
|
|
|
|
close(code?: number, reason?: string): void;
|
|
|
|
}
|
2023-06-01 17:52:58 -04:00
|
|
|
/**
|
|
|
|
* A function which can be used to re-create a WebSocket connection
|
|
|
|
* on disconnect.
|
|
|
|
*/
|
2023-03-03 18:25:07 -07:00
|
|
|
export type WebSocketCreator = () => WebSocketLike;
|
2023-06-01 17:52:58 -04:00
|
|
|
/**
|
|
|
|
* A JSON-RPC provider which is backed by a WebSocket.
|
|
|
|
*
|
|
|
|
* WebSockets are often preferred because they retain a live connection
|
|
|
|
* to a server, which permits more instant access to events.
|
|
|
|
*
|
|
|
|
* However, this incurs higher server infrasturture costs, so additional
|
|
|
|
* resources may be required to host your own WebSocket nodes and many
|
|
|
|
* third-party services charge additional fees for WebSocket endpoints.
|
|
|
|
*/
|
2023-03-03 18:25:07 -07:00
|
|
|
export declare class WebSocketProvider extends SocketProvider {
|
|
|
|
#private;
|
|
|
|
get websocket(): WebSocketLike;
|
2023-11-27 06:11:49 -05:00
|
|
|
constructor(url: string | WebSocketLike | WebSocketCreator, network?: Networkish, options?: JsonRpcApiProviderOptions);
|
2023-03-03 18:25:07 -07:00
|
|
|
_write(message: string): Promise<void>;
|
|
|
|
destroy(): Promise<void>;
|
|
|
|
}
|
2023-04-27 21:19:55 +09:00
|
|
|
//# sourceMappingURL=provider-websocket.d.ts.map
|