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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconCheck, 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: 'prejoin-preview-status--warning'
  34. },
  35. ok: {
  36. src: IconCheck,
  37. className: 'prejoin-preview-status--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 = { `prejoin-preview-status ${className}` }
  51. role = 'alert'
  52. tabIndex = { -1 }>
  53. <Icon
  54. className = 'prejoin-preview-icon'
  55. size = { 16 }
  56. src = { src } />
  57. <span
  58. className = 'prejoin-preview-error-desc'
  59. role = 'heading'>
  60. {t(deviceStatusText)}
  61. </span>
  62. { rawError && <span>
  63. { rawError }
  64. </span> }
  65. </div>
  66. );
  67. }
  68. /**
  69. * Maps (parts of) the redux state to the React {@code Component} props.
  70. *
  71. * @param {Object} state - The redux state.
  72. * @returns {{ deviceStatusText: string, deviceStatusText: string }}
  73. */
  74. function mapStateToProps(state) {
  75. return {
  76. deviceStatusText: getDeviceStatusText(state),
  77. deviceStatusType: getDeviceStatusType(state),
  78. rawError: getRawError(state)
  79. };
  80. }
  81. export default translate(connect(mapStateToProps)(DeviceStatus));