decentralised sync engine
0
fork

Configure Feed

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

chore: clean up old project, formatting

serenity 7157cdc5 cc69dd17

+4 -44
-43
src/index.old.ts
··· 1 - import type { ShardMessage } from "@/lib/types/messages"; 2 - import { rawDataToString } from "@/lib/utils"; 3 - import { validateNewMessage } from "@/lib/validators"; 4 - import type { RawData } from "ws"; 5 - import WebSocket from "ws"; 6 - 7 - const wss = new WebSocket.Server({ port: 8080 }); 8 - 9 - const messages: ShardMessage[] = []; 10 - const clients = new Set<WebSocket>(); 11 - 12 - wss.on("connection", (ws) => { 13 - clients.add(ws); 14 - 15 - ws.send( 16 - JSON.stringify({ 17 - type: "shard/history", 18 - messages: messages, 19 - }), 20 - ); 21 - 22 - ws.on("message", (data: RawData) => { 23 - const jsonText = rawDataToString(data); 24 - const jsonData: unknown = JSON.parse(jsonText); 25 - 26 - const shardMessage = validateNewMessage(jsonData); 27 - if (!shardMessage) return; 28 - 29 - messages.push(shardMessage); 30 - 31 - clients.forEach((client) => { 32 - if (client.readyState === WebSocket.OPEN) { 33 - client.send(JSON.stringify(shardMessage)); 34 - } 35 - }); 36 - }); 37 - 38 - ws.on("close", () => { 39 - clients.delete(ws); 40 - }); 41 - }); 42 - 43 - console.log("Server running on ws://localhost:8080");
+4 -1
src/index.ts
··· 95 95 await performHandshakes(latticeAtUri); 96 96 97 97 const test = await connectToShards(); 98 - console.log("connected to", test.map((socket) => socket.url)); 98 + console.log( 99 + "connected to", 100 + test.map((socket) => socket.url), 101 + ); 99 102 100 103 // TODO: change this to the actual WS sessions 101 104 const handshakeTokenEntries = handshakeTokens.entries().toArray();