examples/live-notes Public
id: presence
type: concept
owner: justin
reviewed: 2026-10-15
component: note-room
describes:
- src/presence.ts
- src/note-room.ts
Presence
The room knows who has each note open. It gives every editor a name and a color, tells everyone when someone joins or leaves, and marks each op it passes on with who made it.
Who is here
When a socket connects, the room lists the editors on the sockets already open and picks a
name and a color nobody there is using (pickEditor()). Names come from a fixed list of
twelve animals; past twelve editors they repeat with a number. The editor is stored on the
socket with serializeAttachment, and the room sends:
- to the newcomer, after the snapshot:
presencewith everyone here andyouset to itself; - to everyone else:
presencewith the new list.
When a socket closes or errors, the room sends the remaining list to everyone left. Every
presence message carries the whole list, so an editor that misses one is corrected by the
next, and the page never has to apply joins and leaves in order.
The id is random per connection. The same person in two tabs is two editors, and a reload gets a new name if the old one was taken in the meantime.
Why nothing is stored
The list of who is here is the list of open sockets, by definition. Writing it to SQLite would add a second copy that can disagree with the first after a crash or a deploy. See [[0003-presence-lives-on-the-sockets]].
Who made an edit
op broadcasts carry by, the id of the sender, read from the sending socket's attachment.
The room does not check by against
anything: it comes from the room itself, never from the editor.