Skip to content

Commit

Permalink
Fix webcam in Safari on Mac and iOS, add facingMode: user
Browse files Browse the repository at this point in the history
using stream directly on srcObject video attribute, instead of createObjectURL
  • Loading branch information
arturi committed Feb 7, 2018
1 parent 992a9ac commit 8c087d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/plugins/Webcam/CameraScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CameraScreen extends Component {
return (
<div class="uppy uppy-Webcam-container">
<div class="uppy-Webcam-videoContainer">
<video class={`uppy-Webcam-video ${this.props.mirror ? 'uppy-Webcam-video--mirrored' : ''}`} autoplay muted src={this.props.src || ''} />
<video class={`uppy-Webcam-video ${this.props.mirror ? 'uppy-Webcam-video--mirrored' : ''}`} autoplay muted playsinline srcObject={this.props.src || ''} />
</div>
<div class="uppy-Webcam-buttonContainer" ref={(el) => { this.btnContainer = el }}>
{shouldShowSnapshotButton ? SnapshotButton(this.props) : null}
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/Webcam/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = class Webcam extends Plugin {
countdown: false,
locale: defaultLocale,
mirror: true,
facingMode: 'user',
modes: [
'video-audio',
'video-only',
Expand Down Expand Up @@ -109,7 +110,7 @@ module.exports = class Webcam extends Plugin {

return {
audio: acceptsAudio,
video: acceptsVideo
video: acceptsVideo ? { facingMode: this.opts.facingMode } : false
}
}

Expand All @@ -126,8 +127,7 @@ module.exports = class Webcam extends Plugin {
return this.mediaDevices.getUserMedia(constraints)
.then((stream) => {
this.stream = stream
console.log(stream)
this.streamSrc = URL.createObjectURL(this.stream)
// this.streamSrc = URL.createObjectURL(this.stream)
this.setPluginState({
cameraReady: true
})
Expand Down Expand Up @@ -192,7 +192,6 @@ module.exports = class Webcam extends Plugin {
})
this.webcamActive = false
this.stream = null
this.streamSrc = null
}

getVideoElement () {
Expand Down Expand Up @@ -327,7 +326,7 @@ module.exports = class Webcam extends Plugin {
supportsRecording: supportsMediaRecorder(),
recording: webcamState.isRecording,
mirror: this.opts.mirror,
src: this.streamSrc
src: this.stream
}))
}

Expand Down

0 comments on commit 8c087d1

Please sign in to comment.