libero/push

Server-side push support.

Allows the server to send MsgFromServer messages to connected WebSocket clients without a prior request. Uses BEAM pg (process groups) for topic-based subscriptions.

Import this module only if your app needs server push. If unused, no processes or groups are created.

Values

pub fn init() -> Nil

Ensure the push pg scope is started. Call once at server boot. Idempotent — safe to call multiple times.

pub fn join(topic topic: String) -> Nil

Subscribe the calling process to a topic for broadcast pushes. The process will receive {libero_push, BitArray} messages when send_to_clients is called for this topic.

Note: topics starting with __client: are reserved for internal targeted push routing. Using them directly in join would receive messages intended for specific clients. This is not validated at runtime (by design) because the API is server-side only and topic names are controlled by the developer, not external input.

pub fn leave(topic topic: String) -> Nil

Unsubscribe the calling process from a topic.

pub fn register(client_id client_id: String) -> Nil

Register the calling process with a unique client ID. Used for targeted pushes via send_to_client. Typically called in the WebSocket on_init with a session-derived ID.

pub fn send_to_client(
  client_id client_id: String,
  module module: String,
  msg msg: a,
) -> Nil

Send a message to a specific client by ID.

pub fn send_to_clients(
  topic topic: String,
  module module: String,
  msg msg: a,
) -> Nil

Send a message to all clients subscribed to a topic.

pub fn unregister(client_id client_id: String) -> Nil

Unregister the calling process from a client ID.

Search Document