2021-06-10 12:48:44 +00:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2022-08-26 09:54:03 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2022-08-26 09:54:03 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../../../app/types';
|
2022-08-26 09:54:03 +00:00
|
|
|
import { translate } from '../../../i18n/functions';
|
|
|
|
import Icon from '../../../icons/components/Icon';
|
2022-11-08 10:24:32 +00:00
|
|
|
import { IconArrowDown, IconWifi1Bar, IconWifi2Bars, IconWifi3Bars } from '../../../icons/svg';
|
2022-08-26 09:54:03 +00:00
|
|
|
import { connect } from '../../../redux/functions';
|
2022-03-15 11:28:16 +00:00
|
|
|
import { PREJOIN_DEFAULT_CONTENT_WIDTH } from '../../../ui/components/variables';
|
2020-07-29 10:27:32 +00:00
|
|
|
import { CONNECTION_TYPE } from '../../constants';
|
|
|
|
import { getConnectionData } from '../../functions';
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2020-07-29 10:27:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of strings with details about the connection.
|
|
|
|
*/
|
2022-10-17 09:28:04 +00:00
|
|
|
connectionDetails?: string[];
|
2020-07-29 10:27:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the connection. Can be: 'none', 'poor', 'nonOptimal' or 'good'.
|
|
|
|
*/
|
2022-10-17 09:28:04 +00:00
|
|
|
connectionType?: string;
|
2020-07-29 10:27:32 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 07:50:22 +00:00
|
|
|
const useStyles = makeStyles()(theme => {
|
2022-03-15 11:28:16 +00:00
|
|
|
return {
|
|
|
|
connectionStatus: {
|
|
|
|
borderRadius: '6px',
|
|
|
|
color: '#fff',
|
|
|
|
fontSize: '12px',
|
|
|
|
letterSpacing: '0.16px',
|
|
|
|
lineHeight: '16px',
|
|
|
|
position: 'absolute',
|
|
|
|
width: '100%',
|
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
[theme.breakpoints.down(400)]: {
|
2022-03-15 11:28:16 +00:00
|
|
|
margin: 0,
|
|
|
|
width: '100%'
|
|
|
|
},
|
|
|
|
|
2022-03-16 13:16:01 +00:00
|
|
|
'@media (max-width: 720px)': {
|
2022-03-15 11:28:16 +00:00
|
|
|
margin: `${theme.spacing(4)} auto`,
|
|
|
|
position: 'fixed',
|
|
|
|
top: 0,
|
|
|
|
width: PREJOIN_DEFAULT_CONTENT_WIDTH
|
|
|
|
},
|
|
|
|
|
|
|
|
// mobile phone landscape
|
|
|
|
'@media (max-height: 420px)': {
|
|
|
|
display: 'none'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-header': {
|
|
|
|
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
|
|
|
alignItems: 'center',
|
|
|
|
display: 'flex',
|
|
|
|
padding: '14px 16px'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-circle': {
|
|
|
|
borderRadius: '50%',
|
|
|
|
display: 'inline-block',
|
|
|
|
padding: theme.spacing(1),
|
|
|
|
marginRight: theme.spacing(3)
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status--good': {
|
|
|
|
background: '#31B76A'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status--poor': {
|
|
|
|
background: '#E12D2D'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status--non-optimal': {
|
|
|
|
background: '#E39623'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-arrow': {
|
|
|
|
marginLeft: 'auto',
|
|
|
|
transition: 'background-color 0.16s ease-out'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-arrow--up': {
|
|
|
|
transform: 'rotate(180deg)'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-arrow > svg': {
|
|
|
|
cursor: 'pointer'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-arrow:hover': {
|
|
|
|
backgroundColor: 'rgba(1, 1, 1, 0.1)'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-text': {
|
|
|
|
textAlign: 'center'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-details': {
|
|
|
|
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
|
|
|
borderTop: '1px solid #5E6D7A',
|
|
|
|
padding: theme.spacing(3),
|
|
|
|
transition: 'opacity 0.16s ease-out'
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-details-visible': {
|
|
|
|
opacity: 1
|
|
|
|
},
|
|
|
|
|
|
|
|
'& .con-status-details-hidden': {
|
|
|
|
opacity: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-09-06 17:32:20 +00:00
|
|
|
const CONNECTION_TYPE_MAP: {
|
|
|
|
[key: string]: {
|
|
|
|
connectionClass: string;
|
|
|
|
connectionText: string;
|
|
|
|
icon: Function;
|
2022-09-08 09:52:36 +00:00
|
|
|
};
|
2022-09-06 17:32:20 +00:00
|
|
|
} = {
|
2020-07-29 10:27:32 +00:00
|
|
|
[CONNECTION_TYPE.POOR]: {
|
|
|
|
connectionClass: 'con-status--poor',
|
|
|
|
icon: IconWifi1Bar,
|
|
|
|
connectionText: 'prejoin.connection.poor'
|
|
|
|
},
|
|
|
|
[CONNECTION_TYPE.NON_OPTIMAL]: {
|
|
|
|
connectionClass: 'con-status--non-optimal',
|
|
|
|
icon: IconWifi2Bars,
|
|
|
|
connectionText: 'prejoin.connection.nonOptimal'
|
|
|
|
},
|
|
|
|
[CONNECTION_TYPE.GOOD]: {
|
|
|
|
connectionClass: 'con-status--good',
|
|
|
|
icon: IconWifi3Bars,
|
|
|
|
connectionText: 'prejoin.connection.good'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component displaying information related to the connection & audio/video quality.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IProps} props - The props of the component.
|
2020-07-29 10:27:32 +00:00
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function ConnectionStatus({ connectionDetails, t, connectionType }: IProps) {
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes } = useStyles();
|
2022-03-15 11:28:16 +00:00
|
|
|
|
2020-07-29 10:27:32 +00:00
|
|
|
const [ showDetails, toggleDetails ] = useState(false);
|
|
|
|
const arrowClassName = showDetails
|
|
|
|
? 'con-status-arrow con-status-arrow--up'
|
|
|
|
: 'con-status-arrow';
|
2022-10-17 09:28:04 +00:00
|
|
|
const detailsText = connectionDetails?.map(d => t(d)).join(' ');
|
2020-09-29 11:00:30 +00:00
|
|
|
const detailsClassName = showDetails
|
|
|
|
? 'con-status-details-visible'
|
|
|
|
: 'con-status-details-hidden';
|
2020-07-29 10:27:32 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const onToggleDetails = useCallback(e => {
|
|
|
|
e.preventDefault();
|
|
|
|
toggleDetails(!showDetails);
|
|
|
|
}, [ showDetails, toggleDetails ]);
|
|
|
|
|
|
|
|
const onKeyPressToggleDetails = useCallback(e => {
|
|
|
|
if (toggleDetails && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
e.preventDefault();
|
|
|
|
toggleDetails(!showDetails);
|
|
|
|
}
|
|
|
|
}, [ showDetails, toggleDetails ]);
|
|
|
|
|
2022-03-16 08:59:24 +00:00
|
|
|
if (connectionType === CONNECTION_TYPE.NONE) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-10-17 09:28:04 +00:00
|
|
|
const { connectionClass, icon, connectionText } = CONNECTION_TYPE_MAP[connectionType ?? ''];
|
2022-03-16 08:59:24 +00:00
|
|
|
|
2020-07-29 10:27:32 +00:00
|
|
|
return (
|
2022-03-15 11:28:16 +00:00
|
|
|
<div className = { classes.connectionStatus }>
|
2021-08-20 08:53:11 +00:00
|
|
|
<div
|
|
|
|
aria-level = { 1 }
|
|
|
|
className = 'con-status-header'
|
|
|
|
role = 'heading'>
|
|
|
|
<div className = { `con-status-circle ${connectionClass}` }>
|
2020-07-29 10:27:32 +00:00
|
|
|
<Icon
|
2021-08-20 08:53:11 +00:00
|
|
|
size = { 16 }
|
|
|
|
src = { icon } />
|
2020-07-29 10:27:32 +00:00
|
|
|
</div>
|
2021-08-20 08:53:11 +00:00
|
|
|
<span
|
|
|
|
aria-hidden = { !showDetails }
|
|
|
|
className = 'con-status-text'
|
|
|
|
id = 'connection-status-description'>{t(connectionText)}</span>
|
|
|
|
<Icon
|
|
|
|
ariaDescribedBy = 'connection-status-description'
|
|
|
|
ariaPressed = { showDetails }
|
|
|
|
className = { arrowClassName }
|
|
|
|
onClick = { onToggleDetails }
|
|
|
|
onKeyPress = { onKeyPressToggleDetails }
|
|
|
|
role = 'button'
|
|
|
|
size = { 24 }
|
2022-11-08 10:24:32 +00:00
|
|
|
src = { IconArrowDown }
|
2021-08-20 08:53:11 +00:00
|
|
|
tabIndex = { 0 } />
|
2020-07-29 10:27:32 +00:00
|
|
|
</div>
|
2021-08-20 08:53:11 +00:00
|
|
|
<div
|
2022-08-26 09:54:03 +00:00
|
|
|
aria-level = { 2 }
|
2021-08-20 08:53:11 +00:00
|
|
|
className = { `con-status-details ${detailsClassName}` }
|
|
|
|
role = 'heading'>
|
|
|
|
{detailsText}</div>
|
2020-07-29 10:27:32 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the React {@code Component} props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function mapStateToProps(state: IReduxState): Object {
|
2020-07-29 10:27:32 +00:00
|
|
|
const { connectionDetails, connectionType } = getConnectionData(state);
|
|
|
|
|
|
|
|
return {
|
|
|
|
connectionDetails,
|
|
|
|
connectionType
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(mapStateToProps)(ConnectionStatus));
|