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

179 lines
4.1 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';
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',
},
meeting_ended: {
id: 'app.meeting.endedMessage',
},
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',
},
max_participants_reason: {
id: 'app.meeting.logout.maxParticipantsReached',
},
guest_deny: {
id: 'app.guest.guestDeny',
},
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,
]),
error: PropTypes.object,
errorInfo: PropTypes.object,
2017-03-11 04:47:23 +08:00
};
const defaultProps = {
2022-10-18 00:35:23 +08:00
code: '500',
2023-12-08 02:37:04 +08:00
callback: () => {},
endedReason: null,
error: {},
errorInfo: null,
2017-03-11 04:47:23 +08:00
};
class ErrorScreen extends PureComponent {
componentDidMount() {
2023-12-08 02:37:04 +08:00
const { code, callback, endedReason } = this.props;
// stop audio
document.querySelector('audio').pause();
navigator
.mediaDevices
.getUserMedia({ audio: true, video: true })
.then((m) => m.getTracks().forEach((t) => t.stop()));
2023-12-08 02:37:04 +08:00
callback(endedReason, () => Meteor.disconnect());
console.error({ 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,
error,
errorInfo,
} = this.props;
let formatedMessage = 'Oops, something went wrong';
let errorMessageDescription = Session.get('errorMessageDescription');
if (intl) {
formatedMessage = intl.formatMessage(intlMessages[defaultProps.code]);
2017-03-11 04:47:23 +08:00
if (code in intlMessages) {
formatedMessage = intl.formatMessage(intlMessages[code]);
}
2017-03-11 04:47:23 +08:00
errorMessageDescription = Session.get('errorMessageDescription');
2017-03-11 04:47:23 +08:00
if (errorMessageDescription in intlMessages) {
errorMessageDescription = intl.formatMessage(intlMessages[errorMessageDescription]);
}
}
if (error) {
errorMessageDescription = error.message;
}
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
}
{
errorInfo
? (
<textarea
rows="5"
cols="33"
disabled
>
{JSON.stringify(errorInfo)}
</textarea>
)
: null
}
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
export { ErrorScreen };
2017-03-11 04:47:23 +08:00
ErrorScreen.propTypes = propTypes;
ErrorScreen.defaultProps = defaultProps;