您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbox.native.js 12KB

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