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

Relay

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

Barebones relay client that deals directly with relay messages.

class Relay {
constructor(socket: WebSocket);
socket: WebSocket;
 
close(code?: number, reason?: string): Promise<void>;
send(msg: [string, ...unknown[]]): Promise<void>;
async *stream(signal: AbortSignal): AsyncGenerator<[string, ...unknown[]]>;
}

§Constructors

§
new Relay(socket: WebSocket)
[src]

§Properties

§
socket: WebSocket
[src]

Relay's internal WebSocket connection.

§Methods

§
close(code?: number, reason?: string): Promise<void>
[src]

Close the connection to the relay. This closes the socket. Once closed, it cannot be reopened without creating a new Relay instance.

§
send(msg: [string, ...unknown[]]): Promise<void>
[src]

Send a Nostr message to the relay. If the relay isn't open yet, it will be opened.

§
stream(signal: AbortSignal): AsyncGenerator<[string, ...unknown[]]>
[src]

Get relay messages in an async iterable. It goes on forever until the socket closes or the signal is aborted.

@example
for await (const msg of relay.stream(controller.signal)) {
  switch(msg[0]) {
    case 'EOSE':
      controller.abort();
      break;
    case 'EVENT':
      handleEvent(msg[2]);
      break;
  }
}