decentralised sync engine

chore: clean up old project, formatting

serenity 7157cdc5 cc69dd17

Changed files
+4 -44
src
-43
src/index.old.ts
···
-
import type { ShardMessage } from "@/lib/types/messages";
-
import { rawDataToString } from "@/lib/utils";
-
import { validateNewMessage } from "@/lib/validators";
-
import type { RawData } from "ws";
-
import WebSocket from "ws";
-
-
const wss = new WebSocket.Server({ port: 8080 });
-
-
const messages: ShardMessage[] = [];
-
const clients = new Set<WebSocket>();
-
-
wss.on("connection", (ws) => {
-
clients.add(ws);
-
-
ws.send(
-
JSON.stringify({
-
type: "shard/history",
-
messages: messages,
-
}),
-
);
-
-
ws.on("message", (data: RawData) => {
-
const jsonText = rawDataToString(data);
-
const jsonData: unknown = JSON.parse(jsonText);
-
-
const shardMessage = validateNewMessage(jsonData);
-
if (!shardMessage) return;
-
-
messages.push(shardMessage);
-
-
clients.forEach((client) => {
-
if (client.readyState === WebSocket.OPEN) {
-
client.send(JSON.stringify(shardMessage));
-
}
-
});
-
});
-
-
ws.on("close", () => {
-
clients.delete(ws);
-
});
-
});
-
-
console.log("Server running on ws://localhost:8080");
···
+4 -1
src/index.ts
···
await performHandshakes(latticeAtUri);
const test = await connectToShards();
-
console.log("connected to", test.map((socket) => socket.url));
// TODO: change this to the actual WS sessions
const handshakeTokenEntries = handshakeTokens.entries().toArray();
···
await performHandshakes(latticeAtUri);
const test = await connectToShards();
+
console.log(
+
"connected to",
+
test.map((socket) => socket.url),
+
);
// TODO: change this to the actual WS sessions
const handshakeTokenEntries = handshakeTokens.entries().toArray();