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.3KB

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