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.

DeviceSelectionDialog.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import {
  5. setAudioInputDevice,
  6. setAudioOutputDevice,
  7. setVideoInputDevice
  8. } from '../../base/devices';
  9. import { hideDialog } from '../../base/dialog';
  10. import DeviceSelectionDialogBase from './DeviceSelectionDialogBase';
  11. /**
  12. * React component for previewing and selecting new audio and video sources.
  13. *
  14. * @extends Component
  15. */
  16. class DeviceSelectionDialog extends Component {
  17. /**
  18. * DeviceSelectionDialog component's property types.
  19. *
  20. * @static
  21. */
  22. static propTypes = {
  23. /**
  24. * All known audio and video devices split by type. This prop comes from
  25. * the app state.
  26. */
  27. _availableDevices: PropTypes.object,
  28. /**
  29. * Device id for the current audio input device. This device will be set
  30. * as the default audio input device to preview.
  31. */
  32. currentAudioInputId: PropTypes.string,
  33. /**
  34. * Device id for the current audio output device. This device will be
  35. * set as the default audio output device to preview.
  36. */
  37. currentAudioOutputId: PropTypes.string,
  38. /**
  39. * Device id for the current video input device. This device will be set
  40. * as the default video input device to preview.
  41. */
  42. currentVideoInputId: PropTypes.string,
  43. /**
  44. * Whether or not the audio selector can be interacted with. If true,
  45. * the audio input selector will be rendered as disabled. This is
  46. * specifically used to prevent audio device changing in Firefox, which
  47. * currently does not work due to a browser-side regression.
  48. */
  49. disableAudioInputChange: PropTypes.bool,
  50. /**
  51. * True if device changing is configured to be disallowed. Selectors
  52. * will display as disabled.
  53. */
  54. disableDeviceChange: PropTypes.bool,
  55. /**
  56. * Invoked to notify the store of app state changes.
  57. */
  58. dispatch: PropTypes.func,
  59. /**
  60. * Function that checks whether or not a new audio input source can be
  61. * selected.
  62. */
  63. hasAudioPermission: PropTypes.func,
  64. /**
  65. * Function that checks whether or not a new video input sources can be
  66. * selected.
  67. */
  68. hasVideoPermission: PropTypes.func,
  69. /**
  70. * If true, the audio meter will not display. Necessary for browsers or
  71. * configurations that do not support local stats to prevent a
  72. * non-responsive mic preview from displaying.
  73. */
  74. hideAudioInputPreview: PropTypes.bool,
  75. /**
  76. * Whether or not the audio output source selector should display. If
  77. * true, the audio output selector and test audio link will not be
  78. * rendered. This is specifically used for hiding audio output on
  79. * temasys browsers which do not support such change.
  80. */
  81. hideAudioOutputSelect: PropTypes.bool
  82. };
  83. /**
  84. * Implements React's {@link Component#render()}.
  85. *
  86. * @inheritdoc
  87. */
  88. render() {
  89. const {
  90. currentAudioInputId,
  91. currentAudioOutputId,
  92. currentVideoInputId,
  93. disableAudioInputChange,
  94. disableDeviceChange,
  95. dispatch,
  96. hasAudioPermission,
  97. hasVideoPermission,
  98. hideAudioInputPreview,
  99. hideAudioOutputSelect
  100. } = this.props;
  101. const props = {
  102. availableDevices: this.props._availableDevices,
  103. closeModal: () => dispatch(hideDialog()),
  104. currentAudioInputId,
  105. currentAudioOutputId,
  106. currentVideoInputId,
  107. disableAudioInputChange,
  108. disableDeviceChange,
  109. hasAudioPermission,
  110. hasVideoPermission,
  111. hideAudioInputPreview,
  112. hideAudioOutputSelect,
  113. setAudioInputDevice: id => {
  114. dispatch(setAudioInputDevice(id));
  115. return Promise.resolve();
  116. },
  117. setAudioOutputDevice: id => {
  118. dispatch(setAudioOutputDevice(id));
  119. return Promise.resolve();
  120. },
  121. setVideoInputDevice: id => {
  122. dispatch(setVideoInputDevice(id));
  123. return Promise.resolve();
  124. }
  125. };
  126. return <DeviceSelectionDialogBase { ...props } />;
  127. }
  128. }
  129. /**
  130. * Maps (parts of) the Redux state to the associated DeviceSelectionDialog's
  131. * props.
  132. *
  133. * @param {Object} state - The Redux state.
  134. * @private
  135. * @returns {{
  136. * _availableDevices: Object
  137. * }}
  138. */
  139. function _mapStateToProps(state) {
  140. return {
  141. _availableDevices: state['features/base/devices']
  142. };
  143. }
  144. export default connect(_mapStateToProps)(DeviceSelectionDialog);