2024-06-07 02:47:41 +08:00
|
|
|
import { useCallback } from 'react';
|
|
|
|
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
|
|
|
import logger from '/imports/startup/client/logger';
|
|
|
|
import AudioManager from '/imports/ui/services/audio-manager';
|
|
|
|
import useToggleVoice from './useToggleVoice';
|
2024-06-22 05:45:05 +08:00
|
|
|
import useWhoIsUnmuted from '/imports/ui/core/hooks/useWhoIsUnmuted';
|
2024-06-07 02:47:41 +08:00
|
|
|
|
|
|
|
const useMuteMicrophone = () => {
|
|
|
|
const { data: currentUser } = useCurrentUser((u) => ({
|
|
|
|
userId: u.userId,
|
|
|
|
}));
|
|
|
|
const toggleVoice = useToggleVoice();
|
2024-06-22 05:45:05 +08:00
|
|
|
const { data: unmutedUsers } = useWhoIsUnmuted();
|
2024-06-28 01:31:20 +08:00
|
|
|
const muted = currentUser?.userId && !unmutedUsers[currentUser?.userId];
|
2024-06-20 01:18:58 +08:00
|
|
|
const userId = currentUser?.userId ?? '';
|
2024-06-07 02:47:41 +08:00
|
|
|
|
|
|
|
return useCallback(() => {
|
|
|
|
if (!muted) {
|
|
|
|
logger.info({
|
|
|
|
logCode: 'audiomanager_mute_audio',
|
|
|
|
extraInfo: { logType: 'user_action' },
|
|
|
|
}, 'User wants to leave conference. Microphone muted');
|
|
|
|
AudioManager.setSenderTrackEnabled(false);
|
|
|
|
toggleVoice(userId as string, true);
|
|
|
|
}
|
|
|
|
}, [muted, userId, toggleVoice]);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useMuteMicrophone;
|