2017-08-05 04:05:18 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2017-10-31 02:27:17 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import VoiceUsers from '/imports/api/voice-users';
|
2017-08-05 04:05:18 +08:00
|
|
|
|
|
|
|
export default function muteToggle(credentials, userId) {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.redis;
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'MuteUserCmdMsg';
|
2017-10-31 03:15:43 +08:00
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
|
|
|
const ALLOW_MODERATOR_TO_UNMUTE_AUDIO = APP_CONFIG.allowModeratorToUnmuteAudio;
|
2017-11-03 03:23:27 +08:00
|
|
|
const USER_CONFIG = Meteor.settings.public.user;
|
|
|
|
const ROLE_MODERATOR = USER_CONFIG.role_moderator;
|
2017-08-05 04:05:18 +08:00
|
|
|
|
|
|
|
const { meetingId, requesterUserId } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
|
2017-11-25 06:02:14 +08:00
|
|
|
const requester = Users.findOne({
|
2017-10-31 02:27:17 +08:00
|
|
|
meetingId,
|
|
|
|
userId: requesterUserId,
|
|
|
|
});
|
|
|
|
|
2017-11-03 03:23:27 +08:00
|
|
|
const voiceUser = VoiceUsers.findOne({
|
2017-10-31 02:27:17 +08:00
|
|
|
intId: userId,
|
|
|
|
});
|
|
|
|
|
2017-11-25 06:02:14 +08:00
|
|
|
if (!requester || !voiceUser) return;
|
2017-11-03 03:23:27 +08:00
|
|
|
|
2017-11-25 06:02:14 +08:00
|
|
|
const { listenOnly, muted } = voiceUser;
|
|
|
|
if (listenOnly) return;
|
2017-11-03 03:23:27 +08:00
|
|
|
|
2017-11-25 06:02:14 +08:00
|
|
|
const isModerator = requester.roles.includes(ROLE_MODERATOR.toLowerCase());
|
2017-11-03 03:23:27 +08:00
|
|
|
const isNotHimself = requesterUserId !== userId;
|
|
|
|
|
2017-11-25 06:02:14 +08:00
|
|
|
// the ability for a moderator to unmute other users is configurable (on/off)
|
2017-11-03 03:23:27 +08:00
|
|
|
if (!ALLOW_MODERATOR_TO_UNMUTE_AUDIO &&
|
|
|
|
isModerator &&
|
2017-11-25 06:02:14 +08:00
|
|
|
muted &&
|
2017-11-03 03:23:27 +08:00
|
|
|
isNotHimself) return;
|
2017-10-31 02:27:17 +08:00
|
|
|
|
2017-11-25 06:02:14 +08:00
|
|
|
const payload = {
|
|
|
|
userId,
|
|
|
|
mutedBy: requesterUserId,
|
|
|
|
mute: !muted,
|
|
|
|
};
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
2017-09-08 00:47:20 +08:00
|
|
|
}
|