bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/requestUserLeaving.js

63 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-05-13 01:43:59 +08:00
import { publish } from '/imports/startup/server/helpers';
2016-05-17 02:05:44 +08:00
import Meetings from '/imports/api/meetings';
import Users from '/imports/api/users';
2016-05-13 01:43:59 +08:00
import { logger } from '/imports/startup/server/logger';
import { redisConfig } from '/config';
// Corresponds to a valid action on the HTML clientside
// After authorization, publish a user_leaving_request in redis
// params: meetingid, userid as defined in BBB-App
export function requestUserLeaving(meetingId, userId) {
2016-05-16 22:35:59 +08:00
let listenOnlyMessage, message, userObject, meetingObject, voiceConf;
userObject = Users.findOne({
meetingId: meetingId,
userId: userId,
});
meetingObject = Meetings.findOne({
meetingId: meetingId,
});
if (meetingObject != null) {
voiceConf = meetingObject.voiceConf;
}
2016-05-13 01:43:59 +08:00
2016-05-16 22:35:59 +08:00
if ((userObject != null) && (voiceConf != null) && (userId != null) && (meetingId != null)) {
let lOnly = false;
if (userObject.hasOwnProperty('user') && userObject.user.hasOwnProperty('listenOnly')) {
lOnly = userObject.user.listenOnly;
}
2016-05-13 01:43:59 +08:00
2016-05-16 22:35:59 +08:00
// end listenOnly audio for the departing user
if (null != lOnly && lOnly) {
listenOnlyMessage = {
payload: {
userid: userId,
meeting_id: meetingId,
voice_conf: voiceConf,
name: userObject.user.name,
},
header: {
timestamp: new Date().getTime(),
name: 'user_disconnected_from_global_audio',
},
};
publish(redisConfig.channels.toBBBApps.meeting, listenOnlyMessage);
2016-05-13 01:43:59 +08:00
}
2016-05-16 22:35:59 +08:00
// remove user from meeting
message = {
payload: {
meeting_id: meetingId,
userid: userId,
},
header: {
timestamp: new Date().getTime(),
name: 'user_leaving_request',
},
};
logger.info(`sending a user_leaving_request for ${meetingId}:${userId}`);
return publish(redisConfig.channels.toBBBApps.users, message);
} else {
return logger.info('did not have enough information to send a user_leaving_request');
}
2016-05-13 01:43:59 +08:00
};