diff --git a/apps/dispatch-server/socket-events/connect-desktop.ts b/apps/dispatch-server/socket-events/connect-desktop.ts index 24d30d96..779eb341 100644 --- a/apps/dispatch-server/socket-events/connect-desktop.ts +++ b/apps/dispatch-server/socket-events/connect-desktop.ts @@ -1,13 +1,18 @@ -import { prisma, User } from "@repo/db"; +import { getPublicUser, prisma, User } from "@repo/db"; import { Socket, Server } from "socket.io"; +interface PTTData { + shouldTransmit: boolean; + source: string; +} + export const handleConnectDesktop = (socket: Socket, io: Server) => () => { const user = socket.data.user as User; socket.join(`user:${user.id}`); socket.join(`desktop:${user.id}`); - socket.on("ptt", async (data) => { + socket.on("ptt", async (data: PTTData) => { socket.to(`user:${user.id}`).emit("ptt", data); const connectedAircraft = await prisma.connectedAircraft.findFirst({ where: { @@ -25,12 +30,16 @@ export const handleConnectDesktop = (socket: Socket, io: Server) => () => { logoutTime: null, }, }); - socket.to("pilots").emit("other-ptt", { - publicUser: user.publicId, + const otherPttData = { + publicUser: getPublicUser(user), source: connectedAircraft?.Station.bosCallsignShort || connectedDispatcher ? "Leitstelle" : user.publicId, - }); + }; + if (data.shouldTransmit) { + socket.to("pilots").emit("other-ptt", otherPttData); + socket.to("pilots").emit("other-ptt", otherPttData); + } }); }; diff --git a/apps/dispatch-server/socket-events/connect-dispatch.ts b/apps/dispatch-server/socket-events/connect-dispatch.ts index 7378bcc1..7eee5a32 100644 --- a/apps/dispatch-server/socket-events/connect-dispatch.ts +++ b/apps/dispatch-server/socket-events/connect-dispatch.ts @@ -83,6 +83,22 @@ export const handleConnectDispatch = io.to("dispatchers").emit("dispatchers-update"); io.to("pilots").emit("dispatchers-update"); + // dispatch-events + socket.on("ptt", async ({ shouldTransmit, channel }) => { + if (shouldTransmit) { + io.to("dispatchers").emit("other-ptt", { + publicUser: getPublicUser(user), + channel, + source: "Leitstelle", + }); + io.to("piots").emit("other-ptt", { + publicUser: getPublicUser(user), + channel, + source: "Leitstelle", + }); + } + }); + socket.on("disconnect", async () => { console.log("Disconnected from dispatch server"); await prisma.connectedDispatcher.update({ diff --git a/apps/dispatch-server/socket-events/connect-pilot.ts b/apps/dispatch-server/socket-events/connect-pilot.ts index 322a2918..b07e3f91 100644 --- a/apps/dispatch-server/socket-events/connect-pilot.ts +++ b/apps/dispatch-server/socket-events/connect-pilot.ts @@ -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 () => { diff --git a/apps/dispatch/app/_components/Audio.tsx b/apps/dispatch/app/_components/Audio.tsx index f0cc5dea..f3b5bc42 100644 --- a/apps/dispatch/app/_components/Audio.tsx +++ b/apps/dispatch/app/_components/Audio.tsx @@ -39,9 +39,12 @@ export const Audio = () => { useEffect(() => { setShowSource(true); - setTimeout(() => { + const timeout = setTimeout(() => { setShowSource(false); - }, 2000); + }, 6000); + return () => { + clearTimeout(timeout); + }; }, [source, isTalking]); useEffect(() => { const joinRoom = async () => { @@ -65,7 +68,7 @@ export const Audio = () => {