2016-11-14 19:57:10 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
|
|
|
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
|
|
|
|
2016-11-29 03:48:02 +08:00
|
|
|
const getUrlParams = urlToParse => {
|
|
|
|
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;
|
2016-11-19 01:14:00 +08:00
|
|
|
const CLIENT_HTML = 'HTML5';
|
2016-11-14 19:57:10 +08:00
|
|
|
|
|
|
|
const {
|
2016-11-23 23:32:04 +08:00
|
|
|
noRedirectJoinURL,
|
2016-11-14 19:57:10 +08:00
|
|
|
} = payload;
|
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
check(noRedirectJoinURL, String);
|
2016-11-15 00:12:54 +08:00
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
const urlParams = getUrlParams(noRedirectJoinURL);
|
2016-11-14 19:57:10 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
externalMeetingId: urlParams.meetingID,
|
|
|
|
};
|
|
|
|
|
|
|
|
let breakout = Breakouts.findOne(selector);
|
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
breakout = Breakouts.findOne(selector);
|
|
|
|
|
|
|
|
const { response } = parsedXML;
|
|
|
|
let users = breakout.users;
|
|
|
|
|
|
|
|
let user = {
|
2016-11-14 19:57:10 +08:00
|
|
|
userId: payload.userId,
|
2016-11-23 23:32:04 +08:00
|
|
|
urlParams: {
|
|
|
|
meetingId: response.meeting_id[0],
|
|
|
|
userId: response.user_id[0],
|
|
|
|
authToken: response.auth_token[0],
|
|
|
|
},
|
2016-11-14 19:57:10 +08:00
|
|
|
};
|
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
const userExists = users.find(u => user.userId === u.userId);
|
2016-11-19 01:14:00 +08:00
|
|
|
|
2016-11-23 23:32:04 +08:00
|
|
|
if (userExists) {
|
|
|
|
return;
|
2016-11-19 01:14:00 +08:00
|
|
|
}
|
2016-11-23 23:32:04 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-23 23:32:04 +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
|
|
|
}
|