added auto disconnect when changing link

This commit is contained in:
PxlLoewe
2025-06-02 15:04:15 -07:00
parent 72998a36a4
commit af36b82221
9 changed files with 72 additions and 5 deletions

View File

@@ -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", () => {});