UNPKG

@electrum-cash/web-socket

Version:

@electrum-cash/web-socket implements the ElectrumSocket interface using web sockets.

52 lines (50 loc) 1.95 kB
import { EventEmitter } from "eventemitter3"; import { ElectrumSocket, ElectrumSocketEvents } from "@electrum-cash/network"; /** * Web Socket used when communicating with Electrum servers. */ export class ElectrumWebSocket extends EventEmitter<ElectrumSocketEvents> implements ElectrumSocket { host: string; port: number; encrypted: boolean; timeout: number; /** * Creates a socket configured with connection information for a given Electrum server. * * @param host Fully qualified domain name or IP address of the host * @param port Network port for the host to connect to, defaults to the standard TLS port * @param encrypted If false, uses an unencrypted connection instead of the default on TLS * @param timeout If no connection is established after `timeout` ms, the connection is terminated */ constructor(host: string, port?: number, encrypted?: boolean, timeout?: number); /** * Returns a string for the host identifier for usage in debug messages. */ get hostIdentifier(): string; /** * Connect to host:port using the specified transport */ connect(): void; /** * Forcibly terminate the connection. * * @throws {Error} if no connection was found */ disconnect(): void; /** * Write data to the socket * * @param data Data to be written to the socket * @param callback Callback function to be called when the write has completed * * @throws {Error} if no connection was found * @returns true if the message was fully flushed to the socket, false if part of the message * is queued in the user memory */ write(data: Uint8Array | string, callback?: (err?: Error) => void): boolean; readonly connected: []; readonly disconnected: []; readonly data: [string]; readonly error: [Error]; } //# sourceMappingURL=index.d.ts.map