Last active
February 8, 2018 17:15
-
-
Save matt-mcalister/ea4c69531c0a49bce1878248aed94f8f 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
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