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

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