2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
2020-04-16 10:47:10 +00:00
|
|
|
import React from 'react';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../../app/types';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
|
|
|
import Icon from '../../../base/icons/components/Icon';
|
|
|
|
import { IconCheckSolid, IconExclamationTriangle } from '../../../base/icons/svg';
|
|
|
|
import { connect } from '../../../base/redux/functions';
|
2020-04-16 10:47:10 +00:00
|
|
|
import {
|
2022-09-27 07:10:28 +00:00
|
|
|
getDeviceStatusText,
|
|
|
|
getDeviceStatusType
|
2020-04-16 10:47:10 +00:00
|
|
|
} from '../../functions';
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
export interface IProps extends WithTranslation {
|
2020-04-16 10:47:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The text to be displayed in relation to the status of the audio/video devices.
|
|
|
|
*/
|
2022-10-17 09:28:04 +00:00
|
|
|
deviceStatusText?: string;
|
2020-04-16 10:47:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of status for current devices, controlling the background color of the text.
|
|
|
|
* Can be `ok` or `warning`.
|
|
|
|
*/
|
2022-10-17 09:28:04 +00:00
|
|
|
deviceStatusType?: string;
|
2022-08-25 11:35:19 +00:00
|
|
|
}
|
2020-04-16 10:47:10 +00:00
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
2022-03-15 10:48:05 +00:00
|
|
|
return {
|
|
|
|
deviceStatus: {
|
|
|
|
alignItems: 'center',
|
|
|
|
color: '#fff',
|
|
|
|
display: 'flex',
|
|
|
|
fontSize: '14px',
|
|
|
|
lineHeight: '20px',
|
|
|
|
padding: '6px',
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
|
|
'& span': {
|
|
|
|
marginLeft: theme.spacing(3)
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.device-status-error': {
|
|
|
|
alignItems: 'flex-start',
|
|
|
|
backgroundColor: theme.palette.warning01,
|
|
|
|
borderRadius: '6px',
|
|
|
|
color: theme.palette.uiBackground,
|
|
|
|
padding: '12px 16px',
|
|
|
|
textAlign: 'left'
|
|
|
|
},
|
|
|
|
'& .device-icon': {
|
|
|
|
backgroundPosition: 'center',
|
|
|
|
backgroundRepeat: 'no-repeat',
|
|
|
|
display: 'inline-block',
|
|
|
|
height: '16px',
|
|
|
|
width: '16px'
|
|
|
|
},
|
|
|
|
'& .device-icon--ok svg path': {
|
|
|
|
fill: '#189B55'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
const iconMap = {
|
|
|
|
warning: {
|
2021-09-17 10:12:34 +00:00
|
|
|
src: IconExclamationTriangle,
|
2021-08-20 08:53:11 +00:00
|
|
|
className: 'device-icon--warning'
|
2020-04-16 10:47:10 +00:00
|
|
|
},
|
|
|
|
ok: {
|
2021-08-20 08:53:11 +00:00
|
|
|
src: IconCheckSolid,
|
|
|
|
className: 'device-icon--ok'
|
2020-04-16 10:47:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip showing the current status of the devices.
|
|
|
|
* User is informed if there are missing or malfunctioning devices.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function DeviceStatus({ deviceStatusType, deviceStatusText, t }: IProps) {
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes, cx } = useStyles();
|
2022-08-25 11:35:19 +00:00
|
|
|
const { src, className } = iconMap[deviceStatusType as keyof typeof iconMap];
|
2021-09-17 10:12:34 +00:00
|
|
|
const hasError = deviceStatusType === 'warning';
|
2022-09-13 07:36:00 +00:00
|
|
|
const containerClassName = cx(classes.deviceStatus, { 'device-status-error': hasError });
|
2020-04-16 10:47:10 +00:00
|
|
|
|
|
|
|
return (
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
2021-09-17 10:12:34 +00:00
|
|
|
className = { containerClassName }
|
2021-06-10 12:48:44 +00:00
|
|
|
role = 'alert'
|
|
|
|
tabIndex = { -1 }>
|
2020-04-16 10:47:10 +00:00
|
|
|
<Icon
|
2021-08-20 08:53:11 +00:00
|
|
|
className = { `device-icon ${className}` }
|
2020-04-16 10:47:10 +00:00
|
|
|
size = { 16 }
|
|
|
|
src = { src } />
|
2021-09-17 10:12:34 +00:00
|
|
|
<span role = 'heading'>
|
2022-10-17 09:28:04 +00:00
|
|
|
{hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText ?? '')}
|
2021-06-10 12:48:44 +00:00
|
|
|
</span>
|
2020-04-16 10:47:10 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the React {@code Component} props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {{ deviceStatusText: string, deviceStatusText: string }}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function mapStateToProps(state: IReduxState) {
|
2020-04-16 10:47:10 +00:00
|
|
|
return {
|
|
|
|
deviceStatusText: getDeviceStatusText(state),
|
2021-09-17 10:12:34 +00:00
|
|
|
deviceStatusType: getDeviceStatusType(state)
|
2020-04-16 10:47:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(mapStateToProps)(DeviceStatus));
|