Follow the focus¶
The focus lane lets a device say where the attention is, such as the card under a thumb, and lets every other device follow it, without a move or a version per movement. The server registers the lane; each device that wants it turns it on.
On the server¶
Register the focus entity and its rows, name the vocabulary's focusKeys, and pass the lane to the
endpoint as focus = Some(FocusLane(Focuses, FocusRows)). Serve surfaces does
all three. Without the lane the endpoint has no focus routes.
On the device¶
Turn the lane on with focus: true:
const options: SurfaceModelOptions = {
baseUrl: "/api/surfaces",
id: "ada",
device: "phone-1",
deviceClass: "phone",
focus: true,
};
With the lane on, connect also fetches the focus and streams it. Listen for it, and set it as the
attention moves:
model.subscribeFocus((focus) => highlight(focus.fields["card"]));
await model.connect();
// Under the thumb now: shown here at once, sent at most once per interval.
model.focus({ card: "m1" });
The listener is called with the focus fetched on connect, then with the local focus at once, then
with the server's answer, and then with every focus another device sets. model.focused holds the
latest.
The throttle¶
focus applies the value locally at once, and sends at most one value per focusIntervalMs, 120 by
default; the last value in a window is always sent. A thumb crossing a shelf therefore costs a few
writes, and the value where it stops always arrives. A send that fails is dropped: the next value
goes with the next window, and focus is never worth a retry.
focus({}) clears it: empty fields mean nothing is focused.
On a device in a room¶
A television that only follows turns the lane on and listens, and never calls focus. It takes a
streamed focus only at a higher version than it holds, as it does the surface, so it shows where the
phone's thumb is now.
The focus names the device that set it. A renderer that shows focus from one steering device and
ignores another's reads focus.device.
What it does not do¶
Focus is kept per surface, not per device: the latest value from whichever device set it last. Two
people pointing at once on one surface see one focus. Closing a surface does not clear its focus, so a
surface opened again under the same id starts with the last focus it had; clear it with focus({})
before closing if that matters.