您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DeviceStatus.js 2.2KB

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