bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/audio/audio-graphql/hooks/useToggleVoice.ts

31 lines
924 B
TypeScript
Raw Normal View History

2024-01-29 20:49:40 +08:00
import { useCallback } from 'react';
import { useMutation } from '@apollo/client';
2024-01-29 20:49:40 +08:00
import Auth from '/imports/ui/services/auth';
import { USER_SET_MUTED } from '../mutations';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
2024-01-29 20:49:40 +08:00
const useToggleVoice = () => {
const [userSetMuted] = useMutation(USER_SET_MUTED);
const { data: currentUserData } = useCurrentUser((u) => ({
voice: {
muted: u.voice?.muted,
},
}));
2024-01-29 20:49:40 +08:00
const toggleVoice = async (userId?: string | null, muted?: boolean | null) => {
let shouldMute = muted;
const userToMute = userId ?? Auth.userID;
if (muted === undefined || muted === null) {
const muted = currentUserData?.voice?.muted;
shouldMute = !muted;
2024-01-29 20:49:40 +08:00
}
userSetMuted({ variables: { muted: shouldMute, userId: userToMute } });
};
return useCallback(toggleVoice, [currentUserData?.voice?.muted]);
2024-01-29 20:49:40 +08:00
};
export default useToggleVoice;