PhoenixKit.Entities.Presence (phoenix_kit v1.5.1)
View SourcePresence tracking for collaborative entity editing.
Uses Phoenix.Presence to track who is currently editing an entity or data record. The first person to join a topic becomes the "owner" (can edit), and everyone else becomes "spectators" (read-only mode).
How It Works
- When a user opens an edit form, they join a Presence topic (e.g., "entity_edit:5")
- Presence tracks all connected users with metadata (user info, joined_at timestamp)
- Users are sorted by joined_at to determine order (FIFO)
- First user in the sorted list = owner (readonly?: false)
- All other users = spectators (readonly?: true)
- When owner leaves, Presence removes them automatically
- All connected users receive presence_diff event
- Each user re-evaluates: "Am I first now?"
- New first user auto-promotes to owner
Automatic Cleanup
Phoenix.Presence automatically detects when LiveView processes die and removes them immediately via process monitoring. When a user closes a tab or navigates away:
- WebSocket disconnects
- LiveView process terminates
- Presence automatically cleaned up (via process monitoring)
- All other users receive presence_diff event instantly
No manual cleanup or timeout configuration needed!
Topics
- Entity editing: "entity_edit:<entity_id>"
- Data editing: "data_edit:<data_id>"
Summary
Functions
Callback implementation for Phoenix.Presence.fetch/2.
Callback implementation for Phoenix.Presence.get_by_key/2.
Callback implementation for Phoenix.Presence.list/1.
Callback implementation for Phoenix.Presence.track/3.
Callback implementation for Phoenix.Presence.track/4.
Callback implementation for Phoenix.Presence.untrack/2.
Callback implementation for Phoenix.Presence.untrack/3.
Callback implementation for Phoenix.Presence.update/3.
Callback implementation for Phoenix.Presence.update/4.
Functions
Callback implementation for Phoenix.Presence.fetch/2.
Callback implementation for Phoenix.Presence.get_by_key/2.
Callback implementation for Phoenix.Presence.list/1.
Callback implementation for Phoenix.Presence.track/3.
Callback implementation for Phoenix.Presence.track/4.
Callback implementation for Phoenix.Presence.untrack/2.
Callback implementation for Phoenix.Presence.untrack/3.
Callback implementation for Phoenix.Presence.update/3.
Callback implementation for Phoenix.Presence.update/4.