finished conenct modal

This commit is contained in:
PxlLoewe
2025-03-15 20:40:40 -07:00
parent 2ecc91adb9
commit cf61740698
8 changed files with 147 additions and 95 deletions

View File

@@ -1,14 +1,34 @@
import { pubClient } from "modules/redis";
import { Server, Socket } from "socket.io";
export const handle = (socket: Socket, io: Server) => async (jwt: string) => {
const userId = socket.data.user.id; // User ID aus dem JWT-Token
await pubClient.set(`dispatchers:${socket.id}`, userId);
export const handle =
(socket: Socket, io: Server) =>
async ({
logoffTime,
selectedZone,
}: {
logoffTime: string;
selectedZone: string;
}) => {
const userId = socket.data.user.id; // User ID aus dem JWT-Token
await pubClient.json.set(`dispatchers:${socket.id}`, "$", {
logoffTime,
selectedZone,
userId,
});
socket.join("dispatchers"); // Dem Dispatcher-Raum beitreten
socket.join("dispatchers"); // Dem Dispatcher-Raum beitreten
socket.on("disconnect", async () => {
console.log("Disconnected from dispatch server");
await pubClient.del(`dispatchers:${socket.id}`);
});
};
const keys = await pubClient.keys("dispatchers:*");
const dispatchers = await Promise.all(
keys.map(async (key) => {
return await pubClient.json.get(key);
}),
);
console.log(dispatchers);
socket.on("disconnect", async () => {
console.log("Disconnected from dispatch server");
await pubClient.json.del(`dispatchers:${socket.id}`);
});
};