Live video on the AT Protocol
1import { useMemo } from "react";
2import { StreamplaceAgent } from "streamplace";
3import { useStreamplaceStore, useUrl } from ".";
4
5export function usePDSAgent(): StreamplaceAgent | null {
6 const oauthSession = useStreamplaceStore((state) => state.oauthSession);
7 // oauthsession is
8 // - undefined when loading
9 // - null when logged out, and
10 // - SessionManager when logged in
11 return useMemo(() => {
12 if (!oauthSession) {
13 if (oauthSession === undefined) return null;
14 // TODO: change once we allow unauthed requests + profile indexing
15 // it's bluesky's AppView b/c otherwise we'd have goosewithpipe.jpg
16 // showing up everywhere
17 return new StreamplaceAgent("https://public.api.bsky.app"); // nodeUrl);
18 }
19
20 return new StreamplaceAgent(oauthSession);
21 }, [oauthSession]);
22}
23
24// can be unauthed, but will always use the current node URL
25export function usePossiblyUnauthedPDSAgent(): StreamplaceAgent | null {
26 const nodeUrl = useUrl();
27 const oauthSession = useStreamplaceStore((state) => state.oauthSession);
28 // oauthsession is
29 // - undefined when loading
30 // - null when logged out, and
31 // - SessionManager when logged in
32 return useMemo(() => {
33 if (!oauthSession) {
34 return new StreamplaceAgent(nodeUrl);
35 }
36
37 return new StreamplaceAgent(oauthSession);
38 }, [oauthSession]);
39}