Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

NiceRelay

import { NiceRelay } from "https://gitlab.com/soapbox-pub/nostr-machina/-/raw/main/mod.ts";

Opinionated relay implementation that manages subscriptions and auto-reconnects.

class NiceRelay {
constructor(url: string | URL, opts?: NiceRelayOpts);
socket: WebSocket;
 
async close();
req<K extends number>(filters: Filter<K>[], opts?: ReqOpts): NiceRelaySub<K>;
async send(msg: ["EVENT", {
id: string;
}
]
, opts?: SendOpts): Promise<RelayOK | void>;
async send(msg: [string, ...unknown[]], opts?: SendOpts): Promise<void>;
async send(msg: [string, ...unknown[]], opts?: SendOpts): Promise<RelayOK | void>;
}

§Constructors

§
new NiceRelay(url: string | URL, opts?: NiceRelayOpts)
[src]

§Properties

§
socket: WebSocket
[src]

Internal WebSocket for the relay connection.

§Methods

§
close()
[src]

Close the relay connection. Resolves when the WebSocket is fully closed.

§
req<K extends number>(filters: Filter<K>[], opts?: ReqOpts): NiceRelaySub<K>
[src]

Subscribe to events from the relay.

@example
const sub = relay.req([
  { kinds: [1], authors: ['79c2...'] },
]);

for await (const event of sub) {
  handleEvent(event);
}
§
send(msg: ["EVENT", {
id: string;
}
]
, opts?: SendOpts): Promise<RelayOK | void>
[src]

Send a message to the relay, and wait for the OK if it's an event message.

send(msg: [string, ...unknown[]], opts?: SendOpts): Promise<void>
[src]
send(msg: [string, ...unknown[]], opts?: SendOpts): Promise<RelayOK | void>
[src]