removed console log
This commit is contained in:
@@ -3,24 +3,15 @@ import { Server, Socket } from "socket.io";
|
|||||||
|
|
||||||
export const handleConnectDispatch =
|
export const handleConnectDispatch =
|
||||||
(socket: Socket, io: Server) =>
|
(socket: Socket, io: Server) =>
|
||||||
async ({
|
async ({ logoffTime, selectedZone }: { logoffTime: string; selectedZone: string }) => {
|
||||||
logoffTime,
|
|
||||||
selectedZone,
|
|
||||||
}: {
|
|
||||||
logoffTime: string;
|
|
||||||
selectedZone: string;
|
|
||||||
}) => {
|
|
||||||
try {
|
try {
|
||||||
const user: User = socket.data.user; // User ID aus dem JWT-Token
|
const user: User = socket.data.user; // User ID aus dem JWT-Token
|
||||||
console.log("User connected to dispatch server");
|
|
||||||
|
|
||||||
if (!user) return Error("User not found");
|
if (!user) return Error("User not found");
|
||||||
|
console.log("Disponent connected:", user.publicId);
|
||||||
|
|
||||||
if (!user.permissions?.includes("DISPO")) {
|
if (!user.permissions?.includes("DISPO")) {
|
||||||
socket.emit(
|
socket.emit("error", "You do not have permission to connect to the dispatch server.");
|
||||||
"error",
|
|
||||||
"You do not have permission to connect to the dispatch server.",
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,9 +23,7 @@ export const handleConnectDispatch =
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (existingConnection) {
|
if (existingConnection) {
|
||||||
await io
|
await io.to(`user:${user.id}`).emit("force-disconnect", "double-connection");
|
||||||
.to(`user:${user.id}`)
|
|
||||||
.emit("force-disconnect", "double-connection");
|
|
||||||
await prisma.connectedDispatcher.updateMany({
|
await prisma.connectedDispatcher.updateMany({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
@@ -100,7 +89,6 @@ export const handleConnectDispatch =
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("disconnect", async () => {
|
socket.on("disconnect", async () => {
|
||||||
console.log("Disconnected from dispatch server");
|
|
||||||
await prisma.connectedDispatcher.update({
|
await prisma.connectedDispatcher.update({
|
||||||
where: {
|
where: {
|
||||||
id: connectedDispatcherEntry.id,
|
id: connectedDispatcherEntry.id,
|
||||||
@@ -112,11 +100,7 @@ export const handleConnectDispatch =
|
|||||||
io.to("dispatchers").emit("dispatchers-update");
|
io.to("dispatchers").emit("dispatchers-update");
|
||||||
io.to("pilots").emit("dispatchers-update");
|
io.to("pilots").emit("dispatchers-update");
|
||||||
});
|
});
|
||||||
socket.on("reconnect", async () => {
|
|
||||||
console.log("Reconnected to dispatch server");
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error connecting to dispatch server:", error);
|
console.error("Error connecting to dispatch server:", error);
|
||||||
console.log("Error connecting to dispatch server:", error);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getPublicUser, prisma } from "@repo/db";
|
import { getPublicUser, prisma, User } from "@repo/db";
|
||||||
import { channel } from "diagnostics_channel";
|
import { channel } from "diagnostics_channel";
|
||||||
import { Server, Socket } from "socket.io";
|
import { Server, Socket } from "socket.io";
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ export const handleConnectPilot =
|
|||||||
(socket: Socket, io: Server) =>
|
(socket: Socket, io: Server) =>
|
||||||
async ({ logoffTime, stationId }: { logoffTime: string; stationId: string }) => {
|
async ({ logoffTime, stationId }: { logoffTime: string; stationId: string }) => {
|
||||||
try {
|
try {
|
||||||
const user = socket.data.user; // User ID aus dem JWT-Token
|
const user: User = socket.data.user; // User ID aus dem JWT-Token
|
||||||
const userId = socket.data.user.id; // User ID aus dem JWT-Token
|
const userId = socket.data.user.id; // User ID aus dem JWT-Token
|
||||||
|
|
||||||
const Station = await prisma.station.findFirst({
|
const Station = await prisma.station.findFirst({
|
||||||
@@ -14,10 +14,10 @@ export const handleConnectPilot =
|
|||||||
id: parseInt(stationId),
|
id: parseInt(stationId),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log("Pilot connected:", userId);
|
|
||||||
|
|
||||||
if (!user) return Error("User not found");
|
if (!user) return Error("User not found");
|
||||||
|
|
||||||
|
console.log("Pilot connected:", user.publicId);
|
||||||
const existingConnection = await prisma.connectedAircraft.findFirst({
|
const existingConnection = await prisma.connectedAircraft.findFirst({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
@@ -73,8 +73,6 @@ export const handleConnectPilot =
|
|||||||
socket.join(`user:${userId}`); // Join the user-specific room
|
socket.join(`user:${userId}`); // Join the user-specific room
|
||||||
socket.join(`station:${stationId}`); // Join the station-specific room
|
socket.join(`station:${stationId}`); // Join the station-specific room
|
||||||
|
|
||||||
console.log(`Pilot in: station:${stationId}`);
|
|
||||||
|
|
||||||
io.to("dispatchers").emit("pilots-update");
|
io.to("dispatchers").emit("pilots-update");
|
||||||
io.to("pilots").emit("pilots-update");
|
io.to("pilots").emit("pilots-update");
|
||||||
|
|
||||||
@@ -100,7 +98,6 @@ export const handleConnectPilot =
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("disconnect", async () => {
|
socket.on("disconnect", async () => {
|
||||||
console.log("Disconnected from dispatch server");
|
|
||||||
await prisma.connectedAircraft
|
await prisma.connectedAircraft
|
||||||
.update({
|
.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user