changes pilot socket to reperate pilto socket, added pilot stats

This commit is contained in:
PxlLoewe
2025-05-17 23:51:04 -07:00
parent 16e05a08a6
commit 6b58f564b2
16 changed files with 583 additions and 352 deletions

View File

@@ -1,12 +1,17 @@
import { create } from "zustand";
import { dispatchSocket } from "../../dispatch/socket";
import { Station } from "@repo/db";
import { Mission, Station } from "@repo/db";
import { pilotSocket } from "pilot/socket";
interface ConnectionStore {
status: "connected" | "disconnected" | "connecting" | "error";
message: string;
selectedStation: Station | null;
activeMission:
| (Mission & {
Stations: Station[];
})
| null;
connect: (
uid: string,
stationId: string,
@@ -20,13 +25,14 @@ export const usePilotConnectionStore = create<ConnectionStore>((set) => ({
status: "disconnected",
message: "",
selectedStation: null,
activeMission: null,
connect: async (uid, stationId, logoffTime, station) =>
new Promise((resolve) => {
set({ status: "connecting", message: "", selectedStation: station });
dispatchSocket.auth = { uid };
dispatchSocket.connect();
dispatchSocket.once("connect", () => {
dispatchSocket.emit("connect-pilot", {
pilotSocket.auth = { uid };
pilotSocket.connect();
pilotSocket.once("connect", () => {
pilotSocket.emit("connect-pilot", {
logoffTime,
stationId,
});
@@ -34,30 +40,36 @@ export const usePilotConnectionStore = create<ConnectionStore>((set) => ({
});
}),
disconnect: () => {
dispatchSocket.disconnect();
pilotSocket.disconnect();
},
}));
dispatchSocket.on("connect", () => {
pilotSocket.disconnect();
pilotSocket.on("connect", () => {
dispatchSocket.disconnect();
usePilotConnectionStore.setState({ status: "connected", message: "" });
});
dispatchSocket.on("connect_error", (err) => {
pilotSocket.on("connect_error", (err) => {
usePilotConnectionStore.setState({
status: "error",
message: err.message,
});
});
dispatchSocket.on("disconnect", () => {
pilotSocket.on("disconnect", () => {
usePilotConnectionStore.setState({ status: "disconnected", message: "" });
});
dispatchSocket.on("force-disconnect", (reason: string) => {
pilotSocket.on("force-disconnect", (reason: string) => {
console.log("force-disconnect", reason);
usePilotConnectionStore.setState({
status: "disconnected",
message: reason,
});
});
pilotSocket.on("mission-alert", (data) => {
usePilotConnectionStore.setState({
activeMission: data,
});
});