2021-10-19 04:52:59 +08:00
|
|
|
import React, { Fragment, PureComponent } from 'react';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2024-07-05 04:26:09 +08:00
|
|
|
import { useReactiveVar } from '@apollo/client';
|
2021-10-19 04:52:59 +08:00
|
|
|
import Styled from './styles';
|
|
|
|
import Icon from '/imports/ui/components/connection-status/icon/component';
|
|
|
|
import SettingsMenuContainer from '/imports/ui/components/settings/container';
|
2024-07-05 04:26:09 +08:00
|
|
|
import connectionStatus from '/imports/ui/core/graphql/singletons/connectionStatus';
|
|
|
|
import { getWorstStatus } from '../service';
|
2021-10-19 04:52:59 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
label: {
|
|
|
|
id: 'app.connection-status.label',
|
|
|
|
description: 'Connection status label',
|
|
|
|
},
|
|
|
|
settings: {
|
|
|
|
id: 'app.connection-status.settings',
|
|
|
|
description: 'Connection settings label',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
class ConnectionStatusIcon extends PureComponent {
|
2023-03-25 04:48:00 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = { isSettingsMenuModalOpen: false };
|
|
|
|
|
|
|
|
this.setSettingsMenuModalIsOpen = this.setSettingsMenuModalIsOpen.bind(this);
|
|
|
|
}
|
2024-07-05 04:26:09 +08:00
|
|
|
// eslint-disable-next-line
|
2021-10-19 04:52:59 +08:00
|
|
|
renderIcon(level = 'normal') {
|
2024-07-05 04:26:09 +08:00
|
|
|
return (
|
2021-10-19 04:52:59 +08:00
|
|
|
<Styled.IconWrapper>
|
|
|
|
<Icon
|
|
|
|
level={level}
|
|
|
|
grayscale
|
|
|
|
/>
|
|
|
|
</Styled.IconWrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
openAdjustSettings() {
|
2023-03-25 04:48:00 +08:00
|
|
|
this.setSettingsMenuModalIsOpen(true);
|
|
|
|
}
|
2021-10-19 04:52:59 +08:00
|
|
|
|
2023-03-25 04:48:00 +08:00
|
|
|
setSettingsMenuModalIsOpen(value) {
|
2024-07-05 04:26:09 +08:00
|
|
|
const { closeModal } = this.props;
|
|
|
|
|
|
|
|
this.setState({ isSettingsMenuModalOpen: value });
|
2023-03-25 04:48:00 +08:00
|
|
|
if (!value) {
|
|
|
|
closeModal();
|
|
|
|
}
|
2021-10-19 04:52:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
2024-07-05 04:26:09 +08:00
|
|
|
currentStatus,
|
2021-10-19 04:52:59 +08:00
|
|
|
} = this.props;
|
2023-12-06 20:12:25 +08:00
|
|
|
|
2021-10-19 04:52:59 +08:00
|
|
|
let color;
|
2023-12-06 20:12:25 +08:00
|
|
|
switch (currentStatus) {
|
2021-10-19 04:52:59 +08:00
|
|
|
case 'warning':
|
|
|
|
color = 'success';
|
|
|
|
break;
|
|
|
|
case 'danger':
|
|
|
|
color = 'warning';
|
|
|
|
break;
|
|
|
|
case 'critical':
|
|
|
|
color = 'danger';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
color = 'success';
|
|
|
|
}
|
|
|
|
|
2023-03-25 04:48:00 +08:00
|
|
|
const { isSettingsMenuModalOpen } = this.state;
|
|
|
|
|
2021-10-19 04:52:59 +08:00
|
|
|
return (
|
2024-07-05 04:26:09 +08:00
|
|
|
<>
|
2021-10-19 04:52:59 +08:00
|
|
|
<Styled.StatusIconWrapper color={color}>
|
2023-12-06 20:12:25 +08:00
|
|
|
{this.renderIcon(currentStatus)}
|
2021-10-19 04:52:59 +08:00
|
|
|
</Styled.StatusIconWrapper>
|
|
|
|
<Styled.Label>
|
|
|
|
{intl.formatMessage(intlMessages.label)}
|
|
|
|
</Styled.Label>
|
2023-12-06 20:12:25 +08:00
|
|
|
{(currentStatus === 'critical' || currentStatus === 'danger') || isSettingsMenuModalOpen
|
2022-06-09 23:01:05 +08:00
|
|
|
? (
|
2021-10-19 04:52:59 +08:00
|
|
|
<div>
|
|
|
|
<Styled.Settings
|
2024-07-05 04:26:09 +08:00
|
|
|
// eslint-disable-next-line
|
2021-10-19 04:52:59 +08:00
|
|
|
onClick={this.openAdjustSettings.bind(this)}
|
|
|
|
role="button"
|
|
|
|
>
|
|
|
|
{intl.formatMessage(intlMessages.settings)}
|
|
|
|
</Styled.Settings>
|
2024-07-05 04:26:09 +08:00
|
|
|
{isSettingsMenuModalOpen
|
|
|
|
? (
|
|
|
|
<SettingsMenuContainer
|
|
|
|
selectedTab={2}
|
|
|
|
{...{
|
|
|
|
onRequestClose: () => this.setSettingsMenuModalIsOpen(false),
|
|
|
|
priority: 'medium',
|
|
|
|
setIsOpen: this.setSettingsMenuModalIsOpen,
|
|
|
|
isOpen: isSettingsMenuModalOpen,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : null}
|
2021-10-19 04:52:59 +08:00
|
|
|
</div>
|
|
|
|
)
|
2022-06-09 23:01:05 +08:00
|
|
|
: (
|
|
|
|
<div> </div>
|
2024-07-05 04:26:09 +08:00
|
|
|
)}
|
|
|
|
</>
|
2021-10-19 04:52:59 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-05 04:26:09 +08:00
|
|
|
const WrapConnectionStatus = (props) => {
|
|
|
|
const rttStatus = useReactiveVar(connectionStatus.getRttStatusVar());
|
|
|
|
const packetLossStatus = useReactiveVar(connectionStatus.getPacketLossStatusVar());
|
2024-07-31 02:59:49 +08:00
|
|
|
const status = getWorstStatus([rttStatus, packetLossStatus]);
|
2024-07-05 04:26:09 +08:00
|
|
|
return (
|
|
|
|
<ConnectionStatusIcon
|
|
|
|
{...props}
|
|
|
|
currentStatus={status}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default injectIntl(WrapConnectionStatus);
|