provider-websocket.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { SocketProvider } from "./provider-socket.js";
  2. import type { JsonRpcApiProviderOptions } from "./provider-jsonrpc.js";
  3. import type { Networkish } from "./network.js";
  4. /**
  5. * A generic interface to a Websocket-like object.
  6. */
  7. export 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. */
  19. export 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. */
  30. export 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