// Hello Jetstream (Skyware) // Minimal example using the @skyware/jetstream library directly. // This is a reference showing the third-party API — our lib/ wraps the same protocol. // // Usage: npx tsx examples/hello-jetstream.ts [--raw] import { Jetstream } from "@skyware/jetstream"; import WebSocket from "ws"; import { formatTruncated } from "../lib/index.js"; const raw = process.argv.includes("--raw"); const jetstream = new Jetstream({ ws: WebSocket, wantedCollections: ["app.bsky.feed.post"], endpoint: "wss://jetstream2.us-east.bsky.network/subscribe", }); jetstream.onCreate("app.bsky.feed.post", (event) => { if (raw) { console.log(JSON.stringify(event, null, 2)); } else { const record = event.commit?.record as any; const text = record?.text ?? "(no text)"; console.log(` @${event.did}`); console.log(` ${formatTruncated(text, 120)}`); if (record?.langs?.length) console.log(` lang: ${record.langs.join(", ")}`); } console.log("---"); }); jetstream.start(); console.log("Connected to Jetstream. Streaming posts... (use --raw for full JSON)\n");