Skip to content

Presence

tilttek/table-presence

A table has 1 to 40 members, in order, each named by an opaque identifier: 1 to 128 letters, digits, _, ., : or -, starting with a letter, never an address. Each member has a role: GameMaster, Assistant, Player or Observer; the game master and the assistants lead the table. Presence::open() opens a table with its members, no one at it yet.

$presence->open('table-4', ['gm-1' => Role::GameMaster, 'player-1' => Role::Player], new PresencePolicy(45, 20, 5), TableStatus::Gathering);

admit() adds a member last, remove() takes one away with their presence; the last member is not removed: the table is closed instead.

Connections and heartbeats

A member opens one connection per tab or device, named by an opaque identifier the application chooses — never an address or a device name. connect() counts a connection as live; each heartbeat calls it again with the same identifier. A member keeps the policy's most connections, five by default: past it, the one seen the longest ago is dropped.

The table hears that a member arrived — MemberArrived — at their first connection of a stay, once: a second tab, or a reload, tells nothing.

The grace delay

A member is at the table while one of their connections is live — its last heartbeat within the timeout, 45 seconds by default — and then through the grace delay, 20 seconds by default, counted from their last contact: the moment their last connection was closed by disconnect(), or the last heartbeat plus the timeout for a connection that went silent. A reload, a tab moved to another device, or a short network drop is not a departure.

The sweep

Between two calls nothing happens on its own: the presence is computed at each read. sweep() drops the connections whose heartbeat is over the timeout, keeping their last contact, and tells the table who left — MemberLeft — once their grace delay is over. A member who leaves is here again at their next stay: what they said of themselves is forgotten, who sees them is kept. A sweep where nothing is over keeps nothing and tells nothing, so an application sweeps each open table every few seconds at little cost.

The timeout is 5 to 600 seconds, the grace delay 0 to 600 seconds. A heartbeat every third of the timeout survives a lost beat.

What a member says

setAvailability() says where a member is: Here, Away from the screen, or OnBreak, with 1 to 240 minutes until they expect to be back, or none. The member chooses it: the library never turns silence into "away". Saying the same thing again changes nothing; a break given new minutes counts from now.

Who sees whom

setVisibility() says who sees a member's presence:

VisibilityWho sees the member's state
TableEvery member of the table: the default, unless the policy says otherwise.
LeadsThe game master and the assistants.
NobodyThe member alone.

A member hidden from a viewer is shown to them as Offline, never as hidden, so hiding tells nothing. A member who blocked a viewer, as the Contract\BlockList says, is offline to that viewer too, whatever their visibility. Every member sees themselves as they are.

The view

view() gives the presence as one member of the table sees it; anyone else is refused with PresenceNotFound. Each View\MemberPresence holds the member, their role, their state — Online, Away, OnBreak or Offline —, whether it is the viewer, the seconds until their expected return while on a break, rounded up, and, for the viewer alone, their live connections. PresenceView::$present counts the members the viewer sees at the table. No view ever holds the moment of a last connection: a member's absence is never dated for others.

online() lists the members at the table now, whoever sees them, for the server's own rules — whether the game master is there, who may take the scene. It is never shown as it is.

The table's status

setStatus() sets the table's own status — Gathering, Playing, Paused or OnBreak — and a label of up to 80 characters, trimmed, without control or format characters: "Scene 3", "Back at 21:00". Setting the same again changes nothing.

Erasing and closing

forget() erases a member's presence: their connections, their last contact and what they said of themselves. They stay a member, with their role and who sees them; the table hears they left first, when it heard they arrived.

close() erases every member's presence, tells the table who left, in order, then that it closed. A closed table changes no more: every change is refused with PresenceRefused, and a sweep of it changes nothing.