Choose handlers or one update function
Register one handler for each topic pattern. beryl/channel routes each event to the correct channel. Each channel keeps private, typed state. You can also route all events in one typed update function.
Type-safe real-time channels and presence for Gleam, targeting the Erlang (BEAM) runtime.

import beryl/channelimport gleam/json
// One handler per topic pattern, with private typed state.pub fn room() -> channel.Handler { channel.handler("room:*", fn(ctx) { channel.accept(0) |> channel.on_message(fn(count, msg: channel.Message) { case msg.event { "new_msg" -> channel.next(count + 1, [ channel.broadcast("new_msg", json.int(count + 1)), ]) _ -> channel.stay(count) } }) |> channel.with_reply(json.string(ctx.topic)) })}Download the tutorial app and connect a browser to its first checkpoint. The example includes the server and browser client.
Run the first checkpoint →Follow one app through the live-poll tutorial. Learn the state-update loop, add voting and server messages, then move to channel handlers.
Build a live poll →Add beryl and the Ewe transport to your project. Use the channel guide for handlers and actions, or adapt a complete example. For control over socket routing, compare the two APIs.
Installation guide →Register one handler for each topic pattern. beryl/channel routes each event to the correct channel. Each channel keeps private, typed state. You can also route all events in one typed update function.
Track connected users across Erlang nodes. A conflict-free replicated data type (CRDT) resolves joins and leaves that happen at the same time.
Presence guide →Send events between connected Erlang nodes through pg process groups. You do not need a separate message broker.
Use beryl's Phoenix codec with Phoenix client libraries. The examples use Ewe for WebSockets; you can also use Mist. Phoenix users can compare the concepts.
WebSocket guide →