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

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