Files
diplom-frontend/app/stores/voice-state-store.ts
2025-05-21 08:46:12 +03:00

47 lines
1.1 KiB
TypeScript

import { create } from "zustand";
import { useWebRTCStore } from "./webrtc-store";
interface VoiceState {
activeChannel: { serverId: string; channelId: string } | null;
error: string | null;
// Actions
joinVoiceChannel: (serverId: string, channelId: string) => void;
leaveVoiceChannel: () => void;
setError: (error: string) => void;
resetError: () => void;
}
export const useVoiceStateStore = create<VoiceState>()((set, get) => {
return {
activeChannel: null,
error: null,
joinVoiceChannel: (serverId, channelId) => {
set({
activeChannel: { serverId, channelId },
error: null,
});
},
leaveVoiceChannel: () => {
const currentState = get();
if (currentState.activeChannel) {
useWebRTCStore.getState().disconnect();
set({
activeChannel: null,
});
}
},
setError: (error) => {
set({ error });
},
resetError: () => {
set({ error: null });
},
};
});