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

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