OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-bridge / curtest.mjs

17 lines · javascript ref:
import WebSocket from 'ws'
import { decodeFrame } from 'atproto-store/lib/firehose.js'
function probe(cursor) {
  return new Promise((resolve) => {
    const ws = new WebSocket(`wss://pds.7rnx.net/xrpc/com.atproto.sync.subscribeRepos?cursor=${cursor}`)
    const seen = {}
    const t = setTimeout(() => { try{ws.close()}catch{}; resolve({cursor, seen}) }, 8000)
    ws.on('message', (d) => { const f = decodeFrame(new Uint8Array(d)); const k = f ? f.t : 'unknown/#info?'; seen[k]=(seen[k]||0)+1 })
    ws.on('error', () => { clearTimeout(t); resolve({cursor, seen, error:true}) })
    ws.on('close', () => { clearTimeout(t); resolve({cursor, seen}) })
  })
}
console.log('cursor=0    →', JSON.stringify((await probe(0)).seen))
console.log('cursor=5    →', JSON.stringify((await probe(5)).seen))
console.log('cursor=99999→', JSON.stringify((await probe(99999)).seen), '(future cursor — bsky is likely here)')
process.exit(0)