.
This commit is contained in:
46
app/stores/voice-state-store.ts
Normal file
46
app/stores/voice-state-store.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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 });
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user