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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // @flow
  2. import { isMobileBrowser } from '../../../base/environment/utils';
  3. import { translate } from '../../../base/i18n';
  4. import { IconCameraRefresh } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  7. import { isLocalCameraTrackMuted, toggleCamera } 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 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, any> {
  29. accessibilityLabel = 'toolbar.accessibilityLabel.toggleCamera';
  30. icon = IconCameraRefresh;
  31. label = 'toolbar.toggleCamera';
  32. /**
  33. * Handles clicking/pressing the button.
  34. *
  35. * @returns {void}
  36. */
  37. _handleClick() {
  38. this.props.dispatch(toggleCamera());
  39. }
  40. /**
  41. * Whether this button is disabled or not.
  42. *
  43. * @returns {boolean}
  44. */
  45. _isDisabled() {
  46. return this.props._audioOnly || this.props._videoMuted;
  47. }
  48. }
  49. /**
  50. * Maps (parts of) the redux state to the associated props for the
  51. * {@code ToggleCameraButton} component.
  52. *
  53. * @param {Object} state - The Redux state.
  54. * @returns {Props}
  55. */
  56. function mapStateToProps(state): Object {
  57. const { enabled: audioOnly } = state['features/base/audio-only'];
  58. const tracks = state['features/base/tracks'];
  59. const { videoInput } = state['features/base/devices'].availableDevices;
  60. return {
  61. _audioOnly: Boolean(audioOnly),
  62. _videoMuted: isLocalCameraTrackMuted(tracks),
  63. visible: isMobileBrowser() && videoInput.length > 1
  64. };
  65. }
  66. export default translate(connect(mapStateToProps)(ToggleCameraButton));