added last talking info to Audio Pannel

This commit is contained in:
PxlLoewe
2025-05-21 15:20:04 -07:00
parent c2799fbb49
commit f22335b1bf
6 changed files with 82 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
import { getPublicUser, prisma } from "@repo/db";
import { channel } from "diagnostics_channel";
import { Server, Socket } from "socket.io";
export const handleConnectPilot =
@@ -14,6 +15,11 @@ export const handleConnectPilot =
const user = socket.data.user; // User ID aus dem JWT-Token
const userId = socket.data.user.id; // User ID aus dem JWT-Token
const Station = await prisma.station.findFirst({
where: {
id: parseInt(stationId),
},
});
console.log("Pilot connected:", userId);
if (!user) return Error("User not found");
@@ -84,10 +90,19 @@ export const handleConnectPilot =
);
// Add a listener for station-specific events
socket.on(`station:${stationId}:event`, async (data) => {
console.log(`Received event for station ${stationId}:`, data);
// Handle station-specific logic here
io.to(`station:${stationId}`).emit("station-event-update", data);
socket.on("ptt", async ({ shouldTransmit, channel }) => {
if (shouldTransmit) {
io.to("dispatchers").emit("other-ptt", {
publicUser: getPublicUser(user),
channel,
source: Station?.bosCallsignShort,
});
io.to("piots").emit("other-ptt", {
publicUser: getPublicUser(user),
channel,
source: Station?.bosCallsignShort,
});
}
});
socket.on("disconnect", async () => {