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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 {
  175. _audioOnly: audioOnly,
  176. _videoMuted: videoMuted
  177. } = this.props;
  178. /* eslint-disable react/jsx-curly-spacing,react/jsx-handler-names */
  179. return (
  180. <View style = { styles.secondaryToolbar }>
  181. <ToolbarButton
  182. disabled = { audioOnly || videoMuted }
  183. iconName = 'switch-camera'
  184. iconStyle = { iconStyle }
  185. onClick = { this.props._onToggleCameraFacingMode }
  186. style = { style }
  187. underlayColor = { underlayColor } />
  188. <ToolbarButton
  189. iconName = {
  190. this.props._locked ? 'security-locked' : 'security'
  191. }
  192. iconStyle = { iconStyle }
  193. onClick = { this.props._onRoomLock }
  194. style = { style }
  195. underlayColor = { underlayColor } />
  196. <ToolbarButton
  197. iconName = { audioOnly ? 'visibility-off' : 'visibility' }
  198. iconStyle = { iconStyle }
  199. onClick = { this.props._onToggleAudioOnly }
  200. style = { style }
  201. underlayColor = { underlayColor } />
  202. <ToolbarButton
  203. iconName = 'link'
  204. iconStyle = { iconStyle }
  205. onClick = { this.props._onShareRoom }
  206. style = { style }
  207. underlayColor = { underlayColor } />
  208. </View>
  209. );
  210. /* eslint-enable react/jsx-curly-spacing,react/jsx-handler-names */
  211. }
  212. }
  213. /**
  214. * Additional properties for various icons, which are now platform-dependent.
  215. * This is done to have common logic of generating styles for web and native.
  216. * TODO As soon as we have common font sets for web and native, this will no
  217. * longer be required.
  218. */
  219. Object.assign(Toolbox.prototype, {
  220. audioIcon: 'microphone',
  221. audioMutedIcon: 'mic-disabled',
  222. videoIcon: 'camera',
  223. videoMutedIcon: 'camera-disabled'
  224. });
  225. /**
  226. * Maps actions to React component props.
  227. *
  228. * @param {Function} dispatch - Redux action dispatcher.
  229. * @returns {{
  230. * _onRoomLock: Function,
  231. * _onToggleAudioOnly: Function,
  232. * _onToggleCameraFacingMode: Function,
  233. * }}
  234. * @private
  235. */
  236. function _mapDispatchToProps(dispatch) {
  237. return {
  238. ...abstractMapDispatchToProps(dispatch),
  239. /**
  240. * Sets the lock i.e. password protection of the conference/room.
  241. *
  242. * @private
  243. * @returns {Object} Dispatched action.
  244. * @type {Function}
  245. */
  246. _onRoomLock() {
  247. dispatch(beginRoomLockRequest());
  248. },
  249. /**
  250. * Begins the UI procedure to share the conference/room URL.
  251. *
  252. * @private
  253. * @returns {void} Dispatched action.
  254. * @type {Function}
  255. */
  256. _onShareRoom() {
  257. dispatch(beginShareRoom());
  258. },
  259. /**
  260. * Toggles the audio-only flag of the conference.
  261. *
  262. * @private
  263. * @returns {Object} Dispatched action.
  264. * @type {Function}
  265. */
  266. _onToggleAudioOnly() {
  267. dispatch(toggleAudioOnly());
  268. },
  269. /**
  270. * Switches between the front/user-facing and back/environment-facing
  271. * cameras.
  272. *
  273. * @private
  274. * @returns {Object} Dispatched action.
  275. * @type {Function}
  276. */
  277. _onToggleCameraFacingMode() {
  278. dispatch(toggleCameraFacingMode());
  279. }
  280. };
  281. }
  282. /**
  283. * Maps part of Redux store to React component props.
  284. *
  285. * @param {Object} state - Redux store.
  286. * @returns {{
  287. * _audioOnly: boolean,
  288. * _locked: boolean
  289. * }}
  290. * @private
  291. */
  292. function _mapStateToProps(state) {
  293. const conference = state['features/base/conference'];
  294. return {
  295. ...abstractMapStateToProps(state),
  296. /**
  297. * The indicator which determines whether the conference is in
  298. * audio-only mode.
  299. *
  300. * @protected
  301. * @type {boolean}
  302. */
  303. _audioOnly: Boolean(conference.audioOnly),
  304. /**
  305. * The indicator which determines whether the conference is
  306. * locked/password-protected.
  307. *
  308. * @protected
  309. * @type {boolean}
  310. */
  311. _locked: Boolean(conference.locked)
  312. };
  313. }
  314. export default connect(_mapStateToProps, _mapDispatchToProps)(Toolbox);