DeviceDropdown.tsx 941 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Media } from '@andyet/simplewebrtc';
  2. import React from 'react';
  3. interface Props {
  4. devices: MediaDeviceInfo[];
  5. currentMedia: Media;
  6. selectMedia: (deviceId?: string) => void;
  7. }
  8. const DeviceDropdown: React.SFC<Props> = ({
  9. currentMedia,
  10. devices,
  11. selectMedia
  12. }) => (
  13. <select
  14. defaultValue=""
  15. onChange={e => {
  16. if (!e.target.value) {
  17. return;
  18. }
  19. if (e.target.value === 'disable') {
  20. selectMedia();
  21. }
  22. selectMedia(e.target.value);
  23. }}
  24. >
  25. {currentMedia && (
  26. <option>{currentMedia.track.label || 'Unknown Device'}</option>
  27. )}
  28. {currentMedia && <option>---</option>}
  29. {devices.map(device => (
  30. <option key={device.deviceId} value={device.deviceId}>
  31. {device.label}
  32. </option>
  33. ))}
  34. {currentMedia && <option>---</option>}
  35. {currentMedia && <option value="disable">Disable</option>}
  36. </select>
  37. );
  38. export default DeviceDropdown;