Created
December 13, 2020 05:47
-
-
Save akionsight/2b19117fd7c97c658c3f76dce5b2b0a2 to your computer and use it in GitHub Desktop.
A small script that detects if a browser supports webRTC or not and if yes, then gets both the video and audio streams. if no, then brings up an alert
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 hasUserMedia() { | |
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia | |
|| navigator.mozGetUserMedia || navigator.msGetUserMedia; | |
return !!navigator.getUserMedia; | |
} | |
if (hasUserMedia()) { | |
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia | |
|| navigator.mozGetUserMedia || navigator.msGetUserMedia; | |
//get both video and audio streams from user's camera | |
navigator.getUserMedia({ video: true, audio: true }, function (stream) { | |
var video = document.querySelector('video'); | |
//insert stream into the video tag | |
video.src = window.URL.createObjectURL(stream); | |
}, function (err) {}); | |
}else { | |
alert("Error. WebRTC is not supported!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment