beryl/presence/wire
Phoenix-compatible wire encoding for presence diffs.
Functions
Section titled “Functions”encode_diff
Section titled “encode_diff”pub fn encode_diff( presence.Diff, String) -> json.JsonEncode a presence diff for one topic as a Phoenix-compatible payload.
The resulting JSON has joins and leaves maps. Presence keys index the
maps. Each value contains the tracked metadata under metas.
Encoding does not include the diff's delivery scope. Prefer
beryl.broadcast_presence_diff for socket delivery; a custom publisher must
honor presence.diff_scope before sending this payload to other nodes.
{ "joins": { "user:1": { "metas": [{ "status": "online" }] } }, "leaves": { "user:2": { "metas": [{ "status": "offline" }] } }}encode_state
Section titled “encode_state”pub fn encode_state(List(presence.PresenceEntry)) -> json.JsonEncode a topic's full presence list as a Phoenix-compatible
presence_state payload.
The resulting JSON is a map indexed by presence key. Each value contains
the tracked metadata under metas. This is the same shape as one side of
a presence_diff:
{ "user:1": { "metas": [{ "status": "online", "phx_ref": "..." }] } }Phoenix clients expect a presence_state event with this payload after
they join a presence-enabled topic. Incremental presence_diff events
follow it. Build the entry list with presence.list.
