edgeport - v1.0.6
    Preparing search index...

    Type Alias WsMessage

    WsMessage:
        | { data: string; type: "text"; json<T = unknown>(): T; text(): string }
        | {
            data: Uint8Array;
            type: "binary";
            json<T = unknown>(): T;
            text(): string;
        }

    A single inbound WebSocket message.

    Text frames arrive as { type: 'text' } with a string payload; binary frames arrive as { type: 'binary' } with a Uint8Array payload. Branch on type before reading data.

    Type Declaration

    • { data: string; type: "text"; json<T = unknown>(): T; text(): string }
      • data: string
      • type: "text"
      • json: function
        • Parses the text payload as JSON.

          Type Parameters

          • T = unknown

            The expected shape of the decoded value.

          Returns T

          The parsed value.

          If the text is not valid JSON.

          1.0.2

      • text: function
        • Returns the message as text (the identity for a text frame).

          Present on both frame types so msg.text() works without branching on type.

          Returns string

          The text payload.

          1.0.4

    • { data: Uint8Array; type: "binary"; json<T = unknown>(): T; text(): string }
      • data: Uint8Array
      • type: "binary"
      • json: function
        • Decodes the binary payload as UTF-8 and parses it as JSON.

          Type Parameters

          • T = unknown

            The expected shape of the decoded value.

          Returns T

          The parsed value.

          If the decoded payload is not valid JSON.

          1.0.4

      • text: function
        • Decodes the binary payload as UTF-8 text.

          Present on both frame types so msg.text() works without branching on type - handy for servers that send JSON or text over binary frames.

          Returns string

          The payload decoded as UTF-8.

          1.0.4

    1.0.0