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

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