RecorderScreen.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* eslint-disable react/jsx-props-no-spreading */
  2. import { h, Component } from 'preact'
  3. import RecordButton from './RecordButton.jsx'
  4. import SubmitButton from './SubmitButton.jsx'
  5. import StopWatch from './StopWatch.jsx'
  6. import StreamStatus from './StreamStatus.jsx'
  7. class RecorderScreen extends Component {
  8. componentWillUnmount () {
  9. const { onStop } = this.props
  10. onStop()
  11. }
  12. render () {
  13. const { recording, stream: videoStream, recordedVideo } = this.props
  14. const videoProps = {
  15. playsinline: true,
  16. }
  17. // show stream
  18. if (recording || (!recordedVideo && !recording)) {
  19. videoProps.muted = true
  20. videoProps.autoplay = true
  21. videoProps.srcObject = videoStream
  22. }
  23. // show preview
  24. if (recordedVideo && !recording) {
  25. videoProps.muted = false
  26. videoProps.controls = true
  27. videoProps.src = recordedVideo
  28. // reset srcObject in dom. If not resetted, stream sticks in element
  29. if (this.videoElement) {
  30. this.videoElement.srcObject = undefined
  31. }
  32. }
  33. return (
  34. <div className="uppy uppy-ScreenCapture-container">
  35. <div className="uppy-ScreenCapture-videoContainer">
  36. <StreamStatus {...this.props} />
  37. {/* eslint-disable-next-line jsx-a11y/media-has-caption */}
  38. <video ref={videoElement => { this.videoElement = videoElement }} className="uppy-ScreenCapture-video" {...videoProps} />
  39. <StopWatch {...this.props} />
  40. </div>
  41. <div className="uppy-ScreenCapture-buttonContainer">
  42. <RecordButton {...this.props} />
  43. <SubmitButton {...this.props} />
  44. </div>
  45. </div>
  46. )
  47. }
  48. }
  49. export default RecorderScreen