bigbluebutton-Github/bigbluebutton-html5/imports/api/1.1/breakouts/server/handlers/breakoutJoinURL.js

83 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-06-19 19:57:32 +08:00
import Breakouts from '/imports/api/1.1/breakouts';
2016-11-14 19:57:10 +08:00
import Logger from '/imports/startup/server/logger';
2016-11-15 00:12:54 +08:00
import { check } from 'meteor/check';
2017-03-21 02:37:55 +08:00
2016-11-14 19:57:10 +08:00
import xml2js from 'xml2js';
2016-11-29 03:48:02 +08:00
import url from 'url';
2016-11-30 00:52:15 +08:00
const xmlParser = new xml2js.Parser();
2016-11-14 19:57:10 +08:00
2017-06-03 03:25:02 +08:00
const getUrlParams = (urlToParse) => {
2016-11-29 03:48:02 +08:00
const options = { parseQueryString: true };
const parsedUrl = url.parse(urlToParse, options);
return parsedUrl.query;
2016-11-14 19:57:10 +08:00
};
2016-11-30 00:52:15 +08:00
export default function handleBreakoutJoinURL({ payload }) {
2016-11-14 19:57:10 +08:00
const REDIS_CONFIG = Meteor.settings.redis;
const CLIENT_HTML = 'HTML5';
2016-11-14 19:57:10 +08:00
const {
noRedirectJoinURL,
2016-11-14 19:57:10 +08:00
} = payload;
check(noRedirectJoinURL, String);
2016-11-15 00:12:54 +08:00
const urlParams = getUrlParams(noRedirectJoinURL);
2016-11-14 19:57:10 +08:00
const selector = {
externalMeetingId: urlParams.meetingID,
};
let breakout = Breakouts.findOne(selector);
const res = Meteor.http.call('get', noRedirectJoinURL);
xmlParser.parseString(res.content, (err, parsedXML) => {
2016-11-29 03:48:02 +08:00
if (err) {
2016-11-30 00:52:15 +08:00
return Logger.error(`An Error occured when parsing xml response for: ${noRedirectJoinURL}`);
2016-11-29 03:48:02 +08:00
}
breakout = Breakouts.findOne(selector);
const { response } = parsedXML;
2017-06-03 03:25:02 +08:00
const users = breakout.users;
2017-06-03 03:25:02 +08:00
const user = {
2016-11-14 19:57:10 +08:00
userId: payload.userId,
urlParams: {
meetingId: response.meeting_id[0],
userId: response.user_id[0],
authToken: response.auth_token[0],
},
2016-11-14 19:57:10 +08:00
};
const userExists = users.find(u => user.userId === u.userId);
if (userExists) {
return;
}
const modifier = {
$push: {
users: user,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding breakout to collection: ${err}`);
2016-11-14 19:57:10 +08:00
}
const {
insertedId,
} = numChanged;
if (insertedId) {
return Logger.info(`Added breakout id=${urlParams.meetingID}`);
}
return Logger.info(`Upserted breakout id=${urlParams.meetingID}`);
};
return Breakouts.upsert(selector, modifier, cb);
});
2016-11-14 19:57:10 +08:00
}