Setu-TS
    Preparing search index...

    Class ReplyInboxObjectCore

    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:

    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);
    }
    }

    0.2.0

    Index
    • 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.

      Parameters

      • request: Request

        The request the stub forwarded

      Returns Promise<Response>

      A 101 carrying the client half, a 200 reporting how many sockets received the reply, a 405, or a 426

      When WebSocketPair is unavailable and no host was injected

      0.2.0

    • 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.

      Parameters

      • socket: IDurableObjectWebSocket

        The socket that closed

      • code: number

        The close code the peer sent

      • reason: string

        The close reason the peer sent

      Returns void

      0.2.0