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

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