Skip to content

beryl : real-time channels for Gleam

Type-safe real-time channels and presence for Gleam, targeting the Erlang (BEAM) runtime.

presence.gleam
import beryl
import beryl/presence
// Track who's online and broadcast every change to the room —
// Phoenix-compatible presence diffs, backed by a CRDT.
let config =
presence.Config(
pubsub: Some(ps),
replica: "node-1",
broadcast_interval_ms: 1500,
on_diff: Some(fn(diff) {
beryl.broadcast_presence_diff(channels, "room:lobby", diff)
}),
)
// …then, inside your channel's join callback:
let _ref =
presence.track(p, "room:lobby", "user:alice", socket.id(socket), meta)
// ps, channels, p and meta come from your app — see the Presence guide.
  1. Install beryl

    Add beryl and its BEAM dependencies to your Gleam project. beryl installs as a git dependency, which needs Gleam 1.18+.

    Installation guide →
  2. Build your first channel

    Wire up server callbacks, the WebSocket transport, and a Phoenix JS client, end to end, in one sitting.

    Open the Quick Start →
  3. See it running

    Browse complete, runnable examples, then go deeper in the guides or the API reference.

    View examples →

Real-time channels

Define channels with typed callbacks and pattern-matched topics. Join, leave, and broadcast with compile-time guarantees on socket state: the Gleam compiler holds you to your own assigns type.

Channels guide →

Presence tracking

Know who's online with a CRDT-backed presence system. An add-wins observed-remove set resolves joins and leaves automatically across distributed nodes.

Presence guide →

PubSub on OTP

Distributed publish/subscribe powered by Erlang's pg process groups. Works across cluster nodes with zero configuration.

PubSub guide →

Phoenix-compatible wire

A JSON array wire format compatible with Phoenix client libraries, served over WebSockets by beryl_mist or beryl_ewe.

WebSocket guide →