bigbluebutton-Github/bigbluebutton-html5/imports/api/voice-users/server/methods/muteToggle.js

67 lines
2.0 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { extractCredentials } from '/imports/api/common/server/helpers';
import RedisPubSub from '/imports/startup/server/redis';
import Users from '/imports/api/users';
import VoiceUsers from '/imports/api/voice-users';
import Meetings from '/imports/api/meetings';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
export default async function muteToggle(uId, toggle) {
try {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'MuteUserCmdMsg';
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
const userToMute = uId || requesterUserId;
const requester = await Users.findOneAsync({
meetingId,
userId: requesterUserId,
});
const voiceUser = await VoiceUsers.findOneAsync({
intId: userToMute,
meetingId,
});
if (!requester || !voiceUser) return;
const { listenOnly, muted } = voiceUser;
if (listenOnly) return;
// if allowModsToUnmuteUsers is false, users will be kicked out for attempting to unmute others
if (requesterUserId !== userToMute && muted) {
const meeting = await Meetings.findOneAsync({ meetingId },
{ fields: { 'usersProp.allowModsToUnmuteUsers': 1 } });
if (meeting.usersProp && !meeting.usersProp.allowModsToUnmuteUsers) {
Logger.warn(`Attempted unmuting by another user meetingId:${meetingId} requester: ${requesterUserId} userId: ${userToMute}`);
return;
}
}
let _muted;
if ((toggle === undefined) || (toggle === null)) {
_muted = !muted;
} else {
_muted = !!toggle;
}
const payload = {
userId: userToMute,
mutedBy: requesterUserId,
mute: _muted,
};
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} catch (err) {
Logger.error(`Exception while invoking method muteToggle ${err.stack}`);
}
}