From 1844a876aa19933d816a6d442f0ffe7ec5ea880b Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Mon, 19 May 2025 23:16:51 -0700 Subject: [PATCH] fixed bug that prevented pilots and dispos from receiving socket events after disconnect --- .../app/_store/dispatch/connectionStore.ts | 22 +++++++----------- .../app/_store/pilot/connectionStore.ts | 22 +++++++++++++----- grafana/grafana.db | Bin 1122304 -> 1122304 bytes 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/apps/dispatch/app/_store/dispatch/connectionStore.ts b/apps/dispatch/app/_store/dispatch/connectionStore.ts index daf7f225..9c4eef98 100644 --- a/apps/dispatch/app/_store/dispatch/connectionStore.ts +++ b/apps/dispatch/app/_store/dispatch/connectionStore.ts @@ -23,13 +23,10 @@ export const useDispatchConnectionStore = create((set) => ({ new Promise((resolve) => { set({ status: "connecting", message: "" }); dispatchSocket.auth = { uid }; - set({ selectedZone }); + set({ selectedZone, logoffTime }); dispatchSocket.connect(); + dispatchSocket.once("connect", () => { - dispatchSocket.emit("connect-dispatch", { - logoffTime, - selectedZone, - }); resolve(); }); }), @@ -39,6 +36,12 @@ export const useDispatchConnectionStore = create((set) => ({ })); dispatchSocket.on("connect", () => { + const { logoffTime, selectedZone } = useDispatchConnectionStore.getState(); + + dispatchSocket.emit("connect-dispatch", { + logoffTime, + selectedZone, + }); useDispatchConnectionStore.setState({ status: "connected", message: "" }); }); @@ -61,11 +64,4 @@ dispatchSocket.on("force-disconnect", (reason: string) => { }); }); -dispatchSocket.on("reconnect", () => { - const { logoffTime, selectedZone } = useDispatchConnectionStore.getState(); - - dispatchSocket.emit("connect-dispatch", { - logoffTime, - selectedZone, - }); -}); +dispatchSocket.on("reconnect", () => {}); diff --git a/apps/dispatch/app/_store/pilot/connectionStore.ts b/apps/dispatch/app/_store/pilot/connectionStore.ts index 4e8e49d5..7c5cfca8 100644 --- a/apps/dispatch/app/_store/pilot/connectionStore.ts +++ b/apps/dispatch/app/_store/pilot/connectionStore.ts @@ -7,6 +7,7 @@ import { useDmeStore } from "_store/pilot/dmeStore"; interface ConnectionStore { status: "connected" | "disconnected" | "connecting" | "error"; message: string; + logoffTime: string; selectedStation: Station | null; connectedAircraft: ConnectedAircraft | null; activeMission: @@ -27,12 +28,18 @@ interface ConnectionStore { export const usePilotConnectionStore = create((set) => ({ status: "disconnected", message: "", + logoffTime: "", selectedStation: null, connectedAircraft: null, activeMission: null, connect: async (uid, stationId, logoffTime, station, user) => new Promise((resolve) => { - set({ status: "connecting", message: "", selectedStation: station }); + set({ + status: "connecting", + message: "", + selectedStation: station, + logoffTime, + }); pilotSocket.auth = { uid }; pilotSocket.connect(); @@ -42,10 +49,7 @@ export const usePilotConnectionStore = create((set) => ({ station, user, }); - pilotSocket.emit("connect-pilot", { - logoffTime, - stationId, - }); + resolve(); }); }), @@ -55,8 +59,14 @@ export const usePilotConnectionStore = create((set) => ({ })); pilotSocket.on("connect", () => { - dispatchSocket.disconnect(); usePilotConnectionStore.setState({ status: "connected", message: "" }); + const { logoffTime, selectedStation } = usePilotConnectionStore.getState(); + dispatchSocket.disconnect(); + + pilotSocket.emit("connect-pilot", { + logoffTime, + stationId: selectedStation?.id, + }); }); pilotSocket.on("connect_error", (err) => { diff --git a/grafana/grafana.db b/grafana/grafana.db index b32f901d8806baf90b3ceee904df35d255671910..be84e9e43b98cb53b41cc98c3a54c0599ff9859c 100644 GIT binary patch delta 87 zcmZoT;L>owWr8&0n~5^cjBgqfS`!#s6PQ{Pm|GKAS`%1X6WCf4*taHdl0mPg@%mu{UK+FTgygowWr8&0>xnYXjISFLS`!#s6PQ{Pm|GKAS`%1X6WCf4*taHdlT hYrmz>0mPg@%mu{UK+FTgyg