bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/join-handler/component.jsx
Daniel Schreiber c46556e1f6 Allow BBB to run behind a proxy the avoid gUM permission queries per node
The idea is to run a loadbalancer node which maps each BBB node to a
path. That way each user gets only one gUM permission query for a
cluster. The loadbalancer node only serves the html5 client, each BBB
node will serve its own API and handle the websockets for freeswitch and
bbb-webrtc-sfu.

Configuring a cluster setup
===========================

* let bbb-lb.example.com be the loadbalancer node
* let bbb-01.eaxmple.com be a BBB node

Loadbalancer
------------

On the loadbalancer node add an nginx configuration similar to this one
for each BBB node:

```
location /bbb-01/html5client/ {
  proxy_pass https://bbb-01.example.com/bbb-01/html5client/;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "Upgrade";
}

```

BBB Node
--------

On the BBB node add the following options to
`/etc/bigbluebutton/bbb-web.properties`:

```
defaultHTML5ClientUrl=https://bbb-lb.example.com/bbb-01/html5client/join
presentationBaseURL=https://bbb-01.example.com/bigbluebutton/presentation
accessControlAllowOrigin=https://bbb-lb.example.com
```

Add the following options to `/etc/bigbluebutton/bbb-html5.yml`:

```
public:
  app:
    basename: '/bbb-01/html5client'
    bbbWebBase: 'https://bbb-01.eaxmple.com/bigbluebutton'
    learningDashboardBase: 'https://bbb-01.eaxmple.com/learning-dashboard'
  media:
    stunTurnServersFetchAddress: 'https://bbb-01.eaxmple.com/bigbluebutton/api/stuns'
    sip_ws_host: 'bbb-01.eaxmple.com'
  presentation:
    uploadEndpoint: 'https://bbb-01.eaxmple.com/bigbluebutton/presentation/upload'
```

Create the following unit file overrides:

* `/etc/systemd/system/bbb-html5-frontend@.service.d/cluster.conf`
* `/etc/systemd/system/bbb-html5-backend@.service.d/cluster.conf`

with the following content:

```
[Service]
Environment=ROOT_URL=https://127.0.0.1/bbb-01/html5client
```

Change the nginx `$bbb_loadbalancer_node` variable to the name of the
load balancer node in `/etc/bigbluebutton/nginx/loadbalancer.nginx` to
allow CORS requests:

```
set $bbb_loadbalancer_node https://bbb-lb.example.com
```

Prepend the mount point of bbb-html5 in all location sections except
from the `location @html5client` section in
`/etc/bigbluebutton/nginx/bbb-html5.nginx`

```
location @html5client {
    ...
}
location /bbb-01/html5client/locales {
    ...
}
```
2021-11-20 22:13:47 +01:00

234 lines
6.8 KiB
JavaScript
Executable File

import React, { Component } from 'react';
import { Session } from 'meteor/session';
import PropTypes from 'prop-types';
import SanitizeHTML from 'sanitize-html';
import Auth from '/imports/ui/services/auth';
import { setCustomLogoUrl, setModeratorOnlyMessage } from '/imports/ui/components/user-list/service';
import { makeCall } from '/imports/ui/services/api';
import logger from '/imports/startup/client/logger';
import LoadingScreen from '/imports/ui/components/loading-screen/component';
import Users from '/imports/api/users';
const propTypes = {
children: PropTypes.element.isRequired,
};
class JoinHandler extends Component {
static setError(codeError) {
if (codeError) Session.set('codeError', codeError);
}
constructor(props) {
super(props);
this.fetchToken = this.fetchToken.bind(this);
this.state = {
joined: false,
};
}
componentDidMount() {
this._isMounted = true;
if (!this.firstJoinTime) {
this.firstJoinTime = new Date();
}
Tracker.autorun((c) => {
const {
connected,
status,
} = Meteor.status();
if (status === 'connecting') {
this.setState({ joined: false });
}
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;
}
});
}
componentWillUnmount() {
this._isMounted = false;
}
async fetchToken() {
const APP = Meteor.settings.public.app;
if (!this._isMounted) return;
const urlParams = new URLSearchParams(window.location.search);
const sessionToken = urlParams.get('sessionToken');
if (!sessionToken) {
JoinHandler.setError('400');
Session.set('errorMessageDescription', 'Session token was not provided');
}
// 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({
logCode: 'joinhandler_component_clientinfo',
extraInfo: { clientInfo },
},
'Log information about the client');
};
const setAuth = (resp) => {
const {
meetingID, internalUserID, authToken, logoutUrl,
fullname, externUserID, confname,
} = resp;
return new Promise((resolve) => {
Auth.set(
meetingID, internalUserID, authToken, logoutUrl,
sessionToken, fullname, externUserID, confname,
);
resolve(resp);
});
};
const setLogoutURL = (url) => {
Auth.logoutURL = url;
return true;
};
const setLogoURL = (resp) => {
setCustomLogoUrl(resp.customLogoURL);
return resp;
};
const setModOnlyMessage = (resp) => {
if (resp && resp.modOnlyMessage) {
const sanitizedModOnlyText = SanitizeHTML(resp.modOnlyMessage, {
allowedTags: ['a', 'b', 'br', 'i', 'img', 'li', 'small', 'span', 'strong', 'u', 'ul'],
allowedAttributes: {
a: ['href', 'name', 'target'],
img: ['src', 'width', 'height'],
},
allowedSchemes: ['https'],
});
setModeratorOnlyMessage(sanitizedModOnlyText);
}
return resp;
};
const setCustomData = (resp) => {
const { customdata } = resp;
return new Promise((resolve) => {
if (customdata.length) {
makeCall('addUserSettings', customdata).then((r) => resolve(r));
}
resolve(true);
});
};
const setBannerProps = (resp) => {
Session.set('bannerText', resp.bannerText);
Session.set('bannerColor', resp.bannerColor);
};
// use enter api to get params for the client
const url = `${APP.bbbWebBase}/api/enter?sessionToken=${sessionToken}`;
const fetchContent = await fetch(url, { credentials: 'include' });
const parseToJson = await fetchContent.json();
const { response } = parseToJson;
setLogoutURL(response);
logUserInfo();
if (response.returncode !== 'FAILED') {
await setAuth(response);
setBannerProps(response);
setLogoURL(response);
setModOnlyMessage(response);
Tracker.autorun(async (cd) => {
const user = Users.findOne({ userId: Auth.userID, approved: true }, { fields: { _id: 1 } });
if (user) {
await setCustomData(response);
cd.stop();
}
});
logger.info({
logCode: 'joinhandler_component_joinroutehandler_success',
extraInfo: {
response,
},
}, 'User successfully went through main.joinRouteHandler');
} else {
const e = new Error(response.message);
if (!Session.get('codeError')) Session.set('errorMessageDescription', response.message);
logger.error({
logCode: 'joinhandler_component_joinroutehandler_error',
extraInfo: {
response,
error: e,
},
}, 'User faced an error on main.joinRouteHandler.');
}
this.setState({ joined: true });
}
render() {
const { children } = this.props;
const { joined } = this.state;
return joined
? children
: (<LoadingScreen />);
}
}
export default JoinHandler;
JoinHandler.propTypes = propTypes;