33 lines
591 B
TypeScript
33 lines
591 B
TypeScript
type VoiceState = {
|
|
connected: boolean;
|
|
shouldBeConnected: boolean;
|
|
participants: string[];
|
|
muted: boolean;
|
|
};
|
|
|
|
const state: VoiceState = {
|
|
connected: false,
|
|
shouldBeConnected: false,
|
|
participants: [],
|
|
muted: false,
|
|
};
|
|
|
|
const listeners = new Set<() => void>();
|
|
|
|
export function getVoiceState() {
|
|
return state;
|
|
}
|
|
|
|
export function setVoiceState(patch: Partial<VoiceState>) {
|
|
Object.assign(state, patch);
|
|
listeners.forEach((l) => l());
|
|
}
|
|
|
|
export function subscribeVoice(cb: () => void): () => void {
|
|
listeners.add(cb);
|
|
|
|
return () => {
|
|
listeners.delete(cb);
|
|
};
|
|
}
|