Extension points
tilttek/table-presenceThe package is at 0.x: its extension points are stable only from its 1.0 release. Until then, a minor version may
change them, and its CHANGELOG says how.
| To | Do |
|---|---|
| Keep the tables | Implement Contract\PresenceStore, and pass it to Presence. |
| Act on what happened | Implement Contract\PresenceObserver, and pass it to Presence. |
| Hide a member from those they blocked | Implement Contract\BlockList, and pass it to Presence. |
| Give the time | Pass a PSR-20 ClockInterface. |
| Set the timeout, the grace delay, the most connections and the default visibility | Pass a PresencePolicy to Presence::open(). |
| Say who may admit, remove, set the status, close, or speak for a member | Check it in the application before calling Presence. |
The store
Contract\PresenceStore keeps the tables, each at a version:
table()gives one by its identifier, or null;save()keeps one at the next version and returns it. One at version 0 is new, and the store has none of its identifier; any other is kept only when the store holds it at that version, andPresenceConflictis raised otherwise, nothing kept.
Two tabs send a heartbeat at once and both read version 7: the first save keeps version 8, and the second is refused
with PresenceConflict. A heartbeat refused so needs no retry: the next beat carries it. Any other change is made
again on what is read anew.
Store\InMemoryPresenceStore keeps them in memory, as long as the object lasts: it is for tests. An application keeps
them in its database. A table holds strings, an integer version, a boolean, its status — an enumeration whose value is
its string case —, its policy — three integers and an enumeration —, and its members, each strings, enumerations, a
boolean, up to two moments and their connections, each an identifier and a moment.
The observer and its events
Contract\PresenceObserver::notify() is told each fact once the table is kept, by identifiers only:
| Event | When | Carries |
|---|---|---|
Event\TableOpened | A table was opened. | |
Event\MemberAdmitted | A member was admitted. | the member |
Event\MemberArrived | A member arrived: their first connection of a stay. | the member |
Event\MemberLeft | A member left: no live connection, and their grace delay is over; or they were removed, erased, or the table closed. | the member |
Event\AvailabilityChanged | A member said something else of themselves. | the member, the availability |
Event\VisibilityChanged | A member changed who sees them. | the member, the visibility |
Event\PresenceForgotten | A member's presence was erased. | the member |
Event\MemberRemoved | A member was removed. | the member |
Event\TableStatusChanged | The table's status or label changed. | the status |
Event\TableClosed | A table was closed. |
Every event implements Event\PresenceEvent, whose table is an identifier; the events of one member implement
Event\MemberEvent, which adds member. When a member who was there is removed, MemberLeft comes first, then
MemberRemoved; when their presence is erased, MemberLeft then PresenceForgotten; when a table closes, one
MemberLeft per member who was there, in order, then TableClosed. A call that changes nothing tells nothing.
The events do not say who may see the member: an application sends a message from them — through Messenger, with the
identifiers alone —, then pushes to each member the view Presence::view() builds for them, never the event itself. A
member hidden from others thus never shows through a push.
The block list
Contract\BlockList::blocks() says whether a member blocked a viewer. It is asked while building a view, once per
other member; an application answers from what it holds in memory for the request, or from a cache, not from a query
per call.
The clock
Presence reads the time from the PSR-20 ClockInterface it is given, and from nothing else. A clock that goes back
counts a connection as live, never as gone before its time.