From 1385c555f441d30e832f0bd5cd47198da085c0a8 Mon Sep 17 00:00:00 2001 From: Elijah R Date: Mon, 25 Nov 2024 19:24:16 -0500 Subject: [PATCH] add rudimentary multiroom support --- server/src/index.ts | 19 ++++++++++++++++++- webapp/src/html/index.html | 2 +- webapp/src/ts/client.ts | 11 +++++++++++ webapp/src/ts/main.ts | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index ab77534..366faa9 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -108,7 +108,9 @@ if (config.discord.enabled) { // Image upload let img = new ImageUploader(app, config.images); -let room = new MSAgentChatRoom(config.chat, rootLogger.child({module: "Room#Default"}), config.agents, db, img, tts, discord); +let primaryRoom = new MSAgentChatRoom(config.chat, rootLogger.child({module: "Room#Default"}), config.agents, db, img, tts, discord); + +let rooms = new Map(); app.register(async (app) => { app.get('/api/socket', { websocket: true }, async (socket, req) => { @@ -143,6 +145,21 @@ app.register(async (app) => { }); return; } + + let room : MSAgentChatRoom; + + if ((req.query as any).room !== undefined) { + let requestedRoom = (req.query as any).room; + if (rooms.has(requestedRoom)) { + room = rooms.get(requestedRoom)!; + } else { + room = new MSAgentChatRoom(config.chat, rootLogger.child({module: `Room#${requestedRoom}`}), config.agents, db, img, tts, null); + rooms.set(requestedRoom, room); + } + } else { + room = primaryRoom; + } + let o = room.clients.filter((c) => c.ip === ip); if (o.length >= config.chat.maxConnectionsPerIP) { o[0].socket.close(); diff --git a/webapp/src/html/index.html b/webapp/src/html/index.html index 294d028..a6df8f0 100644 --- a/webapp/src/html/index.html +++ b/webapp/src/html/index.html @@ -28,7 +28,7 @@
- +