bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/error-screen/component.jsx

141 lines
3.3 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
2017-03-11 04:47:23 +08:00
import { defineMessages, injectIntl } from 'react-intl';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import AudioManager from '/imports/ui/services/audio-manager';
import logger from '/imports/startup/client/logger';
2021-10-28 03:51:43 +08:00
import Styled from './styles';
2017-03-11 04:47:23 +08:00
const intlMessages = defineMessages({
503: {
id: 'app.error.503',
},
2017-03-11 04:47:23 +08:00
500: {
id: 'app.error.500',
defaultMessage: 'Oops, something went wrong',
2017-03-11 04:47:23 +08:00
},
2019-04-27 01:52:18 +08:00
410: {
id: 'app.error.410',
},
409: {
id: 'app.error.409',
},
408: {
id: 'app.error.408',
},
2017-03-11 04:47:23 +08:00
404: {
id: 'app.error.404',
defaultMessage: 'Not found',
2017-03-11 04:47:23 +08:00
},
2019-04-27 01:14:37 +08:00
403: {
id: 'app.error.403',
},
2017-03-11 04:47:23 +08:00
401: {
2017-04-18 01:14:31 +08:00
id: 'app.error.401',
2017-03-11 04:47:23 +08:00
},
400: {
id: 'app.error.400',
},
user_logged_out_reason: {
id: 'app.error.userLoggedOut',
},
validate_token_failed_eject_reason: {
id: 'app.error.ejectedUser',
},
banned_user_rejoining_reason: {
id: 'app.error.userBanned',
},
joined_another_window_reason: {
id: 'app.error.joinedAnotherWindow',
},
user_inactivity_eject_reason: {
id: 'app.meeting.logout.userInactivityEjectReason',
},
user_requested_eject_reason: {
id: 'app.meeting.logout.ejectedFromMeeting',
},
duplicate_user_in_meeting_eject_reason: {
id: 'app.meeting.logout.duplicateUserEjectReason',
},
not_enough_permission_eject_reason: {
id: 'app.meeting.logout.permissionEjectReason',
},
able_to_rejoin_user_disconnected_reason: {
id: 'app.error.disconnected.rejoin',
},
2017-03-11 04:47:23 +08:00
});
const propTypes = {
code: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
};
const defaultProps = {
2022-10-18 00:35:23 +08:00
code: '500',
callback: async () => {},
2017-03-11 04:47:23 +08:00
};
class ErrorScreen extends PureComponent {
componentDidMount() {
const { code, callback } = this.props;
2022-10-18 00:35:23 +08:00
const log = code === '403' ? 'warn' : 'error';
AudioManager.exitAudio();
callback().finally(() => {
Meteor.disconnect();
});
logger[log]({ logCode: 'startup_client_usercouldnotlogin_error' }, `User could not log in HTML5, hit ${code}`);
}
2017-03-11 04:47:23 +08:00
render() {
const {
intl,
code,
children,
} = this.props;
2017-03-11 04:47:23 +08:00
let formatedMessage = intl.formatMessage(intlMessages[defaultProps.code]);
2017-03-11 04:47:23 +08:00
if (code in intlMessages) {
formatedMessage = intl.formatMessage(intlMessages[code]);
}
let errorMessageDescription = Session.get('errorMessageDescription');
if (errorMessageDescription in intlMessages) {
errorMessageDescription = intl.formatMessage(intlMessages[errorMessageDescription]);
}
2017-03-11 04:47:23 +08:00
return (
2021-10-28 03:51:43 +08:00
<Styled.Background>
<Styled.Message data-test="errorScreenMessage">
2017-03-11 04:47:23 +08:00
{formatedMessage}
2021-10-28 03:51:43 +08:00
</Styled.Message>
2019-01-08 00:26:23 +08:00
{
!errorMessageDescription
|| formatedMessage === errorMessageDescription
|| (
2021-10-28 03:51:43 +08:00
<Styled.SessionMessage>
{errorMessageDescription}
2021-10-28 03:51:43 +08:00
</Styled.SessionMessage>
)
2019-01-08 00:26:23 +08:00
}
2021-10-28 03:51:43 +08:00
<Styled.Separator />
<Styled.CodeError>
2020-06-19 20:49:07 +08:00
{code}
2021-10-28 03:51:43 +08:00
</Styled.CodeError>
2018-12-06 01:42:31 +08:00
<div>
2017-03-11 04:47:23 +08:00
{children}
2017-04-29 04:16:07 +08:00
</div>
2021-10-28 03:51:43 +08:00
</Styled.Background>
2017-03-11 04:47:23 +08:00
);
}
}
export default injectIntl(ErrorScreen);
2017-03-11 04:47:23 +08:00
ErrorScreen.propTypes = propTypes;
ErrorScreen.defaultProps = defaultProps;