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.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconCheckSolid, IconExclamationTriangle } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import {
  7. getDeviceStatusType,
  8. getDeviceStatusText
  9. } from '../../functions';
  10. export type Props = {
  11. /**
  12. * The text to be displayed in relation to the status of the audio/video devices.
  13. */
  14. deviceStatusText: string,
  15. /**
  16. * The type of status for current devices, controlling the background color of the text.
  17. * Can be `ok` or `warning`.
  18. */
  19. deviceStatusType: string,
  20. /**
  21. * Used for translation.
  22. */
  23. t: Function
  24. };
  25. const iconMap = {
  26. warning: {
  27. src: IconExclamationTriangle,
  28. className: 'device-icon--warning'
  29. },
  30. ok: {
  31. src: IconCheckSolid,
  32. className: 'device-icon--ok'
  33. }
  34. };
  35. /**
  36. * Strip showing the current status of the devices.
  37. * User is informed if there are missing or malfunctioning devices.
  38. *
  39. * @returns {ReactElement}
  40. */
  41. function DeviceStatus({ deviceStatusType, deviceStatusText, t }: Props) {
  42. const { src, className } = iconMap[deviceStatusType];
  43. const hasError = deviceStatusType === 'warning';
  44. const containerClassName = `device-status ${hasError ? 'device-status-error' : ''}`;
  45. return (
  46. <div
  47. className = { containerClassName }
  48. role = 'alert'
  49. tabIndex = { -1 }>
  50. <Icon
  51. className = { `device-icon ${className}` }
  52. size = { 16 }
  53. src = { src } />
  54. <span role = 'heading'>
  55. {hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText)}
  56. </span>
  57. </div>
  58. );
  59. }
  60. /**
  61. * Maps (parts of) the redux state to the React {@code Component} props.
  62. *
  63. * @param {Object} state - The redux state.
  64. * @returns {{ deviceStatusText: string, deviceStatusText: string }}
  65. */
  66. function mapStateToProps(state) {
  67. return {
  68. deviceStatusText: getDeviceStatusText(state),
  69. deviceStatusType: getDeviceStatusType(state)
  70. };
  71. }
  72. export default translate(connect(mapStateToProps)(DeviceStatus));