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, 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 className = { `prejoin-preview-status ${className}` }>
  50. <Icon
  51. className = 'prejoin-preview-icon'
  52. size = { 16 }
  53. src = { src } />
  54. <span className = 'prejoin-preview-error-desc'>{t(deviceStatusText)}</span>
  55. <span>{rawError}</span>
  56. </div>
  57. );
  58. }
  59. /**
  60. * Maps (parts of) the redux state to the React {@code Component} props.
  61. *
  62. * @param {Object} state - The redux state.
  63. * @returns {{ deviceStatusText: string, deviceStatusText: string }}
  64. */
  65. function mapStateToProps(state) {
  66. return {
  67. deviceStatusText: getDeviceStatusText(state),
  68. deviceStatusType: getDeviceStatusType(state),
  69. rawError: getRawError(state)
  70. };
  71. }
  72. export default translate(connect(mapStateToProps)(DeviceStatus));