A TypeScript toolkit for consuming the Bluesky network in real-time.
1// Hello Jetstream (Skyware)
2// Minimal example using the @skyware/jetstream library directly.
3// This is a reference showing the third-party API — our lib/ wraps the same protocol.
4//
5// Usage: npx tsx examples/hello-jetstream.ts [--raw]
6
7import { Jetstream } from "@skyware/jetstream";
8import WebSocket from "ws";
9import { formatTruncated } from "../lib/index.js";
10
11const raw = process.argv.includes("--raw");
12
13const jetstream = new Jetstream({
14 ws: WebSocket,
15 wantedCollections: ["app.bsky.feed.post"],
16 endpoint: "wss://jetstream2.us-east.bsky.network/subscribe",
17});
18
19jetstream.onCreate("app.bsky.feed.post", (event) => {
20 if (raw) {
21 console.log(JSON.stringify(event, null, 2));
22 } else {
23 const record = event.commit?.record as any;
24 const text = record?.text ?? "(no text)";
25 console.log(` @${event.did}`);
26 console.log(` ${formatTruncated(text, 120)}`);
27 if (record?.langs?.length) console.log(` lang: ${record.langs.join(", ")}`);
28 }
29 console.log("---");
30});
31
32jetstream.start();
33console.log("Connected to Jetstream. Streaming posts... (use --raw for full JSON)\n");