Fixed docker deploments, moved files to _folders in dispatch app

This commit is contained in:
PxlLoewe
2025-05-27 17:34:44 -07:00
parent 5d5b2dc91f
commit 571ddfba85
60 changed files with 251 additions and 406 deletions

View File

@@ -0,0 +1,39 @@
import { ConnectedAircraft, ConnectedDispatcher } from "@repo/db";
import axios from "axios";
import { getSession } from "next-auth/react";
export const serverApi = axios.create({
baseURL: process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL,
timeout: 10000,
headers: {
"Content-Type": "application/json",
},
});
serverApi.interceptors.request.use(
async (config) => {
const session = await getSession();
const token = session?.user.id; /* session?.accessToken */ // abhängig von deinem NextAuth setup
if (token) {
config.headers.Authorization = `User ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
},
);
export const getConenctedUsers = async (): Promise<
(ConnectedDispatcher | ConnectedAircraft)[]
> => {
const res = await serverApi.get<(ConnectedDispatcher | ConnectedAircraft)[]>(
"/status/connected-users",
);
if (res.status !== 200) {
throw new Error("Failed to fetch connected users");
}
return res.data;
};

View File

@@ -0,0 +1,6 @@
import clsx, { ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export const cn = (...inputs: ClassValue[]) => {
return twMerge(clsx(inputs));
};

View File

@@ -0,0 +1,11 @@
import { HpgState } from "@repo/db";
export const hpgStateToFMSStatus = (state: HpgState): string => {
if (state === "DISPATCHED") {
return "3";
}
if (state === "ON_SCENE") {
return "4";
}
return "2";
};

View File

@@ -0,0 +1,15 @@
import { ConnectedAircraft } from "@repo/db";
export const HPGValidationRequired = (
missionStationIds?: number[],
aircrafts?: ConnectedAircraft[],
hpgMissionString?: string | null,
) => {
return (
missionStationIds?.some((id) => {
const aircraft = aircrafts?.find((a) => a.stationId === id);
return aircraft?.posH145active;
}) && hpgMissionString?.length !== 0
);
};

View File

@@ -0,0 +1,46 @@
import {
LocalParticipant,
LocalTrackPublication,
Participant,
RemoteParticipant,
RemoteTrack,
RemoteTrackPublication,
Track,
} from "livekit-client";
export const handleTrackSubscribed = (
track: RemoteTrack,
publication: RemoteTrackPublication,
participant: RemoteParticipant,
) => {
if (track.kind === Track.Kind.Video || track.kind === Track.Kind.Audio) {
// attach it to a new HTMLVideoElement or HTMLAudioElement
const element = track.attach();
element.play();
}
};
export const handleTrackUnsubscribed = (
track: RemoteTrack,
publication: RemoteTrackPublication,
participant: RemoteParticipant,
) => {
// remove tracks from all attached elements
track.detach();
};
export const handleLocalTrackUnpublished = (
publication: LocalTrackPublication,
participant: LocalParticipant,
) => {
// when local tracks are ended, update UI to remove them from rendering
publication.track?.detach();
};
export const handleActiveSpeakerChange = (speakers: Participant[]) => {
// show UI indicators when participant is speaking
};
export const handleDisconnect = () => {
console.log("disconnected from room");
};

View File

@@ -0,0 +1,62 @@
// Helper function for distortion curve generation
function createDistortionCurve(amount: number): Float32Array {
const k = typeof amount === "number" ? amount : 50;
const nSamples = 44100;
const curve = new Float32Array(nSamples);
const deg = Math.PI / 180;
for (let i = 1; i < nSamples; i += 1) {
const x = (i * 2) / nSamples - 1;
curve[i] = ((3 + k) * x * 20 * deg) / (Math.PI + k * Math.abs(x));
}
return curve;
}
export const getRadioStream = (stream: MediaStream, volume: number): MediaStream | null => {
try {
const audioContext = new window.AudioContext();
const sourceNode = audioContext.createMediaStreamSource(stream);
const destinationNode = audioContext.createMediaStreamDestination();
const gainNode = audioContext.createGain();
gainNode.gain.setValueAtTime(volume, audioContext.currentTime); // Lower gain for reduced volume
// Create distortion node to simulate radio-like audio
const distortionNode = audioContext.createWaveShaper();
distortionNode.curve = createDistortionCurve(15);
distortionNode.oversample = "none";
// Compressor node for dynamic range compression
const compressorNode = audioContext.createDynamicsCompressor();
compressorNode.threshold.setValueAtTime(-60, audioContext.currentTime); // Lower threshold for more compression
compressorNode.knee.setValueAtTime(30, audioContext.currentTime); // Slightly softer knee for smoother compression
compressorNode.ratio.setValueAtTime(15, audioContext.currentTime); // Higher ratio for stronger compression
compressorNode.attack.setValueAtTime(0.002, audioContext.currentTime); // Faster attack for more aggressive compression
compressorNode.release.setValueAtTime(0.15, audioContext.currentTime); // Faster release for a "snappier" sound
// Low-pass filter to simulate reduced fidelity
const lowPassFilterNode = audioContext.createBiquadFilter();
lowPassFilterNode.type = "lowpass";
lowPassFilterNode.frequency.setValueAtTime(2800, audioContext.currentTime);
// High-pass filter to reduce low-end noise
const highPassFilterNode = audioContext.createBiquadFilter();
highPassFilterNode.type = "highpass";
highPassFilterNode.frequency.setValueAtTime(400, audioContext.currentTime);
// Chain the nodes
sourceNode
.connect(distortionNode) // Apply distortion first
.connect(highPassFilterNode) // Remove low-end noise
.connect(lowPassFilterNode) // Simulate reduced fidelity
.connect(compressorNode) // Apply compression
.connect(gainNode) // Connect to gain node
.connect(destinationNode); // Connect to output
// Return the modified stream
return destinationNode.stream;
} catch (error) {
console.error("Error processing audio stream:", error);
return null; // In case of error, return null so that the page doesnt hang
}
};

View File

@@ -0,0 +1,28 @@
export const selectRandomHPGMissionSzenery = (code: string) => {
const scenery = code
.split("_")
.map((n: string) => {
const numbers = n.split(",");
const parsedNumbers = numbers
.map((num) => {
if (num.includes("-")) {
const [min, max] = num.split("-").map(Number);
// creae a range of numbers
return Array.from(
{
length: max! - min! + 1,
},
(_, ai) => ai + min!,
);
}
return Number(num);
})
.flat();
const randomI = Math.floor(Math.random() * parsedNumbers.length);
return parsedNumbers[randomI];
})
.join("_");
console.log("scenery", scenery);
return scenery;
};

View File

@@ -0,0 +1,2 @@
export const checkSimulatorConnected = (date: Date) =>
date && Date.now() - new Date(date).getTime() <= 3000_000;