Skip to content

Commit

Permalink
feat: add basic ssr support
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Apr 30, 2019
1 parent 06fe388 commit bbf6f51
Show file tree
Hide file tree
Showing 2 changed files with 1,484 additions and 1,262 deletions.
43 changes: 26 additions & 17 deletions src/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ export default class VideoRecorder extends Component {
constructor (props) {
super(props)

const isInlineRecordingSupported =
!!window.MediaSource && !!window.MediaRecorder

const isVideoInputSupported =
document.createElement('input').capture !== undefined

this.state = {
isRecording: false,
isCameraOn: false,
Expand All @@ -114,8 +108,8 @@ export default class VideoRecorder extends Component {
isReplayVideoMuted: true,
thereWasAnError: false,
streamIsReady: false,
isInlineRecordingSupported,
isVideoInputSupported,
isInlineRecordingSupported: null,
isVideoInputSupported: null,
stream: undefined
}

Expand All @@ -135,18 +129,33 @@ export default class VideoRecorder extends Component {
this.timeSinceInactivity = 0
}

componentWillMount () {
if (this.state.isInlineRecordingSupported) {
componentDidMount () {
const isInlineRecordingSupported =
!!window.MediaSource && !!window.MediaRecorder

const isVideoInputSupported =
document.createElement('input').capture !== undefined

if (isInlineRecordingSupported) {
this.mediaSource = new window.MediaSource()
}
}

componentDidMount () {
if (this.state.isInlineRecordingSupported && this.props.isOnInitially) {
this.turnOnCamera()
} else if (this.state.isVideoInputSupported && this.props.isOnInitially) {
this.handleOpenVideoInput()
}
this.setState(
{
isInlineRecordingSupported,
isVideoInputSupported
},
() => {
if (this.state.isInlineRecordingSupported && this.props.isOnInitially) {
this.turnOnCamera()
} else if (
this.state.isVideoInputSupported &&
this.props.isOnInitially
) {
this.handleOpenVideoInput()
}
}
)
}

componentDidUpdate (prevProps, prevState) {
Expand Down
Loading

0 comments on commit bbf6f51

Please sign in to comment.