-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjetstreamClient.js
More file actions
31 lines (26 loc) · 1.05 KB
/
Copy pathjetstreamClient.js
File metadata and controls
31 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {Jetstream, CommitType} from "@skyware/jetstream";
// Create a new JetStream instance with ALL posts collection
const jetstream = new Jetstream({
wantedCollections: ["app.bsky.feed.post"]
});
jetstream.start();
jetstream.onCreate("app.bsky.feed.post", (event) => {
console.log("New post:", JSON.stringify(event, null, 2))
});
jetstream.on("commit", (event) => {
if (event.commit.operation === CommitType.Create) {
console.log("create in ", event.commit.collection, event.commit.record);
} else if (event.commit.operation === CommitType.Update) {
console.log("update in", event.commit.collection, event.commit.rkey);
} else if (event.commit.operation === CommitType.Delete) {
console.log("delete in", event.commit.collection, event.commit.rkey);
}
});
// Listen for account status updates
jetstream.on("account", (event) => {
console.log("account update", event.account.status)
});
// Listen for identity updates
jetstream.on("identity", (event) => {
console.log("identity update", event.identity.did)
});