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 () => {
|
||||
|
||||
@@ -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 = () => {
|
||||
<div className="h-4 flex items-center">{message}</div>
|
||||
)}
|
||||
{showSource && source && (
|
||||
<div className="h-4 flex items-center">{source}</div>
|
||||
<div className="h-4 flex items-center ml-2">{source}</div>
|
||||
)}
|
||||
<button
|
||||
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 { serverApi } from "helpers/axios";
|
||||
import {
|
||||
@@ -44,6 +47,20 @@ export const useAudioStore = create<TalkState>((set, get) => ({
|
||||
const { room, isTalking } = get();
|
||||
if (!room) return;
|
||||
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" }));
|
||||
},
|
||||
@@ -132,11 +149,17 @@ 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);
|
||||
useAudioStore.setState({
|
||||
source: data.source,
|
||||
});
|
||||
if (data.channel === currentChannel)
|
||||
useAudioStore.setState({
|
||||
source: data.source,
|
||||
});
|
||||
};
|
||||
|
||||
pilotSocket.on("ptt", handlePTT);
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user