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

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