baml.ws.WebSocket

A WebSocket connection.

Reference version

Signature

class baml.ws.WebSocket

A WebSocket connection.

Source:<builtin>/baml/ns_ws/ws.bamlbytes 891819

Fields

_handle

$rust_type

Instance methods

function

close

(self, code: int, reason: string) -> void throws baml.errors.InvalidArgument

Begin the closing handshake, sending code and reason to the peer.

This returns as soon as the close frame is queued. The connection ends when the peer echoes it, which next reports as a CloseEvent.

Throws

  • baml.errors.InvalidArgument if code is not one an endpoint may send (RFC 6455: 1000-1003, 1007-1013, 3000-3999, 4000-4999; not the undefined codes or the inferred-only 1004/1005/1006/1015), or if reason exceeds 123 bytes, the most a close frame can carry.
function

next

(self) -> string | uint8array | baml.ws.CloseEvent throws baml.errors.Io

Block until the next frame arrives.

A text frame is a string and a binary frame a uint8array. Pings are answered here automatically, and neither ping nor pong frames surface. Once the connection ends — closed by either party, or dropped — this returns the same CloseEvent on every call, so a receive loop terminates on the first one rather than blocking forever.

Throws

  • baml.errors.Io if the connection fails while receiving.
function

send

(self, data: string | uint8array) -> void throws baml.errors.Io

Send one frame: a string becomes a text frame, a uint8array a binary one.

Throws

  • baml.errors.Io if the connection is already closed, or the send fails.

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 747779