Skip to main content

latest

Framework for Nostr on Deno and web. 🛸

This package works with Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
94%
Published
2 weeks ago (0.36.2)
class NRelay1
implements NRelay

Single relay connection over WebSocket.

Constructors

new
NRelay1(
url: string,
opts?: NRelay1Opts,
)

Properties

private
ee: EventTarget
private
abstract
idleTimer: number
socket: Websocket
private
subs: Map<string, NostrClientREQ>
readonly
subscriptions: readonly NostrClientREQ[]

Methods

close(): Promise<void>

Close the relay connection and prevent it from reconnecting. After this you should dispose of the NRelay1 instance and create a new one to connect again.

count(
filters: NostrFilter[],
opts?: { signal?: AbortSignal; },
): Promise<{ count: number; approximate?: boolean; }>
private
createSocket(): Websocket

Create (and open) a WebSocket connection with automatic reconnect.

event(
event: NostrEvent,
opts?: { signal?: AbortSignal; },
): Promise<void>
private
maybeStartIdleTimer(): void

Start the idle time if applicable.

private
on<K extends keyof EventMap>(
key: K,
signal?: AbortSignal,
): AsyncIterable<EventMap[K]>

Get a stream of EE events.

private
once<K extends keyof EventMap>(
key: K,
signal?: AbortSignal,
): Promise<EventMap[K]>

Wait for a single EE event.

query(
filters: NostrFilter[],
opts?: { signal?: AbortSignal; },
): Promise<NostrEvent[]>
protected
receive(msg: NostrRelayMsg): void

Handle a NIP-01 relay message.

req(
filters: NostrFilter[],
opts?: { signal?: AbortSignal; },
): AsyncGenerator<
NostrRelayEVENT
| NostrRelayEOSE
| NostrRelayCLOSED
>
protected
send(msg: NostrClientMsg): void

Send a NIP-01 client message to the relay.

private
stopIdleTimer(): void

Stop the idle timer.

private
wake(): void

Make a new WebSocket, but only if it was closed by an idle timeout.

Add Package

deno add jsr:@nostrify/nostrify

Import symbol

import { NRelay1 } from "@nostrify/nostrify";

---- OR ----

Import directly with a jsr specifier

import { NRelay1 } from "jsr:@nostrify/nostrify";

Add Package

npx jsr add @nostrify/nostrify

Import symbol

import { NRelay1 } from "@nostrify/nostrify";

Add Package

yarn dlx jsr add @nostrify/nostrify

Import symbol

import { NRelay1 } from "@nostrify/nostrify";

Add Package

pnpm dlx jsr add @nostrify/nostrify

Import symbol

import { NRelay1 } from "@nostrify/nostrify";

Add Package

bunx jsr add @nostrify/nostrify

Import symbol

import { NRelay1 } from "@nostrify/nostrify";