Skip to content

Instantly share code, notes, and snippets.

@jonathanhculver
Created September 1, 2013 18:20
Show Gist options
  • Save jonathanhculver/6406264 to your computer and use it in GitHub Desktop.
Save jonathanhculver/6406264 to your computer and use it in GitHub Desktop.
javascript for webrtc webcam stream
window.onload = function() {
var video = document.querySelector('video');
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
var localMediaStream = null;
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
/* creates the stream if user allows webcam to start */
navigator.getUserMedia({video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
localMediaStream = stream;
}, onFail);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment