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.9KB

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