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.ts 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { connect } from 'react-redux';
  2. import { IReduxState } from '../../../app/types';
  3. import { translate } from '../../../base/i18n/functions';
  4. import { IconCameraRefresh } from '../../../base/icons/svg';
  5. import { MEDIA_TYPE } from '../../../base/media/constants';
  6. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  7. import { toggleCamera } from '../../../base/tracks/actions';
  8. import { isLocalTrackMuted, isToggleCameraEnabled } from '../../../base/tracks/functions';
  9. import { setOverflowMenuVisible } from '../../actions.web';
  10. /**
  11. * The type of the React {@code Component} props of {@link ToggleCameraButton}.
  12. */
  13. interface IProps extends AbstractButtonProps {
  14. /**
  15. * Whether the current conference is in audio only mode or not.
  16. */
  17. _audioOnly: boolean;
  18. /**
  19. * Whether video is currently muted or not.
  20. */
  21. _videoMuted: boolean;
  22. }
  23. /**
  24. * An implementation of a button for toggling the camera facing mode.
  25. */
  26. class ToggleCameraButton extends AbstractButton<IProps> {
  27. accessibilityLabel = 'toolbar.accessibilityLabel.toggleCamera';
  28. icon = IconCameraRefresh;
  29. label = 'toolbar.toggleCamera';
  30. /**
  31. * Handles clicking/pressing the button.
  32. *
  33. * @returns {void}
  34. */
  35. _handleClick() {
  36. const { dispatch } = this.props;
  37. dispatch(toggleCamera());
  38. dispatch(setOverflowMenuVisible(false));
  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 {IProps}
  55. */
  56. function mapStateToProps(state: IReduxState) {
  57. const { enabled: audioOnly } = state['features/base/audio-only'];
  58. const tracks = state['features/base/tracks'];
  59. return {
  60. _audioOnly: Boolean(audioOnly),
  61. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO),
  62. visible: isToggleCameraEnabled(state)
  63. };
  64. }
  65. export default translate(connect(mapStateToProps)(ToggleCameraButton));