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.

VideoSettingsPopup.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React, { ReactNode } from 'react';
  2. import { connect } from 'react-redux';
  3. import { makeStyles } from 'tss-react/mui';
  4. import { IReduxState } from '../../../../app/types';
  5. import {
  6. setVideoInputDeviceAndUpdateSettings
  7. } from '../../../../base/devices/actions.web';
  8. import {
  9. getVideoDeviceIds
  10. } from '../../../../base/devices/functions.web';
  11. import Popover from '../../../../base/popover/components/Popover.web';
  12. import { SMALL_MOBILE_WIDTH } from '../../../../base/responsive-ui/constants';
  13. import { getCurrentCameraDeviceId } from '../../../../base/settings/functions.web';
  14. import { toggleVideoSettings } from '../../../actions';
  15. import { getVideoSettingsVisibility } from '../../../functions.web';
  16. import VideoSettingsContent from './VideoSettingsContent';
  17. interface IProps {
  18. /**
  19. * Component children (the Video button).
  20. */
  21. children: ReactNode;
  22. /**
  23. * The deviceId of the camera device currently being used.
  24. */
  25. currentCameraDeviceId: string;
  26. /**
  27. * Flag controlling the visibility of the popup.
  28. */
  29. isOpen: boolean;
  30. /**
  31. * Callback executed when the popup closes.
  32. */
  33. onClose: Function;
  34. /**
  35. * The popup placement enum value.
  36. */
  37. popupPlacement: string;
  38. /**
  39. * Callback invoked to change current camera.
  40. */
  41. setVideoInputDevice: Function;
  42. /**
  43. * All the camera device ids currently connected.
  44. */
  45. videoDeviceIds: string[];
  46. }
  47. const useStyles = makeStyles()(() => {
  48. return {
  49. container: {
  50. background: 'none',
  51. display: 'inline-block'
  52. }
  53. };
  54. });
  55. /**
  56. * Popup with a preview of all the video devices.
  57. *
  58. * @returns {ReactElement}
  59. */
  60. function VideoSettingsPopup({
  61. currentCameraDeviceId,
  62. children,
  63. isOpen,
  64. onClose,
  65. popupPlacement,
  66. setVideoInputDevice,
  67. videoDeviceIds
  68. }: IProps) {
  69. const { classes, cx } = useStyles();
  70. return (
  71. <div className = { cx('video-preview', classes.container) }>
  72. <Popover
  73. allowClick = { true }
  74. content = { <VideoSettingsContent
  75. currentCameraDeviceId = { currentCameraDeviceId }
  76. setVideoInputDevice = { setVideoInputDevice }
  77. toggleVideoSettings = { onClose }
  78. videoDeviceIds = { videoDeviceIds } /> }
  79. headingId = 'video-settings-button'
  80. onPopoverClose = { onClose }
  81. position = { popupPlacement }
  82. trigger = 'click'
  83. visible = { isOpen }>
  84. { children }
  85. </Popover>
  86. </div>
  87. );
  88. }
  89. /**
  90. * Maps (parts of) the redux state to the associated {@code VideoSettingsPopup}'s
  91. * props.
  92. *
  93. * @param {Object} state - Redux state.
  94. * @returns {Object}
  95. */
  96. function mapStateToProps(state: IReduxState) {
  97. const { clientWidth } = state['features/base/responsive-ui'];
  98. return {
  99. currentCameraDeviceId: getCurrentCameraDeviceId(state),
  100. isOpen: Boolean(getVideoSettingsVisibility(state)),
  101. popupPlacement: clientWidth <= Number(SMALL_MOBILE_WIDTH) ? 'auto' : 'top-end',
  102. videoDeviceIds: getVideoDeviceIds(state) ?? []
  103. };
  104. }
  105. const mapDispatchToProps = {
  106. onClose: toggleVideoSettings,
  107. setVideoInputDevice: setVideoInputDeviceAndUpdateSettings
  108. };
  109. export default connect(mapStateToProps, mapDispatchToProps)(VideoSettingsPopup);