everything but the leave works yall

This commit is contained in:
2026-07-17 23:46:27 -05:00
parent 0a3b13c147
commit e3c9fd955b
8 changed files with 113 additions and 5 deletions
+8 -4
View File
@@ -8,6 +8,14 @@ export class Clients {
this.clients = new Map();
}
get clientList(): ClientList {
return this.clients;
}
get roomList(): string[] {
return Array.from(this.clients.keys());
}
userInRoom(username: string): boolean {
this.clients.forEach((room) => {
if (room.some((client) => client.username === username)) {
@@ -18,10 +26,6 @@ export class Clients {
return false;
}
get clientList(): ClientList {
return this.clients;
}
addClient(roomId: string, username: string, ws: ElysiaWS) {
if (!this.clients.has(roomId)) {
this.clients.set(roomId, []);
+8 -1
View File
@@ -1,6 +1,6 @@
import Elysia from "elysia";
import type { ElysiaWS } from "elysia/ws";
import { ClientMessage, ClientMessageSchema } from "./types";
import { ClientMessage, ClientMessageSchema, ServerMessage } from "./types";
import { Clients } from "./classes";
import { db, message as messageTable } from "@/lib/db";
@@ -57,6 +57,13 @@ async function handleMessage(ws: ElysiaWS, message: ClientMessage) {
break;
}
case "rooms": {
ws.send({
type: "rooms",
rooms: clients.roomList,
} as ServerMessage);
break;
}
}
}
+7
View File
@@ -33,6 +33,9 @@ const ClientMessageSchema = t.Union([
roomId: t.String(),
// No need for username as we can just directly send the sync through the WS
}),
t.Object({
type: t.Literal("rooms"),
}),
]);
// Server -> Client(s)
@@ -55,6 +58,10 @@ const ServerMessageSchema = t.Union([
roomId: t.String(),
messages: t.Array(MessageSchema),
}),
t.Object({
type: t.Literal("rooms"),
rooms: t.Array(t.String()),
}),
]);
type ClientList = Map<