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

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-08-05 04:05:18 +08:00
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';
2017-08-05 04:05:18 +08:00
export default function muteToggle(uId, toggle) {
2021-05-06 02:05:59 +08:00
try {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'MuteUserCmdMsg';
2017-08-05 04:05:18 +08:00
2021-05-06 02:05:59 +08:00
const { meetingId, requesterUserId } = extractCredentials(this.userId);
2021-05-06 02:05:59 +08:00
check(meetingId, String);
check(requesterUserId, String);
2021-05-06 02:05:59 +08:00
const userToMute = uId || requesterUserId;
2017-08-05 04:05:18 +08:00
2021-05-06 02:05:59 +08:00
const requester = Users.findOne({
meetingId,
userId: requesterUserId,
});
2021-05-06 02:05:59 +08:00
const voiceUser = VoiceUsers.findOne({
intId: userToMute,
meetingId,
});
2021-05-06 02:05:59 +08:00
if (!requester || !voiceUser) return;
2017-11-03 03:23:27 +08:00
2021-05-06 02:05:59 +08:00
const { listenOnly, muted } = voiceUser;
if (listenOnly) return;
2017-11-03 03:23:27 +08:00
2021-05-06 02:05:59 +08:00
// if allowModsToUnmuteUsers is false, users will be kicked out for attempting to unmute others
if (requesterUserId !== userToMute && muted) {
const meeting = Meetings.findOne({ 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;
}
}
2021-05-06 02:05:59 +08:00
let _muted;
2021-05-06 02:05:59 +08:00
if ((toggle === undefined) || (toggle === null)) {
_muted = !muted;
} else {
_muted = !!toggle;
}
2021-05-06 02:05:59 +08:00
const payload = {
userId: userToMute,
mutedBy: requesterUserId,
mute: _muted,
};
2017-11-25 06:02:14 +08:00
2021-05-06 02:05:59 +08:00
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} catch (err) {
Logger.error(`Exception while invoking method muteToggle ${err.stack}`);
}
2017-09-08 00:47:20 +08:00
}