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

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