Skip to content

Instantly share code, notes, and snippets.

@matt-mcalister
Last active February 8, 2018 17:15
Show Gist options
  • Save matt-mcalister/ea4c69531c0a49bce1878248aed94f8f to your computer and use it in GitHub Desktop.
Save matt-mcalister/ea4c69531c0a49bce1878248aed94f8f to your computer and use it in GitHub Desktop.
import React from "react";
class VideoChat extends React.Component {
state = {
source: ""
}
componentDidMount(){
navigator.mediaDevices.getUserMedia({video: true, audio: true})
.then(this.handleVideo)
.catch(this.videoError)
}
handleVideo = (stream) => {
this.setState({
source: window.URL.createObjectURL(stream)
})
}
videoError = (err) => {
alert(err.name)
}
render() {
return (
<video id="video-chat" src={this.state.source} autoPlay="true">
</video>
)
}
}
export default VideoChat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment