2018-11-15 01:11:10 +08:00
|
|
|
import React, { Component } from 'react';
|
2018-11-20 00:53:25 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2018-11-15 01:11:10 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import { setCustomLogoUrl } from '/imports/ui/components/user-list/service';
|
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
|
|
|
import logger from '/imports/startup/client/logger';
|
|
|
|
import LoadingScreen from '/imports/ui/components/loading-screen/component';
|
|
|
|
|
2018-11-16 23:58:49 +08:00
|
|
|
|
2018-11-15 01:11:10 +08:00
|
|
|
class JoinHandler extends Component {
|
|
|
|
static setError(codeError) {
|
|
|
|
Session.set('hasError', true);
|
|
|
|
if (codeError) Session.set('codeError', codeError);
|
|
|
|
}
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-11-19 23:40:42 +08:00
|
|
|
this.fetchToken = this.fetchToken.bind(this);
|
2018-11-15 01:11:10 +08:00
|
|
|
this.changeToJoin = this.changeToJoin.bind(this);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
joined: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-11-19 23:40:42 +08:00
|
|
|
this.fetchToken();
|
2018-11-15 01:11:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
changeToJoin(bool) {
|
|
|
|
this.setState({ joined: bool });
|
|
|
|
}
|
|
|
|
|
2018-11-19 23:40:42 +08:00
|
|
|
fetchToken() {
|
2018-11-15 01:11:10 +08:00
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const sessionToken = urlParams.get('sessionToken');
|
|
|
|
if (!sessionToken) {
|
|
|
|
JoinHandler.setError('404');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Old credentials stored in memory were being used when joining a new meeting
|
|
|
|
Auth.clearCredentials();
|
|
|
|
const logUserInfo = () => {
|
|
|
|
const userInfo = window.navigator;
|
|
|
|
|
|
|
|
// Browser information is sent once on startup
|
|
|
|
// Sent here instead of Meteor.startup, as the
|
|
|
|
// user might not be validated by then, thus user's data
|
|
|
|
// would not be sent with this information
|
|
|
|
const clientInfo = {
|
|
|
|
language: userInfo.language,
|
|
|
|
userAgent: userInfo.userAgent,
|
|
|
|
screenSize: { width: window.screen.width, height: window.screen.height },
|
|
|
|
windowSize: { width: window.innerWidth, height: window.innerHeight },
|
|
|
|
bbbVersion: Meteor.settings.public.app.bbbServerVersion,
|
|
|
|
location: window.location.href,
|
|
|
|
};
|
|
|
|
|
|
|
|
logger.info(clientInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
const setAuth = (resp) => {
|
|
|
|
const {
|
|
|
|
meetingID, internalUserID, authToken, logoutUrl,
|
|
|
|
fullname, externUserID, confname,
|
|
|
|
} = resp;
|
|
|
|
Auth.set(
|
|
|
|
meetingID, internalUserID, authToken, logoutUrl,
|
|
|
|
sessionToken, fullname, externUserID, confname,
|
|
|
|
);
|
|
|
|
return resp;
|
|
|
|
};
|
|
|
|
|
2018-11-30 06:37:51 +08:00
|
|
|
const setLogoutURL = (url) => {
|
|
|
|
Auth.logoutURL = url;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2018-11-19 23:40:42 +08:00
|
|
|
const setLogoURL = (resp) => {
|
2018-11-15 01:11:10 +08:00
|
|
|
setCustomLogoUrl(resp.customLogoURL);
|
|
|
|
return resp;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setCustomData = (resp) => {
|
|
|
|
const {
|
|
|
|
meetingID, internalUserID, customdata,
|
|
|
|
} = resp;
|
|
|
|
|
|
|
|
if (customdata.length) {
|
|
|
|
makeCall('addUserSettings', meetingID, internalUserID, customdata);
|
|
|
|
}
|
|
|
|
return resp;
|
|
|
|
};
|
|
|
|
// use enter api to get params for the client
|
|
|
|
const url = `/bigbluebutton/api/enter?sessionToken=${sessionToken}`;
|
|
|
|
|
|
|
|
const validAuth = new Promise((resolve, reject) => {
|
|
|
|
fetch(url, { credentials: 'same-origin' })
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(({ response }) => response)
|
|
|
|
.then((resp) => {
|
2018-11-21 04:13:34 +08:00
|
|
|
setLogoutURL(resp.logoutURL);
|
2018-11-16 23:58:49 +08:00
|
|
|
if (resp.returncode !== 'FAILED') {
|
2018-11-30 06:37:51 +08:00
|
|
|
logger.info(`User successfully went through main.joinRouteHandler with [${JSON.stringify(resp)}].`);
|
2018-11-16 23:58:49 +08:00
|
|
|
return resolve(resp);
|
|
|
|
}
|
2018-11-30 06:37:51 +08:00
|
|
|
const e = new Error('Session not found');
|
2018-11-16 23:58:49 +08:00
|
|
|
logger.error(`User faced [${e}] on main.joinRouteHandler. Error was:`, JSON.stringify(resp));
|
2018-11-15 01:11:10 +08:00
|
|
|
return reject(e);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
validAuth
|
|
|
|
.then(setCustomData)
|
|
|
|
.then(setAuth)
|
2018-11-19 23:40:42 +08:00
|
|
|
.then(setLogoURL)
|
2018-11-15 01:11:10 +08:00
|
|
|
.then(logUserInfo)
|
2018-11-16 23:58:49 +08:00
|
|
|
.then(() => Session.set('isUserListOpen', deviceInfo.type().isPhone))
|
2018-11-23 00:54:40 +08:00
|
|
|
.then(() => this.changeToJoin(true))
|
|
|
|
.catch(() => this.changeToJoin(true));
|
2018-11-15 01:11:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
const { joined } = this.state;
|
|
|
|
return joined ?
|
|
|
|
children :
|
|
|
|
(<LoadingScreen />);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default JoinHandler;
|