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.

VideoMuteButton.js 3.6KB

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