您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbox.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { View } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { Container } from '../../../base/react';
  6. import {
  7. isNarrowAspectRatio,
  8. makeAspectRatioAware
  9. } from '../../../base/responsive-ui';
  10. import { ColorPalette } from '../../../base/styles';
  11. import { InviteButton } from '../../../invite';
  12. import { AudioRouteButton } from '../../../mobile/audio-mode';
  13. import { PictureInPictureButton } from '../../../mobile/picture-in-picture';
  14. import { RoomLockButton } from '../../../room-lock';
  15. import AudioMuteButton from '../AudioMuteButton';
  16. import AudioOnlyButton from './AudioOnlyButton';
  17. import HangupButton from '../HangupButton';
  18. import styles from './styles';
  19. import ToggleCameraButton from './ToggleCameraButton';
  20. import VideoMuteButton from '../VideoMuteButton';
  21. /**
  22. * Styles for the hangup button.
  23. */
  24. const hangupButtonStyles = {
  25. iconStyle: styles.whitePrimaryToolbarButtonIcon,
  26. style: styles.hangup,
  27. underlayColor: ColorPalette.buttonUnderlay
  28. };
  29. /**
  30. * Styles for buttons in the primary toolbar.
  31. */
  32. const primaryToolbarButtonStyles = {
  33. iconStyle: styles.primaryToolbarButtonIcon,
  34. style: styles.primaryToolbarButton
  35. };
  36. /**
  37. * Styles for buttons in the primary toolbar.
  38. */
  39. const primaryToolbarToggledButtonStyles = {
  40. iconStyle: styles.whitePrimaryToolbarButtonIcon,
  41. style: styles.whitePrimaryToolbarButton
  42. };
  43. /**
  44. * Styles for buttons in the secondary toolbar.
  45. */
  46. const secondaryToolbarButtonStyles = {
  47. iconStyle: styles.secondaryToolbarButtonIcon,
  48. style: styles.secondaryToolbarButton,
  49. underlayColor: 'transparent'
  50. };
  51. /**
  52. * The type of {@link Toolbox}'s React {@code Component} props.
  53. */
  54. type Props = {
  55. /**
  56. * The indicator which determines whether the toolbox is enabled.
  57. */
  58. _enabled: boolean,
  59. /**
  60. * Flag showing whether toolbar is visible.
  61. */
  62. _visible: boolean
  63. };
  64. /**
  65. * Implements the conference toolbox on React Native.
  66. */
  67. class Toolbox extends Component<Props> {
  68. /**
  69. * Implements React's {@link Component#render()}.
  70. *
  71. * @inheritdoc
  72. * @returns {ReactElement}
  73. */
  74. render() {
  75. if (!this.props._enabled) {
  76. return null;
  77. }
  78. const toolboxStyle
  79. = isNarrowAspectRatio(this)
  80. ? styles.toolboxNarrow
  81. : styles.toolboxWide;
  82. return (
  83. <Container
  84. style = { toolboxStyle }
  85. visible = { this.props._visible } >
  86. { this._renderToolbars() }
  87. </Container>
  88. );
  89. }
  90. /**
  91. * Renders the toolbar which contains the primary buttons such as hangup,
  92. * audio and video mute.
  93. *
  94. * @private
  95. * @returns {ReactElement}
  96. */
  97. _renderPrimaryToolbar() {
  98. return (
  99. <View
  100. key = 'primaryToolbar'
  101. pointerEvents = 'box-none'
  102. style = { styles.primaryToolbar }>
  103. <AudioMuteButton
  104. styles = { primaryToolbarButtonStyles }
  105. toggledStyles = { primaryToolbarToggledButtonStyles } />
  106. <HangupButton styles = { hangupButtonStyles } />
  107. <VideoMuteButton
  108. styles = { primaryToolbarButtonStyles }
  109. toggledStyles = { primaryToolbarToggledButtonStyles } />
  110. </View>
  111. );
  112. }
  113. /**
  114. * Renders the toolbar which contains the secondary buttons such as toggle
  115. * camera facing mode.
  116. *
  117. * @private
  118. * @returns {ReactElement}
  119. */
  120. _renderSecondaryToolbar() {
  121. return (
  122. <View
  123. key = 'secondaryToolbar'
  124. pointerEvents = 'box-none'
  125. style = { styles.secondaryToolbar }>
  126. <AudioRouteButton styles = { secondaryToolbarButtonStyles } />
  127. <ToggleCameraButton styles = { secondaryToolbarButtonStyles } />
  128. <AudioOnlyButton styles = { secondaryToolbarButtonStyles } />
  129. <RoomLockButton styles = { secondaryToolbarButtonStyles } />
  130. <InviteButton styles = { secondaryToolbarButtonStyles } />
  131. <PictureInPictureButton
  132. styles = { secondaryToolbarButtonStyles } />
  133. </View>
  134. );
  135. }
  136. /**
  137. * Renders the primary and the secondary toolbars.
  138. *
  139. * @private
  140. * @returns {[ReactElement, ReactElement]}
  141. */
  142. _renderToolbars() {
  143. return [
  144. this._renderSecondaryToolbar(),
  145. this._renderPrimaryToolbar()
  146. ];
  147. }
  148. }
  149. /**
  150. * Maps parts of the redux state to {@link Toolbox} (React {@code Component})
  151. * props.
  152. *
  153. * @param {Object} state - The redux state of which parts are to be mapped to
  154. * {@code Toolbox} props.
  155. * @private
  156. * @returns {{
  157. * _enabled: boolean,
  158. * _visible: boolean
  159. * }}
  160. */
  161. function _mapStateToProps(state: Object): Object {
  162. const { enabled, visible } = state['features/toolbox'];
  163. return {
  164. /**
  165. * The indicator which determines whether the toolbox is enabled.
  166. *
  167. * @private
  168. * @type {boolean}
  169. */
  170. _enabled: enabled,
  171. /**
  172. * Flag showing whether toolbox is visible.
  173. *
  174. * @protected
  175. * @type {boolean}
  176. */
  177. _visible: visible
  178. };
  179. }
  180. export default connect(_mapStateToProps)(makeAspectRatioAware(Toolbox));