Merge branch 'main' of https://github.com/VAR-Virtual-Air-Rescue/var-monorepo
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";
|
import { Socket, Server } from "socket.io";
|
||||||
|
|
||||||
|
interface PTTData {
|
||||||
|
shouldTransmit: boolean;
|
||||||
|
source: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const handleConnectDesktop = (socket: Socket, io: Server) => () => {
|
export const handleConnectDesktop = (socket: Socket, io: Server) => () => {
|
||||||
const user = socket.data.user as User;
|
const user = socket.data.user as User;
|
||||||
|
|
||||||
socket.join(`user:${user.id}`);
|
socket.join(`user:${user.id}`);
|
||||||
socket.join(`desktop:${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);
|
socket.to(`user:${user.id}`).emit("ptt", data);
|
||||||
const connectedAircraft = await prisma.connectedAircraft.findFirst({
|
const connectedAircraft = await prisma.connectedAircraft.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -25,12 +30,16 @@ export const handleConnectDesktop = (socket: Socket, io: Server) => () => {
|
|||||||
logoutTime: null,
|
logoutTime: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
socket.to("pilots").emit("other-ptt", {
|
const otherPttData = {
|
||||||
publicUser: user.publicId,
|
publicUser: getPublicUser(user),
|
||||||
source:
|
source:
|
||||||
connectedAircraft?.Station.bosCallsignShort || connectedDispatcher
|
connectedAircraft?.Station.bosCallsignShort || connectedDispatcher
|
||||||
? "Leitstelle"
|
? "Leitstelle"
|
||||||
: user.publicId,
|
: 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("dispatchers").emit("dispatchers-update");
|
||||||
io.to("pilots").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 () => {
|
socket.on("disconnect", async () => {
|
||||||
console.log("Disconnected from dispatch server");
|
console.log("Disconnected from dispatch server");
|
||||||
await prisma.connectedDispatcher.update({
|
await prisma.connectedDispatcher.update({
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { getPublicUser, prisma } from "@repo/db";
|
import { getPublicUser, prisma } from "@repo/db";
|
||||||
|
import { channel } from "diagnostics_channel";
|
||||||
import { Server, Socket } from "socket.io";
|
import { Server, Socket } from "socket.io";
|
||||||
|
|
||||||
export const handleConnectPilot =
|
export const handleConnectPilot =
|
||||||
@@ -14,6 +15,11 @@ export const handleConnectPilot =
|
|||||||
const user = socket.data.user; // User ID aus dem JWT-Token
|
const 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({
|
||||||
|
where: {
|
||||||
|
id: parseInt(stationId),
|
||||||
|
},
|
||||||
|
});
|
||||||
console.log("Pilot connected:", userId);
|
console.log("Pilot connected:", userId);
|
||||||
|
|
||||||
if (!user) return Error("User not found");
|
if (!user) return Error("User not found");
|
||||||
@@ -84,10 +90,19 @@ export const handleConnectPilot =
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add a listener for station-specific events
|
// Add a listener for station-specific events
|
||||||
socket.on(`station:${stationId}:event`, async (data) => {
|
socket.on("ptt", async ({ shouldTransmit, channel }) => {
|
||||||
console.log(`Received event for station ${stationId}:`, data);
|
if (shouldTransmit) {
|
||||||
// Handle station-specific logic here
|
io.to("dispatchers").emit("other-ptt", {
|
||||||
io.to(`station:${stationId}`).emit("station-event-update", data);
|
publicUser: getPublicUser(user),
|
||||||
|
channel,
|
||||||
|
source: Station?.bosCallsignShort,
|
||||||
|
});
|
||||||
|
io.to("piots").emit("other-ptt", {
|
||||||
|
publicUser: getPublicUser(user),
|
||||||
|
channel,
|
||||||
|
source: Station?.bosCallsignShort,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("disconnect", async () => {
|
socket.on("disconnect", async () => {
|
||||||
|
|||||||
@@ -39,9 +39,12 @@ export const Audio = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setShowSource(true);
|
setShowSource(true);
|
||||||
setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
setShowSource(false);
|
setShowSource(false);
|
||||||
}, 2000);
|
}, 6000);
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
}, [source, isTalking]);
|
}, [source, isTalking]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const joinRoom = async () => {
|
const joinRoom = async () => {
|
||||||
@@ -65,7 +68,7 @@ export const Audio = () => {
|
|||||||
<div className="h-4 flex items-center">{message}</div>
|
<div className="h-4 flex items-center">{message}</div>
|
||||||
)}
|
)}
|
||||||
{showSource && source && (
|
{showSource && source && (
|
||||||
<div className="h-4 flex items-center">{source}</div>
|
<div className="h-4 flex items-center ml-2">{source}</div>
|
||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { PublicUser } from "@repo/db";
|
||||||
|
import { usePilotConnectionStore } from "_store/pilot/connectionStore";
|
||||||
|
import { channel } from "diagnostics_channel";
|
||||||
import { dispatchSocket } from "dispatch/socket";
|
import { dispatchSocket } from "dispatch/socket";
|
||||||
import { serverApi } from "helpers/axios";
|
import { serverApi } from "helpers/axios";
|
||||||
import {
|
import {
|
||||||
@@ -44,6 +47,20 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
|||||||
const { room, isTalking } = get();
|
const { room, isTalking } = get();
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
room.localParticipant.setMicrophoneEnabled(!isTalking);
|
room.localParticipant.setMicrophoneEnabled(!isTalking);
|
||||||
|
if (!isTalking) {
|
||||||
|
// If old status was not talking, we need to emit the PTT event
|
||||||
|
if (pilotSocket.connected) {
|
||||||
|
pilotSocket.emit("ptt", {
|
||||||
|
shouldTransmit: true,
|
||||||
|
channel: room.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (dispatchSocket.connected)
|
||||||
|
dispatchSocket.emit("ptt", {
|
||||||
|
shouldTransmit: true,
|
||||||
|
channel: room.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
set((state) => ({ isTalking: !state.isTalking, source: "web-app" }));
|
set((state) => ({ isTalking: !state.isTalking, source: "web-app" }));
|
||||||
},
|
},
|
||||||
@@ -132,8 +149,14 @@ const handlePTT = (data: PTTData) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOtherPTT = (data: PTTData) => {
|
const handleOtherPTT = (data: {
|
||||||
|
publicUser: PublicUser;
|
||||||
|
channel: string;
|
||||||
|
source: string;
|
||||||
|
}) => {
|
||||||
|
const currentChannel = useAudioStore.getState().room?.name;
|
||||||
console.log("Other PTT", data);
|
console.log("Other PTT", data);
|
||||||
|
if (data.channel === currentChannel)
|
||||||
useAudioStore.setState({
|
useAudioStore.setState({
|
||||||
source: data.source,
|
source: data.source,
|
||||||
});
|
});
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user