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.

ToggleCameraButton.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // @flow
  2. import { translate } from '../../../base/i18n';
  3. import { IconCameraRefresh } from '../../../base/icons';
  4. import { connect } from '../../../base/redux';
  5. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  6. import { isLocalCameraTrackMuted, isToggleCameraEnabled, toggleCamera } from '../../../base/tracks';
  7. /**
  8. * The type of the React {@code Component} props of {@link ToggleCameraButton}.
  9. */
  10. type Props = AbstractButtonProps & {
  11. /**
  12. * Whether the current conference is in audio only mode or not.
  13. */
  14. _audioOnly: boolean,
  15. /**
  16. * Whether video is currently muted or not.
  17. */
  18. _videoMuted: boolean,
  19. /**
  20. * The Redux dispatch function.
  21. */
  22. dispatch: Function
  23. };
  24. /**
  25. * An implementation of a button for toggling the camera facing mode.
  26. */
  27. class ToggleCameraButton extends AbstractButton<Props, any> {
  28. accessibilityLabel = 'toolbar.accessibilityLabel.toggleCamera';
  29. icon = IconCameraRefresh;
  30. label = 'toolbar.toggleCamera';
  31. /**
  32. * Handles clicking/pressing the button.
  33. *
  34. * @returns {void}
  35. */
  36. _handleClick() {
  37. this.props.dispatch(toggleCamera());
  38. }
  39. /**
  40. * Whether this button is disabled or not.
  41. *
  42. * @returns {boolean}
  43. */
  44. _isDisabled() {
  45. return this.props._audioOnly || this.props._videoMuted;
  46. }
  47. }
  48. /**
  49. * Maps (parts of) the redux state to the associated props for the
  50. * {@code ToggleCameraButton} component.
  51. *
  52. * @param {Object} state - The Redux state.
  53. * @returns {Props}
  54. */
  55. function mapStateToProps(state): Object {
  56. const { enabled: audioOnly } = state['features/base/audio-only'];
  57. const tracks = state['features/base/tracks'];
  58. return {
  59. _audioOnly: Boolean(audioOnly),
  60. _videoMuted: isLocalCameraTrackMuted(tracks),
  61. visible: isToggleCameraEnabled(state)
  62. };
  63. }
  64. export default translate(connect(mapStateToProps)(ToggleCameraButton));