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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 {
  6. MEDIA_TYPE,
  7. setAudioMuted,
  8. setVideoMuted,
  9. toggleCameraFacingMode
  10. } from '../../base/media';
  11. import { Container } from '../../base/react';
  12. import { ColorPalette } from '../../base/styles';
  13. import { beginRoomLockRequest } from '../../room-lock';
  14. import { beginShareRoom } from '../../share-room';
  15. import {
  16. abstractMapDispatchToProps,
  17. abstractMapStateToProps
  18. } from '../functions';
  19. import styles from './styles';
  20. import ToolbarButton from './ToolbarButton';
  21. /**
  22. * Implements the conference toolbox on React Native.
  23. */
  24. class Toolbox extends Component {
  25. /**
  26. * Toolbox component's property types.
  27. *
  28. * @static
  29. */
  30. static propTypes = {
  31. /**
  32. * Flag showing that audio is muted.
  33. */
  34. _audioMuted: React.PropTypes.bool,
  35. /**
  36. * Flag showing whether the audio-only mode is in use.
  37. */
  38. _audioOnly: React.PropTypes.bool,
  39. /**
  40. * Flag showing whether room is locked.
  41. */
  42. _locked: React.PropTypes.bool,
  43. /**
  44. * Handler for hangup.
  45. */
  46. _onHangup: React.PropTypes.func,
  47. /**
  48. * Sets the lock i.e. password protection of the conference/room.
  49. */
  50. _onRoomLock: React.PropTypes.func,
  51. /**
  52. * Begins the UI procedure to share the conference/room URL.
  53. */
  54. _onShareRoom: React.PropTypes.func,
  55. /**
  56. * Toggles the audio-only flag of the conference.
  57. */
  58. _onToggleAudioOnly: React.PropTypes.func,
  59. /**
  60. * Switches between the front/user-facing and back/environment-facing
  61. * cameras.
  62. */
  63. _onToggleCameraFacingMode: React.PropTypes.func,
  64. /**
  65. * Flag showing whether video is muted.
  66. */
  67. _videoMuted: React.PropTypes.bool,
  68. /**
  69. * Flag showing whether toolbar is visible.
  70. */
  71. _visible: React.PropTypes.bool,
  72. dispatch: React.PropTypes.func
  73. };
  74. /**
  75. * Initializes a new {@code Toolbox} instance.
  76. *
  77. * @param {Object} props - The read-only React {@code Component} props with
  78. * which the new instance is to be initialized.
  79. */
  80. constructor(props) {
  81. super(props);
  82. // Bind event handlers so they are only bound once per instance.
  83. this._onToggleAudio = this._onToggleAudio.bind(this);
  84. this._onToggleVideo = this._onToggleVideo.bind(this);
  85. }
  86. /**
  87. * Implements React's {@link Component#render()}.
  88. *
  89. * @inheritdoc
  90. * @returns {ReactElement}
  91. */
  92. render() {
  93. return (
  94. <Container
  95. style = { styles.toolbarContainer }
  96. visible = { this.props._visible }>
  97. {
  98. this._renderPrimaryToolbar()
  99. }
  100. {
  101. this._renderSecondaryToolbar()
  102. }
  103. </Container>
  104. );
  105. }
  106. /**
  107. * Gets the styles for a button that toggles the mute state of a specific
  108. * media type.
  109. *
  110. * @param {string} mediaType - The {@link MEDIA_TYPE} associated with the
  111. * button to get styles for.
  112. * @protected
  113. * @returns {{
  114. * iconName: string,
  115. * iconStyle: Object,
  116. * style: Object
  117. * }}
  118. */
  119. _getMuteButtonStyles(mediaType) {
  120. let iconName;
  121. let iconStyle;
  122. let style;
  123. if (this.props[`_${mediaType}Muted`]) {
  124. iconName = this[`${mediaType}MutedIcon`];
  125. iconStyle = styles.whitePrimaryToolbarButtonIcon;
  126. style = styles.whitePrimaryToolbarButton;
  127. } else {
  128. iconName = this[`${mediaType}Icon`];
  129. iconStyle = styles.primaryToolbarButtonIcon;
  130. style = styles.primaryToolbarButton;
  131. }
  132. return {
  133. iconName,
  134. iconStyle,
  135. style
  136. };
  137. }
  138. /**
  139. * Dispatches an action to toggle the mute state of the audio/microphone.
  140. *
  141. * @private
  142. * @returns {void}
  143. */
  144. _onToggleAudio() {
  145. // The user sees the reality i.e. the state of base/tracks and intends
  146. // to change reality by tapping on the respective button i.e. the user
  147. // sets the state of base/media. Whether the user's intention will turn
  148. // into reality is a whole different story which is of no concern to the
  149. // tapping.
  150. this.props.dispatch(setAudioMuted(!this.props._audioMuted));
  151. }
  152. /**
  153. * Dispatches an action to toggle the mute state of the video/camera.
  154. *
  155. * @private
  156. * @returns {void}
  157. */
  158. _onToggleVideo() {
  159. // The user sees the reality i.e. the state of base/tracks and intends
  160. // to change reality by tapping on the respective button i.e. the user
  161. // sets the state of base/media. Whether the user's intention will turn
  162. // into reality is a whole different story which is of no concern to the
  163. // tapping.
  164. this.props.dispatch(setVideoMuted(!this.props._videoMuted));
  165. }
  166. /**
  167. * Renders the toolbar which contains the primary buttons such as hangup,
  168. * audio and video mute.
  169. *
  170. * @private
  171. * @returns {ReactElement}
  172. */
  173. _renderPrimaryToolbar() {
  174. const audioButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.AUDIO);
  175. const videoButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.VIDEO);
  176. /* eslint-disable react/jsx-handler-names */
  177. return (
  178. <View style = { styles.primaryToolbar }>
  179. <ToolbarButton
  180. iconName = { audioButtonStyles.iconName }
  181. iconStyle = { audioButtonStyles.iconStyle }
  182. onClick = { this._onToggleAudio }
  183. style = { audioButtonStyles.style } />
  184. <ToolbarButton
  185. iconName = 'hangup'
  186. iconStyle = { styles.whitePrimaryToolbarButtonIcon }
  187. onClick = { this.props._onHangup }
  188. style = { styles.hangup }
  189. underlayColor = { ColorPalette.buttonUnderlay } />
  190. <ToolbarButton
  191. disabled = { this.props._audioOnly }
  192. iconName = { videoButtonStyles.iconName }
  193. iconStyle = { videoButtonStyles.iconStyle }
  194. onClick = { this._onToggleVideo }
  195. style = { videoButtonStyles.style } />
  196. </View>
  197. );
  198. /* eslint-enable react/jsx-handler-names */
  199. }
  200. /**
  201. * Renders the toolbar which contains the secondary buttons such as toggle
  202. * camera facing mode.
  203. *
  204. * @private
  205. * @returns {ReactElement}
  206. */
  207. _renderSecondaryToolbar() {
  208. const iconStyle = styles.secondaryToolbarButtonIcon;
  209. const style = styles.secondaryToolbarButton;
  210. const underlayColor = 'transparent';
  211. const {
  212. _audioOnly: audioOnly,
  213. _videoMuted: videoMuted
  214. } = this.props;
  215. /* eslint-disable react/jsx-curly-spacing,react/jsx-handler-names */
  216. return (
  217. <View style = { styles.secondaryToolbar }>
  218. <ToolbarButton
  219. disabled = { audioOnly || videoMuted }
  220. iconName = 'switch-camera'
  221. iconStyle = { iconStyle }
  222. onClick = { this.props._onToggleCameraFacingMode }
  223. style = { style }
  224. underlayColor = { underlayColor } />
  225. <ToolbarButton
  226. iconName = {
  227. this.props._locked ? 'security-locked' : 'security'
  228. }
  229. iconStyle = { iconStyle }
  230. onClick = { this.props._onRoomLock }
  231. style = { style }
  232. underlayColor = { underlayColor } />
  233. <ToolbarButton
  234. iconName = { audioOnly ? 'visibility-off' : 'visibility' }
  235. iconStyle = { iconStyle }
  236. onClick = { this.props._onToggleAudioOnly }
  237. style = { style }
  238. underlayColor = { underlayColor } />
  239. <ToolbarButton
  240. iconName = 'link'
  241. iconStyle = { iconStyle }
  242. onClick = { this.props._onShareRoom }
  243. style = { style }
  244. underlayColor = { underlayColor } />
  245. </View>
  246. );
  247. /* eslint-enable react/jsx-curly-spacing,react/jsx-handler-names */
  248. }
  249. }
  250. /**
  251. * Additional properties for various icons, which are now platform-dependent.
  252. * This is done to have common logic of generating styles for web and native.
  253. * TODO As soon as we have common font sets for web and native, this will no
  254. * longer be required.
  255. */
  256. Object.assign(Toolbox.prototype, {
  257. audioIcon: 'microphone',
  258. audioMutedIcon: 'mic-disabled',
  259. videoIcon: 'camera',
  260. videoMutedIcon: 'camera-disabled'
  261. });
  262. /**
  263. * Maps actions to React component props.
  264. *
  265. * @param {Function} dispatch - Redux action dispatcher.
  266. * @returns {{
  267. * _onRoomLock: Function,
  268. * _onToggleAudioOnly: Function,
  269. * _onToggleCameraFacingMode: Function,
  270. * }}
  271. * @private
  272. */
  273. function _mapDispatchToProps(dispatch) {
  274. return {
  275. ...abstractMapDispatchToProps(dispatch),
  276. /**
  277. * Sets the lock i.e. password protection of the conference/room.
  278. *
  279. * @private
  280. * @returns {Object} Dispatched action.
  281. * @type {Function}
  282. */
  283. _onRoomLock() {
  284. dispatch(beginRoomLockRequest());
  285. },
  286. /**
  287. * Begins the UI procedure to share the conference/room URL.
  288. *
  289. * @private
  290. * @returns {void} Dispatched action.
  291. * @type {Function}
  292. */
  293. _onShareRoom() {
  294. dispatch(beginShareRoom());
  295. },
  296. /**
  297. * Toggles the audio-only flag of the conference.
  298. *
  299. * @private
  300. * @returns {Object} Dispatched action.
  301. * @type {Function}
  302. */
  303. _onToggleAudioOnly() {
  304. dispatch(toggleAudioOnly());
  305. },
  306. /**
  307. * Switches between the front/user-facing and back/environment-facing
  308. * cameras.
  309. *
  310. * @private
  311. * @returns {Object} Dispatched action.
  312. * @type {Function}
  313. */
  314. _onToggleCameraFacingMode() {
  315. dispatch(toggleCameraFacingMode());
  316. }
  317. };
  318. }
  319. /**
  320. * Maps part of Redux store to React component props.
  321. *
  322. * @param {Object} state - Redux store.
  323. * @returns {{
  324. * _audioOnly: boolean,
  325. * _locked: boolean
  326. * }}
  327. * @private
  328. */
  329. function _mapStateToProps(state) {
  330. const conference = state['features/base/conference'];
  331. return {
  332. ...abstractMapStateToProps(state),
  333. /**
  334. * The indicator which determines whether the conference is in
  335. * audio-only mode.
  336. *
  337. * @protected
  338. * @type {boolean}
  339. */
  340. _audioOnly: Boolean(conference.audioOnly),
  341. /**
  342. * The indicator which determines whether the conference is
  343. * locked/password-protected.
  344. *
  345. * @protected
  346. * @type {boolean}
  347. */
  348. _locked: Boolean(conference.locked)
  349. };
  350. }
  351. export default connect(_mapStateToProps, _mapDispatchToProps)(Toolbox);