Skip to content

Instantly share code, notes, and snippets.

@grifdail
Created January 16, 2014 13:48
Show Gist options
  • Select an option

  • Save grifdail/8455243 to your computer and use it in GitHub Desktop.

Select an option

Save grifdail/8455243 to your computer and use it in GitHub Desktop.
getUserMediaAsPromise.js
function getVideoStream(succes, reject) {
navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
if (navigator.getMedia) {
navigator.getMedia({video: true, audio: true}, function(stream) {
var video = document.createElement("video");
video.src = window.URL.createObjectURL(stream);
video.autoplay = true;
succes(video);
},reject);
} else {
reject();
}
}
var videoPromise = new Promise(getVideoStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment