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

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-02-07 23:29:27 +08:00
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
import { isAllowedTo } from '/imports/startup/server/userPermissions';
2017-02-07 23:29:27 +08:00
import Users from '/imports/api/users';
2017-02-07 23:29:27 +08:00
import setConnectionStatus from '../modifiers/setConnectionStatus';
2017-02-10 20:24:14 +08:00
import listenOnlyToggle from './listenOnlyToggle';
export default function userLeaving(credentials, userId) {
const REDIS_CONFIG = Meteor.settings.redis;
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.meeting;
const EVENT_NAME = 'user_leaving_request';
const { meetingId, requesterUserId } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(userId, String);
// TODO: Should we check if requesterUserId is equal to userId?
const User = Users.findOne({
meetingId,
userId: requesterUserId,
});
if (!User) {
throw new Meteor.Error(
'user-not-found', `You need a valid user to be able to toggle audio`);
}
2017-02-07 23:29:27 +08:00
setConnectionStatus(meetingId, requesterUserId, 'offline');
if (User.user.listenOnly) {
2017-02-10 20:24:14 +08:00
listenOnlyToggle(credentials, false);
}
let payload = {
meeting_id: meetingId,
userid: userId,
};
Logger.verbose(`User '${requesterUserId}' ${isJoining ? 'joined' : 'left'} global audio from meeting '${meetingId}'`);
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
};