Skip to content

Commit

Permalink
index.html demo fixed to get valid-devices-labels on Firefox.
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Feb 11, 2017
1 parent de322fd commit 4ff16d8
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,14 @@ <h2 id="welcome">DetectRTC!</h2>
};
}

function reloadDetectRTC() {
DetectRTC.load(onDetectRTCLoaded);
function reloadDetectRTC(callback) {
DetectRTC.load(function() {
onDetectRTCLoaded();

if(callback && typeof callback == 'function') {
callback();
}
});
}

DetectRTC.load(function() {
Expand All @@ -336,9 +342,19 @@ <h2 id="welcome">DetectRTC!</h2>
try {
if(DetectRTC.MediaDevices[0] && DetectRTC.MediaDevices[0].label === 'Please invoke getUserMedia once.') {
navigator.mediaDevices.getUserMedia({audio: true, video: true}).then(function(stream) {
reloadDetectRTC();

var video;
try {
video = document.createElement('video');
video.muted = true;
video.volume = 0;
video.src = URL.createObjectURL(stream);
video.style.display = 'none';
video.style.opacity = 0;
(document.body || document.documentElement).appendChild(vide);
}
catch(e) {}

reloadDetectRTC(function() {
// release camera
stream.getVideoTracks().forEach(function(track) {
track.stop();
Expand All @@ -347,8 +363,11 @@ <h2 id="welcome">DetectRTC!</h2>
stream.getAudioTracks().forEach(function(track) {
track.stop();
});
}
catch(e) {}

if(video && video.parentNode) {
video.parentNode.removeChild(video);
}
});
}).catch(reloadDetectRTC);
return;
}
Expand Down

0 comments on commit 4ff16d8

Please sign in to comment.