mirror of
https://github.com/transloadit/uppy.git
synced 2026-08-02 06:43:19 +00:00
* add Audio plugin
* add audio-oscilloscope to visualize the recording
* refactor: rename everything to Audio, use oscilloscope, re-init when appropriate, improved preview screen
* tweak styles
* add @uppy/audio to the Uppy bundle
* update Readme and package.json
* add docs, update locales, add website example
* webcam plugin also shouldn’t show recording length counter on video preview screen
* update package.json and yarn.lock
* update types
* update locale
* fix locale issues
* remove leftover webcam test
* Delete index.test-d.ts
* Revert "Delete index.test-d.ts"
This reverts commit f4ec431f6a.
* fix lint and type tests
* Update website/src/docs/audio.md
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/src/audio-oscilloscope/index.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/src/DiscardButton.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/src/audio-oscilloscope/index.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/src/supportsMediaRecorder.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update website/src/docs/audio.md
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/types/index.d.ts
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/src/index.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/src/index.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* Update packages/@uppy/audio/src/index.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
* remove unused method
* remove unused commented declarations
* make all methods private
* convert class component to hooks
* more private
* fix lint
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
119 lines
3.6 KiB
JavaScript
119 lines
3.6 KiB
JavaScript
/* eslint-disable jsx-a11y/media-has-caption */
|
|
const { h, Component } = require('preact')
|
|
const SnapshotButton = require('./SnapshotButton')
|
|
const RecordButton = require('./RecordButton')
|
|
const RecordingLength = require('./RecordingLength')
|
|
const VideoSourceSelect = require('./VideoSourceSelect')
|
|
const SubmitButton = require('./SubmitButton')
|
|
const DiscardButton = require('./DiscardButton')
|
|
|
|
function isModeAvailable (modes, mode) {
|
|
return modes.indexOf(mode) !== -1
|
|
}
|
|
|
|
class CameraScreen extends Component {
|
|
componentDidMount () {
|
|
const { onFocus } = this.props
|
|
onFocus()
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
const { onStop } = this.props
|
|
onStop()
|
|
}
|
|
|
|
render () {
|
|
const {
|
|
src,
|
|
recordedVideo,
|
|
recording,
|
|
modes,
|
|
supportsRecording,
|
|
videoSources,
|
|
showVideoSourceDropdown,
|
|
showRecordingLength,
|
|
onSubmit,
|
|
i18n,
|
|
mirror,
|
|
onSnapshot,
|
|
onStartRecording,
|
|
onStopRecording,
|
|
onDiscardRecordedVideo,
|
|
recordingLengthSeconds,
|
|
} = this.props
|
|
|
|
const hasRecordedVideo = !!recordedVideo
|
|
const shouldShowRecordButton = !hasRecordedVideo && supportsRecording && (
|
|
isModeAvailable(modes, 'video-only')
|
|
|| isModeAvailable(modes, 'audio-only')
|
|
|| isModeAvailable(modes, 'video-audio')
|
|
)
|
|
const shouldShowSnapshotButton = !hasRecordedVideo && isModeAvailable(modes, 'picture')
|
|
const shouldShowRecordingLength = supportsRecording && showRecordingLength && !hasRecordedVideo
|
|
const shouldShowVideoSourceDropdown = showVideoSourceDropdown && videoSources && videoSources.length > 1
|
|
|
|
const videoProps = {
|
|
playsinline: true,
|
|
}
|
|
|
|
if (recordedVideo) {
|
|
videoProps.muted = false
|
|
videoProps.controls = true
|
|
videoProps.src = recordedVideo
|
|
|
|
// reset srcObject in dom. If not resetted, stream sticks in element
|
|
if (this.videoElement) {
|
|
this.videoElement.srcObject = undefined
|
|
}
|
|
} else {
|
|
videoProps.muted = true
|
|
videoProps.autoplay = true
|
|
videoProps.srcObject = src
|
|
}
|
|
|
|
return (
|
|
<div className="uppy uppy-Webcam-container">
|
|
<div className="uppy-Webcam-videoContainer">
|
|
<video
|
|
/* eslint-disable-next-line no-return-assign */
|
|
ref={(videoElement) => (this.videoElement = videoElement)}
|
|
className={`uppy-Webcam-video ${mirror ? 'uppy-Webcam-video--mirrored' : ''}`}
|
|
/* eslint-disable-next-line react/jsx-props-no-spreading */
|
|
{...videoProps}
|
|
/>
|
|
</div>
|
|
<div className="uppy-Webcam-footer">
|
|
<div className="uppy-Webcam-videoSourceContainer">
|
|
{shouldShowVideoSourceDropdown
|
|
? VideoSourceSelect(this.props)
|
|
: null}
|
|
</div>
|
|
<div className="uppy-Webcam-buttonContainer">
|
|
{shouldShowSnapshotButton && <SnapshotButton onSnapshot={onSnapshot} i18n={i18n} />}
|
|
|
|
{shouldShowRecordButton && (
|
|
<RecordButton
|
|
recording={recording}
|
|
onStartRecording={onStartRecording}
|
|
onStopRecording={onStopRecording}
|
|
i18n={i18n}
|
|
/>
|
|
)}
|
|
|
|
{hasRecordedVideo && <SubmitButton onSubmit={onSubmit} i18n={i18n} />}
|
|
|
|
{hasRecordedVideo && <DiscardButton onDiscard={onDiscardRecordedVideo} i18n={i18n} />}
|
|
</div>
|
|
|
|
<div className="uppy-Webcam-recordingLength">
|
|
{shouldShowRecordingLength && (
|
|
<RecordingLength recordingLengthSeconds={recordingLengthSeconds} i18n={i18n} />
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
module.exports = CameraScreen
|