class DurableObjectBackplane
implements IRealtimeBackplane
Since 0.2.0

Carries RealtimeFrames between replicas over one WebSocket to a Durable Object.

The guarantee is narrower than "a durable cross-replica subscription", and deliberately so. A Cloudflare Worker isolate is evicted at the platform's discretion and its outbound WebSockets go with it, so no Worker can hold a subscription indefinitely. What makes that sound rather than lossy is the coupling: the members this subscription serves are client WebSockets held by the same isolate, and an HTTP-triggered Worker stays alive as long as its clients remain connected. Losing the isolate loses the subscription and the members it was fanning out to together, which is consistent. The socket is therefore opened lazily on the first publish and reopened after any failure, rather than held open by a keepalive that would only fight the platform's eviction.

Examples

Example 1

app.register(CloudflarePlugin({
  env,
  waitUntil,
  durableObject: { binding: 'REALTIME', topic: 'chat' },
}));
// websocket-plugin and sse-plugin resolve it themselves; nothing else to wire.

Constructors

DurableObjectBackplane()
Parameters

The Durable Object namespace binding

Identity, topic, and the logger thunk

Properties

readonly
origin: string

This instance's identity, stamped onto every frame it publishes.

Stable for the lifetime of the instance and distinct from every peer's.

Methods

close(): Promise<void>

Closes the socket and drops every handler.

connect(): Promise<void>

Opens the socket to the Durable Object. Idempotent and concurrency-safe.

publish(frame: RealtimeFrame): Promise<void>

Publishes a frame to every other subscribed replica.

subscribe(handler: RealtimeFrameHandler): Promise<() => void>

Registers a handler for frames arriving from other replicas.

Usage

import { DurableObjectBackplane } from "cloudflare-plugin/src/index.ts";