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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { View } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { toggleAudioOnly } from '../../base/conference';
  6. import {
  7. MEDIA_TYPE,
  8. toggleCameraFacingMode
  9. } from '../../base/media';
  10. import { Container } from '../../base/react';
  11. import {
  12. isNarrowAspectRatio,
  13. makeAspectRatioAware
  14. } from '../../base/responsive-ui';
  15. import {
  16. InviteButton,
  17. isAddPeopleEnabled,
  18. isDialOutEnabled
  19. } from '../../invite';
  20. import {
  21. EnterPictureInPictureToolbarButton
  22. } from '../../mobile/picture-in-picture';
  23. import { beginRoomLockRequest } from '../../room-lock';
  24. import { beginShareRoom } from '../../share-room';
  25. import {
  26. abstractMapDispatchToProps,
  27. abstractMapStateToProps
  28. } from '../functions';
  29. import AudioRouteButton from './AudioRouteButton';
  30. import styles from './styles';
  31. import ToolbarButton from './ToolbarButton';
  32. import { AudioMuteButton, HangupButton, VideoMuteButton } from './buttons';
  33. /**
  34. * The type of {@link Toolbox}'s React {@code Component} props.
  35. */
  36. type Props = {
  37. /**
  38. * Flag showing that audio is muted.
  39. */
  40. _audioMuted: boolean,
  41. /**
  42. * Flag showing whether the audio-only mode is in use.
  43. */
  44. _audioOnly: boolean,
  45. /**
  46. * Whether or not the feature to directly invite people into the
  47. * conference is available.
  48. */
  49. _enableAddPeople: boolean,
  50. /**
  51. * Whether or not the feature to dial out to number to join the
  52. * conference is available.
  53. */
  54. _enableDialOut: boolean,
  55. /**
  56. * The indicator which determines whether the toolbox is enabled.
  57. */
  58. _enabled: boolean,
  59. /**
  60. * Flag showing whether room is locked.
  61. */
  62. _locked: boolean,
  63. /**
  64. * Handler for hangup.
  65. */
  66. _onHangup: Function,
  67. /**
  68. * Sets the lock i.e. password protection of the conference/room.
  69. */
  70. _onRoomLock: Function,
  71. /**
  72. * Begins the UI procedure to share the conference/room URL.
  73. */
  74. _onShareRoom: Function,
  75. /**
  76. * Toggles the audio-only flag of the conference.
  77. */
  78. _onToggleAudioOnly: Function,
  79. /**
  80. * Switches between the front/user-facing and back/environment-facing
  81. * cameras.
  82. */
  83. _onToggleCameraFacingMode: Function,
  84. /**
  85. * Flag showing whether video is muted.
  86. */
  87. _videoMuted: boolean,
  88. /**
  89. * Flag showing whether toolbar is visible.
  90. */
  91. _visible: boolean,
  92. dispatch: Function
  93. };
  94. /**
  95. * Implements the conference toolbox on React Native.
  96. */
  97. class Toolbox extends Component<Props> {
  98. /**
  99. * Implements React's {@link Component#render()}.
  100. *
  101. * @inheritdoc
  102. * @returns {ReactElement}
  103. */
  104. render() {
  105. if (!this.props._enabled) {
  106. return null;
  107. }
  108. const toolboxStyle
  109. = isNarrowAspectRatio(this)
  110. ? styles.toolboxNarrow
  111. : styles.toolboxWide;
  112. return (
  113. <Container
  114. style = { toolboxStyle }
  115. visible = { this.props._visible } >
  116. { this._renderToolbars() }
  117. </Container>
  118. );
  119. }
  120. /**
  121. * Gets the styles for a button that toggles the mute state of a specific
  122. * media type.
  123. *
  124. * @param {string} mediaType - The {@link MEDIA_TYPE} associated with the
  125. * button to get styles for.
  126. * @protected
  127. * @returns {{
  128. * iconName: string,
  129. * iconStyle: Object,
  130. * style: Object
  131. * }}
  132. */
  133. _getMuteButtonStyles(mediaType) {
  134. let iconName;
  135. let iconStyle;
  136. let style;
  137. if (this.props[`_${mediaType}Muted`]) {
  138. iconName = `${mediaType}MutedIcon`;
  139. iconStyle = styles.whitePrimaryToolbarButtonIcon;
  140. style = styles.whitePrimaryToolbarButton;
  141. } else {
  142. iconName = `${mediaType}Icon`;
  143. iconStyle = styles.primaryToolbarButtonIcon;
  144. style = styles.primaryToolbarButton;
  145. }
  146. return {
  147. // $FlowExpectedError
  148. iconName: this[iconName],
  149. iconStyle,
  150. style
  151. };
  152. }
  153. /**
  154. * Renders the toolbar which contains the primary buttons such as hangup,
  155. * audio and video mute.
  156. *
  157. * @private
  158. * @returns {ReactElement}
  159. */
  160. _renderPrimaryToolbar() {
  161. const audioButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.AUDIO);
  162. const videoButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.VIDEO);
  163. /* eslint-disable react/jsx-handler-names */
  164. return (
  165. <View
  166. key = 'primaryToolbar'
  167. pointerEvents = 'box-none'
  168. style = { styles.primaryToolbar }>
  169. <AudioMuteButton buttonStyles = { audioButtonStyles } />
  170. <HangupButton />
  171. <VideoMuteButton buttonStyles = { videoButtonStyles } />
  172. </View>
  173. );
  174. /* eslint-enable react/jsx-handler-names */
  175. }
  176. /**
  177. * Renders the toolbar which contains the secondary buttons such as toggle
  178. * camera facing mode.
  179. *
  180. * @private
  181. * @returns {ReactElement}
  182. */
  183. _renderSecondaryToolbar() {
  184. const iconStyle = styles.secondaryToolbarButtonIcon;
  185. const style = styles.secondaryToolbarButton;
  186. const underlayColor = 'transparent';
  187. const {
  188. _audioOnly: audioOnly,
  189. _enableAddPeople: enableAddPeople,
  190. _enableDialOut: enableDialOut,
  191. _videoMuted: videoMuted
  192. } = this.props;
  193. const showInviteButton = enableAddPeople || enableDialOut;
  194. /* eslint-disable react/jsx-curly-spacing,react/jsx-handler-names */
  195. return (
  196. <View
  197. key = 'secondaryToolbar'
  198. pointerEvents = 'box-none'
  199. style = { styles.secondaryToolbar }>
  200. {
  201. AudioRouteButton
  202. && <AudioRouteButton
  203. iconName = { 'volume' }
  204. iconStyle = { iconStyle }
  205. style = { style }
  206. underlayColor = { underlayColor } />
  207. }
  208. <ToolbarButton
  209. disabled = { audioOnly || videoMuted }
  210. iconName = 'switch-camera'
  211. iconStyle = { iconStyle }
  212. onClick = { this.props._onToggleCameraFacingMode }
  213. style = { style }
  214. underlayColor = { underlayColor } />
  215. <ToolbarButton
  216. iconName = { audioOnly ? 'visibility-off' : 'visibility' }
  217. iconStyle = { iconStyle }
  218. onClick = { this.props._onToggleAudioOnly }
  219. style = { style }
  220. underlayColor = { underlayColor } />
  221. <ToolbarButton
  222. iconName = {
  223. this.props._locked ? 'security-locked' : 'security'
  224. }
  225. iconStyle = { iconStyle }
  226. onClick = { this.props._onRoomLock }
  227. style = { style }
  228. underlayColor = { underlayColor } />
  229. {
  230. !showInviteButton
  231. && <ToolbarButton
  232. iconName = 'link'
  233. iconStyle = { iconStyle }
  234. onClick = { this.props._onShareRoom }
  235. style = { style }
  236. underlayColor = { underlayColor } />
  237. }
  238. {
  239. showInviteButton
  240. && <InviteButton
  241. enableAddPeople = { enableAddPeople }
  242. enableDialOut = { enableDialOut }
  243. iconStyle = { iconStyle }
  244. style = { style }
  245. underlayColor = { underlayColor } />
  246. }
  247. <EnterPictureInPictureToolbarButton
  248. iconStyle = { iconStyle }
  249. style = { style }
  250. underlayColor = { underlayColor } />
  251. </View>
  252. );
  253. /* eslint-enable react/jsx-curly-spacing,react/jsx-handler-names */
  254. }
  255. /**
  256. * Renders the primary and the secondary toolbars.
  257. *
  258. * @private
  259. * @returns {[ReactElement, ReactElement]}
  260. */
  261. _renderToolbars() {
  262. return [
  263. this._renderSecondaryToolbar(),
  264. this._renderPrimaryToolbar()
  265. ];
  266. }
  267. }
  268. /**
  269. * Additional properties for various icons, which are now platform-dependent.
  270. * This is done to have common logic of generating styles for web and native.
  271. * TODO As soon as we have common font sets for web and native, this will no
  272. * longer be required.
  273. */
  274. // $FlowExpectedError
  275. Object.assign(Toolbox.prototype, {
  276. audioIcon: 'microphone',
  277. audioMutedIcon: 'mic-disabled',
  278. videoIcon: 'camera',
  279. videoMutedIcon: 'camera-disabled'
  280. });
  281. /**
  282. * Maps redux actions to {@link Toolbox}'s React {@code Component} props.
  283. *
  284. * @param {Function} dispatch - The redux action {@code dispatch} function.
  285. * @private
  286. * @returns {{
  287. * _onRoomLock: Function,
  288. * _onToggleAudioOnly: Function,
  289. * _onToggleCameraFacingMode: Function,
  290. * }}
  291. */
  292. function _mapDispatchToProps(dispatch) {
  293. return {
  294. ...abstractMapDispatchToProps(dispatch),
  295. /**
  296. * Sets the lock i.e. password protection of the conference/room.
  297. *
  298. * @private
  299. * @returns {void}
  300. * @type {Function}
  301. */
  302. _onRoomLock() {
  303. dispatch(beginRoomLockRequest());
  304. },
  305. /**
  306. * Begins the UI procedure to share the conference/room URL.
  307. *
  308. * @private
  309. * @returns {void}
  310. * @type {Function}
  311. */
  312. _onShareRoom() {
  313. dispatch(beginShareRoom());
  314. },
  315. /**
  316. * Toggles the audio-only flag of the conference.
  317. *
  318. * @private
  319. * @returns {void}
  320. * @type {Function}
  321. */
  322. _onToggleAudioOnly() {
  323. dispatch(toggleAudioOnly());
  324. },
  325. /**
  326. * Switches between the front/user-facing and back/environment-facing
  327. * cameras.
  328. *
  329. * @private
  330. * @returns {void}
  331. * @type {Function}
  332. */
  333. _onToggleCameraFacingMode() {
  334. dispatch(toggleCameraFacingMode());
  335. }
  336. };
  337. }
  338. /**
  339. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  340. * props.
  341. *
  342. * @param {Object} state - The redux store/state.
  343. * @private
  344. * @returns {{
  345. * _audioOnly: boolean,
  346. * _enabled: boolean,
  347. * _locked: boolean
  348. * }}
  349. */
  350. function _mapStateToProps(state) {
  351. const conference = state['features/base/conference'];
  352. const { enabled } = state['features/toolbox'];
  353. return {
  354. ...abstractMapStateToProps(state),
  355. /**
  356. * The indicator which determines whether the conference is in
  357. * audio-only mode.
  358. *
  359. * @protected
  360. * @type {boolean}
  361. */
  362. _audioOnly: Boolean(conference.audioOnly),
  363. /**
  364. * Whether or not the feature to directly invite people into the
  365. * conference is available.
  366. *
  367. * @type {boolean}
  368. */
  369. _enableAddPeople: isAddPeopleEnabled(state),
  370. /**
  371. * Whether or not the feature to dial out to number to join the
  372. * conference is available.
  373. *
  374. * @type {boolean}
  375. */
  376. _enableDialOut: isDialOutEnabled(state),
  377. /**
  378. * The indicator which determines whether the toolbox is enabled.
  379. *
  380. * @private
  381. * @type {boolean}
  382. */
  383. _enabled: enabled,
  384. /**
  385. * The indicator which determines whether the conference is
  386. * locked/password-protected.
  387. *
  388. * @protected
  389. * @type {boolean}
  390. */
  391. _locked: Boolean(conference.locked)
  392. };
  393. }
  394. export default connect(_mapStateToProps, _mapDispatchToProps)(
  395. makeAspectRatioAware(Toolbox));