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.

AbstractVideoMuteButton.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // @flow
  2. import PropTypes from 'prop-types';
  3. import { Component } from 'react';
  4. import {
  5. VIDEO_MUTE,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import {
  10. VIDEO_MUTISM_AUTHORITY,
  11. setVideoMuted
  12. } from '../../../base/media';
  13. /**
  14. * An abstract implementation of a button for toggling video mute.
  15. */
  16. export default class AbstractVideoMuteButton extends Component<*> {
  17. /**
  18. * {@code AbstractVideoMuteButton} component's property types.
  19. *
  20. * @static
  21. */
  22. static propTypes = {
  23. /**
  24. * Whether or not the local camera is muted.
  25. */
  26. _videoMuted: PropTypes.bool,
  27. /**
  28. * Invoked to toggle video mute.
  29. */
  30. dispatch: PropTypes.func
  31. };
  32. /**
  33. * Initializes a new {@code AbstractVideoMuteButton} 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._onToolbarToggleVideo = this._onToolbarToggleVideo.bind(this);
  42. }
  43. /**
  44. * Dispatches an action to toggle the mute state of the video/camera.
  45. *
  46. * @private
  47. * @returns {void}
  48. */
  49. _doToggleVideo() {
  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. setVideoMuted(
  57. !this.props._videoMuted,
  58. VIDEO_MUTISM_AUTHORITY.USER,
  59. /* ensureTrack */ true));
  60. }
  61. _onToolbarToggleVideo: () => void;
  62. /**
  63. * Creates an analytics toolbar event and dispatches an action for toggling
  64. * video mute.
  65. *
  66. * @private
  67. * @returns {void}
  68. */
  69. _onToolbarToggleVideo() {
  70. sendAnalytics(createToolbarEvent(
  71. VIDEO_MUTE,
  72. {
  73. enable: !this.props._videoMuted
  74. }));
  75. this._doToggleVideo();
  76. }
  77. }