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

DeviceSelectionDialog.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * Whether or not a new audio input source can be selected.
  60. */
  61. hasAudioPermission: React.PropTypes.bool,
  62. /**
  63. * Whether or not a new video input sources can be selected.
  64. */
  65. hasVideoPermission: React.PropTypes.bool,
  66. /**
  67. * If true, the audio meter will not display. Necessary for browsers or
  68. * configurations that do not support local stats to prevent a
  69. * non-responsive mic preview from displaying.
  70. */
  71. hideAudioInputPreview: React.PropTypes.bool,
  72. /**
  73. * Whether or not the audio output source selector should display. If
  74. * true, the audio output selector and test audio link will not be
  75. * rendered. This is specifically used for hiding audio output on
  76. * temasys browsers which do not support such change.
  77. */
  78. hideAudioOutputSelect: React.PropTypes.bool
  79. };
  80. /**
  81. * Implements React's {@link Component#render()}.
  82. *
  83. * @inheritdoc
  84. */
  85. render() {
  86. const {
  87. currentAudioInputId,
  88. currentAudioOutputId,
  89. currentVideoInputId,
  90. disableAudioInputChange,
  91. disableDeviceChange,
  92. dispatch,
  93. hasAudioPermission,
  94. hasVideoPermission,
  95. hideAudioInputPreview,
  96. hideAudioOutputSelect
  97. } = this.props;
  98. const props = {
  99. availableDevices: this.props._availableDevices,
  100. closeModal: () => dispatch(hideDialog()),
  101. currentAudioInputId,
  102. currentAudioOutputId,
  103. currentVideoInputId,
  104. disableAudioInputChange,
  105. disableDeviceChange,
  106. hasAudioPermission,
  107. hasVideoPermission,
  108. hideAudioInputPreview,
  109. hideAudioOutputSelect,
  110. setAudioInputDevice: id => {
  111. dispatch(setAudioInputDevice(id));
  112. return Promise.resolve();
  113. },
  114. setAudioOutputDevice: id => {
  115. dispatch(setAudioOutputDevice(id));
  116. return Promise.resolve();
  117. },
  118. setVideoInputDevice: id => {
  119. dispatch(setVideoInputDevice(id));
  120. return Promise.resolve();
  121. }
  122. };
  123. return <DeviceSelectionDialogBase { ...props } />;
  124. }
  125. }
  126. /**
  127. * Maps (parts of) the Redux state to the associated DeviceSelectionDialog's
  128. * props.
  129. *
  130. * @param {Object} state - The Redux state.
  131. * @private
  132. * @returns {{
  133. * _availableDevices: Object
  134. * }}
  135. */
  136. function _mapStateToProps(state) {
  137. return {
  138. _availableDevices: state['features/base/devices']
  139. };
  140. }
  141. export default connect(_mapStateToProps)(DeviceSelectionDialog);