Gamend.Lobbies.SpectatorTracker (gamend_core v1.0.1192)

Copy Markdown View Source

Who is watching a lobby without being a member.

Backed by Gamend.Presence, so counts are cluster-wide. The previous ETS version was node-local: with more than one node every lobby undercounted, silently and by an amount nobody could see.

Entries follow the watching channel process, so a disconnect — or a whole node going down — removes them with no cleanup path to forget.

Summary

Functions

Spectator counts for several lobbies, as %{lobby_id => count}.

Tracks the calling process as a spectator.

Functions

count(lobby_id)

@spec count(Ecto.UUID.t()) :: non_neg_integer()

counts(lobby_ids)

@spec counts([Ecto.UUID.t()]) :: %{required(Ecto.UUID.t()) => non_neg_integer()}

Spectator counts for several lobbies, as %{lobby_id => count}.

list(lobby_id)

@spec list(Ecto.UUID.t()) :: [Ecto.UUID.t()]

track(lobby_id, user_id)

@spec track(Ecto.UUID.t(), Ecto.UUID.t()) :: :ok

Tracks the calling process as a spectator.

Call from the channel process: presence follows that process's lifetime.

untrack(lobby_id, user_id)

@spec untrack(Ecto.UUID.t(), Ecto.UUID.t()) :: :ok