frontend added and socket io

This commit is contained in:
2026-03-16 18:07:23 -05:00
parent 81dc575b4f
commit 5db2a7fe75
45 changed files with 11947 additions and 5546 deletions

View File

@@ -1,6 +1,6 @@
import type { RoomId } from "./types.socket.js";
export const MAX_HISTORY = 20;
export const MAX_HISTORY = 50;
export const FLUSH_INTERVAL = 100; // 50ms change higher if needed
export const roomHistory = new Map<RoomId, unknown[]>();

View File

@@ -1,6 +1,5 @@
import { logs } from "backend/db/schema/logs.schema.js";
import { desc } from "drizzle-orm";
import { db } from "../db/db.controller.js";
import { logs } from "../db/schema/logs.schema.js";
import type { RoomId } from "./types.socket.js";
type RoomDefinition<T = unknown> = {
@@ -14,10 +13,10 @@ export const roomDefinition: Record<RoomId, RoomDefinition> = {
const rows = await db
.select()
.from(logs)
.orderBy(desc(logs.createdAt))
.orderBy(logs.createdAt)
.limit(limit);
return rows.reverse();
return rows; //.reverse();
} catch (e) {
console.error("Failed to seed logs:", e);
return [];
@@ -27,6 +26,7 @@ export const roomDefinition: Record<RoomId, RoomDefinition> = {
labels: {
seed: async (limit) => {
console.info(limit);
return [];
},
},

View File

@@ -4,6 +4,7 @@ import type { Server as HttpServer } from "node:http";
import { instrument } from "@socket.io/admin-ui";
import { Server } from "socket.io";
import { createLogger } from "../logger/logger.controller.js";
import { allowedOrigins } from "../utils/cors.utils.js";
import { registerEmitter } from "./roomEmitter.socket.js";
import { createRoomEmitter, preseedRoom } from "./roomService.socket.js";
@@ -15,7 +16,7 @@ export const setupSocketIORoutes = (baseUrl: string, server: HttpServer) => {
const io = new Server(server, {
path: `${baseUrl}/api/socket.io`,
cors: {
origin: ["http://localhost:3000", "https://admin.socket.io"],
origin: allowedOrigins,
credentials: true,
},
});
@@ -38,7 +39,7 @@ export const setupSocketIORoutes = (baseUrl: string, server: HttpServer) => {
// get room seeded
const history = await preseedRoom(rn);
log.info({}, `User joined ${rn}: ${s.id}`);
// send the intial data
s.emit("room-update", {
roomId: rn,
@@ -46,6 +47,11 @@ export const setupSocketIORoutes = (baseUrl: string, server: HttpServer) => {
initial: true,
});
});
s.on("leave-room", (room) => {
s.leave(room);
log.info({}, `${s.id} left room: ${room}`);
});
});
io.on("disconnect", (s) => {