Status Toast wird nur für Aircraft auf der selben RG wie Disponent angezeigt

This commit is contained in:
PxlLoewe
2025-07-23 18:44:07 -07:00
parent b1dcaee565
commit 2ef98363b9
3 changed files with 31 additions and 5 deletions

View File

@@ -83,6 +83,7 @@ router.patch("/:id", async (req, res) => {
data: { data: {
stationId: updatedConnectedAircraft.stationId, stationId: updatedConnectedAircraft.stationId,
aircraftId: updatedConnectedAircraft.id, aircraftId: updatedConnectedAircraft.id,
userId: updatedConnectedAircraft.userId,
}, },
} as NotificationPayload); } as NotificationPayload);
} }

View File

@@ -3,7 +3,9 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { BaseNotification } from "_components/customToasts/BaseNotification"; import { BaseNotification } from "_components/customToasts/BaseNotification";
import { FMS_STATUS_COLORS } from "_helpers/fmsStatusColors"; import { FMS_STATUS_COLORS } from "_helpers/fmsStatusColors";
import { editConnectedAircraftAPI, getConnectedAircraftsAPI } from "_querys/aircrafts"; import { editConnectedAircraftAPI, getConnectedAircraftsAPI } from "_querys/aircrafts";
import { getLivekitRooms } from "_querys/livekit";
import { getStationsAPI } from "_querys/stations"; import { getStationsAPI } from "_querys/stations";
import { useAudioStore } from "_store/audioStore";
import { useMapStore } from "_store/mapStore"; import { useMapStore } from "_store/mapStore";
import { X } from "lucide-react"; import { X } from "lucide-react";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
@@ -20,6 +22,23 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) =>
const status5Sounds = useRef<HTMLAudioElement | null>(null); const status5Sounds = useRef<HTMLAudioElement | null>(null);
const status9Sounds = useRef<HTMLAudioElement | null>(null); const status9Sounds = useRef<HTMLAudioElement | null>(null);
const { data: livekitRooms } = useQuery({
queryKey: ["livekit-rooms"],
queryFn: () => getLivekitRooms(),
refetchInterval: 10000,
});
const audioRoom = useAudioStore((s) => s.room?.name);
const participants =
livekitRooms?.flatMap((room) =>
room.participants.map((p) => ({
...p,
roomName: room.room.name,
})),
) || [];
const livekitUser = participants.find((p) => p.attributes.userId === event.data?.userId);
useEffect(() => { useEffect(() => {
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
status0Sounds.current = new Audio("/sounds/status-0.mp3"); status0Sounds.current = new Audio("/sounds/status-0.mp3");
@@ -83,6 +102,11 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) =>
default: default:
soundRef = null; soundRef = null;
} }
if (audioRoom !== livekitUser?.roomName) {
toast.remove(t.id);
return;
}
if (soundRef?.current) { if (soundRef?.current) {
soundRef.current.currentTime = 0; soundRef.current.currentTime = 0;
soundRef.current.volume = 0.7; soundRef.current.volume = 0.7;
@@ -94,15 +118,15 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) =>
soundRef.current.currentTime = 0; soundRef.current.currentTime = 0;
} }
}; };
}, [event.status]); }, [event.status, livekitUser?.roomName, audioRoom, t.id]);
if (!connectedAircraft || !station) return null; if (!connectedAircraft || !station) return null;
return ( return (
<BaseNotification> <BaseNotification>
<div className="flex flex-row gap-14 items-center"> <div className="flex flex-row items-center gap-14">
<p> <p>
<span <span
className="underline mr-1 cursor-pointer font-bold" className="mr-1 cursor-pointer font-bold underline"
onClick={() => { onClick={() => {
if (!connectedAircraft.posLat || !connectedAircraft.posLng) return; if (!connectedAircraft.posLat || !connectedAircraft.posLng) return;
mapStore.setOpenAircraftMarker({ mapStore.setOpenAircraftMarker({
@@ -119,12 +143,12 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) =>
</span> </span>
sendet Status {event.status} sendet Status {event.status}
</p> </p>
<div className="flex gap-2 items-center"> <div className="flex items-center gap-2">
{QUICK_RESPONSE[String(event.status)]?.map((status) => ( {QUICK_RESPONSE[String(event.status)]?.map((status) => (
<button <button
key={status} key={status}
className={ className={
"flex justify-center items-center min-w-10 min-h-10 cursor-pointer text-lg font-bold" "flex min-h-10 min-w-10 cursor-pointer items-center justify-center text-lg font-bold"
} }
style={{ style={{
backgroundColor: FMS_STATUS_COLORS[status], backgroundColor: FMS_STATUS_COLORS[status],

View File

@@ -36,6 +36,7 @@ export interface StationStatus {
data?: { data?: {
stationId: number; stationId: number;
aircraftId: number; aircraftId: number;
userId?: string;
}; };
} }