import { ConnectionStats } from "./ConnectionStats"; import { NostrEvent, ReqCommand, TaggedRawEvent, u256 } from "./Nostr"; import { RelayInfo } from "./RelayInfo"; import ExternalStore from "./ExternalStore"; export type AuthHandler = (challenge: string, relay: string) => Promise; /** * Relay settings */ export interface RelaySettings { read: boolean; write: boolean; } /** * Snapshot of connection stats */ export interface ConnectionStateSnapshot { connected: boolean; disconnects: number; avgLatency: number; events: { received: number; send: number; }; settings?: RelaySettings; info?: RelayInfo; pendingRequests: Array; activeRequests: Array; id: string; ephemeral: boolean; address: string; } export declare class Connection extends ExternalStore { #private; Id: string; Address: string; Socket: WebSocket | null; PendingRaw: Array; PendingRequests: Array<{ cmd: ReqCommand; cb: () => void; }>; ActiveRequests: Set; Settings: RelaySettings; Info?: RelayInfo; ConnectTimeout: number; Stats: ConnectionStats; HasStateChange: boolean; IsClosed: boolean; ReconnectTimer: ReturnType | null; EventsCallback: Map void>; OnConnected?: () => void; OnEvent?: (sub: string, e: TaggedRawEvent) => void; OnEose?: (sub: string) => void; OnDisconnect?: (id: string) => void; Auth?: AuthHandler; AwaitingAuth: Map; Authed: boolean; Ephemeral: boolean; EphemeralTimeout: ReturnType | undefined; Down: boolean; constructor(addr: string, options: RelaySettings, auth?: AuthHandler, ephemeral?: boolean); ResetEphemeralTimeout(): void; Connect(): Promise; Close(): void; OnOpen(): void; OnClose(e: CloseEvent): void; OnMessage(e: MessageEvent): void; OnError(e: Event): void; /** * Send event on this connection */ SendEvent(e: NostrEvent): void; /** * Send event on this connection and wait for OK response */ SendAsync(e: NostrEvent, timeout?: number): Promise; /** * Using relay document to determine if this relay supports a feature */ SupportsNip(n: number): boolean; /** * Queue or send command to the relay * @param cmd The REQ to send to the server */ QueueReq(cmd: ReqCommand, cbSent: () => void): void; CloseReq(id: string): void; takeSnapshot(): ConnectionStateSnapshot; _OnAuthAsync(challenge: string): Promise; } //# sourceMappingURL=Connection.d.ts.map