Presence
Who is online and who is in each topic, kept by Folkways from live connections, with optional status data.
Presence tells your app who is online and who is in a topic. Nobody publishes join or leave events: Folkways keeps presence from the connections themselves, so it is right even when a phone loses signal.
There are two views, both system topics you subscribe to like any other:
| Topic | Holds | Typical use |
|---|---|---|
$online/{identity} | One entry per open connection of that identity. Empty means offline | A friends list, a "last seen" dot |
$presence/{topic} | One entry per connection present in the topic or anywhere below it | "Who's in this room", viewer counts |
Both are KV topics: subscribe once and keep a map by key. The snapshot fills it, then each change updates it, and a leave arrives as a deletion.
Being present in a topic
Turn on presence in a topic rule. Then subscribing to a matching topic makes the connection present in that topic and in every area above it:
Unsubscribing, losing the right on a token refresh, or disconnecting removes the entry at once. A connection that drops without closing cleanly is removed when Folkways notices, at worst after the 90-second idle timeout.
Entries
Each entry's key is identity#session (in $online, just the session), and its value is JSON:
{ "identity": "user:7", "session": "9f1c…e2", "device": "ios", "since": 1792000000000, "data": { "status": "busy" } }device is the label the client sent when connecting, if any. data is your own status data: publish up to 1,024
bytes of JSON to your own $online/{identity} and it appears in your online entry and in every presence entry of
that connection. Nobody can write anyone else's.
Who may read
Reading presence needs the presence op, which is separate from subscribe:
{ "topic": "$online/>", "ops": ["presence"] }lets a user see who is online;{ "topic": "chat/>", "ops": ["presence"] }lets them see who is in each chat topic.
A user can always read their own $online. A reader without the right gets Forbidden, whether or not the person
exists, so presence can't be used to look anyone up.
Presence of private topics is closed to client tokens: it would show who is in a private room. Your backend can still read it.
Staying out of presence
A connection can be invisible: it subscribes and publishes as usual but never appears in $online or
$presence. Set "presence": false in the token, or ask for it when connecting. Anonymous connections and HTTP
requests never appear in presence.
Cost
Presence entries and their deliveries don't count as billed messages.
In code
See Presence in the JavaScript SDK, or presence on the wire.