Where the people of a room are, and what they are doing: their places, selections, drags and locks, many times a second.
Awareness is ephemeral by design: never saved, never replicated by
Phoenix.Presence's CRDT, and only the latest state of each session
matters. A room has one awareness process on each node where it has
sessions. Each one:
- keeps the latest state of each local session (
put/5); - every
:awareness_interval(50 ms), sends one frame with the states that changed, to the room's sessions on every node, so that each session receives about 20 frames a second whatever the size of the room, instead of a message from every other person on every move; - sends every state now and then (
:awareness_full_everyframes, 5 seconds), and when another node's awareness of the room starts, so that a session that missed a frame, or joined late, catches up; - forgets a session when its process stops, and a node it stopped hearing from;
- keeps the room's whole picture from every node's frames, for
states/2andlocks/2(agents that look before they act).
It stops when its node has no session left in the room.
A state's keys
Issho owns a state's top-level keys: "place" (an Issho.Place),
"locks" (a list of places), "status", "pointer" (the page's
pointer), "view" (what the page shows), "motion" (an agent's last
gesture), "path" (the page an agent is on), "task" (an agent's
task, its steps and whether it is paused: Issho.Work) and "blocks". A
component keeps its own keys (a canvas's cursor and viewport, a
selection of its own) under its document, in "blocks":
%{"blocks" => %{"board:42" => %{"cursor" => [10, 20]}}}, set with
Issho.Live.merge_block/3, Issho.Participant.aware_block/3 or the
browser's room.awareBlock, and read with block/2. So two
components of a page, or a component and Issho, never write over each
other's keys.
Summary
Functions
A component's own keys in a state: what it set under its document in
"blocks" (an empty map for none).
The places locked in the room, each with the key of the actor that holds it.
Sets the state of a session (a channel or an agent process, pid) in
the room, for the actor key. nil clears it.
The session id of a process, as frames name it.
The states of the room, from every node: %{session_id => %{"key" => actor_key, "state" => state}}.
Functions
A component's own keys in a state: what it set under its document in
"blocks" (an empty map for none).
The places locked in the room, each with the key of the actor that holds it.
Sets the state of a session (a channel or an agent process, pid) in
the room, for the actor key. nil clears it.
The session id of a process, as frames name it.
The states of the room, from every node: %{session_id => %{"key" => actor_key, "state" => state}}.