Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AbstractAudioMuteButton.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import PropTypes from 'prop-types';
  3. import { Component } from 'react';
  4. import {
  5. AUDIO_MUTE,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import {
  10. VIDEO_MUTISM_AUTHORITY,
  11. setAudioMuted
  12. } from '../../../base/media';
  13. /**
  14. * An abstract implementation of a button for toggling audio mute.
  15. */
  16. export default class AbstractAudioMuteButton extends Component<*> {
  17. /**
  18. * {@code AbstractAudioMuteButton} component's property types.
  19. *
  20. * @static
  21. */
  22. static propTypes = {
  23. /**
  24. * Whether or not the local microphone is muted.
  25. */
  26. _audioMuted: PropTypes.bool,
  27. /**
  28. * Invoked to toggle audio mute.
  29. */
  30. dispatch: PropTypes.func
  31. };
  32. /**
  33. * Initializes a new {@code AbstractAudioMuteButton} instance.
  34. *
  35. * @param {Props} props - The read-only React {@code Component} props with
  36. * which the new instance is to be initialized.
  37. */
  38. constructor(props: Object) {
  39. super(props);
  40. // Bind event handler so it is only bound once per instance.
  41. this._onToolbarToggleAudio = this._onToolbarToggleAudio.bind(this);
  42. }
  43. /**
  44. * Dispatches an action to toggle audio mute.
  45. *
  46. * @private
  47. * @returns {void}
  48. */
  49. _doToggleAudio() {
  50. // The user sees the reality i.e. the state of base/tracks and intends
  51. // to change reality by tapping on the respective button i.e. the user
  52. // sets the state of base/media. Whether the user's intention will turn
  53. // into reality is a whole different story which is of no concern to the
  54. // tapping.
  55. this.props.dispatch(
  56. setAudioMuted(
  57. !this.props._audioMuted,
  58. VIDEO_MUTISM_AUTHORITY.USER,
  59. /* ensureTrack */ true));
  60. }
  61. _onToolbarToggleAudio: () => void;
  62. /**
  63. * Creates an analytics toolbar event and dispatches an action for toggling
  64. * audio mute.
  65. *
  66. * @private
  67. * @returns {void}
  68. */
  69. _onToolbarToggleAudio() {
  70. sendAnalytics(createToolbarEvent(
  71. AUDIO_MUTE,
  72. {
  73. enable: !this.props._audioMuted
  74. }));
  75. this._doToggleAudio();
  76. }
  77. }