You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeviceStatus.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { makeStyles } from 'tss-react/mui';
  4. import { IReduxState } from '../../../../app/types';
  5. import { translate } from '../../../../base/i18n/functions';
  6. import Icon from '../../../../base/icons/components/Icon';
  7. import { IconCheck, IconExclamationTriangle } from '../../../../base/icons/svg';
  8. import { connect } from '../../../../base/redux/functions';
  9. import {
  10. getDeviceStatusText,
  11. getDeviceStatusType
  12. } from '../../../functions';
  13. export interface IProps extends WithTranslation {
  14. /**
  15. * The text to be displayed in relation to the status of the audio/video devices.
  16. */
  17. deviceStatusText?: string;
  18. /**
  19. * The type of status for current devices, controlling the background color of the text.
  20. * Can be `ok` or `warning`.
  21. */
  22. deviceStatusType?: string;
  23. }
  24. const useStyles = makeStyles()(theme => {
  25. return {
  26. deviceStatus: {
  27. alignItems: 'center',
  28. color: '#fff',
  29. display: 'flex',
  30. fontSize: '14px',
  31. lineHeight: '20px',
  32. padding: '6px',
  33. textAlign: 'center',
  34. '& span': {
  35. marginLeft: theme.spacing(3)
  36. },
  37. '&.device-status-error': {
  38. alignItems: 'flex-start',
  39. backgroundColor: theme.palette.warning01,
  40. borderRadius: '6px',
  41. color: theme.palette.uiBackground,
  42. padding: '12px 16px',
  43. textAlign: 'left'
  44. },
  45. '& .device-icon': {
  46. backgroundPosition: 'center',
  47. backgroundRepeat: 'no-repeat',
  48. display: 'inline-block',
  49. height: '16px',
  50. width: '16px'
  51. },
  52. '& .device-icon--ok svg path': {
  53. fill: '#189B55'
  54. }
  55. }
  56. };
  57. });
  58. const iconMap = {
  59. warning: {
  60. src: IconExclamationTriangle,
  61. className: 'device-icon--warning'
  62. },
  63. ok: {
  64. src: IconCheck,
  65. className: 'device-icon--ok'
  66. }
  67. };
  68. /**
  69. * Strip showing the current status of the devices.
  70. * User is informed if there are missing or malfunctioning devices.
  71. *
  72. * @returns {ReactElement}
  73. */
  74. function DeviceStatus({ deviceStatusType, deviceStatusText, t }: IProps) {
  75. const { classes, cx } = useStyles();
  76. const { src, className } = iconMap[deviceStatusType as keyof typeof iconMap];
  77. const hasError = deviceStatusType === 'warning';
  78. const containerClassName = cx(classes.deviceStatus, { 'device-status-error': hasError });
  79. return (
  80. <div
  81. className = { containerClassName }
  82. role = 'alert'
  83. tabIndex = { -1 }>
  84. <Icon
  85. className = { `device-icon ${className}` }
  86. size = { 16 }
  87. src = { src } />
  88. <span role = 'heading'>
  89. {hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText ?? '')}
  90. </span>
  91. </div>
  92. );
  93. }
  94. /**
  95. * Maps (parts of) the redux state to the React {@code Component} props.
  96. *
  97. * @param {Object} state - The redux state.
  98. * @returns {{ deviceStatusText: string, deviceStatusText: string }}
  99. */
  100. function mapStateToProps(state: IReduxState) {
  101. return {
  102. deviceStatusText: getDeviceStatusText(state),
  103. deviceStatusType: getDeviceStatusType(state)
  104. };
  105. }
  106. export default translate(connect(mapStateToProps)(DeviceStatus));