Live video on the AT Protocol
79
fork

Configure Feed

Select the types of activity you want to include in your feed.

app: more aggressive on session restoration

Eli Mallon ef08853f c451b8c6

+34 -21
+1
js/app/features/base/baseSlice.tsx
··· 1 1 import { createAppSlice } from "../../hooks/createSlice"; 2 2 import Storage from "../../storage"; 3 3 export const STORED_KEY_KEY = "storedKey"; 4 + export const DID_KEY = "did"; 4 5 5 6 export interface StreamKey { 6 7 privateKey: string;
+27 -19
js/app/features/bluesky/blueskySlice.tsx
··· 8 8 } from "@atproto/api"; 9 9 import { ProfileViewDetailed } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; 10 10 import { bytesToMultibase, Secp256k1Keypair } from "@atproto/crypto"; 11 - import { hydrate, STORED_KEY_KEY } from "features/base/baseSlice"; 11 + import { hydrate, STORED_KEY_KEY, DID_KEY } from "features/base/baseSlice"; 12 12 import { openLoginLink } from "features/platform/platformSlice"; 13 13 import { 14 14 LivestreamViewHydrated, ··· 36 36 isLink, 37 37 isMention, 38 38 } from "@atproto/api/dist/client/types/app/bsky/richtext/facet"; 39 + import { OAuthSession } from "@atproto/oauth-client"; 39 40 40 41 const initialState: BlueskyState = { 41 42 status: "start", ··· 68 69 const uploadThumbnail = async ( 69 70 handle: string, 70 71 u: URL, 71 - pdsAgent: Agent, 72 + pdsAgent: StreamplaceAgent, 72 73 profile: ProfileViewDetailed, 73 74 customThumbnail?: Blob, 74 75 ) => { ··· 148 149 const { streamplace } = getState() as { streamplace: StreamplaceState }; 149 150 const client = await createOAuthClient(streamplace.url); 150 151 const anonPDSAgent = new StreamplaceAgent(streamplace.url); 151 - let initResult = await client.init(); 152 - return { client, initResult, anonPDSAgent }; 152 + const did = await Storage.getItem(DID_KEY); 153 + let session: OAuthSession | null = null; 154 + if (did) { 155 + try { 156 + session = await client.restore(did); 157 + } catch (e) { 158 + console.error("Error restoring session", e); 159 + } 160 + } 161 + // let initResult = await client.init(); 162 + return { client, session, anonPDSAgent }; 153 163 }, 154 164 { 155 165 pending: (state) => { 156 166 // state.status = "loading"; 157 167 }, 158 168 fulfilled: (state, action) => { 159 - const { client, initResult, anonPDSAgent } = action.payload; 169 + const { client, session, anonPDSAgent } = action.payload; 160 170 console.log("loadOAuthClient fulfilled", action.payload); 161 - if (initResult && "session" in initResult) { 171 + if (session) { 162 172 return { 163 173 ...state, 164 174 client: client, 165 - oauthSession: initResult.session as any, 166 - pdsAgent: new StreamplaceAgent(initResult.session) as any, // idk why this is needed 175 + oauthSession: session as any, 176 + pdsAgent: new StreamplaceAgent(session) as any, // idk why this is needed 167 177 anonPDSAgent: anonPDSAgent, 168 178 }; 169 179 } ··· 377 387 } 378 388 throw new Error("Missing params, got: " + url); 379 389 } 380 - const { bluesky } = thunkAPI.getState() as { 381 - bluesky: BlueskyState; 390 + const { streamplace } = thunkAPI.getState() as { 391 + streamplace: StreamplaceState; 382 392 }; 383 - if (!bluesky.client) { 384 - throw new Error("No client"); 385 - } 393 + const client = await createOAuthClient(streamplace.url); 386 394 try { 387 - const ret = await bluesky.client.callback(params); 388 - await Storage.setItem("did", ret.session.did); 389 - 390 - return ret.session as any; 395 + const ret = await client.callback(params); 396 + await Storage.setItem(DID_KEY, ret.session.did); 397 + return { session: ret.session as any, client }; 391 398 } catch (e) { 392 399 let message = e.message; 393 400 while (e.cause) { ··· 407 414 console.log("oauthCallback fulfilled", action.payload); 408 415 return { 409 416 ...state, 410 - oauthSession: action.payload as any, 411 - pdsAgent: new Agent(action.payload) as any, 417 + client: action.payload.client, 418 + oauthSession: action.payload.session as any, 419 + pdsAgent: new StreamplaceAgent(action.payload.session) as any, 412 420 }; 413 421 }, 414 422 rejected: (state, action) => {
+4 -1
js/app/features/streamplace/streamplaceSlice.tsx
··· 270 270 if (!bluesky.pdsAgent) { 271 271 throw new Error("no pdsAgent"); 272 272 } 273 + if (!bluesky.oauthSession) { 274 + throw new Error("no oauthSession"); 275 + } 273 276 return await bluesky.pdsAgent.place.stream.live.getSegments({ 274 - userDID: bluesky.oauthSession?.did, 277 + userDID: bluesky.oauthSession.did, 275 278 }); 276 279 }, 277 280 {
+2 -1
js/atproto-oauth-client-react-native/tsconfig.build.json
··· 2 2 "extends": "../app/tsconfig.base.json", 3 3 "compilerOptions": { 4 4 "rootDir": "./src", 5 - "outDir": "./dist" 5 + "outDir": "./dist", 6 + "declaration": true 6 7 }, 7 8 "include": ["./src"] 8 9 }