Skip to content

How ankka-surface works

ankka-surface is four components and one endpoint inside the consumer's own ankka service, and a model on every device that talks to that endpoint. The surface entity is the only place a surface changes; a view keeps one row per surface, and every device streams that row.

How ankka-surface works. Devices, a phone, a laptop and a television, each hold a SurfaceModel from the device package. A steering device sends moves, says and hears over HTTP to the SurfaceEndpoint inside the consumer's ankka service. The endpoint stamps each command with the time from its clock, calls the consumer's Interpreter for a say or a hear, and sends moves, opens, shows and hides to the surface entity, an event sourced entity that checks every word against the vocabulary and journals one event per change in Postgres. The surface rows view folds those events into one row per surface; every device streams its surface's row over server-sent events. Beside them, optionally, the focus lane: the focus entity, a key value entity holding the latest focus only, and the focus rows view, which a device in a room streams to follow the steering device.

The components

Component Kind What it holds
surface entity event sourced entity one surface by id: every change, journaled, one event per change
surface rows view one row per surface, the whole surface, keyed by its id; what a device streams and what lists an owner's surfaces
focus entity key value entity, optional where the attention is beside one surface, the latest value only
focus rows view, optional one row per focus; what a device streams to follow it

The consumer registers each one by extending the library's companion with a component id of its own, so two kinds of surface in one service stay apart. The endpoint serves them under a prefix and an ACL the consumer chooses. Serve surfaces wires them.

The path of a move

A move goes from a device to the journal and back to every device in five steps:

  1. The device applies the move to the surface it holds, at once, by the same fold the server applies, so the person sees the change before the server answers.
  2. It posts the move to /{id}/moves. The endpoint stamps it with the time from its clock.
  3. The surface entity refuses the move if the surface is not opened, if the move names nothing, or if it uses a word the vocabulary lacks. Otherwise it journals one Moved event and answers the surface at its new version.
  4. The device replaces what it applied locally with that answer.
  5. The rows view folds the event into the surface's row, and every device streaming that row is given it. A device takes a row only when its version is higher than the one it holds, so the device that made the move ignores the echo.

The path of a say

A say is the same path with the interpreter in front of it. The endpoint reads the surface, hands it and the words to the consumer's interpreter, and either applies the interpreter's move with the words as its request, or answers that nothing was understood and why. The device does not apply a say locally, because it cannot know what the interpreter will make of the words. The surface never acts explains what an interpreter may and may not do.

What each half owns

The server half owns The device half owns
the surface and its version one copy of one surface, and the version it holds
refusing words the vocabulary lacks applying its own moves locally before the answer
the interpreter's answer to a say or a hear which say is the newest, so an older answer is not held
the time every change carries reconnecting, and fetching the surface before every stream
which devices are showing the surface showing itself on connect and hiding itself on disconnect

Neither half renders anything. A renderer is the consumer's: it reads the surface the device model holds and draws it however that device draws. Devices says what a renderer honours.

Why a library and not a platform feature

ankka owns entities, views and streams and nothing above them, so what is shown to a person and how it is steered is a layer a service adds. The layer is generic: the consumer's words are data in a vocabulary rather than types in the library, so every consumer shares one JSON, one device package and one HTTP API.