added HPG VEhicles Mission, Audio settings; mission Context menu

This commit is contained in:
PxlLoewe
2025-05-24 12:46:11 -07:00
parent b2890b3ecc
commit 1ca6007ac5
28 changed files with 680 additions and 369 deletions

View File

@@ -1,6 +1,4 @@
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 {
@@ -17,6 +15,8 @@ import { create } from "zustand";
let interval: NodeJS.Timeout;
type TalkState = {
micDeviceId: string | null;
micVolume: number;
isTalking: boolean;
source: string;
state: "connecting" | "connected" | "disconnected" | "error";
@@ -24,7 +24,7 @@ type TalkState = {
connectionQuality: ConnectionQuality;
remoteParticipants: number;
toggleTalking: () => void;
setMic: (micDeviceId: string | null, volume: number) => void;
connect: (roomName: string) => void;
disconnect: () => void;
room: Room | null;
@@ -38,15 +38,23 @@ const getToken = async (roomName: string) => {
export const useAudioStore = create<TalkState>((set, get) => ({
isTalking: false,
message: null,
micDeviceId: null,
micVolume: 1,
state: "disconnected",
source: "",
remoteParticipants: 0,
connectionQuality: ConnectionQuality.Unknown,
room: null,
setMic: (micDeviceId, micVolume) => {
set({ micDeviceId, micVolume });
},
toggleTalking: () => {
const { room, isTalking } = get();
const { room, isTalking, micDeviceId, micVolume } = get();
if (!room) return;
room.localParticipant.setMicrophoneEnabled(!isTalking);
// Todo: use micVolume
room.localParticipant.setMicrophoneEnabled(!isTalking, {
deviceId: micDeviceId ?? undefined,
});
if (!isTalking) {
// If old status was not talking, we need to emit the PTT event
@@ -94,23 +102,19 @@ export const useAudioStore = create<TalkState>((set, get) => ({
handleDisconnect();
})
.on(RoomEvent.ConnectionQualityChanged, (connectionQuality) =>
set({ connectionQuality }),
)
.on(RoomEvent.ConnectionQualityChanged, (connectionQuality) => set({ connectionQuality }))
// Track events
.on(RoomEvent.TrackSubscribed, handleTrackSubscribed)
.on(RoomEvent.TrackUnsubscribed, handleTrackUnsubscribed)
.on(RoomEvent.ActiveSpeakersChanged, handleActiveSpeakerChange)
.on(RoomEvent.LocalTrackUnpublished, handleLocalTrackUnpublished);
await room.connect(url, token);
console.log(room);
await room.connect(url, token, {});
set({ room });
interval = setInterval(() => {
set({
remoteParticipants:
room.numParticipants === 0 ? 0 : room.numParticipants - 1, // Unreliable and delayed
remoteParticipants: room.numParticipants === 0 ? 0 : room.numParticipants - 1, // Unreliable and delayed
});
}, 500);
} catch (error: Error | unknown) {
@@ -150,11 +154,7 @@ const handlePTT = (data: PTTData) => {
}
};
const handleOtherPTT = (data: {
publicUser: PublicUser;
channel: string;
source: string;
}) => {
const handleOtherPTT = (data: { publicUser: PublicUser; channel: string; source: string }) => {
const currentChannel = useAudioStore.getState().room?.name;
console.log("Other PTT", data);
if (data.channel === currentChannel)

View File

@@ -1,19 +1,13 @@
import { create } from "zustand";
import { dispatchSocket } from "../../dispatch/socket";
import toast from "react-hot-toast";
import { HPGnotificationToast } from "_components/customToasts/HPGnotification";
import { NotificationPayload } from "@repo/db";
import { useAudioStore } from "_store/audioStore";
interface ConnectionStore {
status: "connected" | "disconnected" | "connecting" | "error";
message: string;
selectedZone: string;
logoffTime: string;
connect: (
uid: string,
selectedZone: string,
logoffTime: string,
) => Promise<void>;
connect: (uid: string, selectedZone: string, logoffTime: string) => Promise<void>;
disconnect: () => void;
}
@@ -40,7 +34,7 @@ export const useDispatchConnectionStore = create<ConnectionStore>((set) => ({
dispatchSocket.on("connect", () => {
const { logoffTime, selectedZone } = useDispatchConnectionStore.getState();
useAudioStore.getInitialState().connect("LST_01");
dispatchSocket.emit("connect-dispatch", {
logoffTime,
selectedZone,

View File

@@ -1,17 +1,10 @@
import { create } from "zustand";
import { dispatchSocket } from "../../dispatch/socket";
import {
ConnectedAircraft,
Mission,
MissionSdsLog,
NotificationPayload,
Station,
User,
} from "@repo/db";
import { ConnectedAircraft, Mission, MissionSdsLog, Station, User } from "@repo/db";
import { pilotSocket } from "pilot/socket";
import { useDmeStore } from "_store/pilot/dmeStore";
import { useMrtStore } from "_store/pilot/MrtStore";
import toast from "react-hot-toast";
import { useAudioStore } from "_store/audioStore";
interface ConnectionStore {
status: "connected" | "disconnected" | "connecting" | "error";
@@ -71,6 +64,7 @@ pilotSocket.on("connect", () => {
usePilotConnectionStore.setState({ status: "connected", message: "" });
const { logoffTime, selectedStation } = usePilotConnectionStore.getState();
dispatchSocket.disconnect();
useAudioStore.getInitialState().connect("LST_01");
pilotSocket.emit("connect-pilot", {
logoffTime,