9801905960
* fix: improve the hooks of voice activity * Add check for users who haven't talked
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
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';
|
|
import useWhoIsUnmuted from '/imports/ui/core/hooks/useWhoIsUnmuted';
|
|
|
|
const useMuteMicrophone = () => {
|
|
const { data: currentUser } = useCurrentUser((u) => ({
|
|
userId: u.userId,
|
|
}));
|
|
const toggleVoice = useToggleVoice();
|
|
const { data: unmutedUsers } = useWhoIsUnmuted();
|
|
const muted = currentUser?.userId && !unmutedUsers[currentUser?.userId];
|
|
const userId = currentUser?.userId ?? '';
|
|
|
|
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;
|