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.

Toolbox.native.js 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import React, { Component } from 'react';
  2. import { View } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { MEDIA_TYPE, toggleCameraFacingMode } from '../../base/media';
  5. import { Container } from '../../base/react';
  6. import { ColorPalette } from '../../base/styles';
  7. import { beginRoomLockRequest } from '../../room-lock';
  8. import {
  9. abstractMapDispatchToProps,
  10. abstractMapStateToProps
  11. } from '../functions';
  12. import { styles } from './styles';
  13. import ToolbarButton from './ToolbarButton';
  14. /**
  15. * Implements the conference toolbox on React Native.
  16. */
  17. class Toolbox extends Component {
  18. /**
  19. * Toolbox component's property types.
  20. *
  21. * @static
  22. */
  23. static propTypes = {
  24. /**
  25. * Flag showing that audio is muted.
  26. */
  27. _audioMuted: React.PropTypes.bool,
  28. /**
  29. * Flag showing whether room is locked.
  30. */
  31. _locked: React.PropTypes.bool,
  32. /**
  33. * Handler for hangup.
  34. */
  35. _onHangup: React.PropTypes.func,
  36. /**
  37. * Handler for room locking.
  38. */
  39. _onRoomLock: React.PropTypes.func,
  40. /**
  41. * Handler for toggle audio.
  42. */
  43. _onToggleAudio: React.PropTypes.func,
  44. /**
  45. * Handler for toggling camera facing mode.
  46. */
  47. _onToggleCameraFacingMode: React.PropTypes.func,
  48. /**
  49. * Handler for toggling video.
  50. */
  51. _onToggleVideo: React.PropTypes.func,
  52. /**
  53. * Flag showing whether video is muted.
  54. */
  55. _videoMuted: React.PropTypes.bool,
  56. /**
  57. * Flag showing whether toolbar is visible.
  58. */
  59. _visible: React.PropTypes.bool
  60. };
  61. /**
  62. * Implements React's {@link Component#render()}.
  63. *
  64. * @inheritdoc
  65. * @returns {ReactElement}
  66. */
  67. render() {
  68. return (
  69. <Container
  70. style = { styles.toolbarContainer }
  71. visible = { this.props._visible }>
  72. {
  73. this._renderPrimaryToolbar()
  74. }
  75. {
  76. this._renderSecondaryToolbar()
  77. }
  78. </Container>
  79. );
  80. }
  81. /**
  82. * Gets the styles for a button that toggles the mute state of a specific
  83. * media type.
  84. *
  85. * @param {string} mediaType - The {@link MEDIA_TYPE} associated with the
  86. * button to get styles for.
  87. * @protected
  88. * @returns {{
  89. * iconName: string,
  90. * iconStyle: Object,
  91. * style: Object
  92. * }}
  93. */
  94. _getMuteButtonStyles(mediaType) {
  95. let iconName;
  96. let iconStyle;
  97. let style = styles.primaryToolbarButton;
  98. if (this.props[`_${mediaType}Muted`]) {
  99. iconName = this[`${mediaType}MutedIcon`];
  100. iconStyle = styles.whiteIcon;
  101. style = {
  102. ...style,
  103. backgroundColor: ColorPalette.buttonUnderlay
  104. };
  105. } else {
  106. iconName = this[`${mediaType}Icon`];
  107. iconStyle = styles.icon;
  108. }
  109. return {
  110. iconName,
  111. iconStyle,
  112. style
  113. };
  114. }
  115. /**
  116. * Renders the toolbar which contains the primary buttons such as hangup,
  117. * audio and video mute.
  118. *
  119. * @private
  120. * @returns {ReactElement}
  121. */
  122. _renderPrimaryToolbar() {
  123. const audioButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.AUDIO);
  124. const videoButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.VIDEO);
  125. /* eslint-disable react/jsx-handler-names */
  126. return (
  127. <View style = { styles.primaryToolbar }>
  128. <ToolbarButton
  129. iconName = { audioButtonStyles.iconName }
  130. iconStyle = { audioButtonStyles.iconStyle }
  131. onClick = { this.props._onToggleAudio }
  132. style = { audioButtonStyles.style } />
  133. <ToolbarButton
  134. iconName = 'hangup'
  135. iconStyle = { styles.whiteIcon }
  136. onClick = { this.props._onHangup }
  137. style = {{
  138. ...styles.primaryToolbarButton,
  139. backgroundColor: ColorPalette.red
  140. }}
  141. underlayColor = { ColorPalette.buttonUnderlay } />
  142. <ToolbarButton
  143. iconName = { videoButtonStyles.iconName }
  144. iconStyle = { videoButtonStyles.iconStyle }
  145. onClick = { this.props._onToggleVideo }
  146. style = { videoButtonStyles.style } />
  147. </View>
  148. );
  149. /* eslint-enable react/jsx-handler-names */
  150. }
  151. /**
  152. * Renders the toolbar which contains the secondary buttons such as toggle
  153. * camera facing mode.
  154. *
  155. * @private
  156. * @returns {ReactElement}
  157. */
  158. _renderSecondaryToolbar() {
  159. const iconStyle = styles.secondaryToolbarIcon;
  160. const style = styles.secondaryToolbarButton;
  161. const underlayColor = 'transparent';
  162. /* eslint-disable react/jsx-curly-spacing,react/jsx-handler-names */
  163. return (
  164. <View style = { styles.secondaryToolbar }>
  165. <ToolbarButton
  166. iconName = 'switch-camera'
  167. iconStyle = { iconStyle }
  168. onClick = { this.props._onToggleCameraFacingMode }
  169. style = { style }
  170. underlayColor = { underlayColor } />
  171. <ToolbarButton
  172. iconName = {
  173. this.props._locked ? 'security-locked' : 'security'
  174. }
  175. iconStyle = { iconStyle }
  176. onClick = { this.props._onRoomLock }
  177. style = { style }
  178. underlayColor = { underlayColor } />
  179. </View>
  180. );
  181. /* eslint-enable react/jsx-curly-spacing,react/jsx-handler-names */
  182. }
  183. }
  184. /**
  185. * Additional properties for various icons, which are now platform-dependent.
  186. * This is done to have common logic of generating styles for web and native.
  187. * TODO As soon as we have common font sets for web and native, this will no
  188. * longer be required.
  189. */
  190. Object.assign(Toolbox.prototype, {
  191. audioIcon: 'microphone',
  192. audioMutedIcon: 'mic-disabled',
  193. videoIcon: 'camera',
  194. videoMutedIcon: 'camera-disabled'
  195. });
  196. /**
  197. * Maps actions to React component props.
  198. *
  199. * @param {Function} dispatch - Redux action dispatcher.
  200. * @returns {{
  201. * _onRoomLock: Function,
  202. * _onToggleCameraFacingMode: Function,
  203. * }}
  204. * @private
  205. */
  206. function _mapDispatchToProps(dispatch) {
  207. return {
  208. ...abstractMapDispatchToProps(dispatch),
  209. /**
  210. * Dispatches an action to set the lock i.e. password protection of the
  211. * conference/room.
  212. *
  213. * @private
  214. * @returns {Object} - Dispatched action.
  215. * @type {Function}
  216. */
  217. _onRoomLock() {
  218. return dispatch(beginRoomLockRequest());
  219. },
  220. /**
  221. * Switches between the front/user-facing and rear/environment-facing
  222. * cameras.
  223. *
  224. * @private
  225. * @returns {Object} - Dispatched action.
  226. * @type {Function}
  227. */
  228. _onToggleCameraFacingMode() {
  229. return dispatch(toggleCameraFacingMode());
  230. }
  231. };
  232. }
  233. /**
  234. * Maps part of Redux store to React component props.
  235. *
  236. * @param {Object} state - Redux store.
  237. * @returns {{
  238. * _locked: boolean
  239. * }}
  240. * @private
  241. */
  242. function _mapStateToProps(state) {
  243. const conference = state['features/base/conference'];
  244. return {
  245. ...abstractMapStateToProps(state),
  246. /**
  247. * The indicator which determines whether the conference is
  248. * locked/password-protected.
  249. *
  250. * @protected
  251. * @type {boolean}
  252. */
  253. _locked: conference.locked
  254. };
  255. }
  256. export default connect(_mapStateToProps, _mapDispatchToProps)(Toolbox);