您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AudioMuteButton.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // @flow
  2. // We need to reference these files directly to avoid loading things that are not available
  3. // in this environment (e.g. JitsiMeetJS or interfaceConfig)
  4. import AbstractAudioMuteButton from '../base/toolbox/components/AbstractAudioMuteButton';
  5. import type { Props } from '../base/toolbox/components/AbstractButton';
  6. const { api } = window.alwaysOnTop;
  7. /**
  8. * The type of the React {@code Component} state of {@link AudioMuteButton}.
  9. */
  10. type State = {
  11. /**
  12. * Whether audio is available is not.
  13. */
  14. audioAvailable: boolean,
  15. /**
  16. * Whether audio is muted or not.
  17. */
  18. audioMuted: boolean
  19. };
  20. /**
  21. * Stateless "mute/unmute audio" button for the Always-on-Top windows.
  22. */
  23. export default class AudioMuteButton
  24. extends AbstractAudioMuteButton<Props, State> {
  25. accessibilityLabel = 'Audio mute';
  26. /**
  27. * Initializes a new {@code AudioMuteButton} instance.
  28. *
  29. * @param {Props} props - The React {@code Component} props to initialize
  30. * the new {@code AudioMuteButton} instance with.
  31. */
  32. constructor(props: Props) {
  33. super(props);
  34. this.state = {
  35. audioAvailable: false,
  36. audioMuted: true
  37. };
  38. // Bind event handlers so they are only bound once per instance.
  39. this._audioAvailabilityListener
  40. = this._audioAvailabilityListener.bind(this);
  41. this._audioMutedListener = this._audioMutedListener.bind(this);
  42. }
  43. /**
  44. * Sets mouse move listener and initial toolbar timeout.
  45. *
  46. * @inheritdoc
  47. * @returns {void}
  48. */
  49. componentDidMount() {
  50. api.on('audioAvailabilityChanged', this._audioAvailabilityListener);
  51. api.on('audioMuteStatusChanged', this._audioMutedListener);
  52. Promise.all([
  53. api.isAudioAvailable(),
  54. api.isAudioMuted()
  55. ])
  56. .then(([ audioAvailable, audioMuted ]) =>
  57. this.setState({
  58. audioAvailable,
  59. audioMuted
  60. }))
  61. .catch(console.error);
  62. }
  63. /**
  64. * Removes all listeners.
  65. *
  66. * @inheritdoc
  67. * @returns {void}
  68. */
  69. componentWillUnmount() {
  70. api.removeListener(
  71. 'audioAvailabilityChanged',
  72. this._audioAvailabilityListener);
  73. api.removeListener(
  74. 'audioMuteStatusChanged',
  75. this._audioMutedListener);
  76. }
  77. _audioAvailabilityListener: ({ available: boolean }) => void;
  78. /**
  79. * Handles audio available api events.
  80. *
  81. * @param {{ available: boolean }} status - The new available status.
  82. * @returns {void}
  83. */
  84. _audioAvailabilityListener({ available }) {
  85. this.setState({ audioAvailable: available });
  86. }
  87. _audioMutedListener: ({ muted: boolean }) => void;
  88. /**
  89. * Handles audio muted api events.
  90. *
  91. * @param {{ muted: boolean }} status - The new muted status.
  92. * @returns {void}
  93. */
  94. _audioMutedListener({ muted }) {
  95. this.setState({ audioMuted: muted });
  96. }
  97. /**
  98. * Indicates if audio is currently muted ot nor.
  99. *
  100. * @override
  101. * @protected
  102. * @returns {boolean}
  103. */
  104. _isAudioMuted() {
  105. return this.state.audioMuted;
  106. }
  107. /**
  108. * Indicates whether this button is disabled or not.
  109. *
  110. * @override
  111. * @protected
  112. * @returns {boolean}
  113. */
  114. _isDisabled() {
  115. return !this.state.audioAvailable;
  116. }
  117. /**
  118. * Changes the muted state.
  119. *
  120. * @override
  121. * @param {boolean} audioMuted - Whether audio should be muted or not.
  122. * @protected
  123. * @returns {void}
  124. */
  125. _setAudioMuted(audioMuted: boolean) { // eslint-disable-line no-unused-vars
  126. this.state.audioAvailable && api.executeCommand('toggleAudio');
  127. }
  128. }