Delivers RPC replies to the caller waiting on them.
This class holds no state, for the same reason
RealtimeBackplaneObjectCore holds none: sockets are accepted with
state.acceptWebSocket, the hibernation API, so the runtime may evict the
object and re-run this constructor before the reply arrives. A membership
Set in a field would empty itself on the first hibernation while every
test that never hibernates kept passing. state.getWebSockets() survives
hibernation and is the only membership consulted here.
The reply body is forwarded verbatim and never parsed, so this object cannot corrupt an envelope and a future widening of the reply shape needs no redeploy of the class the application owns.
The application owns the class; this owns the behavior:
Example 1
Example 1
import { DurableObject } from 'cloudflare:workers'; import { ReplyInboxObjectCore } from '@setu-ts/cloudflare-plugin'; export class ReplyInboxObject extends DurableObject { #core = new ReplyInboxObjectCore(this.ctx); override fetch(request: Request): Promise<Response> { return this.#core.fetch(request); } webSocketClose(ws: WebSocket, code: number, reason: string): void { this.#core.webSocketClose(ws, code, reason); } }
ReplyInboxObjectCore(state: IDurableObjectState,options?: ReplyInboxObjectCoreOptions)
Builds the core the application's Durable Object class delegates to.
state: IDurableObjectState
The Durable Object's ctx
options: ReplyInboxObjectCoreOptions
Optional seams; the defaults are the deployment path
Serves both halves of the inbox.
A WebSocket upgrade opens the caller's end; a POST delivers a reply from
a responder. Anything else is refused with the method or upgrade the caller
should have used.
webSocketClose(): void
Handles the caller disconnecting.
Nothing is tracked, so nothing needs removing — the runtime drops the
socket from getWebSockets() itself. The handler exists so the
application's class can forward it without a branch.
webSocketError(socket: IDurableObjectWebSocket): void
Handles a socket error.