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.4KB

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