a proof of concept realtime collaborative todo list
0

Configure Feed

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

Add cursor resume

+9 -4
+9 -4
subscribe.js
··· 3 3 // we don't need to re-fetch. 4 4 5 5 export function subscribe({ dids, collections, onCommit }) { 6 - const url = new URL("wss://jetstream1.us-east.bsky.network/subscribe"); 7 - for (const d of dids) url.searchParams.append("wantedDids", d); 8 - for (const c of collections) url.searchParams.append("wantedCollections", c); 9 - 10 6 let ws; 11 7 let closed = false; 12 8 let retry = 0; 9 + let cursor = null; 13 10 14 11 const open = () => { 15 12 if (closed) return; 13 + const url = new URL("wss://jetstream1.us-east.bsky.network/subscribe"); 14 + for (const d of dids) url.searchParams.append("wantedDids", d); 15 + for (const c of collections) url.searchParams.append("wantedCollections", c); 16 + // Resume from the last seen event on reconnect, otherwise Jetstream starts 17 + // a fresh live tail and commits during the downtime are lost for good. 18 + if (cursor) url.searchParams.set("cursor", String(cursor)); 19 + 16 20 ws = new WebSocket(url); 17 21 ws.onopen = () => (retry = 0); 18 22 ws.onmessage = (e) => { ··· 22 26 } catch { 23 27 return; 24 28 } 29 + if (msg.time_us) cursor = msg.time_us; 25 30 if (msg.kind !== "commit" || !msg.commit) return; 26 31 onCommit({ 27 32 did: msg.did,