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 4.1KB

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