FlareWebSocketMessage
class FlareWebSocketMessageRuntime-agnostic representation of a single WebSocket message.
Wraps the raw decoded payload (text as string, binary as Uint8Array) with lazy, memoized
accessors, mirroring FlareRequest: allocating a FlareWebSocketMessage costs only the wrapper, and
decoding/parsing is deferred to first access and cached, so nothing is spent on the per-message hot
path unless a handler actually reads it. The same type represents a message in either direction - the
one delivered to a message handler and, conceptually, the one emitted via ws.send.
The Node codec and the Cloudflare transport both hand up a string | Uint8Array; this is the single
shape they normalize onto.
How you get one
Section titled “How you get one”Handed to you by the framework; see Inline handlers.
Accessors
Section titled “Accessors”isBinary
Section titled “isBinary”get isBinary(): booleanTrue when the message arrived as a binary frame.
returns boolean
get raw(): string | Uint8ArrayThe raw payload exactly as it crossed the wire: text (string) or binary (Uint8Array).
returns string | Uint8Array
get size(): numberByte length of the payload (UTF-8 byte length for a text payload). Memoized.
returns number
Methods
Section titled “Methods”json()
Section titled “json()”json(): JsonValueParses and returns the payload as JSON. Memoized (a valid null result is cached, not re-parsed).
returns JsonValue
Throws:
When the payload is not valid JSON. The memo is only set on success, so a
caller that catches the error and retries re-parses rather than reading a stale undefined.
text()
Section titled “text()”text(): stringReturns the payload as text: the string itself, or the UTF-8 decoding of a binary payload. Memoized.
Decoding is lenient (invalid sequences become the replacement character), matching FlareRequest; an inbound text frame is already validated as UTF-8 by the codec.
returns string
Learn: Inline handlers