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.

Toolbar.native.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import React, { Component } from 'react';
  2. import { View } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { MEDIA_TYPE, toggleCameraFacingMode } from '../../base/media';
  5. import { Container } from '../../base/react';
  6. import { ColorPalette } from '../../base/styles';
  7. import { beginRoomLockRequest } from '../../room-lock';
  8. import {
  9. abstractMapDispatchToProps,
  10. abstractMapStateToProps
  11. } from '../functions';
  12. import { styles } from './styles';
  13. import ToolbarButton from './ToolbarButton';
  14. /**
  15. * Implements the conference toolbar on React Native.
  16. */
  17. class Toolbar extends Component {
  18. /**
  19. * Toolbar component's property types.
  20. *
  21. * @static
  22. */
  23. static propTypes = {
  24. /**
  25. * Flag showing that audio is muted.
  26. */
  27. _audioMuted: React.PropTypes.bool,
  28. /**
  29. * Flag showing whether room is locked.
  30. */
  31. _locked: React.PropTypes.bool,
  32. /**
  33. * Handler for hangup.
  34. */
  35. _onHangup: React.PropTypes.func,
  36. /**
  37. * Handler for room locking.
  38. */
  39. _onRoomLock: React.PropTypes.func,
  40. /**
  41. * Handler for toggle audio.
  42. */
  43. _onToggleAudio: React.PropTypes.func,
  44. /**
  45. * Handler for toggling camera facing mode.
  46. */
  47. _onToggleCameraFacingMode: React.PropTypes.func,
  48. /**
  49. * Handler for toggling video.
  50. */
  51. _onToggleVideo: React.PropTypes.func,
  52. /**
  53. * Flag showing whether video is muted.
  54. */
  55. _videoMuted: React.PropTypes.bool,
  56. /**
  57. * Flag showing whether toolbar is visible.
  58. */
  59. _visible: React.PropTypes.bool
  60. };
  61. /**
  62. * Implements React's {@link Component#render()}.
  63. *
  64. * @inheritdoc
  65. * @returns {ReactElement}
  66. */
  67. render() {
  68. return (
  69. <Container
  70. style = { styles.toolbarContainer }
  71. visible = { this.props._visible }>
  72. {
  73. this._renderPrimaryToolbar()
  74. }
  75. {
  76. this._renderSecondaryToolbar()
  77. }
  78. </Container>
  79. );
  80. }
  81. /**
  82. * Gets the styles for a button that toggles the mute state of a specific
  83. * media type.
  84. *
  85. * @param {string} mediaType - The {@link MEDIA_TYPE} associated with the
  86. * button to get styles for.
  87. * @protected
  88. * @returns {{
  89. * iconName: string,
  90. * iconStyle: Object,
  91. * style: Object
  92. * }}
  93. */
  94. _getMuteButtonStyles(mediaType) {
  95. let iconName;
  96. let iconStyle;
  97. let style = styles.primaryToolbarButton;
  98. if (this.props[`_${mediaType}Muted`]) {
  99. iconName = this[`${mediaType}MutedIcon`];
  100. iconStyle = styles.whiteIcon;
  101. style = {
  102. ...style,
  103. backgroundColor: ColorPalette.buttonUnderlay
  104. };
  105. } else {
  106. iconName = this[`${mediaType}Icon`];
  107. iconStyle = styles.icon;
  108. }
  109. return {
  110. iconName,
  111. iconStyle,
  112. style
  113. };
  114. }
  115. /**
  116. * Renders the toolbar which contains the primary buttons such as hangup,
  117. * audio and video mute.
  118. *
  119. * @private
  120. * @returns {ReactElement}
  121. */
  122. _renderPrimaryToolbar() {
  123. const audioButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.AUDIO);
  124. const videoButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.VIDEO);
  125. /* eslint-disable react/jsx-handler-names */
  126. return (
  127. <View style = { styles.primaryToolbar }>
  128. <ToolbarButton
  129. iconName = { audioButtonStyles.iconName }
  130. iconStyle = { audioButtonStyles.iconStyle }
  131. onClick = { this.props._onToggleAudio }
  132. style = { audioButtonStyles.style } />
  133. <ToolbarButton
  134. iconName = 'hangup'
  135. iconStyle = { styles.whiteIcon }
  136. onClick = { this.props._onHangup }
  137. style = {{
  138. ...styles.primaryToolbarButton,
  139. backgroundColor: ColorPalette.red
  140. }}
  141. underlayColor = { ColorPalette.buttonUnderlay } />
  142. <ToolbarButton
  143. iconName = { videoButtonStyles.iconName }
  144. iconStyle = { videoButtonStyles.iconStyle }
  145. onClick = { this.props._onToggleVideo }
  146. style = { videoButtonStyles.style } />
  147. </View>
  148. );
  149. /* eslint-enable react/jsx-handler-names */
  150. }
  151. /**
  152. * Renders the toolbar which contains the secondary buttons such as toggle
  153. * camera facing mode.
  154. *
  155. * @private
  156. * @returns {ReactElement}
  157. */
  158. _renderSecondaryToolbar() {
  159. const iconStyle = styles.secondaryToolbarIcon;
  160. const style = styles.secondaryToolbarButton;
  161. const underlayColor = 'transparent';
  162. /* eslint-disable react/jsx-curly-spacing,react/jsx-handler-names */
  163. return (
  164. <View style = { styles.secondaryToolbar }>
  165. {/* FIXME There are multiple issues with the toggling of the
  166. * camera facing more. For example, switching from the user
  167. * facing camera to the environment facing camera on iOS may be
  168. * very slow or may not work at all. On Android the toggling
  169. * either works or does not. The causes of the various problems
  170. * have been identified to lie within either
  171. * react-native-webrtc or Google's native WebRTC API.
  172. *
  173. <ToolbarButton
  174. iconName = 'switch-camera'
  175. iconStyle = { iconStyle }
  176. onClick = { this.props._onToggleCameraFacingMode }
  177. style = { style }
  178. underlayColor = { underlayColor } />
  179. */}
  180. <ToolbarButton
  181. iconName = {
  182. this.props._locked ? 'security-locked' : 'security'
  183. }
  184. iconStyle = { iconStyle }
  185. onClick = { this.props._onRoomLock }
  186. style = { style }
  187. underlayColor = { underlayColor } />
  188. </View>
  189. );
  190. /* eslint-enable react/jsx-curly-spacing,react/jsx-handler-names */
  191. }
  192. }
  193. /**
  194. * Additional properties for various icons, which are now platform-dependent.
  195. * This is done to have common logic of generating styles for web and native.
  196. * TODO As soon as we have common font sets for web and native, this will no
  197. * longer be required.
  198. */
  199. Object.assign(Toolbar.prototype, {
  200. audioIcon: 'microphone',
  201. audioMutedIcon: 'mic-disabled',
  202. videoIcon: 'camera',
  203. videoMutedIcon: 'camera-disabled'
  204. });
  205. /**
  206. * Maps actions to React component props.
  207. *
  208. * @param {Function} dispatch - Redux action dispatcher.
  209. * @returns {{
  210. * _onRoomLock: Function,
  211. * _onToggleCameraFacingMode: Function,
  212. * }}
  213. * @private
  214. */
  215. function _mapDispatchToProps(dispatch) {
  216. return {
  217. ...abstractMapDispatchToProps(dispatch),
  218. /**
  219. * Dispatches an action to set the lock i.e. password protection of the
  220. * conference/room.
  221. *
  222. * @private
  223. * @returns {Object} - Dispatched action.
  224. * @type {Function}
  225. */
  226. _onRoomLock() {
  227. return dispatch(beginRoomLockRequest());
  228. },
  229. /**
  230. * Switches between the front/user-facing and rear/environment-facing
  231. * cameras.
  232. *
  233. * @private
  234. * @returns {Object} - Dispatched action.
  235. * @type {Function}
  236. */
  237. _onToggleCameraFacingMode() {
  238. return dispatch(toggleCameraFacingMode());
  239. }
  240. };
  241. }
  242. /**
  243. * Maps part of Redux store to React component props.
  244. *
  245. * @param {Object} state - Redux store.
  246. * @returns {{
  247. * _locked: boolean
  248. * }}
  249. * @private
  250. */
  251. function _mapStateToProps(state) {
  252. const conference = state['features/base/conference'];
  253. return {
  254. ...abstractMapStateToProps(state),
  255. /**
  256. * The indicator which determines whether the conference is
  257. * locked/password-protected.
  258. *
  259. * @protected
  260. * @type {boolean}
  261. */
  262. _locked: conference.locked
  263. };
  264. }
  265. export default connect(_mapStateToProps, _mapDispatchToProps)(Toolbar);