您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbox.native.js 9.3KB

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