Something went wrong. Try again.
Jetstream via @atproto/ws-client
Something went wrong. Try again.
1.2 kB · 39 lines · Created 2mo ago
HTML
12345678910111213141516171819202122232425262728293031323334353637383940<!doctype html><meta charset="utf-8" /><title>Jetstream via @atproto/ws-client</title>
<!-- Browsers don't resolve the package-internal "#transport" conditional import, so the import map pins it to the browser transport.--><script type="importmap"> { "imports": { "@atproto/ws-client": "https://unpkg.com/@atproto/ws-client@0.2.0/dist/index.js", "#transport": "https://unpkg.com/@atproto/ws-client@0.2.0/dist/transport/browser-transport.js" } }</script>
<pre id="feed" style="white-space: pre-wrap; max-width: 72ch"></pre>
<script type="module"> import { websocket } from '@atproto/ws-client'
const buildUrl = (cursor) => { const url = new URL('wss://jetstream1.us-east.bsky.network/subscribe') url.searchParams.set('wantedCollections', 'app.bsky.feed.post') if (cursor) url.searchParams.set('cursor', cursor) return url }
let cursor for await (const message of websocket(() => buildUrl(cursor))) { const event = JSON.parse(message) cursor = event.time_us const text = event.commit?.record?.text if (!text) continue feed.prepend(new Text(text + '\n\n')) while (feed.childNodes.length > 50) feed.lastChild.remove() }</script>