Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. * iconName: string,
  110. * iconStyle: Object,
  111. * style: Object
  112. * }}
  113. */
  114. _getMuteButtonStyles(mediaType) {
  115. let iconName;
  116. let iconStyle;
  117. let style;
  118. if (this.props[`_${mediaType}Muted`]) {
  119. iconName = `${mediaType}MutedIcon`;
  120. iconStyle = styles.whitePrimaryToolbarButtonIcon;
  121. style = styles.whitePrimaryToolbarButton;
  122. } else {
  123. iconName = `${mediaType}Icon`;
  124. iconStyle = styles.primaryToolbarButtonIcon;
  125. style = styles.primaryToolbarButton;
  126. }
  127. return {
  128. // $FlowExpectedError
  129. iconName: this[iconName],
  130. iconStyle,
  131. style
  132. };
  133. }
  134. /**
  135. * Renders the toolbar which contains the primary buttons such as hangup,
  136. * audio and video mute.
  137. *
  138. * @private
  139. * @returns {ReactElement}
  140. */
  141. _renderPrimaryToolbar() {
  142. const audioButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.AUDIO);
  143. const videoButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.VIDEO);
  144. /* eslint-disable react/jsx-handler-names */
  145. return (
  146. <View
  147. key = 'primaryToolbar'
  148. pointerEvents = 'box-none'
  149. style = { styles.primaryToolbar }>
  150. <AudioMuteButton buttonStyles = { audioButtonStyles } />
  151. <HangupButton />
  152. <VideoMuteButton buttonStyles = { 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. * Additional properties for various icons, which are now platform-dependent.
  234. * This is done to have common logic of generating styles for web and native.
  235. * TODO As soon as we have common font sets for web and native, this will no
  236. * longer be required.
  237. */
  238. // $FlowExpectedError
  239. Object.assign(Toolbox.prototype, {
  240. audioIcon: 'microphone',
  241. audioMutedIcon: 'mic-disabled',
  242. videoIcon: 'camera',
  243. videoMutedIcon: 'camera-disabled'
  244. });
  245. /**
  246. * Maps redux actions to {@link Toolbox}'s React {@code Component} props.
  247. *
  248. * @param {Function} dispatch - The redux action {@code dispatch} function.
  249. * @private
  250. * @returns {{
  251. * _onRoomLock: Function,
  252. * _onToggleAudioOnly: Function,
  253. * _onToggleCameraFacingMode: Function,
  254. * }}
  255. */
  256. function _mapDispatchToProps(dispatch) {
  257. return {
  258. ...abstractMapDispatchToProps(dispatch),
  259. /**
  260. * Sets the lock i.e. password protection of the conference/room.
  261. *
  262. * @private
  263. * @returns {void}
  264. * @type {Function}
  265. */
  266. _onRoomLock() {
  267. dispatch(beginRoomLockRequest());
  268. },
  269. /**
  270. * Toggles the audio-only flag of the conference.
  271. *
  272. * @private
  273. * @returns {void}
  274. * @type {Function}
  275. */
  276. _onToggleAudioOnly() {
  277. dispatch(toggleAudioOnly());
  278. },
  279. /**
  280. * Switches between the front/user-facing and back/environment-facing
  281. * cameras.
  282. *
  283. * @private
  284. * @returns {void}
  285. * @type {Function}
  286. */
  287. _onToggleCameraFacingMode() {
  288. dispatch(toggleCameraFacingMode());
  289. }
  290. };
  291. }
  292. /**
  293. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  294. * props.
  295. *
  296. * @param {Object} state - The redux store/state.
  297. * @private
  298. * @returns {{
  299. * _audioOnly: boolean,
  300. * _enabled: boolean,
  301. * _locked: boolean
  302. * }}
  303. */
  304. function _mapStateToProps(state) {
  305. const conference = state['features/base/conference'];
  306. const { enabled } = state['features/toolbox'];
  307. return {
  308. ...abstractMapStateToProps(state),
  309. /**
  310. * The indicator which determines whether the conference is in
  311. * audio-only mode.
  312. *
  313. * @protected
  314. * @type {boolean}
  315. */
  316. _audioOnly: Boolean(conference.audioOnly),
  317. /**
  318. * The indicator which determines whether the toolbox is enabled.
  319. *
  320. * @private
  321. * @type {boolean}
  322. */
  323. _enabled: enabled,
  324. /**
  325. * The indicator which determines whether the conference is
  326. * locked/password-protected.
  327. *
  328. * @protected
  329. * @type {boolean}
  330. */
  331. _locked: Boolean(conference.locked)
  332. };
  333. }
  334. export default connect(_mapStateToProps, _mapDispatchToProps)(
  335. makeAspectRatioAware(Toolbox));