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.

AbstractToolbar.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import React, { Component } from 'react';
  2. import { appNavigate } from '../../app';
  3. import {
  4. toggleAudioMuted,
  5. toggleVideoMuted
  6. } from '../../base/media';
  7. import { ColorPalette } from '../../base/styles';
  8. import { styles } from './styles';
  9. /**
  10. * Abstract (base) class for the conference toolbar.
  11. *
  12. * @abstract
  13. */
  14. export class AbstractToolbar extends Component {
  15. /**
  16. * AbstractToolbar component's property types.
  17. *
  18. * @static
  19. */
  20. static propTypes = {
  21. audioMuted: React.PropTypes.bool,
  22. dispatch: React.PropTypes.func,
  23. videoMuted: React.PropTypes.bool,
  24. visible: React.PropTypes.bool.isRequired
  25. }
  26. /**
  27. * Initializes a new AbstractToolbar instance.
  28. *
  29. * @param {Object} props - The read-only React Component props with which
  30. * the new instance is to be initialized.
  31. */
  32. constructor(props) {
  33. super(props);
  34. // Bind event handlers so they are only bound once for every instance.
  35. this._onHangup = this._onHangup.bind(this);
  36. this._toggleAudio = this._toggleAudio.bind(this);
  37. this._toggleVideo = this._toggleVideo.bind(this);
  38. }
  39. /**
  40. * Gets the styles for a button that toggles the mute state of a specific
  41. * media type.
  42. *
  43. * @param {string} mediaType - The {@link MEDIA_TYPE} associated with the
  44. * button to get styles for.
  45. * @protected
  46. * @returns {{
  47. * buttonStyle: Object,
  48. * iconName: string,
  49. * iconStyle: Object
  50. * }}
  51. */
  52. _getMuteButtonStyles(mediaType) {
  53. let buttonStyle;
  54. let iconName;
  55. let iconStyle;
  56. if (this.props[`${mediaType}Muted`]) {
  57. buttonStyle = {
  58. ...styles.toolbarButton,
  59. backgroundColor: ColorPalette.buttonUnderlay
  60. };
  61. iconName = this[`${mediaType}MutedIcon`];
  62. iconStyle = styles.whiteIcon;
  63. } else {
  64. buttonStyle = styles.toolbarButton;
  65. iconName = this[`${mediaType}Icon`];
  66. iconStyle = styles.icon;
  67. }
  68. return {
  69. buttonStyle,
  70. iconName,
  71. iconStyle
  72. };
  73. }
  74. /**
  75. * Dispatches action to leave the current conference.
  76. *
  77. * @protected
  78. * @returns {void}
  79. */
  80. _onHangup() {
  81. // XXX We don't know here which value is effectively/internally used
  82. // when there's no valid room name to join. It isn't our business to
  83. // know that anyway. The undefined value is our expression of (1) the
  84. // lack of knowledge & (2) the desire to no longer have a valid room
  85. // name to join.
  86. this.props.dispatch(appNavigate(undefined));
  87. }
  88. /**
  89. * Dispatches action to toggle the mute state of the audio/microphone.
  90. *
  91. * @protected
  92. * @returns {void}
  93. */
  94. _toggleAudio() {
  95. this.props.dispatch(toggleAudioMuted());
  96. }
  97. /**
  98. * Dispatches action to toggle the mute state of the video/camera.
  99. *
  100. * @protected
  101. * @returns {void}
  102. */
  103. _toggleVideo() {
  104. this.props.dispatch(toggleVideoMuted());
  105. }
  106. }
  107. /**
  108. * Maps parts of media state to component props.
  109. *
  110. * @param {Object} state - Redux state.
  111. * @returns {{ audioMuted: boolean, videoMuted: boolean }}
  112. */
  113. export function mapStateToProps(state) {
  114. const media = state['features/base/media'];
  115. return {
  116. audioMuted: media.audio.muted,
  117. videoMuted: media.video.muted
  118. };
  119. }