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