diff --git a/apps/dispatch/app/(app)/pilot/_components/mrt/MrtDisplay.tsx b/apps/dispatch/app/(app)/pilot/_components/mrt/MrtDisplay.tsx index 4aa230d5..9a7b23f8 100644 --- a/apps/dispatch/app/(app)/pilot/_components/mrt/MrtDisplay.tsx +++ b/apps/dispatch/app/(app)/pilot/_components/mrt/MrtDisplay.tsx @@ -6,7 +6,7 @@ import PAGE_HOME from "./images/PAGE_Home.png"; import PAGE_Call from "./images/PAGE_Call.png"; import PAGE_Off from "./images/PAGE_Off.png"; import PAGE_STARTUP from "./images/PAGE_Startup.png"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { cn, useDebounce } from "@repo/shared-components"; import "./MrtDisplay.css"; import { useSession } from "next-auth/react"; @@ -16,8 +16,11 @@ import { useAudioStore } from "_store/audioStore"; import { ROOMS } from "_data/livekitRooms"; export const MrtDisplay = () => { - const { page, setPage, popup } = useMrtStore((state) => state); - + const { page, setPage, popup, setPopup, setStringifiedData, stringifiedData } = useMrtStore( + (state) => state, + ); + const callEstablishedRef = useRef(false); + const session = useSession(); const { connectedAircraft, selectedStation } = usePilotConnectionStore((state) => state); const { room, speakingParticipants, isTalking } = useAudioStore((state) => state); const [pageImage, setPageImage] = useState<{ @@ -35,8 +38,6 @@ export const MrtDisplay = () => { | undefined >(undefined); - const session = useSession(); - useDebounce( () => { if (!nextImage) return; @@ -68,6 +69,18 @@ export const MrtDisplay = () => { [page, setPage], ); + useDebounce( + () => { + if (page === "startup") { + setPopup({ + popup: "login", + }); + } + }, + 7500, + [page, setPage], + ); + useDebounce( () => { if (page === "voice-call" && speakingParticipants.length === 0 && !isTalking) { @@ -81,6 +94,67 @@ export const MrtDisplay = () => { ); useEffect(() => { + const timeouts: NodeJS.Timeout[] = []; + if (page === "voice-call") { + setStringifiedData({ + callTextHeader: "Wählen", + }); + timeouts.push( + setTimeout(() => { + setStringifiedData({ + callTextHeader: "Anruf...", + }); + }, 500), + + setTimeout(() => { + setStringifiedData({ + callTextHeader: "Gruppenruf", + }); + }, 800), + setTimeout(() => { + callEstablishedRef.current = true; + }, 1500), + ); + } + return () => { + timeouts.forEach((t) => clearTimeout(t)); + }; + }, [page, setStringifiedData]); + + useDebounce( + () => { + if (isTalking && page === "voice-call") { + setStringifiedData({ + callTextHeader: "Sprechen", + }); + } + }, + 1500, + [page, isTalking], + ); + + useEffect(() => { + if (isTalking && page === "voice-call" && callEstablishedRef.current) { + console.log("SET TO SPRECHEN", stringifiedData.callTextHeader); + setStringifiedData({ + callTextHeader: "Sprechen", + }); + } else if ( + !isTalking && + page === "voice-call" && + stringifiedData.callTextHeader === "Sprechen" + ) { + setStringifiedData({ + callTextHeader: "Gruppenruf", + }); + } + }, [page, stringifiedData.callTextHeader, isTalking, setStringifiedData]); + + useEffect(() => { + if (page !== "voice-call") { + callEstablishedRef.current = false; + } + switch (page) { case "home": setNextImage({ src: PAGE_HOME, name: "home" }); @@ -139,6 +213,9 @@ export const MrtDisplay = () => { )} {pageName == "voice-call" && (
+

+ {stringifiedData.callTextHeader} +

{isTalking && selectedStation?.bosCallsignShort} {speakingParticipants.length > 0 && diff --git a/apps/dispatch/app/(app)/pilot/_components/mrt/MrtPopups.tsx b/apps/dispatch/app/(app)/pilot/_components/mrt/MrtPopups.tsx index 466c5825..2a7c5e70 100644 --- a/apps/dispatch/app/(app)/pilot/_components/mrt/MrtPopups.tsx +++ b/apps/dispatch/app/(app)/pilot/_components/mrt/MrtPopups.tsx @@ -16,7 +16,7 @@ export const MrtPopups = () => { const { sdsReceivedSoundRef } = useSounds(); const { popup, setPopup, setStringifiedData, stringifiedData } = useMrtStore((state) => state); - const { connectedAircraft } = usePilotConnectionStore((state) => state); + const { connectedAircraft, status } = usePilotConnectionStore((state) => state); const [popupImage, setPopupImage] = useState(null); useEffect(() => { @@ -42,22 +42,39 @@ export const MrtPopups = () => { useDebounce( () => { - if (!popup || popup == "sds-received") return; + if (popup == "login") return; + if (popup == "sds-received") return; setPopup(null); }, 3000, [popup], ); + useEffect(() => { + if (status === "connecting") { + setPopup({ popup: "login" }); + } + }, [status, setPopup]); + + useDebounce( + () => { + if (status === "connected") { + setPopup(null); + } + }, + 5000, + [status], + ); + useEffect(() => { pilotSocket.on("sds-status", (data: StationStatus) => { setStringifiedData({ sdsText: data.status + " - " + fmsStatusDescriptionShort[data.status] }); setPopup({ popup: "sds-received" }); + if (sdsReceivedSoundRef.current) { + sdsReceivedSoundRef.current.currentTime = 0; + sdsReceivedSoundRef.current.play(); + } }); - if (sdsReceivedSoundRef.current) { - sdsReceivedSoundRef.current.currentTime = 0; - sdsReceivedSoundRef.current.play(); - } }, [setPopup, setStringifiedData, sdsReceivedSoundRef]); if (!popupImage || !popup) return null; diff --git a/apps/dispatch/app/(app)/pilot/_components/mrt/images/PAGE_Call.png b/apps/dispatch/app/(app)/pilot/_components/mrt/images/PAGE_Call.png index 68995051..956f2986 100644 Binary files a/apps/dispatch/app/(app)/pilot/_components/mrt/images/PAGE_Call.png and b/apps/dispatch/app/(app)/pilot/_components/mrt/images/PAGE_Call.png differ diff --git a/apps/dispatch/app/(app)/pilot/page.tsx b/apps/dispatch/app/(app)/pilot/page.tsx index 5ec04be4..b5874665 100644 --- a/apps/dispatch/app/(app)/pilot/page.tsx +++ b/apps/dispatch/app/(app)/pilot/page.tsx @@ -23,7 +23,7 @@ const Map = dynamic(() => import("_components/map/Map"), { }); const PilotPage = () => { - const { connectedAircraft, status, } = usePilotConnectionStore((state) => state); + const { connectedAircraft, status } = usePilotConnectionStore((state) => state); const { latestMission } = useDmeStore((state) => state); // Query will be cached anyway, due to this, displayed Markers are in sync with own Aircraft connection-warning const { data: aircrafts } = useQuery({ @@ -94,7 +94,7 @@ const PilotPage = () => {

-
+

MRT & DME

diff --git a/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx b/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx index ec73555d..a3d3b64a 100644 --- a/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx +++ b/apps/dispatch/app/_components/customToasts/StationStatusToast.tsx @@ -1,8 +1,8 @@ -import { getPublicUser, MissionSdsStatusLog, Prisma, StationStatus } from "@repo/db"; +import { getPublicUser, MissionSdsStatusLog, StationStatus } from "@repo/db"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { BaseNotification } from "_components/customToasts/BaseNotification"; import { FMS_STATUS_COLORS } from "_helpers/fmsStatusColors"; -import { editConnectedAircraftAPI, getConnectedAircraftsAPI } from "_querys/aircrafts"; +import { getConnectedAircraftsAPI } from "_querys/aircrafts"; import { getLivekitRooms } from "_querys/livekit"; import { sendSdsStatusMessageAPI } from "_querys/missions"; import { getStationsAPI } from "_querys/stations"; diff --git a/apps/dispatch/app/_components/map/AircraftMarker.tsx b/apps/dispatch/app/_components/map/AircraftMarker.tsx index 445babda..3961690d 100644 --- a/apps/dispatch/app/_components/map/AircraftMarker.tsx +++ b/apps/dispatch/app/_components/map/AircraftMarker.tsx @@ -2,7 +2,7 @@ import { Marker, Polyline, useMap } from "react-leaflet"; import { DivIcon, Marker as LMarker, Popup as LPopup } from "leaflet"; import { useMapStore } from "_store/mapStore"; import { Fragment, useCallback, useEffect, useRef, useState, useMemo } from "react"; -import { checkSimulatorConnected, cn } from "@repo/shared-components"; +import { cn } from "@repo/shared-components"; import { ChevronsRightLeft, House, MessageSquareText, Minimize2 } from "lucide-react"; import { SmartPopup, calculateAnchor, useSmartPopup } from "_components/SmartPopup"; import FMSStatusHistory, { diff --git a/apps/dispatch/app/_store/pilot/MrtStore.ts b/apps/dispatch/app/_store/pilot/MrtStore.ts index 0bf9eaf1..a2a4525f 100644 --- a/apps/dispatch/app/_store/pilot/MrtStore.ts +++ b/apps/dispatch/app/_store/pilot/MrtStore.ts @@ -46,6 +46,8 @@ export type SetPopupParams = interface StringifiedData { sdsText?: string; sentSdsText?: string; + + callTextHeader?: string; } interface MrtStore { diff --git a/apps/dispatch/app/_store/pilot/connectionStore.ts b/apps/dispatch/app/_store/pilot/connectionStore.ts index 1976dd40..15e3109d 100644 --- a/apps/dispatch/app/_store/pilot/connectionStore.ts +++ b/apps/dispatch/app/_store/pilot/connectionStore.ts @@ -109,7 +109,7 @@ pilotSocket.on("connect-message", (data) => { }); pilotSocket.on("disconnect", () => { - usePilotConnectionStore.setState({ status: "disconnected" }); + usePilotConnectionStore.setState({ status: "disconnected", connectedAircraft: null }); useAudioStore.getState().disconnect(); });