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

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