decentralised sync engine
0
fork

Configure Feed

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

fix: actually persist the connection

serenity 77f2d868 e5699e35

+15 -10
+6 -6
src/lib/setup.ts
··· 119 119 }; 120 120 121 121 export const connectToShards = async () => { 122 - const shardSessions = handshakeTokens.entries(); 123 - const shardConnectionPromises = shardSessions 124 - .map(async (session) => { 125 - const atUri = session[0]; 126 - const { token } = session[1]; 122 + const handshakes = handshakeTokens.entries(); 123 + const shardConnectionPromises = handshakes 124 + .map(async (handshake) => { 125 + const atUri = handshake[0]; 126 + const sessionInfo = handshake[1]; 127 127 const rkey = atUri.rKey ?? ""; 128 128 const shardDid = isDomain(rkey) 129 129 ? `did:web:${encodeURIComponent(rkey)}` ··· 141 141 return { 142 142 // TODO: xrpc and lexicon this endpoint 143 143 shardUrl: `${shardUrlResult.data.origin}/connect`, 144 - sessionToken: token, 144 + sessionInfo, 145 145 }; 146 146 }) 147 147 .toArray();
+9 -4
src/lib/utils/gmstn.ts
··· 1 + import { shardSessions } from "@/lib/state"; 1 2 import type { Did } from "@/lib/types/atproto"; 3 + import type { ShardSessionInfo } from "@/lib/types/handshake"; 2 4 import { getEndpointFromDid } from "@/lib/utils/atproto"; 3 5 import WebSocket from "ws"; 4 6 ··· 8 10 9 11 export const connectToShard = ({ 10 12 shardUrl, 11 - sessionToken, 13 + sessionInfo, 12 14 }: { 13 15 shardUrl: string; 14 - sessionToken: string; 16 + sessionInfo: ShardSessionInfo; 15 17 }) => { 16 18 const endpoint = new URL(shardUrl); 17 - endpoint.searchParams.append("token", sessionToken); 18 - return new WebSocket(endpoint); 19 + const { token } = sessionInfo; 20 + endpoint.searchParams.append("token", token); 21 + const ws = new WebSocket(endpoint); 22 + shardSessions.set(sessionInfo, ws); 23 + return ws; 19 24 };