2016-06-02 01:18:13 +08:00
|
|
|
import { publish } from '/imports/api/common/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-06-28 02:24:37 +08:00
|
|
|
let voiceConf;
|
2016-06-28 05:48:46 +08:00
|
|
|
const userObject = Users.findOne({
|
2016-05-16 22:35:59 +08:00
|
|
|
meetingId: meetingId,
|
|
|
|
userId: userId,
|
|
|
|
});
|
2016-06-28 05:48:46 +08:00
|
|
|
const meetingObject = Meetings.findOne({
|
2016-05-16 22:35:59 +08:00
|
|
|
meetingId: meetingId,
|
|
|
|
});
|
2016-06-28 05:48:46 +08:00
|
|
|
|
2016-05-16 22:35:59 +08:00
|
|
|
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
|
2016-06-28 02:24:37 +08:00
|
|
|
if (lOnly) {
|
2016-06-28 05:48:46 +08:00
|
|
|
const listenOnlyMessage = {
|
2016-05-16 22:35:59 +08:00
|
|
|
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
|
2016-06-28 05:48:46 +08:00
|
|
|
const message = {
|
2016-05-16 22:35:59 +08:00
|
|
|
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
|
|
|
};
|