Live video on the AT Protocol
1import { PlaceStreamChatProfile } from "streamplace";
2import {
3 getStreamplaceStoreFromContext,
4 useDID,
5 useStreamplaceStore,
6} from "./streamplace-store";
7import { usePDSAgent } from "./xrpc";
8
9export function useGetChatProfile() {
10 const did = useDID();
11 const pdsAgent = usePDSAgent();
12 const store = getStreamplaceStoreFromContext();
13
14 return async () => {
15 if (!did || !pdsAgent) {
16 throw new Error("No DID or PDS agent");
17 }
18 const res = await pdsAgent.com.atproto.repo.getRecord({
19 repo: did,
20 collection: "place.stream.chat.profile",
21 rkey: "self",
22 });
23 if (!res.success) {
24 throw new Error("Failed to get chat profile record");
25 }
26
27 if (PlaceStreamChatProfile.isRecord(res.data.value)) {
28 store.setState({ chatProfile: res.data.value });
29 } else {
30 console.log("not a record", res.data.value);
31 }
32 };
33}
34
35export function useGetBskyProfile() {
36 const did = useDID();
37 const pdsAgent = usePDSAgent();
38 const store = getStreamplaceStoreFromContext();
39
40 return async () => {
41 if (!did || !pdsAgent) {
42 throw new Error("No DID or PDS agent");
43 }
44 const res = await pdsAgent.app.bsky.actor.getProfile({
45 actor: did,
46 });
47 if (!res.success) {
48 throw new Error("Failed to get chat profile record");
49 }
50
51 store.setState({ handle: res.data.handle });
52 };
53}
54
55export function useChatProfile() {
56 return useStreamplaceStore((x) => x.chatProfile);
57}