Aquamarine
v0.1.0 Pre-1.0 package, not yet published to Hex. See the API overview or read the source on GitHub when you need exact signatures.
Aquamarine is the client runtime for Beryl-style WebSocket channels in Gleam. The socket lives in an OTP actor that owns the connection, so reconnect and reply correlation are the library's problem rather than yours — and the wire protocol stays behind a pluggable Codec.
Use the bundled aquamarine/phoenix codec for Phoenix Channels and Beryl, or provide your own codec without changing the channel runtime.
One actor, five moving parts
The public API stays small because the socket actor handles the recurring channel work after the connection opens.
connectOpen and joinStart the WebSocket, send the join frame, and wait for the matching reply.refsCount in orderRefs are minted inside the actor, in the handler that sends the frame carrying them.heartbeatKeep the connection aliveA timed self-message, running for the life of the socket rather than per channel.push / receiveMove application framesInbound frames route by topic; replies correlate back to the push that asked.reconnectCome back on its ownA dropped connection retries on a backoff and rejoins every topic. Your handles stay valid.
One typed error surface
Connect to a Phoenix-compatible endpoint and handle failures through the
same AquamarineError variants returned by every fallible
operation.
import aquamarineimport aquamarine/phoeniximport aquamarine/transportimport gleam/json
case aquamarine.connect( scheme: transport.Ws, host: "localhost", port: 4000, path: "/socket/websocket", topic: "room:lobby", payload: json.object([]), codec: phoenix.codec(),) { Ok(channel) -> { // Push, receive, and close with the same Channel handle. use_channel(channel) Nil }
Error(error) -> handle_connect_error(error)}See Error handling for the
AquamarineError variants returned by connect, push, receive, and
close.
Choose your next path
Recommended start Error handling