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

VideoMuteButton.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // @flow
  2. // XXX Import the button directly in order to avoid bringing in other components
  3. // that use lib-jitsi-meet, which always-on-top does not import.
  4. import AbstractVideoMuteButton
  5. from '../toolbox/components/buttons/AbstractVideoMuteButton';
  6. import type { Props } from '../toolbox/components/buttons/AbstractButton';
  7. const { api } = window.alwaysOnTop;
  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. /**
  27. * Initializes a new {@code VideoMuteButton} instance.
  28. *
  29. * @param {Props} props - The React {@code Component} props to initialize
  30. * the new {@code VideoMuteButton} instance with.
  31. */
  32. constructor(props: Props) {
  33. super(props);
  34. this.state = {
  35. videoAvailable: false,
  36. videoMuted: true
  37. };
  38. // Bind event handlers so they are only bound once per instance.
  39. this._videoAvailabilityListener
  40. = this._videoAvailabilityListener.bind(this);
  41. this._videoMutedListener = this._videoMutedListener.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('videoAvailabilityChanged', this._videoAvailabilityListener);
  51. api.on('videoMuteStatusChanged', this._videoMutedListener);
  52. Promise.all([
  53. api.isVideoAvailable(),
  54. api.isVideoMuted()
  55. ])
  56. .then(([ videoAvailable, videoMuted ]) =>
  57. this.setState({
  58. videoAvailable,
  59. videoMuted
  60. }))
  61. .catch(console.error);
  62. }
  63. /**
  64. * Removes all listeners.
  65. *
  66. * @inheritdoc
  67. * @returns {void}
  68. */
  69. componentWillUnmount() {
  70. api.removeListener(
  71. 'videoAvailabilityChanged',
  72. this._videoAvailabilityListener);
  73. api.removeListener(
  74. 'videoMuteStatusChanged',
  75. this._videoMutedListener);
  76. }
  77. /**
  78. * Indicates whether this button is disabled or not.
  79. *
  80. * @override
  81. * @private
  82. * @returns {boolean}
  83. */
  84. _isDisabled() {
  85. return !this.state.videoAvailable;
  86. }
  87. /**
  88. * Indicates if video is currently muted ot nor.
  89. *
  90. * @override
  91. * @private
  92. * @returns {boolean}
  93. */
  94. _isVideoMuted() {
  95. return this.state.videoMuted;
  96. }
  97. /**
  98. * Changes the muted state.
  99. *
  100. * @param {boolean} videoMuted - Whether video should be muted or not.
  101. * @private
  102. * @returns {void}
  103. */
  104. _setVideoMuted(videoMuted: boolean) { // eslint-disable-line no-unused-vars
  105. this.state.videoAvailable && api.executeCommand('toggleVideo');
  106. }
  107. _videoAvailabilityListener: ({ available: boolean }) => void;
  108. /**
  109. * Handles video available api events.
  110. *
  111. * @param {{ available: boolean }} status - The new available status.
  112. * @returns {void}
  113. */
  114. _videoAvailabilityListener({ available }) {
  115. this.setState({ videoAvailable: available });
  116. }
  117. _videoMutedListener: ({ muted: boolean }) => void;
  118. /**
  119. * Handles video muted api events.
  120. *
  121. * @param {{ muted: boolean }} status - The new muted status.
  122. * @returns {void}
  123. */
  124. _videoMutedListener({ muted }) {
  125. this.setState({ videoMuted: muted });
  126. }
  127. }