Click a face to follow them: their tab, their frame, their play, their pointer

A collaborator's face in the top bar follows them. You go where they go —
the symbol they open, the frame they are on, play when they play — and each
of you sees the other's pointer on the stage, named and in their colour.
Clicking the face again, ringed while you are together, leaves.

tl's parties, nearly line for line. Nobody hosts: following someone on
their own takes their connection id as the party, so two people following
each other at once land in one, and anyone in it drives the rest. That is
why the eye beside the faces says whether you may be followed. The browsers
work it out from gossip; the server only relays `nav` and `cursor`, and
does not remember them.

Only deliberate moves go out. Every member plays the document off its own
clock, so a play is sent once with its frame rather than streamed. A dive
into a symbol made a moment ago waits for its write to land, and a dropped
socket rejoins the same party on the way back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Olive Vaughn 2026-10-11 01:53:20 -04:00
parent 14b0d6fa85
commit fbdecfb5d2
10 changed files with 502 additions and 53 deletions

View file

@ -4,7 +4,8 @@ Two things ride it. DELTAS, which the server sends after a write commits — the
socket is read-only for the document, and a dropped socket cannot lose a write.
PRESENCE, which peers gossip between themselves: all the server does is hand out
a connection id and stamp the sender's identity onto every message, so nobody can
post as somebody else.
post as somebody else. A party — people following each other — is worked out in
the browsers from that gossip (`arthur.domain.party`); nothing here knows of it.
"""
import json
import uuid
@ -32,7 +33,10 @@ def broadcast(project_id, delta, kind="delta"):
class ProjectConsumer(AsyncWebsocketConsumer):
RELAYED = ("state",)
# `state` is who you are and which party you carry, and is remembered for
# the next joiner. `nav` and `cursor` are where a party is looking, and are
# stale the moment the next one is sent, so they are only passed on.
RELAYED = ("state", "nav", "cursor")
@property
def room(self):
@ -68,7 +72,7 @@ class ProjectConsumer(AsyncWebsocketConsumer):
return
if not isinstance(msg, dict) or msg.get("kind") not in self.RELAYED:
return
if self.cid in self.room:
if msg["kind"] == "state" and self.cid in self.room:
self.room[self.cid].update(
{k: v for k, v in msg.items() if k not in ("kind", "cid", "user")}
)

View file

@ -1227,3 +1227,37 @@ class SocketTests(TestCase):
await peer.disconnect()
async_to_sync(scenario)()
def test_where_a_party_looks_is_passed_on_and_not_remembered(self):
from asgiref.sync import async_to_sync
from channels.testing import WebsocketCommunicator
from server.asgi import application
from django.contrib.auth import get_user_model
project = Project.objects.create(
name="shared", owner=get_user_model().objects.create_user("host"))
async def join():
peer = WebsocketCommunicator(application, f"/ws/projects/{project.id}",
headers=[(b"origin", b"http://localhost")])
self.assertTrue((await peer.connect())[0])
welcome = await peer.receive_json_from()
roster = (await peer.receive_json_from())["peers"]
await peer.receive_json_from() # our own join
return peer, welcome["cid"], roster
async def scenario():
a, a_cid, _ = await join()
await a.send_json_to({"kind": "state", "party": a_cid, "joinable": True})
await a.receive_json_from()
await a.send_json_to({"kind": "nav", "open": "main", "frame": 7, "playing": True})
self.assertEqual(7, (await a.receive_json_from())["frame"])
await a.send_json_to({"kind": "cursor", "open": "main", "at": [3, 4]})
self.assertEqual([3, 4], (await a.receive_json_from())["at"])
b, _, roster = await join()
self.assertEqual([{"cid": a_cid, "user": None, "party": a_cid, "joinable": True}],
roster)
await a.disconnect(); await b.disconnect()
async_to_sync(scenario)()