added auto disconnect when changing link
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { create } from "zustand";
|
||||
import { dispatchSocket } from "../../dispatch/socket";
|
||||
import { useAudioStore } from "_store/audioStore";
|
||||
import { ConnectedDispatcher } from "@repo/db";
|
||||
|
||||
interface ConnectionStore {
|
||||
status: "connected" | "disconnected" | "connecting" | "error";
|
||||
connectedDispatcher: ConnectedDispatcher | null;
|
||||
message: string;
|
||||
selectedZone: string;
|
||||
logoffTime: string;
|
||||
@@ -13,6 +15,7 @@ interface ConnectionStore {
|
||||
|
||||
export const useDispatchConnectionStore = create<ConnectionStore>((set) => ({
|
||||
status: "disconnected",
|
||||
connectedDispatcher: null,
|
||||
message: "",
|
||||
selectedZone: "LST_01",
|
||||
logoffTime: "",
|
||||
@@ -51,6 +54,7 @@ dispatchSocket.on("connect_error", (err) => {
|
||||
|
||||
dispatchSocket.on("disconnect", () => {
|
||||
useDispatchConnectionStore.setState({ status: "disconnected", message: "" });
|
||||
useAudioStore.getState().disconnect();
|
||||
});
|
||||
|
||||
dispatchSocket.on("force-disconnect", (reason: string) => {
|
||||
@@ -60,5 +64,10 @@ dispatchSocket.on("force-disconnect", (reason: string) => {
|
||||
message: reason,
|
||||
});
|
||||
});
|
||||
dispatchSocket.on("dispatchers-update", (dispatch: ConnectedDispatcher) => {
|
||||
useDispatchConnectionStore.setState({
|
||||
connectedDispatcher: dispatch,
|
||||
});
|
||||
});
|
||||
|
||||
dispatchSocket.on("reconnect", () => {});
|
||||
|
||||
@@ -81,6 +81,7 @@ pilotSocket.on("connect_error", (err) => {
|
||||
|
||||
pilotSocket.on("disconnect", () => {
|
||||
usePilotConnectionStore.setState({ status: "disconnected", message: "" });
|
||||
useAudioStore.getState().disconnect();
|
||||
});
|
||||
|
||||
pilotSocket.on("force-disconnect", (reason: string) => {
|
||||
@@ -95,7 +96,6 @@ pilotSocket.on("aircraft-update", (data) => {
|
||||
usePilotConnectionStore.setState({
|
||||
connectedAircraft: data,
|
||||
});
|
||||
/* useMrtStore.getState().setLines(getNew); */
|
||||
});
|
||||
|
||||
pilotSocket.on("mission-alert", (data: Mission & { Stations: Station[] }) => {
|
||||
|
||||
Reference in New Issue
Block a user