Skip to main content
Home

latest
Works with
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 Score94%•
Downloads261/wk
•
Published4 months ago (0.46.5)

Framework for Nostr on Deno and web. 🛸

class NRelay1
implements NRelay

Single relay connection over WebSocket.

Constructors

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

Properties

private
ee: EventTarget
private
optional
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
log(log: NRelay1Log): 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.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

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

pnpm i jsr:@nostrify/nostrify
or (using pnpm 10.8 or older)
pnpm dlx jsr add @nostrify/nostrify

Import symbol

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

Add Package

yarn add jsr:@nostrify/nostrify
or (using Yarn 4.8 or older)
yarn dlx jsr add @nostrify/nostrify

Import symbol

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

Add Package

vlt install jsr:@nostrify/nostrify

Import symbol

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

Add Package

npx 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";