UNPKG

rx-nostr

Version:

A library based on RxJS, which allows Nostr applications to easily communicate with relays.

69 lines 2.74 kB
import { Observable } from 'rxjs'; import { FilledRxNostrConfig } from '../config/index.js'; import { AuthPacket, ClosedPacket, ConnectionState, ConnectionStatePacket, EosePacket, EventPacket, MessagePacket, OkPacket, OutgoingMessagePacket } from '../packet.js'; import * as Nostr from "nostr-typedef"; export declare class RelayConnection { url: string; private config; private socket; private buffer; private unsent; private reconnected$; private outgoing$; private message$; private error$; private retryTimer; private sendAttempted$; private isFirstTry; private maybeDown; private disposed; private state$; private _state; get state(): ConnectionState; private setState; constructor(url: string, config: FilledRxNostrConfig); connectManually(): void; private connect; private createSocket; private pack; disconnect(code: WebSocketCloseCode): void; send(message: Nostr.ToRelayMessage.Any): Promise<void>; getEVENTObservable(): Observable<EventPacket>; getEOSEObservable(): Observable<EosePacket>; getCLOSEDObservable(): Observable<ClosedPacket>; getOKObservable(): Observable<OkPacket>; getAUTHObservable(): Observable<AuthPacket>; getAllMessageObservable(): Observable<MessagePacket>; getOutgoingMessageObservable(): Observable<OutgoingMessagePacket>; getReconnectedObservable(): Observable<Nostr.ToRelayMessage.Any[]>; getConnectionStateObservable(): Observable<ConnectionStatePacket>; getErrorObservable(): Observable<unknown>; dispose(): void; [Symbol.dispose](): void; } export declare const WebSocketCloseCode: { /** * 1006 is a reserved value and MUST NOT be set as a status code in a * Close control frame by an endpoint. It is designated for use in * applications expecting a status code to indicate that the * connection was closed abnormally, e.g., without sending or * receiving a Close control frame. * * See also: https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1 */ readonly ABNORMAL_CLOSURE: 1006; /** * When a websocket is closed by the relay with a status code 4000 * that means the client shouldn't try to connect again. * * See also: https://github.com/nostr-protocol/nips/blob/fab6a21a779460f696f11169ddf343b437327592/01.md?plain=1#L113 */ readonly DONT_RETRY: 4000; /** @internal rx-nostr uses it internally. */ readonly RX_NOSTR_IDLE: 4537; /** @internal rx-nostr uses it internally. */ readonly RX_NOSTR_DISPOSED: 4538; }; type WebSocketCloseCode = (typeof WebSocketCloseCode)[keyof typeof WebSocketCloseCode]; export {}; //# sourceMappingURL=relay.d.ts.map