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.

Toolbar.native.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import React from 'react';
  2. import { View } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { MEDIA_TYPE, toggleCameraFacingMode } from '../../base/media';
  5. import { Container } from '../../base/react';
  6. import { ColorPalette } from '../../base/styles';
  7. import { AbstractToolbar, _mapStateToProps } from './AbstractToolbar';
  8. import { styles } from './styles';
  9. import ToolbarButton from './ToolbarButton';
  10. /**
  11. * Implements the conference toolbar on React Native.
  12. *
  13. * @extends AbstractToolbar
  14. */
  15. class Toolbar extends AbstractToolbar {
  16. /**
  17. * Toolbar component's property types.
  18. *
  19. * @static
  20. */
  21. static propTypes = AbstractToolbar.propTypes
  22. /**
  23. * Initializes a new Toolbar instance.
  24. *
  25. * @param {Object} props - The read-only React Component props with which
  26. * the new instance is to be initialized.
  27. */
  28. constructor(props) {
  29. super(props);
  30. // Bind event handlers so they are only bound once for every instance.
  31. this._toggleCameraFacingMode
  32. = this._toggleCameraFacingMode.bind(this);
  33. }
  34. /**
  35. * Implements React's {@link Component#render()}.
  36. *
  37. * @inheritdoc
  38. * @returns {ReactElement}
  39. */
  40. render() {
  41. return (
  42. <Container
  43. style = { styles.toolbarContainer }
  44. visible = { this.props.visible }>
  45. {
  46. this._renderPrimaryToolbar()
  47. }
  48. {
  49. this._renderSecondaryToolbar()
  50. }
  51. </Container>
  52. );
  53. }
  54. /**
  55. * Renders the toolbar which contains the primary buttons such as hangup,
  56. * audio and video mute.
  57. *
  58. * @private
  59. * @returns {ReactElement}
  60. */
  61. _renderPrimaryToolbar() {
  62. const audioButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.AUDIO);
  63. const videoButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.VIDEO);
  64. /* eslint-disable react/jsx-handler-names */
  65. return (
  66. <View style = { styles.primaryToolbar }>
  67. <ToolbarButton
  68. iconName = { audioButtonStyles.iconName }
  69. iconStyle = { audioButtonStyles.iconStyle }
  70. onClick = { this._toggleAudio }
  71. style = { audioButtonStyles.style } />
  72. <ToolbarButton
  73. iconName = 'hangup'
  74. iconStyle = { styles.whiteIcon }
  75. onClick = { this._onHangup }
  76. style = {{
  77. ...styles.primaryToolbarButton,
  78. backgroundColor: ColorPalette.red
  79. }}
  80. underlayColor = { ColorPalette.buttonUnderlay } />
  81. <ToolbarButton
  82. iconName = { videoButtonStyles.iconName }
  83. iconStyle = { videoButtonStyles.iconStyle }
  84. onClick = { this._toggleVideo }
  85. style = { videoButtonStyles.style } />
  86. </View>
  87. );
  88. /* eslint-enable react/jsx-handler-names */
  89. }
  90. /**
  91. * Renders the toolbar which contains the secondary buttons such as toggle
  92. * camera facing mode.
  93. *
  94. * @private
  95. * @returns {ReactElement}
  96. */
  97. _renderSecondaryToolbar() {
  98. const iconStyle = styles.secondaryToolbarIcon;
  99. const style = styles.secondaryToolbarButton;
  100. const underlayColor = 'transparent';
  101. /* eslint-disable react/jsx-curly-spacing,react/jsx-handler-names */
  102. // TODO Use an appropriate icon for toggle camera facing mode.
  103. return (
  104. <View style = { styles.secondaryToolbar }>
  105. <ToolbarButton
  106. iconName = 'switch-camera'
  107. iconStyle = { iconStyle }
  108. onClick = { this._toggleCameraFacingMode }
  109. style = { style }
  110. underlayColor = { underlayColor } />
  111. <ToolbarButton
  112. iconName = {
  113. this.props._locked ? 'security-locked' : 'security'
  114. }
  115. iconStyle = { iconStyle }
  116. onClick = { this._onRoomLock }
  117. style = { style }
  118. underlayColor = { underlayColor } />
  119. </View>
  120. );
  121. /* eslint-enable react/jsx-curly-spacing,react/jsx-handler-names */
  122. }
  123. /**
  124. * Switches between the front/user-facing and rear/environment-facing
  125. * cameras.
  126. *
  127. * @private
  128. * @returns {void}
  129. */
  130. _toggleCameraFacingMode() {
  131. this.props.dispatch(toggleCameraFacingMode());
  132. }
  133. }
  134. /**
  135. * Additional properties for various icons, which are now platform-dependent.
  136. * This is done to have common logic of generating styles for web and native.
  137. * TODO As soon as we have common font sets for web and native, this will no
  138. * longer be required.
  139. */
  140. Object.assign(Toolbar.prototype, {
  141. audioIcon: 'microphone',
  142. audioMutedIcon: 'mic-disabled',
  143. videoIcon: 'camera',
  144. videoMutedIcon: 'camera-disabled'
  145. });
  146. export default connect(_mapStateToProps)(Toolbar);