added last talking info to Audio Pannel
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user