a proof of concept realtime collaborative text editor using atproto as a sync server jake.tngl.io/y-pds/
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use jetstream cursor

+11
+11
y-pds.js
··· 41 41 /** @type {Set<string>} */ 42 42 #repos = new Set(); 43 43 44 + #cursor = 0; 45 + #destroyed = false; 46 + 44 47 /** 45 48 * @param {Y.Doc} ydoc 46 49 * @param {string} atUri at://ownerDid/collection/rkey ··· 192 195 url.searchParams.append("wantedCollections", DOC_COLLECTION); 193 196 for (const repo of this.#repos) url.searchParams.append("wantedDids", repo); 194 197 198 + if (this.#cursor) url.searchParams.set("cursor", this.#cursor); 199 + 195 200 this.#ws = new WebSocket(url); 201 + this.#ws.onclose = e => { 202 + if (e.target !== this.#ws || this.#destroyed) return; 203 + setTimeout(() => this.#subscribe(), 1000); 204 + }; 196 205 this.#ws.onmessage = async e => { 197 206 const event = JSON.parse(e.data); 207 + this.#cursor = event.time_us; 198 208 if (event.kind !== "commit") return; 199 209 200 210 if (event.commit.collection === DOC_COLLECTION) { ··· 248 258 } 249 259 250 260 destroy() { 261 + this.#destroyed = true; 251 262 this.#ydoc.off("update", this.#onUpdate); 252 263 this.awareness.off("change", this.#onAwarenessChange); 253 264 this.awareness.destroy();