mute/unmute audio and camera on away mode
This commit is contained in:
parent
c5e19baef3
commit
bd2d56f1a2
@ -92,7 +92,7 @@ const isVoiceUser = () => {
|
||||
return voiceUser ? voiceUser.joined : false;
|
||||
};
|
||||
|
||||
const toggleMuteMicrophone = throttle((toggleVoice) => {
|
||||
const toggleMuteMicrophone = throttle((toggleVoice, voiceToggle) => {
|
||||
const user = VoiceUsers.findOne({
|
||||
userId: Auth.userID,
|
||||
}, { fields: { muted: 1 } });
|
||||
@ -104,13 +104,13 @@ const toggleMuteMicrophone = throttle((toggleVoice) => {
|
||||
logCode: 'audiomanager_unmute_audio',
|
||||
extraInfo: { logType: 'user_action' },
|
||||
}, 'microphone unmuted by user');
|
||||
toggleVoice();
|
||||
toggleVoice(user.userId, voiceToggle);
|
||||
} else {
|
||||
logger.info({
|
||||
logCode: 'audiomanager_mute_audio',
|
||||
extraInfo: { logType: 'user_action' },
|
||||
}, 'microphone muted by user');
|
||||
toggleVoice();
|
||||
toggleVoice(user.userId, voiceToggle);
|
||||
}
|
||||
}, TOGGLE_MUTE_THROTTLE_TIME);
|
||||
|
||||
|
@ -28,6 +28,9 @@ import {
|
||||
isVoiceOnlyUser,
|
||||
} from './service';
|
||||
|
||||
import VideoService from '/imports/ui/components/video-provider/service';
|
||||
import AudioService from '/imports/ui/components/audio/service';
|
||||
|
||||
import { isChatEnabled } from '/imports/ui/services/features';
|
||||
import { layoutDispatch } from '/imports/ui/components/layout/context';
|
||||
import { PANELS, ACTIONS } from '/imports/ui/components/layout/enums';
|
||||
@ -314,6 +317,7 @@ const UserActions: React.FC<UserActionsProps> = ({
|
||||
const [setLocked] = useMutation(SET_LOCKED);
|
||||
const [userEjectCameras] = useMutation(USER_EJECT_CAMERAS);
|
||||
const [requestUserInfo] = useMutation(REQUEST_USER_INFO);
|
||||
const prevMutedRef = React.useRef<boolean>(false);
|
||||
|
||||
const removeUser = (userId: string, banUser: boolean) => {
|
||||
if (isVoiceOnlyUser(user.userId)) {
|
||||
@ -333,6 +337,25 @@ const UserActions: React.FC<UserActionsProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const muteAway = () => {
|
||||
const isMuted = user.voice?.muted;
|
||||
const prevAwayMuted = prevMutedRef.current;
|
||||
|
||||
if (!isMuted && !user.away && !prevAwayMuted) {
|
||||
AudioService.toggleMuteMicrophone(toggleVoice, voiceToggle);
|
||||
prevMutedRef.current = true;
|
||||
} else if (isMuted && user.away && prevAwayMuted) {
|
||||
AudioService.toggleMuteMicrophone(toggleVoice, voiceToggle);
|
||||
prevMutedRef.current = false;
|
||||
}
|
||||
|
||||
if (!user.away) {
|
||||
VideoService.setTrackEnabled(false);
|
||||
} else {
|
||||
VideoService.setTrackEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
const dropdownOptions = [
|
||||
...makeDropdownPluginItem(userDropdownItems.filter(
|
||||
(item: PluginSdk.UserListDropdownInterface) => (item?.type === UserListDropdownItemType.INFORMATION),
|
||||
@ -569,6 +592,7 @@ const UserActions: React.FC<UserActionsProps> = ({
|
||||
key: 'setAway',
|
||||
label: intl.formatMessage(user.away ? messages.notAwayLabel : messages.awayLabel),
|
||||
onClick: () => {
|
||||
muteAway();
|
||||
setAway({
|
||||
variables: {
|
||||
away: !user.away,
|
||||
|
@ -23,6 +23,7 @@ import {
|
||||
sortVideoStreams,
|
||||
} from '/imports/ui/components/video-provider/stream-sorting';
|
||||
import getFromMeetingSettings from '/imports/ui/services/meeting-settings';
|
||||
import MediaStreamUtils from '/imports/utils/media-stream-utils';
|
||||
|
||||
const CAMERA_PROFILES = window.meetingClientSettings.public.kurento.cameraProfiles;
|
||||
const MULTIPLE_CAMERAS = window.meetingClientSettings.public.app.enableMultipleCameras;
|
||||
@ -1059,6 +1060,19 @@ class VideoService {
|
||||
updatePeerDictionaryReference(newRef) {
|
||||
this.webRtcPeersRef = newRef;
|
||||
}
|
||||
|
||||
setTrackEnabled(value) {
|
||||
const localPeers = Object.values(this.webRtcPeersRef).filter(
|
||||
(peer) => peer.isPublisher,
|
||||
);
|
||||
localPeers.forEach((peer) => {
|
||||
const stream = peer.getLocalStream();
|
||||
MediaStreamUtils.getVideoTracks(stream).forEach((track) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
track.enabled = value;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const videoService = new VideoService();
|
||||
@ -1120,4 +1134,5 @@ export default {
|
||||
fetchVideoStreams: () => videoService.fetchVideoStreams(),
|
||||
getGridUsers: (users = [], streams = []) => videoService.getGridUsers(users, streams),
|
||||
webcamsOnlyForModerators: () => videoService.webcamsOnlyForModerator(),
|
||||
setTrackEnabled: (value) => videoService.setTrackEnabled(value),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user