Skip to content

Instantly share code, notes, and snippets.

@akionsight
Created December 13, 2020 05:47
Show Gist options
  • Save akionsight/2b19117fd7c97c658c3f76dce5b2b0a2 to your computer and use it in GitHub Desktop.
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
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