Creates a new instance of the driver.
Configuration for the driver.
Optionalprefix?: stringOptional prefix for namespaces.
WebSocket URLs of the Nostr relays. There is no default list.
OptionalWebSocket?: NostrWebSocketConstructorOptional WebSocket constructor. Defaults to the global one.
Indicates whether the driver is currently active. Subclasses must keep it
in sync with their connection: signaling messages are only published while
the driver is active, and joined rooms announce themselves again when it
becomes active. A namespace that fails on its own leaves the driver
active, and emitting active once it is subscribed again makes rooms
announce themselves to the peers they missed.
Sets the active state of the driver and emits corresponding events.
Destroys the driver instance, cleaning up any resources.
Emits inactive if the driver was active, then removes all event handlers.
Emits an internal event with optional data.
The event name.
The data to pass to event handlers.
Unregisters an event handler for the specified internal event.
The event name.
The event handler function to remove.
Registers an event handler for the specified internal event.
The event name.
The event handler function.
Optionaloptions: { signal?: AbortSignal }
Listener options.
Optionalsignal?: AbortSignalRemoves the handler when aborted.
A function that removes the handler.
Publishes a signaling message to the specified namespace.
The namespace to publish the message to.
The message data to publish.
Nothing directly; resolves once the message is delivered (async drivers may return a promise).
Subscribes to signaling messages for the specified namespace.
The namespace to subscribe to.
The handler function to call when a message is received.
Nothing directly; resolves once the subscription is established (async drivers may return a promise).
Unsubscribes from signaling messages for the specified namespace.
The namespace to unsubscribe from.
The handler function to remove.
Nothing directly; resolves once the unsubscription is confirmed (async drivers may return a promise).
Nostr-based signaling driver.
This driver uses Nostr relays as a message bus, so signaling needs no server of your own beyond the relays you choose. Each namespace maps to an ephemeral event kind (20000-29999) and an
xtag, and every event is signed with a random key generated for the driver's lifetime. Events are sent to all relays and duplicates are dropped on receipt.The driver has no built-in relay list: you must pass the relays to use. Public relays often throttle or reject ephemeral events, so prefer relays you run or trust. The driver reconnects with backoff, pauses a relay that rate-limits it, and stops using a relay that blocks it. Subscribing fails if no relay confirms the subscription within 10 seconds, and publishing fails while no relay is connected.
Relay messages are not verified, so pair the driver with Peerix encryption when peers must be authenticated.
Example
Running a local relay with nostr-rs-relay for testing: