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.

VideoMuteButton.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 AbstractVideoMuteButton from '../base/toolbox/components/AbstractVideoMuteButton';
  5. import type { Props } from '../base/toolbox/components/AbstractButton';
  6. const { api } = window.alwaysOnTop;
  7. const logger = require('jitsi-meet-logger').getLogger(__filename);
  8. /**
  9. * The type of the React {@code Component} state of {@link VideoMuteButton}.
  10. */
  11. type State = {
  12. /**
  13. * Whether video is available is not.
  14. */
  15. videoAvailable: boolean,
  16. /**
  17. * Whether video is muted or not.
  18. */
  19. videoMuted: boolean
  20. };
  21. /**
  22. * Stateless "mute/unmute video" button for the Always-on-Top windows.
  23. */
  24. export default class VideoMuteButton
  25. extends AbstractVideoMuteButton<Props, State> {
  26. accessibilityLabel = 'Video mute';
  27. /**
  28. * Initializes a new {@code VideoMuteButton} instance.
  29. *
  30. * @param {Props} props - The React {@code Component} props to initialize
  31. * the new {@code VideoMuteButton} instance with.
  32. */
  33. constructor(props: Props) {
  34. super(props);
  35. this.state = {
  36. videoAvailable: false,
  37. videoMuted: true
  38. };
  39. // Bind event handlers so they are only bound once per instance.
  40. this._videoAvailabilityListener
  41. = this._videoAvailabilityListener.bind(this);
  42. this._videoMutedListener = this._videoMutedListener.bind(this);
  43. }
  44. /**
  45. * Sets mouse move listener and initial toolbar timeout.
  46. *
  47. * @inheritdoc
  48. * @returns {void}
  49. */
  50. componentDidMount() {
  51. api.on('videoAvailabilityChanged', this._videoAvailabilityListener);
  52. api.on('videoMuteStatusChanged', this._videoMutedListener);
  53. Promise.all([
  54. api.isVideoAvailable(),
  55. api.isVideoMuted()
  56. ])
  57. .then(([ videoAvailable, videoMuted ]) =>
  58. this.setState({
  59. videoAvailable,
  60. videoMuted
  61. }))
  62. .catch(logger.error);
  63. }
  64. /**
  65. * Removes all listeners.
  66. *
  67. * @inheritdoc
  68. * @returns {void}
  69. */
  70. componentWillUnmount() {
  71. api.removeListener(
  72. 'videoAvailabilityChanged',
  73. this._videoAvailabilityListener);
  74. api.removeListener(
  75. 'videoMuteStatusChanged',
  76. this._videoMutedListener);
  77. }
  78. /**
  79. * Indicates whether this button is disabled or not.
  80. *
  81. * @override
  82. * @protected
  83. * @returns {boolean}
  84. */
  85. _isDisabled() {
  86. return !this.state.videoAvailable;
  87. }
  88. /**
  89. * Indicates if video is currently muted ot nor.
  90. *
  91. * @override
  92. * @protected
  93. * @returns {boolean}
  94. */
  95. _isVideoMuted() {
  96. return this.state.videoMuted;
  97. }
  98. /**
  99. * Changes the muted state.
  100. *
  101. * @override
  102. * @param {boolean} videoMuted - Whether video should be muted or not.
  103. * @protected
  104. * @returns {void}
  105. */
  106. _setVideoMuted(videoMuted: boolean) { // eslint-disable-line no-unused-vars
  107. this.state.videoAvailable && api.executeCommand('toggleVideo');
  108. }
  109. _videoAvailabilityListener: ({ available: boolean }) => void;
  110. /**
  111. * Handles video available api events.
  112. *
  113. * @param {{ available: boolean }} status - The new available status.
  114. * @returns {void}
  115. */
  116. _videoAvailabilityListener({ available }) {
  117. this.setState({ videoAvailable: available });
  118. }
  119. _videoMutedListener: ({ muted: boolean }) => void;
  120. /**
  121. * Handles video muted api events.
  122. *
  123. * @param {{ muted: boolean }} status - The new muted status.
  124. * @returns {void}
  125. */
  126. _videoMutedListener({ muted }) {
  127. this.setState({ videoMuted: muted });
  128. }
  129. }