fixed bug that prevented pilots and dispos from receiving socket events after disconnect

This commit is contained in:
PxlLoewe
2025-05-19 23:16:51 -07:00
parent 060810f1b0
commit 1844a876aa
3 changed files with 25 additions and 19 deletions

View File

@@ -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<ConnectionStore>((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<ConnectionStore>((set) => ({
station,
user,
});
pilotSocket.emit("connect-pilot", {
logoffTime,
stationId,
});
resolve();
});
}),
@@ -55,8 +59,14 @@ export const usePilotConnectionStore = create<ConnectionStore>((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) => {