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.8KB

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