OpenJustin Torre wants to merge 2 commits into main from presence
JTJustin Torreopened this
Editors can now see who else has a note open. Each connection gets an animal name and a color, the page lists everyone above the textarea, and a name shows "typing" for a moment when that editor's op arrives.
How it works
When a socket connects, NoteRoom picks a name and color nobody on the note is using (src/presence.ts) and stores the editor as the socket's attachment.
The newcomer gets a presence message with everyone here and you set to itself; everyone else gets the new list. When a socket closes or errors, the others get the list without it.
op broadcasts now carry by, the sender's editor id, read from the sending socket. It never comes from the client.
Every presence message carries the whole list, so a missed message is corrected by the next one.
Why on the sockets
Presence is never written to SQLite. Attachments survive hibernation, so after a wake the room still knows who is connected, and a socket that goes away takes its editor with it, including after a crash or a deploy. The reasoning is in decision 0003-presence-lives-on-the-sockets.
Architecture and docs
Flows: "Loading a note" gains the two presence steps and a second editor; "An edit reaching other editors" now marks the broadcast with its author; "Leaving a note" is new.
system.yaml: note-room owns src/presence.ts.
New concept presence and decision 0003; note-room and wire-protocol describe the attachment and the new fields.
Testing
test/presence.test.ts covers picking names and colors (including reuse after a leave and numbering past twelve editors), the join and leave messages, and reading attachments back.
Room tests check that broadcasts carry by. The random-delivery simulation still converges with the new argument.
Editors can now see who else has a note open. Each connection gets an animal name and a color, the page lists everyone above the textarea, and a name shows "typing" for a moment when that editor's op arrives.
How it works
NoteRoompicks a name and color nobody on the note is using (src/presence.ts) and stores the editor as the socket's attachment.presencemessage with everyone here andyouset to itself; everyone else gets the new list. When a socket closes or errors, the others get the list without it.opbroadcasts now carryby, the sender's editor id, read from the sending socket. It never comes from the client.presencemessage carries the whole list, so a missed message is corrected by the next one.Why on the sockets
Presence is never written to SQLite. Attachments survive hibernation, so after a wake the room still knows who is connected, and a socket that goes away takes its editor with it, including after a crash or a deploy. The reasoning is in decision
0003-presence-lives-on-the-sockets.Architecture and docs
system.yaml:note-roomownssrc/presence.ts.presenceand decision0003;note-roomandwire-protocoldescribe the attachment and the new fields.Testing
test/presence.test.tscovers picking names and colors (including reuse after a leave and numbering past twelve editors), the join and leave messages, and reading attachments back.by. The random-delivery simulation still converges with the new argument.