atomvm_gleam/websocket

Types

Open options. url is required; other fields are optional.

pub type Config {
  Config(
    url: String,
    owner: option.Option(process.Pid),
    verify: option.Option(Verify),
    network_timeout_ms: option.Option(Int),
    disable_auto_reconnect: option.Option(Bool),
  )
}

Constructors

Errors from the websocket client.

pub type Error {
  Failed
  NotSupported
  Badarg
  Timeout
  MissingUrl
  NotConnected
  Other(String)
}

Constructors

  • Failed
  • NotSupported
  • Badarg
  • Timeout
  • MissingUrl
  • NotConnected
  • Other(String)

TLS verification mode.

pub type Verify {
  CrtBundle
  NoVerify
}

Constructors

  • CrtBundle

    ESP-IDF CA certificate bundle (typical for public wss:// hosts).

  • NoVerify

    No verification (development / cleartext ws:// only).

Opaque websocket port handle.

pub type Websocket

Values

pub fn close(ws: Websocket) -> Result(Nil, Error)

Close the connection.

pub fn error_to_string(error: Error) -> String

Format an Error for logging.

pub fn open(config: Config) -> Result(Websocket, Error)

Open a websocket. Returns once the port exists — wait for connected before sending.

pub fn send_binary(
  ws: Websocket,
  data: BitArray,
) -> Result(Nil, Error)

Send a binary frame.

pub fn send_text(
  ws: Websocket,
  data: BitArray,
) -> Result(Nil, Error)

Send a text frame.

✨ Search Document