Setu-TS
    Preparing search index...

    Function asUpgradeResponse

    • Narrows a Durable Object stub's response to one carrying a socket.

      A stub answering an ordinary Response — a 404 from a DO class with no upgrade path, a 500 from one that threw, a 101 from a runtime that does not populate webSocket — fails here, naming the binding, rather than surfacing later as a TypeError on undefined.accept() with nothing to point at.

      Parameters

      • response: unknown

        The stub's response

      • binding: string

        The Durable Object binding name, for the error message

      Returns DurableObjectUpgradeResponse

      The same response, narrowed

      When the response carries no webSocket

      const response = await stub.fetch('https://do/connect', {
      headers: { Upgrade: 'websocket' },
      });
      const socket = asUpgradeResponse(response, 'REALTIME').webSocket;
      socket.accept();

      0.2.0