Created
January 16, 2014 13:48
-
-
Save grifdail/8455243 to your computer and use it in GitHub Desktop.
getUserMediaAsPromise.js
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
| 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