Created
May 7, 2017 19:14
-
-
Save nkt/c6ece97a1703d363b9b1a292f7dbed7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2017 dialog LLC <[email protected]> | |
* @flow | |
*/ | |
import React, { PureComponent } from 'react'; | |
type Props = { | |
className: string, | |
stream: MediaSource | |
}; | |
class CallVideoStream extends PureComponent { | |
props: Props; | |
video: ?HTMLVideoElement; | |
componentDidMount() { | |
if (this.video) { | |
if ('srcObject' in this.video) { | |
this.video.srcObject = this.props.stream; | |
} else { | |
this.video.src = URL.createObjectURL(this.props.stream); | |
} | |
this.video.play(); | |
} | |
} | |
componentWillUnmount() { | |
if (this.video) { | |
if ('srcObject' in this.video) { | |
this.video.srcObject = null; | |
} else { | |
URL.revokeObjectURL(this.video.src); | |
this.video.src = null; | |
} | |
this.video = null; | |
} | |
} | |
setVideo = (video: ?HTMLVideoElement) => { | |
this.video = video; | |
}; | |
render() { | |
return ( | |
<video | |
ref={this.setVideo} | |
className={this.props.className} | |
/> | |
); | |
} | |
} | |
export default CallVideoStream; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment