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

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