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-12-18 23:15:51 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2020-07-29 23:31:00 +08:00
|
|
|
import SanitizeHTML from 'sanitize-html';
|
2018-11-15 01:11:10 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2020-05-21 03:54:08 +08:00
|
|
|
import { setCustomLogoUrl, setModeratorOnlyMessage } from '/imports/ui/components/user-list/service';
|
2018-11-15 01:11:10 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
import logger from '/imports/startup/client/logger';
|
2022-02-15 22:55:08 +08:00
|
|
|
import LoadingScreen from '/imports/ui/components/common/loading-screen/component';
|
2021-10-05 04:01:20 +08:00
|
|
|
import { CurrentUser } from '/imports/api/users';
|
2018-11-15 01:11:10 +08:00
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
const propTypes = {
|
|
|
|
children: PropTypes.element.isRequired,
|
|
|
|
};
|
2018-11-16 23:58:49 +08:00
|
|
|
|
2018-11-15 01:11:10 +08:00
|
|
|
class JoinHandler extends Component {
|
2019-08-17 05:38:17 +08:00
|
|
|
static setError(codeError) {
|
|
|
|
if (codeError) Session.set('codeError', codeError);
|
|
|
|
}
|
|
|
|
|
2018-11-15 01:11:10 +08:00
|
|
|
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.state = {
|
|
|
|
joined: false,
|
2021-10-20 04:35:39 +08:00
|
|
|
hasAlreadyJoined: false,
|
2018-11-15 01:11:10 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-07-13 03:22:47 +08:00
|
|
|
this._isMounted = true;
|
2019-08-20 00:24:27 +08:00
|
|
|
|
|
|
|
if (!this.firstJoinTime) {
|
|
|
|
this.firstJoinTime = new Date();
|
|
|
|
}
|
|
|
|
Tracker.autorun((c) => {
|
|
|
|
const {
|
|
|
|
connected,
|
|
|
|
status,
|
|
|
|
} = Meteor.status();
|
2021-10-20 04:35:39 +08:00
|
|
|
const { hasAlreadyJoined } = this.state;
|
|
|
|
if (status === 'connecting' && !hasAlreadyJoined) {
|
2020-09-01 20:07:56 +08:00
|
|
|
this.setState({ joined: false });
|
|
|
|
}
|
|
|
|
|
2019-08-20 00:24:27 +08:00
|
|
|
logger.debug(`Initial connection status change. status: ${status}, connected: ${connected}`);
|
|
|
|
if (connected) {
|
|
|
|
const msToConnect = (new Date() - this.firstJoinTime) / 1000;
|
|
|
|
const secondsToConnect = parseFloat(msToConnect).toFixed(2);
|
|
|
|
|
|
|
|
logger.info({
|
|
|
|
logCode: 'joinhandler_component_initial_connection_time',
|
|
|
|
extraInfo: {
|
|
|
|
attemptForUserInfo: Auth.fullInfo,
|
|
|
|
timeToConnect: secondsToConnect,
|
|
|
|
},
|
|
|
|
}, `Connection to Meteor took ${secondsToConnect}s`);
|
|
|
|
|
|
|
|
this.firstJoinTime = undefined;
|
|
|
|
this.fetchToken();
|
|
|
|
} else if (status === 'failed') {
|
|
|
|
c.stop();
|
|
|
|
|
|
|
|
const msToConnect = (new Date() - this.firstJoinTime) / 1000;
|
|
|
|
const secondsToConnect = parseFloat(msToConnect).toFixed(2);
|
|
|
|
logger.info({
|
|
|
|
logCode: 'joinhandler_component_initial_connection_failed',
|
|
|
|
extraInfo: {
|
|
|
|
attemptForUserInfo: Auth.fullInfo,
|
|
|
|
timeToConnect: secondsToConnect,
|
|
|
|
},
|
|
|
|
}, `Connection to Meteor failed, took ${secondsToConnect}s`);
|
|
|
|
|
|
|
|
JoinHandler.setError('400');
|
|
|
|
Session.set('errorMessageDescription', 'Failed to connect to server');
|
|
|
|
this.firstJoinTime = undefined;
|
|
|
|
}
|
|
|
|
});
|
2018-11-15 01:11:10 +08:00
|
|
|
}
|
|
|
|
|
2019-07-13 03:22:47 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
this._isMounted = false;
|
|
|
|
}
|
|
|
|
|
2018-12-10 23:52:25 +08:00
|
|
|
async fetchToken() {
|
2021-10-20 04:35:39 +08:00
|
|
|
const { hasAlreadyJoined } = this.state;
|
2021-11-19 05:52:20 +08:00
|
|
|
const APP = Meteor.settings.public.app;
|
2019-07-13 03:22:47 +08:00
|
|
|
if (!this._isMounted) return;
|
|
|
|
|
2018-11-15 01:11:10 +08:00
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const sessionToken = urlParams.get('sessionToken');
|
2019-01-09 02:38:26 +08:00
|
|
|
|
2018-11-15 01:11:10 +08:00
|
|
|
if (!sessionToken) {
|
2019-08-17 05:38:17 +08:00
|
|
|
JoinHandler.setError('400');
|
2019-01-09 02:38:26 +08:00
|
|
|
Session.set('errorMessageDescription', 'Session token was not provided');
|
2018-11-15 01:11:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Old credentials stored in memory were being used when joining a new meeting
|
2021-10-20 04:35:39 +08:00
|
|
|
if (!hasAlreadyJoined) {
|
|
|
|
Auth.clearCredentials();
|
|
|
|
}
|
2018-11-15 01:11:10 +08:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2019-06-29 05:45:50 +08:00
|
|
|
logger.info({
|
|
|
|
logCode: 'joinhandler_component_clientinfo',
|
|
|
|
extraInfo: { clientInfo },
|
|
|
|
},
|
2019-07-19 05:37:56 +08:00
|
|
|
'Log information about the client');
|
2018-11-15 01:11:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const setAuth = (resp) => {
|
|
|
|
const {
|
|
|
|
meetingID, internalUserID, authToken, logoutUrl,
|
|
|
|
fullname, externUserID, confname,
|
|
|
|
} = resp;
|
2018-12-10 23:52:25 +08:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
Auth.set(
|
|
|
|
meetingID, internalUserID, authToken, logoutUrl,
|
|
|
|
sessionToken, fullname, externUserID, confname,
|
|
|
|
);
|
|
|
|
resolve(resp);
|
|
|
|
});
|
2018-11-15 01:11:10 +08:00
|
|
|
};
|
|
|
|
|
2018-11-30 06:37:51 +08:00
|
|
|
const setLogoutURL = (url) => {
|
|
|
|
Auth.logoutURL = url;
|
|
|
|
return true;
|
2018-11-15 01:11:10 +08:00
|
|
|
};
|
|
|
|
|
2018-11-19 23:40:42 +08:00
|
|
|
const setLogoURL = (resp) => {
|
2018-11-15 01:11:10 +08:00
|
|
|
setCustomLogoUrl(resp.customLogoURL);
|
|
|
|
return resp;
|
|
|
|
};
|
|
|
|
|
2020-05-21 03:54:08 +08:00
|
|
|
const setModOnlyMessage = (resp) => {
|
|
|
|
if (resp && resp.modOnlyMessage) {
|
2020-07-29 23:31:00 +08:00
|
|
|
const sanitizedModOnlyText = SanitizeHTML(resp.modOnlyMessage, {
|
2020-08-11 04:59:09 +08:00
|
|
|
allowedTags: ['a', 'b', 'br', 'i', 'img', 'li', 'small', 'span', 'strong', 'u', 'ul'],
|
2020-07-29 23:31:00 +08:00
|
|
|
allowedAttributes: {
|
|
|
|
a: ['href', 'name', 'target'],
|
2020-08-11 04:59:09 +08:00
|
|
|
img: ['src', 'width', 'height'],
|
2020-07-29 23:31:00 +08:00
|
|
|
},
|
2020-07-30 04:08:47 +08:00
|
|
|
allowedSchemes: ['https'],
|
2020-07-29 23:31:00 +08:00
|
|
|
});
|
|
|
|
setModeratorOnlyMessage(sanitizedModOnlyText);
|
2020-05-21 03:54:08 +08:00
|
|
|
}
|
|
|
|
return resp;
|
|
|
|
};
|
|
|
|
|
2018-11-15 01:11:10 +08:00
|
|
|
const setCustomData = (resp) => {
|
2020-04-29 12:41:16 +08:00
|
|
|
const { customdata } = resp;
|
2018-11-15 01:11:10 +08:00
|
|
|
|
2018-12-10 23:52:25 +08:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
if (customdata.length) {
|
2021-10-05 04:01:20 +08:00
|
|
|
makeCall('addUserSettings', customdata).then((r) => resolve(r));
|
2018-12-10 23:52:25 +08:00
|
|
|
}
|
|
|
|
resolve(true);
|
|
|
|
});
|
2018-11-15 01:11:10 +08:00
|
|
|
};
|
2019-03-16 04:07:14 +08:00
|
|
|
|
|
|
|
const setBannerProps = (resp) => {
|
|
|
|
Session.set('bannerText', resp.bannerText);
|
|
|
|
Session.set('bannerColor', resp.bannerColor);
|
|
|
|
};
|
|
|
|
|
2018-11-15 01:11:10 +08:00
|
|
|
// use enter api to get params for the client
|
2021-11-19 05:52:20 +08:00
|
|
|
const url = `${APP.bbbWebBase}/api/enter?sessionToken=${sessionToken}`;
|
|
|
|
const fetchContent = await fetch(url, { credentials: 'include' });
|
2018-12-10 23:52:25 +08:00
|
|
|
const parseToJson = await fetchContent.json();
|
|
|
|
const { response } = parseToJson;
|
2019-01-08 00:26:23 +08:00
|
|
|
|
2023-09-13 20:37:58 +08:00
|
|
|
setLogoutURL(response.logoutUrl);
|
2020-10-08 03:50:17 +08:00
|
|
|
logUserInfo();
|
2019-08-17 05:38:17 +08:00
|
|
|
|
2018-12-10 23:52:25 +08:00
|
|
|
if (response.returncode !== 'FAILED') {
|
|
|
|
await setAuth(response);
|
2019-03-16 04:07:14 +08:00
|
|
|
|
|
|
|
setBannerProps(response);
|
2018-12-10 23:52:25 +08:00
|
|
|
setLogoURL(response);
|
2020-05-21 03:54:08 +08:00
|
|
|
setModOnlyMessage(response);
|
2018-12-18 11:28:47 +08:00
|
|
|
|
2020-05-05 09:16:52 +08:00
|
|
|
Tracker.autorun(async (cd) => {
|
2021-10-05 04:01:20 +08:00
|
|
|
const user = CurrentUser
|
|
|
|
.findOne({ userId: Auth.userID, approved: true }, { fields: { _id: 1 } });
|
2020-05-05 09:16:52 +08:00
|
|
|
if (user) {
|
|
|
|
await setCustomData(response);
|
|
|
|
cd.stop();
|
|
|
|
}
|
|
|
|
});
|
2019-07-31 03:41:03 +08:00
|
|
|
|
2019-06-29 05:45:50 +08:00
|
|
|
logger.info({
|
|
|
|
logCode: 'joinhandler_component_joinroutehandler_success',
|
|
|
|
extraInfo: {
|
|
|
|
response,
|
|
|
|
},
|
|
|
|
}, 'User successfully went through main.joinRouteHandler');
|
2018-12-10 23:52:25 +08:00
|
|
|
} else {
|
2022-11-24 21:17:48 +08:00
|
|
|
|
2022-11-26 03:17:28 +08:00
|
|
|
if(['missingSession','meetingForciblyEnded','notFound'].includes(response.messageKey)) {
|
2022-11-24 21:17:48 +08:00
|
|
|
JoinHandler.setError('410');
|
|
|
|
Session.set('errorMessageDescription', 'meeting_ended');
|
|
|
|
} else if(response.messageKey == "guestDeny") {
|
|
|
|
JoinHandler.setError('401');
|
|
|
|
Session.set('errorMessageDescription', 'guest_deny');
|
|
|
|
} else if(response.messageKey == "maxParticipantsReached") {
|
|
|
|
JoinHandler.setError('401');
|
|
|
|
Session.set('errorMessageDescription', 'max_participants_reason');
|
|
|
|
} else {
|
|
|
|
JoinHandler.setError('401');
|
|
|
|
Session.set('errorMessageDescription', response.message);
|
|
|
|
}
|
|
|
|
|
2019-06-29 05:45:50 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'joinhandler_component_joinroutehandler_error',
|
|
|
|
extraInfo: {
|
|
|
|
response,
|
2022-11-24 21:17:48 +08:00
|
|
|
error: new Error(response.message),
|
2019-06-29 05:45:50 +08:00
|
|
|
},
|
|
|
|
}, 'User faced an error on main.joinRouteHandler.');
|
2018-12-10 23:52:25 +08:00
|
|
|
}
|
2021-10-20 04:35:39 +08:00
|
|
|
this.setState({
|
|
|
|
joined: true,
|
|
|
|
hasAlreadyJoined: true,
|
|
|
|
});
|
2018-11-15 01:11:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
const { joined } = this.state;
|
2019-08-17 05:38:17 +08:00
|
|
|
return joined
|
|
|
|
? children
|
|
|
|
: (<LoadingScreen />);
|
2018-11-15 01:11:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-17 05:38:17 +08:00
|
|
|
export default JoinHandler;
|
2018-12-18 23:15:51 +08:00
|
|
|
|
|
|
|
JoinHandler.propTypes = propTypes;
|