Skip to content

Commit

Permalink
webcam: add nativeCameraFacingMode to Webcam and Dashboard (#4047)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturi committed Aug 30, 2022
1 parent a0eeb22 commit b78937f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/@uppy/dashboard/src/Dashboard.jsx
Expand Up @@ -971,6 +971,7 @@ export default class Dashboard extends UIPlugin {
showSelectedFiles: this.opts.showSelectedFiles,
showNativePhotoCameraButton: this.opts.showNativePhotoCameraButton,
showNativeVideoCameraButton: this.opts.showNativeVideoCameraButton,
nativeCameraFacingMode: this.opts.nativeCameraFacingMode,
handleCancelRestore: this.handleCancelRestore,
handleRequestThumbnail: this.handleRequestThumbnail,
handleCancelThumbnail: this.handleCancelThumbnail,
Expand Down
14 changes: 9 additions & 5 deletions packages/@uppy/dashboard/src/components/AddFiles.jsx
Expand Up @@ -47,7 +47,7 @@ class AddFiles extends Component {
)
}

renderHiddenCameraInput = (type, refCallback) => {
renderHiddenCameraInput = (type, nativeCameraFacingMode, refCallback) => {
const typeToAccept = { photo: 'image/*', video: 'video/*' }
const accept = typeToAccept[type]

Expand All @@ -60,7 +60,7 @@ class AddFiles extends Component {
type="file"
name={`camera-${type}`}
onChange={this.onFileInputChange}
capture="user"
capture={nativeCameraFacingMode}
accept={accept}
ref={refCallback}
/>
Expand Down Expand Up @@ -275,14 +275,18 @@ class AddFiles extends Component {
}

render () {
const { showNativePhotoCameraButton, showNativeVideoCameraButton } = this.props
const {
showNativePhotoCameraButton,
showNativeVideoCameraButton,
nativeCameraFacingMode,
} = this.props

return (
<div className="uppy-Dashboard-AddFiles">
{this.renderHiddenInput(false, (ref) => { this.fileInput = ref })}
{this.renderHiddenInput(true, (ref) => { this.folderInput = ref })}
{showNativePhotoCameraButton && this.renderHiddenCameraInput('photo', (ref) => { this.mobilePhotoFileInput = ref })}
{showNativeVideoCameraButton && this.renderHiddenCameraInput('video', (ref) => { this.mobileVideoFileInput = ref })}
{showNativePhotoCameraButton && this.renderHiddenCameraInput('photo', nativeCameraFacingMode, (ref) => { this.mobilePhotoFileInput = ref })}
{showNativeVideoCameraButton && this.renderHiddenCameraInput('video', nativeCameraFacingMode, (ref) => { this.mobileVideoFileInput = ref })}
{this.renderDropPasteBrowseTagline()}
{this.renderSourcesList(this.props.acquirers, this.props.disableLocalFiles)}
<div className="uppy-Dashboard-AddFiles-info">
Expand Down
5 changes: 3 additions & 2 deletions packages/@uppy/webcam/src/Webcam.jsx
Expand Up @@ -98,7 +98,7 @@ export default class Webcam extends UIPlugin {
],
mirror: true,
showVideoSourceDropdown: false,
facingMode: 'user',
facingMode: 'user', // @TODO: remove in the next major
preferredImageMimeType: null,
preferredVideoMimeType: null,
showRecordingLength: false,
Expand Down Expand Up @@ -595,12 +595,13 @@ export default class Webcam extends UIPlugin {
}

install () {
const { mobileNativeCamera, modes } = this.opts
const { mobileNativeCamera, modes, facingMode, videoConstraints } = this.opts

if (mobileNativeCamera) {
this.uppy.getPlugin('Dashboard').setOptions({
showNativeVideoCameraButton: isModeAvailable(modes, 'video-only') || isModeAvailable(modes, 'video-audio'),
showNativePhotoCameraButton: isModeAvailable(modes, 'picture'),
nativeCameraFacingMode: videoConstraints?.facingMode || facingMode,
})
return
}
Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/webcam/types/index.d.ts
Expand Up @@ -12,6 +12,9 @@ export interface WebcamOptions extends PluginOptions {
onBeforeSnapshot?: () => Promise<void>
countdown?: number | boolean
mirror?: boolean
/**
* @deprecated Use `videoConstraints.facingMode` instead.
*/
facingMode?: string
showVideoSourceDropdown?: boolean
modes?: WebcamMode[]
Expand Down
11 changes: 6 additions & 5 deletions website/src/docs/webcam.md
Expand Up @@ -64,15 +64,16 @@ uppy.use(Webcam, {
'picture',
],
mirror: true,
showVideoSourceDropdown: false,
/** @deprecated Use `videoConstraints.facingMode` instead. */
facingMode: 'user',
videoConstraints: {
facingMode: 'user',
width: { min: 720, ideal: 1280, max: 1920 },
height: { min: 480, ideal: 800, max: 1080 },
},
showRecordingLength: false,
preferredVideoMimeType: null,
preferredImageMimeType: null,
mobileNativeCamera: isMobile(),
preferredVideoMimeType: null,
showRecordingLength: false,
mobileNativeCamera: isMobile({ tablet: true }),
locale: {},
})
```
Expand Down

0 comments on commit b78937f

Please sign in to comment.