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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. style = { styles.primaryToolbar }>
  162. <AudioMuteButton buttonStyles = { audioButtonStyles } />
  163. <HangupButton />
  164. <VideoMuteButton buttonStyles = { videoButtonStyles } />
  165. </View>
  166. );
  167. /* eslint-enable react/jsx-handler-names */
  168. }
  169. /**
  170. * Renders the toolbar which contains the secondary buttons such as toggle
  171. * camera facing mode.
  172. *
  173. * @private
  174. * @returns {ReactElement}
  175. */
  176. _renderSecondaryToolbar() {
  177. const iconStyle = styles.secondaryToolbarButtonIcon;
  178. const style = styles.secondaryToolbarButton;
  179. const underlayColor = 'transparent';
  180. const {
  181. _audioOnly: audioOnly,
  182. _videoMuted: videoMuted
  183. } = this.props;
  184. /* eslint-disable react/jsx-curly-spacing,react/jsx-handler-names */
  185. return (
  186. <View
  187. key = 'secondaryToolbar'
  188. style = { styles.secondaryToolbar }>
  189. {
  190. AudioRouteButton
  191. && <AudioRouteButton
  192. iconName = { 'volume' }
  193. iconStyle = { iconStyle }
  194. style = { style }
  195. underlayColor = { underlayColor } />
  196. }
  197. <ToolbarButton
  198. disabled = { audioOnly || videoMuted }
  199. iconName = 'switch-camera'
  200. iconStyle = { iconStyle }
  201. onClick = { this.props._onToggleCameraFacingMode }
  202. style = { style }
  203. underlayColor = { underlayColor } />
  204. <ToolbarButton
  205. iconName = { audioOnly ? 'visibility-off' : 'visibility' }
  206. iconStyle = { iconStyle }
  207. onClick = { this.props._onToggleAudioOnly }
  208. style = { style }
  209. underlayColor = { underlayColor } />
  210. <ToolbarButton
  211. iconName = {
  212. this.props._locked ? 'security-locked' : 'security'
  213. }
  214. iconStyle = { iconStyle }
  215. onClick = { this.props._onRoomLock }
  216. style = { style }
  217. underlayColor = { underlayColor } />
  218. {
  219. _SHARE_ROOM_TOOLBAR_BUTTON
  220. && <ToolbarButton
  221. iconName = 'link'
  222. iconStyle = { iconStyle }
  223. onClick = { this.props._onShareRoom }
  224. style = { style }
  225. underlayColor = { underlayColor } />
  226. }
  227. <EnterPictureInPictureToolbarButton
  228. iconStyle = { iconStyle }
  229. style = { style }
  230. underlayColor = { underlayColor } />
  231. </View>
  232. );
  233. /* eslint-enable react/jsx-curly-spacing,react/jsx-handler-names */
  234. }
  235. /**
  236. * Renders the primary and the secondary toolbars.
  237. *
  238. * @private
  239. * @returns {[ReactElement, ReactElement]}
  240. */
  241. _renderToolbars() {
  242. return [
  243. this._renderSecondaryToolbar(),
  244. this._renderPrimaryToolbar()
  245. ];
  246. }
  247. }
  248. /**
  249. * Additional properties for various icons, which are now platform-dependent.
  250. * This is done to have common logic of generating styles for web and native.
  251. * TODO As soon as we have common font sets for web and native, this will no
  252. * longer be required.
  253. */
  254. // $FlowExpectedError
  255. Object.assign(Toolbox.prototype, {
  256. audioIcon: 'microphone',
  257. audioMutedIcon: 'mic-disabled',
  258. videoIcon: 'camera',
  259. videoMutedIcon: 'camera-disabled'
  260. });
  261. /**
  262. * Maps redux actions to {@link Toolbox}'s React {@code Component} props.
  263. *
  264. * @param {Function} dispatch - The redux action {@code dispatch} function.
  265. * @private
  266. * @returns {{
  267. * _onRoomLock: Function,
  268. * _onToggleAudioOnly: Function,
  269. * _onToggleCameraFacingMode: Function,
  270. * }}
  271. */
  272. function _mapDispatchToProps(dispatch) {
  273. return {
  274. ...abstractMapDispatchToProps(dispatch),
  275. /**
  276. * Sets the lock i.e. password protection of the conference/room.
  277. *
  278. * @private
  279. * @returns {void}
  280. * @type {Function}
  281. */
  282. _onRoomLock() {
  283. dispatch(beginRoomLockRequest());
  284. },
  285. /**
  286. * Begins the UI procedure to share the conference/room URL.
  287. *
  288. * @private
  289. * @returns {void}
  290. * @type {Function}
  291. */
  292. _onShareRoom() {
  293. dispatch(beginShareRoom());
  294. },
  295. /**
  296. * Toggles the audio-only flag of the conference.
  297. *
  298. * @private
  299. * @returns {void}
  300. * @type {Function}
  301. */
  302. _onToggleAudioOnly() {
  303. dispatch(toggleAudioOnly());
  304. },
  305. /**
  306. * Switches between the front/user-facing and back/environment-facing
  307. * cameras.
  308. *
  309. * @private
  310. * @returns {void}
  311. * @type {Function}
  312. */
  313. _onToggleCameraFacingMode() {
  314. dispatch(toggleCameraFacingMode());
  315. }
  316. };
  317. }
  318. /**
  319. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  320. * props.
  321. *
  322. * @param {Object} state - The redux store/state.
  323. * @private
  324. * @returns {{
  325. * _audioOnly: boolean,
  326. * _enabled: boolean,
  327. * _locked: boolean
  328. * }}
  329. */
  330. function _mapStateToProps(state) {
  331. const conference = state['features/base/conference'];
  332. const { enabled } = state['features/toolbox'];
  333. return {
  334. ...abstractMapStateToProps(state),
  335. /**
  336. * The indicator which determines whether the conference is in
  337. * audio-only mode.
  338. *
  339. * @protected
  340. * @type {boolean}
  341. */
  342. _audioOnly: Boolean(conference.audioOnly),
  343. /**
  344. * The indicator which determines whether the toolbox is enabled.
  345. *
  346. * @private
  347. * @type {boolean}
  348. */
  349. _enabled: enabled,
  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)(
  361. makeAspectRatioAware(Toolbox));