Skip to content

Commit

Permalink
fix: open video input when isOnInitially
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Nov 17, 2018
1 parent 08c0c22 commit a0c717b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getMimeType = () => {
return mimeType
}

let constraints = {
const CONSTRAINTS = {
audio: true,
video: true
}
Expand Down Expand Up @@ -155,6 +155,8 @@ export default class VideoRecorder extends Component {
componentDidMount () {
if (this.state.isInlineRecordingSupported && this.props.isOnInitially) {
this.turnOnCamera()
} else if (this.state.isVideoInputSupported && this.props.isOnInitially) {
this.handleOpenVideoInput()
}
}

Expand Down Expand Up @@ -186,7 +188,7 @@ export default class VideoRecorder extends Component {
})

navigator.mediaDevices
.getUserMedia(constraints)
.getUserMedia(CONSTRAINTS)
.then(this.handleSuccess)
.catch(this.handleError)
}
Expand Down
56 changes: 34 additions & 22 deletions src/video-recorder.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,37 @@ injectGlobal`
const Wrapper = styled.div`
height: 100%;
`
storiesOf('VideoRecorder', module).add('default', () => {
return (
<Wrapper>
<VideoRecorder
onRecordingComplete={(
videoBlob,
startedAt,
thumbnailBlob,
duration
) => {
const urlCreator = window.URL || window.webkitURL
const thumbUrl = urlCreator.createObjectURL(thumbnailBlob)
const videoUrl = urlCreator.createObjectURL(videoBlob)
console.log('Video Blob', videoBlob.size, videoBlob, videoUrl)
console.log('Thumb Blob', thumbnailBlob, thumbUrl)
console.log('Started:', startedAt)
console.log('Duration:', duration)
}}
/>
</Wrapper>
)
})

const handleRecordingComplete = (
videoBlob,
startedAt,
thumbnailBlob,
duration
) => {
const urlCreator = window.URL || window.webkitURL
const thumbUrl = urlCreator.createObjectURL(thumbnailBlob)
const videoUrl = urlCreator.createObjectURL(videoBlob)
console.log('Video Blob', videoBlob.size, videoBlob, videoUrl)
console.log('Thumb Blob', thumbnailBlob, thumbUrl)
console.log('Started:', startedAt)
console.log('Duration:', duration)
}

storiesOf('VideoRecorder', module)
.add('default', () => {
return (
<Wrapper>
<VideoRecorder onRecordingComplete={handleRecordingComplete} />
</Wrapper>
)
})
.add('isOnInitially', () => {
return (
<Wrapper>
<VideoRecorder
isOnInitially
onRecordingComplete={handleRecordingComplete}
/>
</Wrapper>
)
})

0 comments on commit a0c717b

Please sign in to comment.